/* ClipNSync portal + admin layout. Colors come from /assets/theme.css;
   this file is structure only. Loaded after theme.css so its rules win on
   equal specificity. ASCII only.

   Legacy alias note: earlier pages reference a few short color names. They
   alias the theme tokens 1:1 here. NEVER redefine a canonical token name
   (--bg, --surface, ...) to a different value - that shadow bug bit twice. */
:root {
  --blue: var(--accent);
  --ink: var(--text);
  --line: var(--border);
  --soft: var(--surface-2);
  --err: var(--danger);
}

html { scroll-behavior: smooth; }

/* ---- Top brand bar (printed by portal_header) ---------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px; letter-spacing: -.01em;
  color: var(--text);
}
.topbar .brand:hover { text-decoration: none; }
.topbar .brand svg { width: 30px; height: 30px; border-radius: 8px; flex: none; }

.topbar .nav {
  display: flex; align-items: center; gap: 1.35rem;
  margin-left: auto; flex-wrap: wrap;
}
.topbar .nav a {
  color: var(--muted); font-weight: 600; font-size: 14.5px;
}
.topbar .nav a:hover { color: var(--text); text-decoration: none; }
.topbar .nav a.admin { color: var(--accent); }
.topbar .nav #theme-toggle { margin-left: .35rem; font-size: 13.5px; }

/* ---- Admin sub-navigation ------------------------------------------ */
.subnav {
  position: sticky; top: 52px; z-index: 15;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.subnav-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; gap: .25rem; padding: 0 1.25rem; flex-wrap: wrap;
}
.subnav-inner a {
  color: var(--muted); font-weight: 600; font-size: 14px;
  padding: .7rem .85rem; border-bottom: 2px solid transparent;
}
.subnav-inner a:hover { color: var(--text); text-decoration: none; }
.subnav-inner a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Page container ------------------------------------------------ */
/* Narrow auth/profile card: a centered form panel. */
main.card {
  max-width: 460px;
  margin: 44px auto;
  padding: 30px 30px;
}
main.card h1 { font-size: 23px; margin: 0 0 20px; letter-spacing: -.02em; }
main.card p { margin: 0 0 14px; }

/* Wide "console" pages (dashboard grid, any table, the log pane, and every
   admin page). These drop the single-card framing and become a page-width
   container whose child .card sections and framed tables provide structure,
   so admin pages share one consistent width and rhythm. */
main.admin-page,
main.card:has(.grid),
main.card:has(table),
main.card:has(pre) {
  max-width: 1080px;
  margin: 28px auto 8px;
  padding: 0 1.25rem;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
}
main.admin-page > h1,
main.card:has(.grid) > h1,
main.card:has(table) > h1,
main.card:has(pre) > h1 {
  font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em;
  padding-left: 12px; border-left: 3px solid var(--accent);
}
/* Lead paragraph directly under a console h1 reads as a subtitle. */
main.admin-page > h1 + p,
main.card:has(.grid) > h1 + p,
main.card:has(table) > h1 + p,
main.card:has(pre) > h1 + p { color: var(--muted); margin: 0 0 22px; padding-left: 15px; }

/* Section headings on console pages. */
main.admin-page > h2,
main.card:has(table) > h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 26px 0 10px;
}

