/* DreamPets Bot panel — one small design system, no framework, no CDN.
   Tokens are defined for light first, then overridden for dark, so an explicit
   [data-theme] wins in both directions and nothing depends on the media query alone. */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --line: #dfe4ef;
  --line-2: #c9d1e2;
  --text: #111827;
  --muted: #5b6478;
  --dim: #8b94a8;
  --brand: #3b6fe6;
  --brand-2: #6d4fe0;
  --ok: #0f9d6e;
  --warn: #c7841a;
  --err: #d93a4f;
  --info: #1a86d1;
  --legacy: #6b7488;
  --new: #3b6fe6;
  --reserved: #8b4fd8;
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px;
  --sp1: 4px; --sp2: 8px; --sp3: 12px; --sp4: 16px; --sp5: 24px; --sp6: 32px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-2: 0 12px 32px rgba(16, 24, 40, .16);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0a0d15;
  --surface: #141926;
  --surface-2: #1a2130;
  --line: #232c42;
  --line-2: #313b58;
  --text: #e9eef8;
  --muted: #8b96af;
  --dim: #5b667e;
  --brand: #5b8cff;
  --brand-2: #8a6bff;
  --ok: #2fd6a0;
  --warn: #ffbe5c;
  --err: #ff6b7d;
  --info: #5bc0ff;
  --legacy: #9aa4b8;
  --new: #5b8cff;
  --reserved: #c58bff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 20px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 var(--sp4); }
h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
     margin: 0 0 var(--sp3); font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 var(--sp2); }
p { margin: 0 0 var(--sp2); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px;
  border: 3px solid transparent; background-clip: padding-box; }

