/* Focus Admin — mobile-first. Celular: barra inferior. Tela larga (≥900px): menu lateral. */
:root {
  color-scheme: dark;
  --bg: #111820; --surface: #18222b; --surface-2: #1f2b36; --line: #2b3a46;
  --text: #eef3f7; --muted: #9fb0be; --accent: #f4a340; --on-accent: #111820;
  --ok: #3f9b62; --warn: #c99a2e; --bad: #c4505e; --info: #4b8fd6;
  --radius: 14px; --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f5f7; --surface: #fff; --surface-2: #eef1f4; --line: #dde3e8;
    --text: #15202a; --muted: #5d6c78; --accent: #d9821c; --on-accent: #fff;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f7; --surface: #fff; --surface-2: #eef1f4; --line: #dde3e8;
  --text: #15202a; --muted: #5d6c78; --accent: #d9821c; --on-accent: #fff;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.boot { display: grid; place-items: center; min-height: 100dvh; color: var(--muted); }

/* Layout */
.shell { display: flex; min-height: 100dvh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: calc(12px + var(--safe-t)) 16px calc(84px + var(--safe-b)); }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: var(--tap); }
button svg, .btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.topbar .btn.ghost svg { width: 26px; height: 26px; }
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px;
  color: var(--muted); text-decoration: none; font-size: .72rem; min-height: 56px; justify-content: center;
}
.tabbar a svg, .side a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .side {
    display: flex; flex-direction: column; width: 240px; flex-shrink: 0; position: sticky; top: 0; height: 100dvh;
    background: var(--surface); border-right: 1px solid var(--line); padding: 18px 10px; overflow-y: auto;
  }
  .side .brand { font-weight: 800; padding: 4px 12px 16px; display: flex; gap: 8px; align-items: center; }
  .side .brand img { width: 28px; height: 28px; border-radius: 7px; }
  .side a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
  .side a:hover { background: var(--surface-2); }
  .side a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
  .side .group { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: 16px 12px 6px; }
  .side .foot { margin-top: auto; padding: 12px; color: var(--muted); font-size: .82rem; }
  .main { padding: 24px 32px 40px; max-width: 1280px; }
}

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } .grid.two { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; display: block; }
.stat .n { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; word-break: break-all; }

button, .btn {
  appearance: none; border: 0; border-radius: 10px; min-height: var(--tap); padding: 0 16px; font: inherit; font-weight: 650;
  background: var(--accent); color: var(--on-accent); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--bad); color: #fff; }
button.ghost, .btn.ghost { background: transparent; color: var(--text); padding: 0 6px; margin-left: -6px; }
button:disabled { opacity: .55; cursor: default; }
button.icon { width: var(--tap); padding: 0; }

input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px; /* 16px evita zoom automático no iOS */
}
textarea { min-height: 110px; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .95rem; }
.check input { width: 22px; min-height: 22px; }
.form-grid { display: grid; gap: 0 12px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } }

.search > select { width: auto; max-width: 45%; flex-shrink: 0; }
.search { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 4px 0 10px; display: flex; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips button { min-height: 34px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; white-space: nowrap; }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* Lista: cartões no celular, tabela em tela larga */
.list { display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; color: inherit; text-decoration: none;
}
.item:active { background: var(--surface-2); }
.item .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; }
@media (min-width: 900px) {
  .list.table .item { grid-template-columns: var(--cols, 2fr 1fr 1fr 1fr); align-items: center; }
  .list.table .item .r { grid-row: auto; grid-column: auto; }
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 25%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 25%, transparent); color: var(--bad); }
.badge.info { background: color-mix(in srgb, var(--info) 25%, transparent); color: var(--info); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.error-box { border-color: var(--bad); }
.skeleton { height: 64px; border-radius: 12px; background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* Folha (sheet) / diálogo: de baixo no celular, centralizado em tela larga */
dialog.sheet { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; width: 100%; height: 100%; margin: 0; }
dialog.sheet::backdrop { background: #0009; }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; background: var(--surface); color: var(--text);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); border-top: 1px solid var(--line);
}
@media (min-width: 700px) {
  .sheet-body { left: 50%; top: 50%; bottom: auto; transform: translate(-50%, -50%); width: min(620px, 92vw); border-radius: 18px; border: 1px solid var(--line); }
}
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: .2s; z-index: 100; max-width: 92vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(400px, 100%); padding: 24px; }
.login img { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; margin-bottom: 18px; }

/* Telas antigas embutidas */
.legacy-frame { width: 100%; height: calc(100dvh - 150px - var(--safe-b)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
@media (min-width: 900px) { .legacy-frame { height: calc(100dvh - 110px); } }

.more-list a { display: flex; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; min-height: 52px; }
.more-list a:last-child { border-bottom: 0; }
.more-list svg { width: 22px; height: 22px; color: var(--muted); }
pre.json { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow: auto; max-height: 50dvh; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