/* ---- Cards / panels on console pages ------------------------------- */
.grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin: 6px 0 8px;
}
.grid section.card, section.card, .card.pad {
  padding: 1.15rem 1.3rem; box-shadow: var(--shadow);
}
.grid section h2, section.card h2 {
  margin: 0 0 .55rem; font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.stat { font-size: 36px; font-weight: 700; line-height: 1.05; margin: .1rem 0 .5rem; letter-spacing: -.02em; }
.badge {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: .12rem .6rem; font-size: 13px; font-weight: 600;
}

/* Bare tables on console pages get framed as panels so they read as one
   surface rather than floating rows. */
main.admin-page table,
main.card:has(table) table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin: 0 0 8px;
}
th { color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); border-bottom: 1px solid var(--border); }
td { font-size: 14px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.muted { color: var(--muted); }

/* ---- Forms --------------------------------------------------------- */
form { margin: 0 0 16px; }
/* Stacked auth/profile forms (inside the narrow card). */
main.card:not(.admin-page):not(:has(table)):not(:has(.grid)):not(:has(pre)) form {
  display: flex; flex-direction: column; gap: 14px;
}
main.card form p { margin: 0; }
label { font-size: 14px; font-weight: 600; color: var(--text); }
main.card:not(.admin-page) label {
  display: flex; flex-direction: column; gap: 6px;
}

input, select, textarea {
  font: inherit; font-weight: 400;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: .6rem .7rem;
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"] { width: 100%; }
main.card:not(.admin-page) input[type="text"],
main.card:not(.admin-page) input[type="email"],
main.card:not(.admin-page) input[type="password"] { padding: 11px 13px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
input::placeholder { color: var(--faint); }

/* Second submit in a stacked form reads as the secondary action. */
main.card form button ~ button, button[name="magic"] {
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--border-strong);
}
main.card form button ~ button:hover, button[name="magic"]:hover {
  background: var(--surface-2); border-color: var(--accent);
}

/* ---- Toolbars: the log filter row, admin search, ban form ---------- */
/* Inline forms and control rows on console pages lay out as wrapping
   flex toolbars with real spacing instead of controls jammed together. */
form#f, section.card form, main.admin-page > form:not([style]) {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
}
form#f input, form#f select, form#f button, form#f label { margin: 0; }
form#f label { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; color: var(--muted); }

/* Inline per-row action forms in tables stay compact and side by side. */
td form { display: inline-flex; gap: .35rem; margin: 0 .35rem .35rem 0; align-items: center; }
td .btn, td button { padding: .38rem .6rem; font-size: 13px; font-weight: 600; }
td input, td select { padding: .38rem .5rem; font-size: 13px; }
td input[name="confirm_email"], td input[name="name"] { width: auto; min-width: 9rem; }

/* ---- Status banners ------------------------------------------------ */
/* Pages emit colored status paragraphs a few different ways; normalize
   them all into readable banners in both themes. */
p[style*="d23b3b"], p[style*="--danger"],
p[style*="1a9e5f"], p[style*="--ok"] {
  padding: .7rem 1rem; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; border: 1px solid transparent;
}
p[style*="d23b3b"], p[style*="--danger"] {
  color: var(--danger) !important; background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
p[style*="1a9e5f"], p[style*="--ok"] {
  color: var(--ok) !important; background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}

/* ---- Code / link codes -------------------------------------------- */
code {
  display: inline-block; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .35rem .7rem; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
}

/* ---- Log pane ------------------------------------------------------ */
pre#pane {
  width: 100%; min-height: 58vh; max-height: 72vh; overflow: auto;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; margin: 0;
  font: 13px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--shadow);
}

/* ---- Footer -------------------------------------------------------- */
.site-footer {
  max-width: 1080px; margin: 30px auto 40px; padding: 16px 1.25rem 0;
  border-top: 1px solid var(--border); color: var(--muted); font-size: 13px;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

/* ---- Responsive ---------------------------------------------------- */
@media (max-width: 640px) {
  .topbar { padding: .6rem .9rem; }
  .topbar .nav { gap: 1rem; }
  .subnav { top: 49px; }
  .subnav-inner { padding: 0 .9rem; }
  main.card { margin: 0; max-width: none; border-radius: 0; border-left: 0; border-right: 0; }
  main.admin-page,
  main.card:has(.grid), main.card:has(table), main.card:has(pre) {
    padding: 0 .9rem; margin: 18px auto 8px;
  }
  /* Wide tables scroll horizontally rather than forcing the page wider. */
  main.admin-page table, main.card:has(table) table { display: block; overflow-x: auto; white-space: nowrap; }
  .site-footer { padding: 16px .9rem 0; }
}
