/* robomyadmin — dark-first superadmin console
 * One accent (warm amber), charcoal surfaces, premium mono data cells.
 */

@layer tokens {
  :root {
    /* surfaces */
    --bg0: #08090C;
    --bg1: #0E1014;
    --bg2: #151822;
    --bg3: #1B1F2B;
    --line: #232837;
    --line-soft: #1B202B;

    /* ink */
    --ink-hi: #EDEFF3;
    --ink: #C9CED9;
    --ink-dim: #8B92A1;
    --ink-faint: #5A606E;

    /* single accent */
    --amber: #E2A14A;
    --amber-deep: #C98637;
    --amber-bright: #F2B964;
    --amber-wash: rgba(226, 161, 74, 0.18);

    /* semantic */
    --red: #E5645A;
    --red-wash: rgba(229, 100, 90, 0.14);
    --green: #6FC59C;
    --green-wash: rgba(111, 197, 156, 0.12);
    --blue: #6FA8DC;
    --warn: #E2B95A;

    /* metrics */
    --sidebar-w: 264px;
    --topbar-h: 60px;
    --radius-lg: 14px;
    --radius-md: 10px;
    --radius-sm: 8px;

    --font-sans: "Inter Tight", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  }
}

@layer base {
  * , *::before, *::after { box-sizing: border-box; }
  html { color-scheme: dark; }
  body {
    margin: 0;
    background: var(--bg0);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  h1, h2, h3, h4, p { margin: 0; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  ::selection { background: var(--amber-wash); }
  svg { display: block; }
  [hidden] { display: none !important; }
}

@layer components {
  .hidden { display: none !important; }
  .mono { font-family: var(--font-mono); }
  .dim { color: var(--ink-dim); }
  .faint { color: var(--ink-faint); }

  /* app shell — index.html names this wrapper .shell (id="shell"); the old
     .app selector matched nothing, so the sidebar and main column never
     formed a two-column grid. */
  .shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

  .sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
  .sidebar-brand { padding-bottom: 18px; }
  .nav-section-label {
    font-size: 10.5px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.09em; color: var(--ink-faint);
    padding: 12px 8px 6px;
  }
  .nav-tables { display: flex; flex-direction: column; gap: 2px; }
  .crumb-section { font-size: 13px; font-weight: 600; color: var(--ink-hi); }
  .crumb-count { font-size: 12px; color: var(--ink-faint); }

  .sidebar {
    background: var(--bg1);
    border-right: 1px solid var(--line-soft);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }
  .sidebar::-webkit-scrollbar { width: 8px; }
  .sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

  .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 8px 18px;
  }
  .brand-mark {
    width: 30px; height: 30px; color: var(--amber);
    flex-shrink: 0;
  }
  .brand-name { font-weight: 700; font-size: 15px; color: var(--ink-hi); letter-spacing: -0.01em; }
  .brand-sub { display: block; font-size: 11px; color: var(--ink-faint); font-family: var(--font-mono); }

  .nav-section {
    font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em;
    color: var(--ink-faint); padding: 14px 10px 6px;
  }

  .nav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px; width: 100%; text-align: left;
    border-radius: var(--radius-sm); color: var(--ink-dim);
    transition: background 150ms ease, color 150ms ease;
  }
  .nav-item:hover { background: var(--bg2); color: var(--ink-hi); }
  .nav-item.active { background: var(--amber-wash); color: var(--amber-bright); }
  .nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
  .nav-item .nav-count {
    margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint);
  }
  .nav-item.active .nav-count { color: var(--amber); }

  .sidebar-foot {
    margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line-soft);
  }
  .admin-chip {
    display: flex; align-items: center; gap: 10px; padding: 4px 8px;
  }
  .admin-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--amber-wash); color: var(--amber-bright);
    display: grid; place-items: center;
    font-family: var(--font-mono); font-size: 12px; font-weight: 600;
    flex-shrink: 0;
  }
  .admin-meta { overflow: hidden; }
  .admin-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-hi); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
  .admin-email { display: block; font-size: 11px; color: var(--ink-faint); font-family: var(--font-mono); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }

  .logout-btn {
    width: 100%; margin-top: 10px; padding: 7px 10px; display: flex; align-items: center; gap: 8px;
    color: var(--ink-dim); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
    transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
  }
  .logout-btn:hover { color: var(--red); border-color: var(--red-wash); background: var(--red-wash); }
  .logout-btn svg { width: 14px; height: 14px; }

  .main-col { min-width: 0; }

  .topbar {
    height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(14, 16, 20, 0.78);
    backdrop-filter: blur(14px);
    position: sticky; top: 0; z-index: 20;
  }
  .crumb { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
  .crumb-table { font-size: 15px; font-weight: 650; color: var(--ink-hi); letter-spacing: -0.01em; }
  .crumb-total {
    font-size: 11.5px; color: var(--ink-faint); font-family: var(--font-mono);
  }
  .topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
  .search {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
    padding: 6px 10px; width: 250px;
    transition: border-color 150ms ease, box-shadow 150ms ease;
  }
  .search:focus-within { border-color: var(--amber-deep); box-shadow: 0 0 0 3px var(--amber-wash); }
  .search svg { width: 14px; height: 14px; color: var(--ink-faint); flex-shrink: 0; }
  .search input { background: none; border: none; outline: none; width: 100%; color: var(--ink-hi); font-size: 13px; }
  .search input::placeholder { color: var(--ink-faint); }

  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 7px 14px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 550;
    transition: transform 120ms ease, background 150ms ease, border-color 150ms ease, color 150ms ease;
  }
  .btn:active { transform: translateY(1px); }
  .btn svg { width: 15px; height: 15px; }

  .btn-primary { background: var(--amber); color: #1B1205; font-weight: 650; }
  .btn-primary:hover { background: var(--amber-bright); }
  .btn-ghost { border: 1px solid var(--line); color: var(--ink-dim); background: transparent; }
  .btn-ghost:hover { border-color: var(--ink-faint); color: var(--ink-hi); background: var(--bg2); }
  .btn-danger { border: 1px solid var(--red-wash); color: var(--red); }
  .btn-danger:hover { background: var(--red-wash); border-color: var(--red); }
  .btn-sm { padding: 5px 10px; font-size: 12px; }
  .btn-icon { padding: 6px; }

  /* data grid */
  .grid-toolbar {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
  }
  .grid-count {
    font-size: 12px; color: var(--ink-faint); font-family: var(--font-mono);
  }
  .grid-spacer { flex: 1; }
  .grid-wrap {
    overflow-x: auto;
    scrollbar-color: var(--line) transparent;
    scrollbar-width: thin;
  }
  table.grid {
    width: 100%; border-collapse: collapse; font-size: 13px;
    min-width: max-content;
  }
  table.grid thead th {
    position: sticky; top: 0;
    background: var(--bg1); color: var(--ink-faint);
    font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em;
    text-align: left; padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
    white-space: nowrap;
  }
  table.grid thead th.sortable { cursor: pointer; }
  table.grid thead th.sortable:hover { color: var(--ink-hi); }
  table.grid tbody td {
    padding: 9px 12px; border-bottom: 1px solid var(--line-soft);
    vertical-align: top; white-space: nowrap; max-width: 320px;
    overflow: hidden; text-overflow: ellipsis;
  }
  table.grid tbody tr { transition: background 120ms ease; }
  table.grid tbody tr:hover { background: var(--bg1); }
  table.grid tbody tr.row-linked-hi { background: var(--green-wash); }
  td.cell-bool { text-align: center; }
  td.cell-id { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
  td.cell-id .short { color: var(--ink-hi); }
  td.cell-rel { color: var(--amber); }
  td.cell-rel .rel-sym { color: var(--ink-faint); }
  .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
  .row-actions .iconbtn {
    padding: 5px; border-radius: 6px; color: var(--ink-faint);
    transition: color 140ms ease, background 140ms ease;
  }
  .row-actions .iconbtn svg { width: 14px; height: 14px; }
  .row-actions .iconbtn:hover { color: var(--ink-hi); background: var(--bg2); }
  .row-actions .iconbtn.delete:hover { color: var(--red); background: var(--red-wash); }

  .pager {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 12px 16px; border-top: 1px solid var(--line-soft);
    font-size: 12px; color: var(--ink-faint); font-family: var(--font-mono);
  }
  .pager .spacer { flex: 1; }

  /* empty + error state */
  .state-pane { padding: 48px 24px; text-align: center; }
  .state-pane svg { width: 34px; height: 34px; color: var(--ink-faint); margin: 0 auto 12px; }
  .state-pane h3 { font-size: 14px; color: var(--ink); margin-bottom: 4px; font-weight: 600; }
  .state-pane p { font-size: 13px; color: var(--ink-faint); }

  /* modal */
  .overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(6, 7, 10, 0.72);
    backdrop-filter: blur(6px);
    display: grid; place-items: center; padding: 24px;
    opacity: 0; animation: fade-in 180ms ease forwards;
  }
  .modal {
    width: 100%; max-width: 540px;
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
    transform: translateY(8px) scale(0.98);
    animation: pop-in 200ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
    max-height: calc(100vh - 48px);
    display: flex; flex-direction: column;
  }
  .modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
  }
  .modal-title { font-size: 15px; font-weight: 650; color: var(--ink-hi); }
  .modal-close {
    padding: 5px; border-radius: 6px; color: var(--ink-faint);
    transition: color 140ms ease, background 140ms ease;
  }
  .modal-close:hover { color: var(--ink-hi); background: var(--bg3); }
  .modal-close svg { width: 16px; height: 16px; }
  .modal-body { padding: 20px; overflow-y: auto; }
  .modal-foot {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--line-soft);
  }
  .modal-foot .grow { flex: 1; }

  /* forms */
  .field-label {
    display: block; font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.07em; color: var(--ink-faint); margin-bottom: 6px;
  }
  .field {
    margin-bottom: 16px;
  }
  .field input, .field select, .field textarea {
    width: 100%; background: var(--bg1);
    border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
    padding: 9px 11px; font-size: 13px; color: var(--ink-hi);
    transition: border-color 140ms ease, box-shadow 140ms ease;
  }
  .field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--amber-deep); box-shadow: 0 0 0 3px var(--amber-wash);
  }
  .field textarea { min-height: 88px; resize: vertical; font-family: var(--font-mono); font-size: 12.5px; }
  .field .hint { font-size: 11.5px; color: var(--ink-faint); margin-top: 5px; font-family: var(--font-mono); }
  .field row-req { color: var(--red); margin-left: 4px; }

  /* toasts */
  .toast-root {
    position: fixed; bottom: 18px; right: 18px; z-index: 80;
    display: flex; flex-direction: column; gap: 10px;
  }
  .toast {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg3); border: 1px solid var(--line);
    border-radius: var(--radius-md); padding: 11px 14px;
    font-size: 13px; color: var(--ink-hi);
    box-shadow: 0 14px 40px -12px rgba(0, 0, 0, 0.65);
    animation: toast-in 220ms cubic-bezier(0.2, 0.8, 0.3, 1);
    max-width: 360px;
  }
  .toast svg { width: 16px; height: 16px; flex-shrink: 0; }
  .toast.ok svg { color: var(--green); }
  .toast.err svg { color: var(--red); }
  .toast.leaving { animation: toast-out 200ms ease forwards; }

  /* skeletons */
  .skeleton {
    position: relative; overflow: hidden;
    background: var(--bg2); border-radius: 6px; color: transparent !important;
  }
  .skeleton::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,0.05) 50%, transparent 70%);
    animation: shimmer 1.3s infinite;
    transform: translateX(-100%);
  }
  .sk-row { height: 13px; margin: 9px 12px; }
  /* block placeholder for sidebar/list loading (a <div>, not a <tr>) */
  .skeleton-row {
    height: 13px; border-radius: var(--radius-sm); margin: 6px 8px;
    background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 37%, var(--bg2) 63%);
    background-size: 400% 100%; animation: sk-shimmer 1.4s ease infinite;
  }
  .sk {
    display: block; height: 11px; border-radius: 3px; min-width: 40px;
    background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 37%, var(--bg2) 63%);
    background-size: 400% 100%; animation: sk-shimmer 1.4s ease infinite;
  }
  @keyframes sk-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
  /* sweep highlight used by .skeleton::after */
  @keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

  /* overlay fade / modal entrance / toast lifecycle.
     These were referenced by name but never declared, so the browser silently
     dropped the animation and elements rendered at their unanimated state. */
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(10px); }
  }

  /* empty state — .state-pane keeps its own rules in the "empty + error state" block above */
  .state-pane.small { padding: 20px; }
  .empty {
    display: grid; place-items: center; gap: 6px; padding: 56px 24px; text-align: center;
    color: var(--ink-faint);
  }
  .empty h3 { font-size: 14px; font-weight: 600; color: var(--ink-dim); margin: 0; }
  .empty p { font-size: 12.5px; margin: 0; }
  .empty svg { width: 22px; height: 22px; opacity: 0.5; }

  /* sidebar nav rows */
  .nav-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-state { font-size: 12px; color: var(--ink-faint); padding: 10px 8px; }
  .nav-state-error { color: var(--red); }
  .modal-danger .btn-primary { background: var(--red); border-color: var(--red); }
  .off { opacity: 0.45; }

  /* login gate — selectors follow index.html (.gate* / .form-error).
     The old .login-* names matched nothing in the markup, which left the whole
     sign-in screen unstyled and effectively invisible. */
  .gate {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
      radial-gradient(900px 500px at 75% 10%, rgba(226, 161, 74, 0.08), transparent 60%),
      radial-gradient(700px 500px at 20% 90%, rgba(111, 168, 220, 0.06), transparent 60%),
      var(--bg0);
  }
  .gate-card {
    width: 100%; max-width: 400px;
    background: var(--bg1); border: 1px solid var(--line-soft);
    border-radius: var(--radius-lg); padding: 32px;
    box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  }
  .gate-card .brand { padding: 0 0 8px; }
  .brand-text { display: flex; flex-direction: column; gap: 2px; }
  .gate-title { font-size: 20px; font-weight: 700; color: var(--ink-hi); letter-spacing: -0.01em; }
  .gate-note {
    font-size: 13px; color: var(--ink-faint); margin: 8px 0 24px; line-height: 1.5;
  }
  /* .hidden sets display:none !important, so the un-hidden state needs its
     own display value or the box would render as a zero-height inline box. */
  .form-error {
    background: var(--red-wash); color: var(--red);
    border: 1px solid rgba(229, 100, 90, 0.3);
    border-radius: var(--radius-sm); padding: 9px 12px;
    font-size: 12.5px; margin: 0 0 14px; display: block;
  }
  .form-error.hidden { display: none !important; }
  .field-input { width: 100%; }
  .field-select { width: 100%; background: var(--bg1); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 9px 11px; font-size: 13px; color: var(--ink-hi); }
  .field-check { width: auto; margin-right: 8px; accent-color: var(--amber); }
  .field-inline { display: flex; align-items: center; gap: 10px; }
  .field-inline .field-label { margin-bottom: 0; }
  .btn-block { width: 100%; justify-content: center; }

  /* row action buttons — JS emits .icon-btn on every edit/delete/disable control */
  .icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; padding: 0;
    background: transparent; border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm); color: var(--ink-dim); cursor: pointer;
    transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
  }
  .icon-btn:hover { color: var(--ink-hi); border-color: var(--line); background: var(--bg2); }
  .icon-btn.danger:hover { color: var(--red); border-color: rgba(229, 100, 90, 0.4); background: var(--red-wash); }
  .icon-btn svg { width: 14px; height: 14px; }

  /* auth-user picker inside the link modal */
  .picker-list { display: flex; flex-direction: column; gap: 4px; max-height: 340px; overflow-y: auto; }
  .picker-row {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 10px; text-align: left; cursor: pointer;
    background: var(--bg2); border: 1px solid transparent; border-radius: var(--radius-sm);
    color: var(--ink-hi); transition: border-color 120ms ease, background 120ms ease;
  }
  .picker-row:hover { border-color: var(--amber-deep); background: var(--amber-wash); }
  .picker-avatar {
    display: grid; place-items: center; flex: 0 0 28px; height: 28px;
    background: var(--bg1); border: 1px solid var(--line-soft); border-radius: 50%;
    font-size: 12px; font-weight: 600; color: var(--amber);
  }
  .picker-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
  .picker-name { font-size: 13px; font-weight: 500; }
  .picker-email { font-size: 11.5px; font-family: var(--font-mono); }
  .modal-hint { font-size: 12.5px; color: var(--ink-faint); margin: 0 0 14px; line-height: 1.5; }
  .cell-faint { color: var(--ink-faint); }
  .spacer { flex: 1; }
  /* cell types produced by dom.js formatCell / tableview column typing */
  .col-actions { width: 1%; white-space: nowrap; text-align: right; }
  td.col-actions .icon-btn + .icon-btn { margin-left: 4px; }
  .cell-text { font-family: var(--font-mono); font-size: 12.5px; }
  .cell-dt { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); white-space: nowrap; }
  .cell-null { color: var(--ink-faint); font-style: italic; }
  .cell-bool { color: var(--amber); }
  .cell-array { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
  .cell-link { color: var(--amber); text-decoration: none; }
  .cell-link:hover { text-decoration: underline; }
  .field-list { display: flex; flex-direction: column; gap: 2px; }
  .picker-state { margin-left: auto; }

  /* shared chip styles */
  .chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; font-weight: 550; font-family: var(--font-mono);
    padding: 3px 8px; border-radius: 999px;
  }
  .chip.amber { background: var(--amber-wash); color: var(--amber-bright); }
  .chip.green { background: var(--green-wash); color: var(--green); }
  .chip.red { background: var(--red-wash); color: var(--red); }
  .chip.plain { background: var(--bg2); color: var(--ink-dim); }
  .chip svg { width: 12px; height: 12px; }

  .link-cell { display: inline-flex; align-items: center; gap: 8px; }
  .link-cell .link-user { font-family: var(--font-mono); font-size: 12px; color: var(--green); }
  .link-cell .link-unlink {
    font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint);
    text-decoration: underline; text-underline-offset: 2px;
    transition: color 140ms ease;
  }
  .link-cell .link-unlink:hover { color: var(--red); }
}