/* Light (default) */
:root,
html[data-theme="light"] {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f0f3f6;
  --text: #1a2330;
  --muted: #5c6b7a;
  --accent: #2b7bb9;
  --accent-dim: rgba(43, 123, 185, 0.12);
  --danger: #c43c3c;
  --ok: #2a9a62;
  --border: #d8e0e8;
  --header-bg: rgba(255, 255, 255, 0.92);
  --header-secondary: rgba(240, 243, 246, 0.9);
  --code-bg: #eef2f6;
  --btn-fg: #ffffff;
  --lead: #3d4b5c;
  --flash-error-fg: #8a1f1f;
  --mono: "Cascadia Code", "Consolas", "SF Mono", ui-monospace, monospace;
  --sans: "Segoe UI", system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0c1014;
  --panel: #151c24;
  --panel-2: #1b2430;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #4aa3e8;
  --accent-dim: rgba(74, 163, 232, 0.14);
  --danger: #e85d5d;
  --ok: #3dbf7f;
  --border: #273241;
  --header-bg: rgba(12, 16, 20, 0.92);
  --header-secondary: rgba(21, 28, 36, 0.65);
  --code-bg: #0a0e12;
  --btn-fg: #041018;
  --lead: #d5dde6;
  --flash-error-fg: #ffc9c9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(10px);
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.7rem 1.25rem;
}

.header-row--secondary {
  border-top: 1px solid var(--border);
  background: var(--header-secondary);
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--text);
  margin-right: 0.5rem;
}

.cats, .items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
}

.cat, .item {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.95rem;
}

.cat:hover, .item:hover {
  color: var(--text);
  background: var(--panel-2);
}

.cat.is-active {
  color: var(--text);
  background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.item.is-active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
}

.item--muted {
  border: 0;
  cursor: default;
}

.theme-toggle {
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.theme-toggle--float {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 30;
  margin: 0;
}

.logout {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.logout:hover { color: var(--danger); }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.flash {
  padding: 0.65rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--border);
}

.flash.error { border-color: var(--danger); color: var(--flash-error-fg); }
.flash.info { border-color: var(--accent); }

.login-card {
  max-width: 360px;
  margin: 3.5rem auto;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.login-card h1 { margin: 0 0 0.5rem; font-size: 1.35rem; }

.login-card label {
  display: block;
  margin: 1rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  letter-spacing: 0.15em;
}

.login-card button {
  margin-top: 1.1rem;
  width: 100%;
  padding: 0.7rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--btn-fg);
  font-weight: 650;
  cursor: pointer;
}

.login-card button:hover { filter: brightness(1.08); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.lead { color: var(--lead); line-height: 1.55; max-width: 42rem; }

.page-title {
  font-size: 1.5rem;
  margin: 0 0 0.75rem;
}

.section-head { margin-bottom: 1.25rem; }

.subhead {
  margin: 1.75rem 0 0.75rem;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}

.crumb {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

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

.crumb a:hover { text-decoration: underline; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.apps-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}

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

.apps-table tr:last-child td { border-bottom: 0; }

.apps-table th {
  background: var(--panel-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.apps-table a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.apps-table a:hover { text-decoration: underline; }

.port-link {
  font-family: var(--mono);
  font-weight: 650 !important;
}

.script-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.script-row {
  margin: 0;
}

.script-row__link {
  display: grid;
  grid-template-columns: minmax(8rem, 0.35fr) 1fr auto;
  gap: 0.75rem 1rem;
  align-items: baseline;
  padding: 0.9rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}

.script-row__link:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: var(--panel-2);
}

.script-row__name {
  font-weight: 650;
}

.script-row__desc {
  color: var(--muted);
  font-size: 0.95rem;
}

.script-row__meta {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.file-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.file-row:last-child { border-bottom: 0; }

.file-row a {
  color: var(--accent);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.file-row a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.md h1 { display: none; }
.md > h1:first-child { display: none; }

.md h2 {
  margin-top: 1.75rem;
  font-size: 1.15rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
}

.md p, .md li { line-height: 1.55; color: var(--lead); }

.md a { color: var(--accent); }

.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.md pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.md pre code {
  background: none;
  padding: 0;
  font-size: 0.86rem;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.md th, .md td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: left;
}

.md th { background: var(--panel-2); }

.section-head--row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.btn {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--btn-fg);
  font-weight: 650;
  text-decoration: none;
  border: 0;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.08); }

.panel-form {
  margin-top: 1rem;
  padding: 1.1rem 1.15rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 36rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.panel-form--compact {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  max-width: none;
}

.panel-form label {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-form input[type="text"],
.panel-form input[type="number"],
.panel-form textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.panel-form input[type="file"] {
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-form button {
  margin-top: 0.85rem;
  align-self: flex-start;
  padding: 0.6rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--btn-fg);
  font-weight: 650;
  cursor: pointer;
}

.panel-form--compact button { margin-top: 0; }

.panel-form button:hover { filter: brightness(1.08); }

.script-form .crumb { margin-bottom: 0.5rem; }

@media (max-width: 720px) {
  .script-row__link {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
  .script-row__meta { justify-self: start; }
}
