:root {
  /* Light theme. All colors live here so the palette can be swapped in one place. */
  --bg: #f4f6fa;
  --panel: #ffffff;
  --card: #ffffff;
  --border: #d9e0ea;
  --text: #1b2435;
  --muted: #5f6c83;
  --accent: #2f6fed;
  --ok: #1f9d63;
  --err: #d64545;
  --pending: #c98a2b;

  /* Component surfaces / accents (previously hard-coded). */
  --subtle-bg: #eef2f8; /* inputs, badges, chips, inline code */
  --code-bg: #f0f3f9; /* raw JSON <pre> blocks */
  --accent-text: #ffffff; /* text on accent-colored buttons */
  --secondary: #e2e8f2; /* secondary button background */
  --secondary-text: #1b2435; /* secondary button text */
  --version-text: #1f4fb0; /* version badge text */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

h1 {
  font-size: 1.25rem;
  margin: 0;
}

/* Brand lockup: hexagon mark + "edu-sharing" / "Repo Viewer". Used in the
   header (horizontal) and on the login (vertical, centered). */
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  display: block;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-edu {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.brand-login {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

.brand-login .brand-text {
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

main {
  padding: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.5rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem 0;
}

.toolbar-spacer {
  flex: 1 1 auto;
}

/* Segmented Karten/Liste switch. */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.view-toggle button {
  background: var(--panel);
  color: var(--text);
  border: none;
  border-radius: 0;
  padding: 0.4rem 0.75rem;
  font-weight: 600;
}

.view-toggle button + button {
  border-left: 1px solid var(--border);
}

.view-toggle button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.view-toggle button:not(.active):hover {
  background: var(--subtle-bg);
  filter: none;
}

/* In list mode the card grid collapses to a single full-width column. */
main.list-mode {
  display: block;
}

select {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--subtle-bg);
  color: var(--text);
  cursor: pointer;
}

input,
button {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

input {
  background: var(--subtle-bg);
  color: var(--text);
  flex: 1 1 200px;
  min-width: 140px;
}

button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  cursor: pointer;
  font-weight: 600;
}

button.secondary {
  background: var(--secondary);
  color: var(--secondary-text);
}

button:hover {
  filter: brightness(1.1);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.card-title {
  font-weight: 700;
  font-size: 1.05rem;
  word-break: break-word;
}

.card-title a {
  color: inherit;
  text-decoration: none;
}

.card-title a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.card-url {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.6rem 0;
}

.badge {
  background: var(--subtle-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
}

.badge.version {
  border-color: var(--accent);
  color: var(--version-text);
}

.badge.rs2 {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--accent-text);
  font-weight: 700;
}

/* Environment (repository type) badges: production stands out, staging warns,
   dev stays muted. Hosting is an outlined neutral badge. */
.badge.repo {
  font-weight: 700;
  color: var(--accent-text);
}
.badge.repo-prod {
  background: var(--err);
  border-color: var(--err);
}
.badge.repo-staging {
  background: var(--pending);
  border-color: var(--pending);
}
.badge.repo-dev {
  background: var(--subtle-bg);
  border-color: var(--border);
  color: var(--muted);
  font-weight: 600;
}
.badge.hosting {
  background: var(--subtle-bg);
  border-color: var(--accent);
  color: var(--version-text);
}
/* Auto network/organisation tag (derived from DNS + IP ranges). */
.badge.net {
  background: var(--text);
  border-color: var(--text);
  color: var(--panel);
  font-weight: 600;
}
.badge.net::before {
  content: "🌐 ";
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot.ok {
  background: var(--ok);
}
.dot.error {
  background: var(--err);
}
.dot.pending {
  background: var(--pending);
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.error-text {
  color: var(--err);
  font-size: 0.85rem;
  word-break: break-word;
}

details {
  margin-top: 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.chip {
  background: var(--subtle-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
}

/* Repository chip: title + a muted type pill. */
.repo-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
}

.repo-chip .repo-type {
  font-weight: 400;
  font-size: 0.68rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.pw-link {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.pw-link a {
  color: var(--accent);
  text-decoration: none;
}

.pw-link a:hover {
  text-decoration: underline;
}

.notes {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  background: var(--subtle-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  margin-top: 0.5rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.edit-field input,
.edit-field select {
  /* In this column-flex container, the global `flex: 1 1 200px` would turn
     200px into the input's height. Reset it so the field stays one line tall. */
  flex: none;
  width: 100%;
}

.edit-form textarea {
  font: inherit;
  resize: vertical;
  min-height: 60px;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--subtle-bg);
  color: var(--text);
}

.card-actions button {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

/* Full-screen login overlay shown until a session is established. */
.login {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-box h2 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.login-box button {
  margin-top: 0.25rem;
}

footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

pre.raw {
  max-height: 320px;
  overflow: auto;
  background: var(--code-bg);
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.75rem;
}

code {
  background: var(--subtle-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

/* ---------- list view ---------- */

.list-wrap {
  overflow-x: auto;
}

.list-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.list-table th,
.list-table td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.list-table thead th {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--subtle-bg);
  white-space: nowrap;
}

.list-table tbody tr:last-child td {
  border-bottom: none;
}

.list-table tbody tr:hover {
  background: var(--subtle-bg);
}

/* Keep the data columns as narrow as their content so the label cell soaks up
   the remaining width. */
.list-table th,
.list-table td {
  white-space: nowrap;
}

/* The label cell takes all slack; max-width:0 lets the URL ellipsis kick in
   instead of forcing the column (and table) ever wider. */
.list-label-cell {
  width: 100%;
  max-width: 0;
  white-space: normal;
}

.list-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-label a {
  color: inherit;
  text-decoration: none;
}

.list-label a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Truncate the long _about URL on one line rather than wrapping it per-char. */
.list-label-cell .card-url {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.3rem;
}

.row-pw {
  text-decoration: none;
}

.row-note {
  cursor: help;
}

/* Buttons sit side by side; on narrow screens they stack vertically. */
.list-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.list-actions button {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
}

@media (max-width: 720px) {
  .list-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

.list-edit-row td {
  background: var(--subtle-bg);
  white-space: normal;
}

.list-edit-row .edit-form {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}
