/* Colors, font and sizes follow the CultureWay editor (MUI), so moving between the editor and these
   pages does not feel like switching applications. data-theme is set from the editor's own setting. */

:root {
  --font: 'IBM Plex Mono', ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --sidebar-width: 248px;
  --radius: 6px;

  --bg: #f5f5f5;
  --sidebar: #fafafa;
  --surface: #fff;
  --header: #fff;
  --nav-icon: #aaa;
  --hover: rgba(0, 0, 0, .04);
  --selected: rgba(25, 118, 210, .08);
  --selected-hover: rgba(25, 118, 210, .12);
  --input: #f5f5f5;
  --line: #e0e0e0;
  --line-strong: #d4d4d4;
  --fg: rgba(0, 0, 0, .87);
  --muted: rgba(0, 0, 0, .6);
  --faint: #9e9e9e;
  --accent: #1976d2;
  --on-accent: #fff;
  --accent-soft: rgba(25, 118, 210, .08);
  --danger: #d32f2f;
  --danger-soft: rgba(211, 47, 47, .08);
  --ok: #2e7d32;
  --ok-soft: rgba(46, 125, 50, .08);
  --warn: #ed6c02;
  --warn-soft: rgba(237, 108, 2, .08);
  --backdrop: rgba(0, 0, 0, .4);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1a1a1a;
  --sidebar: #222;
  --surface: #222;
  --header: #1e1e1e;
  --nav-icon: #666;
  --hover: rgba(255, 255, 255, .08);
  --selected: rgba(144, 202, 249, .16);
  --selected-hover: rgba(144, 202, 249, .24);
  --input: #2a2a2a;
  --line: #2e2e2e;
  --line-strong: #3a3a3a;
  --fg: #fff;
  --muted: rgba(255, 255, 255, .7);
  --faint: #666;
  --accent: #90caf9;
  --on-accent: #0b1a2b;
  --accent-soft: rgba(144, 202, 249, .1);
  --danger: #f48b85;
  --danger-soft: rgba(244, 67, 54, .12);
  --ok: #81c784;
  --ok-soft: rgba(102, 187, 106, .12);
  --warn: #ffb74d;
  --warn-soft: rgba(255, 167, 38, .12);
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: var(--font); font-size: .95em; }

svg.icon { width: 16px; height: 16px; flex-shrink: 0; fill: currentColor; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ── Shell: side menu + main column ─────────────────────────────── */

/* Measured against the editor's MUI side menu: 59px head, 34px rows, 26px round icon buttons. */

.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  overflow: hidden;
  z-index: 20;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  flex: 1;
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: .05em;
  color: var(--fg);
}
.brand:hover { text-decoration: none; }

.sidebar-fill { flex: 1; }

.host-menu { flex-shrink: 0; border-top: 1px solid var(--line); }

.nav { padding: 8px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  font-size: .8rem;
  line-height: 1.43;
  color: var(--muted);
  transition: background-color .15s;
}
.nav-item .icon { color: var(--nav-icon); }
.nav-item:hover { background: var(--hover); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--selected); color: var(--fg); font-weight: 600; }
.nav-item[aria-current="page"]:hover { background: var(--selected-hover); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }

.host-divider { margin: 0 16px; border: 0; border-top: 1px solid var(--line); }

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: .8rem;
}
.user-row > .icon { color: var(--nav-icon); }
.user-row .user { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.user-row form { margin: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 59px;
  padding: 12px 24px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.2; }
.topbar .menu-button { display: none; }

.demo-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--warn-soft);
  border-bottom: 1px solid var(--line);
  font-size: .78rem;
}
.demo-banner .icon { flex: none; color: var(--warn); }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.content-inner { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.backdrop { display: none; }

@media (max-width: 899px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .shell.menu-open .sidebar { transform: none; box-shadow: 0 8px 32px rgba(0, 0, 0, .3); }
  .shell.menu-open .backdrop { display: block; position: fixed; inset: 0; background: var(--backdrop); z-index: 10; }
  .topbar { padding: 10px 16px; }
  .demo-banner { padding: 8px 16px; }
  .topbar .menu-button { display: inline-flex; }
  .content { padding: 16px; }
}

/* ── Panels and headings ───────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.panel-body { padding: 20px; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { flex: 1; margin: 0; font-size: .9rem; font-weight: 700; }

.section-label {
  margin: 0 0 8px;
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 400;
}

.muted { color: var(--muted); }
.lead { margin: 0; color: var(--muted); max-width: 70ch; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

/* ── Buttons ───────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: .78rem;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
.btn .icon { width: 14px; height: 14px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { color: var(--on-accent); filter: brightness(1.08); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.btn-danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger.solid:hover { filter: brightness(1.08); color: #fff; }

.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-ghost:hover { border-color: transparent; background: var(--accent-soft); }

.btn-block { width: 100%; padding: 9px 12px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 5px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--accent); background: var(--hover); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.end { justify-content: flex-end; }

/* ── Badges ────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  font-size: .68rem;
  line-height: 1.5;
  color: var(--muted);
  white-space: nowrap;
  vertical-align: middle;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: none; }
.badge.dot::before { display: inline-block; }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.badge.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }

/* ── Alerts ────────────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-size: .8rem;
}
.alert .icon { margin-top: 2px; color: var(--accent); }
.alert > div { flex: 1; min-width: 0; }
.alert p { margin: 0; }
.alert p + p { margin-top: 4px; }
.alert-ok { border-left-color: var(--ok); background: var(--ok-soft); }
.alert-ok .icon { color: var(--ok); }
.alert-error { border-left-color: var(--danger); background: var(--danger-soft); }
.alert-error .icon { color: var(--danger); }
.alert-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.alert-warn .icon { color: var(--warn); }

/* ── Forms ─────────────────────────────────────────────────────── */

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .75rem; color: var(--muted); }
.field .hint { font-size: .72rem; color: var(--faint); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

input[type=text], input[type=password], input[type=date], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--input);
  color: var(--fg);
  font: inherit;
  font-size: .82rem;
  transition: border-color .15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.compact { width: auto; padding: 4px 8px; font-size: .78rem; }

