/* Sumri Admin console. Phone first (MOB-001/002); the environment label stays
   visible at every width (MOB-015). */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5d6470;
  --line: #dde1e7;
  --accent: #3a5bd9;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --warn: #9a6200;
  --danger: #b42323;
  --focus: #3a5bd9;
  --env: #7a1fa2;
  --radius: 10px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e9ecf1;
    --muted: #a1a8b3;
    --line: #2c313a;
    --accent: #7d97ff;
    --accent-text: #0d1020;
    --ok: #5fcf8e;
    --warn: #f0b54d;
    --danger: #ff7a7a;
    --focus: #9fb2ff;
    --env: #d9a3f0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 8px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85em; word-break: break-all; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px var(--gutter);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.env { display: flex; gap: 6px; flex-wrap: wrap; }
.env-chip {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px;
  color: var(--env); border: 1px solid var(--env);
}
.env-emulator { color: var(--warn); border-color: var(--warn); }
.user { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-width: 0; }
.user-email { font-weight: 600; overflow-wrap: anywhere; }
.user-roles { font-size: 0.8rem; }

.layout { display: block; }
.nav {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin;
  padding: 8px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line);
}
.nav[hidden] { display: none; }
.nav a {
  flex: none; padding: 6px 12px; border-radius: 999px;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
.main { padding: var(--gutter); width: 100%; max-width: 1100px; margin: 0 auto; outline: none; min-width: 0; }

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); }
  .layout:has(> .nav[hidden]) { display: block; }
  .nav {
    flex-direction: column; overflow: visible; border-bottom: 0; border-right: 1px solid var(--line);
    min-height: calc(100vh - 52px); position: sticky; top: 52px; align-self: start;
  }
  .nav a { border-radius: 8px; }
  .main { padding: 24px; }
}

.section { margin-bottom: 24px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-width: 0;
}
.card-focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 12px 0; }
.notice { border-left: 3px solid var(--warn); padding-left: 10px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); margin-bottom: 8px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.tile-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.tile-label { color: var(--muted); }

.btn {
  font: inherit; cursor: pointer; min-height: 40px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-small { min-height: 34px; padding: 4px 10px; font-size: 0.9rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-wide { width: 100%; }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; margin: 0 4px 4px 0;
  border-radius: 999px; border: 1px solid currentColor; color: var(--muted);
}
.badge-ok { color: var(--ok); }
.badge-warn { color: var(--warn); }
.badge-danger { color: var(--danger); }
.badge-accent { color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.list-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0 0 8px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.excerpt { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.case-title { font-weight: 600; overflow-wrap: anywhere; }
.json {
  margin: 8px 0; padding: 10px; max-height: 320px; overflow: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font: 0.8rem/1.4 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.secret { display: block; padding: 8px; background: var(--bg); border-radius: 6px; }
details > summary { cursor: pointer; color: var(--accent); margin: 4px 0; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.field-hint { color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; max-width: 100%;
}
.row select { width: auto; }
.checks { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; min-height: 0; }

.auth-card { max-width: 440px; margin: 24px auto; }
.dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0;
  width: min(560px, calc(100vw - 2 * var(--gutter))); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-form, .dialog > .stack { padding: 18px; }
.dialog-body { margin-bottom: 12px; }

.toast {
  position: fixed; left: var(--gutter); right: var(--gutter); bottom: 16px; z-index: 20;
  max-width: 560px; margin: 0 auto; padding: 0; border-radius: var(--radius);
}
.toast:empty { display: none; }
.toast-ok, .toast-error { padding: 12px 16px; background: var(--text); color: var(--bg); }
.toast-error { background: var(--danger); color: #fff; }