/* ── shell ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--sp3);
  padding: 10px var(--sp4); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: var(--sp2); color: var(--text); font-size: 14px; }
.logo { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 800; font-size: 12px; }
.grow { flex: 1; }
.strip { display: flex; gap: var(--sp3); align-items: center; font-size: 12px; color: var(--muted);
  overflow-x: auto; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip .s-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

.shell { display: flex; min-height: calc(100vh - 49px); }
.rail { width: 200px; flex: 0 0 200px; padding: var(--sp3); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 49px; height: calc(100vh - 49px); }
.rail a { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-s);
  color: var(--muted); font-weight: 500; position: relative; }
.rail a:hover { background: var(--surface-2); color: var(--text); }
.rail a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.rail svg, .tabbar svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.rail .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--err); margin-left: auto; }
.view { flex: 1; padding: var(--sp5); max-width: 1280px; margin: 0 auto; width: 100%; }

.tabbar { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom)); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; color: var(--muted); padding: 4px 0; }
.tabbar a.active { color: var(--brand); }
.only-mobile { display: none; }
@media (max-width: 860px) {
  .rail { display: none; }
  .rail.open { display: flex; position: fixed; z-index: 40; top: 49px; left: 0; background: var(--surface);
    box-shadow: var(--shadow-2); }
  .view { padding: var(--sp3); padding-bottom: 78px; }
  .tabbar { display: flex; }
  .only-mobile { display: inline-flex; }
  .topbar .strip { display: none; }
}

/* ── primitives ──────────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--sp4); grid-template-columns: repeat(12, 1fr); }
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c6 { grid-column: span 6; }
.c4 { grid-column: span 4; } .c3 { grid-column: span 3; }
@media (max-width: 1000px) { .grid > * { grid-column: span 12 !important; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: var(--sp4) var(--sp5); box-shadow: var(--shadow-1); }
.card + .card { margin-top: var(--sp4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp3);
  margin-bottom: var(--sp3); }
.card-head h2 { margin: 0; }
.row { display: flex; gap: var(--sp2); align-items: center; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: var(--sp3); }
.muted { color: var(--muted); }
.dim { color: var(--dim); font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.banner { border-radius: var(--radius-l); padding: var(--sp4) var(--sp5); border: 1px solid;
  display: flex; gap: var(--sp4); align-items: flex-start; margin-bottom: var(--sp4); }
.banner.critical { background: color-mix(in srgb, var(--err) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.banner .b-title { font-weight: 700; margin-bottom: 2px; }
.banner .b-body { flex: 1; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--sp3); }
.tile { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: var(--sp3) var(--sp4); position: relative; overflow: hidden; }
.tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); }
.tile.ok::before { background: var(--ok); } .tile.warn::before { background: var(--warn); }
.tile.err::before { background: var(--err); } .tile.flat::before { background: var(--line-2); }
.tile b { display: block; font-size: 22px; font-weight: 750; letter-spacing: -.4px; line-height: 1.15; }
.tile span { color: var(--muted); font-size: 11.5px; }

.btn { font: inherit; font-weight: 600; cursor: pointer; border-radius: var(--radius-s);
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  padding: 8px 13px; display: inline-flex; align-items: center; gap: 6px; transition: .12s; min-height: 36px; }
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: 0; color: #fff; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent);
  background: color-mix(in srgb, var(--err) 8%, var(--surface)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; min-height: 30px; font-size: 12.5px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  width: 32px; height: 32px; border-radius: var(--radius-s); cursor: pointer; font-size: 14px; }
.icon-btn:hover { color: var(--text); }

input, select, textarea { font: inherit; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-s); padding: 8px 10px; min-height: 36px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
label.field { display: block; margin-bottom: var(--sp3); }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.track { width: 38px; height: 22px; border-radius: 999px; background: var(--line-2); position: relative;
  transition: .18s; flex: 0 0 auto; }
.track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: .18s; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.switch input:checked + .track { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.switch input:checked + .track::after { transform: translateX(16px); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  position: static; background: var(--surface); }
.rules-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.rules-layout > .card { min-width: 0; }
.inventory-list { max-height: 65vh; overflow-y: auto; margin-top: 12px; }
.inventory-entry { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 1100px) {
  .rules-layout { grid-template-columns: minmax(0, 1fr); }
  .rules-layout > aside { grid-row: 1; }
  .inventory-list { max-height: 220px; }
}
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td input { min-height: 30px; padding: 4px 7px; }
td .num { width: 92px; } td .name { min-width: 160px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 7px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.err { color: var(--err); background: color-mix(in srgb, var(--err) 12%, transparent);
  border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.badge.info { color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent);
  border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.badge.reserved { color: var(--reserved); background: color-mix(in srgb, var(--reserved) 12%, transparent);
  border-color: color-mix(in srgb, var(--reserved) 30%, transparent); }
.badge.legacy { color: var(--legacy); } .badge.new { color: var(--new); }
.badge.pulse::before { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.thumb { width: 30px; height: 30px; border-radius: 7px; object-fit: contain; background: var(--surface-2);
  border: 1px solid var(--line); flex: 0 0 auto; }
.item-cell { display: flex; align-items: center; gap: 9px; min-width: 0; }
.item-cell b { font-weight: 600; }
.item-cell small { color: var(--muted); display: block; font-size: 11px; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: var(--sp3);
  padding: 7px 8px; border-radius: var(--radius-s); }
.list-row:hover { background: var(--surface-2); }
.log { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; max-height: 60vh; overflow: auto; }
.log .l { display: flex; gap: 10px; padding: 4px 6px; border-bottom: 1px solid var(--line); align-items: baseline; }
.log .t { color: var(--dim); white-space: nowrap; font-size: 11px; }
.log .error { color: var(--err); }

.toasts { position: fixed; bottom: var(--sp4); right: var(--sp4); z-index: 60; display: flex;
  flex-direction: column; gap: var(--sp2); }
@media (max-width: 860px) { .toasts { bottom: 74px; left: var(--sp3); right: var(--sp3); } }
.toast { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-m);
  padding: 11px 15px; box-shadow: var(--shadow-2); font-weight: 600; display: flex; gap: var(--sp3);
  align-items: center; animation: slide .22s ease; }
.toast.err { border-color: color-mix(in srgb, var(--err) 50%, transparent); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

.modal-bg { position: fixed; inset: 0; background: rgba(6, 8, 14, .6); backdrop-filter: blur(3px);
  z-index: 50; display: grid; place-items: center; padding: var(--sp4); }
.modal { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-l);
  padding: var(--sp5); max-width: 560px; width: 100%; max-height: 84vh; overflow: auto; box-shadow: var(--shadow-2); }
.modal h3 { margin-bottom: var(--sp3); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp2); margin-top: var(--sp4); }

.skeleton, .skeleton-page { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2));
  background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius-m); }
.skeleton { height: 14px; } .skeleton-page { height: 320px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; color: var(--muted); padding: var(--sp6) var(--sp4); }
.err-box { color: var(--err); font-size: 13px; }

.spark { display: block; width: 100%; height: 38px; }
.chart { width: 100%; height: 220px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
kbd { background: var(--surface-2); border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font-family: inherit; font-size: 12px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