.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices label {
  padding: 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: .75rem;
  color: var(--muted);
  cursor: pointer;
}
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices input:checked + span { color: var(--accent); }
.choices label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.choices label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Tables ────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: .68rem;
  font-weight: 400;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: left;
  color: var(--muted);
  white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .8rem; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--accent-soft); }
.table .num { white-space: nowrap; color: var(--muted); }
.table td.actions-cell { text-align: right; white-space: nowrap; }
.table td.actions-cell .actions { justify-content: flex-end; flex-wrap: nowrap; }
.table .name { font-weight: 600; }
.table .sub { display: block; font-size: .72rem; color: var(--faint); }
.table form { margin: 0; }

@media (max-width: 699px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table tr:last-child { border-bottom: 0; }
  .table td { padding: 3px 0; border: 0; }
  .table td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 96px; color: var(--faint); font-size: .72rem; }
  .table td.actions-cell { padding-top: 10px; text-align: left; }
  .table td.actions-cell .actions { justify-content: flex-start; flex-wrap: wrap; }
}

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty > .icon { width: 28px; height: 28px; color: var(--faint); margin-bottom: 8px; }
.empty p { margin: 0 0 12px; }

/* ── History ───────────────────────────────────────────────────── */

/* One row on a wide screen, wrapping on a narrow one; the key field gets the most room. */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.filters .field { flex: 1 1 130px; }
.filters .field:first-child { flex-grow: 2; }
/* As tall as the inputs next to them. */
.filters .btn { padding-block: 8px; font-size: .82rem; }
.table a.name { color: inherit; text-decoration: none; }
.table a.name:hover { color: var(--accent); text-decoration: underline; }
.table td.change { max-width: 420px; }
.change-old, .change-new { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.change-old { color: var(--danger); background: var(--danger-soft); text-decoration: line-through; }
.change-new { color: var(--ok); background: var(--ok-soft); }
.change .badge { margin-bottom: 4px; }
.pager { justify-content: center; margin-top: 16px; }

/* ── Dialogs ───────────────────────────────────────────────────── */

dialog.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}
dialog.dialog::backdrop { background: var(--backdrop); }
.dialog-head { padding: 18px 22px 0; font-size: .95rem; font-weight: 700; }
.dialog-body { padding: 14px 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-body > p { color: var(--muted); margin: 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 6px 22px 18px; }

/* ── Token, code blocks ────────────────────────────────────────── */

.token {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--input);
}
.token code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .82rem; }

pre.code {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input);
  font-size: .75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── Overview tiles ────────────────────────────────────────────── */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  transition: border-color .15s;
}
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-label { display: flex; align-items: center; gap: 8px; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tile-label .icon { color: var(--accent); }
.tile-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.tile-note { font-size: .75rem; color: var(--faint); }

/* ── Sign-in page ──────────────────────────────────────────────── */

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(380px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.auth-card .brand { display: block; margin-bottom: 4px; font-size: 1.1rem; }
.auth-card .lead { margin-bottom: 22px; font-size: .8rem; }
.auth-card .theme-toggle { float: right; margin: -6px -8px 0 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--faint); font-size: .72rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.auth-card .alert { margin-bottom: 16px; }
.demo-credentials { margin: 10px 0 0; font-size: .72rem; color: var(--faint); }
.spaced { margin-top: 14px; }
.field .field-label { font-size: .75rem; color: var(--muted); }
.narrow { max-width: 360px; }
