:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef1f4; --text: #16202b; --muted: #5d6b7a;
  --border: #d9dfe5; --accent: #15803d; --accent-text: #ffffff; --danger: #b91c1c; --warn: #b45309; --info: #1d4ed8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720; --surface: #17212c; --surface-2: #1f2b38; --text: #e6edf3; --muted: #93a2b1;
    --border: #2b3a49; --accent: #22c55e; --accent-text: #052e16; --danger: #f87171; --warn: #fbbf24; --info: #60a5fa;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 16px; display: flex; gap: 24px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; padding: 14px 0; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { padding: 14px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
nav a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }
.savebar { position: sticky; bottom: 0; z-index: 4; display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  margin: 8px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface);
  border-top: 1px solid var(--border); box-shadow: 0 -6px 16px rgba(0,0,0,.06); }
.warn-text { color: var(--warn); font-weight: 600; }
nav a#logout { margin-left: 8px; color: var(--danger); }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
h2 { margin: 0 0 16px; }
h3 { margin: 0 0 10px; font-size: 1rem; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.card .label { color: var(--muted); font-size: .85rem; }
.card .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
button, .btn { font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.small { padding: 4px 8px; font-size: .82rem; }
input, select, textarea { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 100%; }
textarea { min-height: 110px; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin: 0 0 16px; background: var(--surface); }
legend { font-weight: 700; padding: 0 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.ok { color: var(--accent); } .badge.warn { color: var(--warn); } .badge.danger { color: var(--danger); } .badge.info { color: var(--info); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.panel ol, .panel ul { margin: 0; padding-left: 22px; }
.panel li { padding: 4px 0; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.panel ol li { display: list-item; }
.row-actions { display: inline-flex; gap: 4px; float: right; }
.muted { color: var(--muted); }
pre.preview { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 8px; font-family: inherit; margin: 0; }
.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); width: min(560px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 10px 12px; border-radius: 10px; max-width: 640px; white-space: pre-wrap; border: 1px solid var(--border); background: var(--surface); }
.msg.in { align-self: flex-end; background: var(--surface-2); }
.msg .meta { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.empty { color: var(--muted); padding: 12px 0; }
a.link { color: var(--info); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }
ul.plain { list-style: none; padding: 0; margin: 0 0 12px; }
ul.plain li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
dialog .cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
select.move { width: auto; padding: 2px 4px; font-size: .78rem; }
.pos { color: var(--accent); } .neg { color: var(--danger); }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: .9rem; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; }
.bar .in { background: var(--accent); } .bar .out { background: var(--danger); }
nav { scrollbar-width: none; } nav::-webkit-scrollbar { display: none; }
header { padding-top: env(safe-area-inset-top); }
@media (max-width: 640px) {
  header { gap: 0; padding: env(safe-area-inset-top) 0 0; }
  .brand { padding: 10px 16px 0; font-size: .95rem; }
  nav { width: 100%; padding: 0 8px; }
  nav a { padding: 10px 10px 12px; }
  main { padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
  h2 { font-size: 1.25rem; }
  /* 16px evita o zoom automático do iPhone ao tocar num campo */
  input, select, textarea, button { font-size: 16px; }
  button.small, .btn.small, select.move { font-size: .85rem; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 12px; }
  .card .value { font-size: 1.25rem; }
  .toolbar > select, .toolbar > input { max-width: none !important; flex: 1 1 100%; }
  .toolbar > button { flex: 1 1 auto; }
  th, td { padding: 8px 6px; font-size: .9rem; }
  .panel li { flex-wrap: wrap; }
  .row-actions { float: none; }
  dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .bar-row { grid-template-columns: 1fr 1fr auto; }
}
