/* Emberlands owner panel. No build step, no external assets: everything here is served by the world itself. */

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #13161b;
  --muted: #586170;
  --faint: #8b93a0;
  --accent: #d9480f;
  --accent-hover: #c2410c;
  --accent-fg: #ffffff;
  --accent-soft: rgba(217, 72, 15, 0.09);
  --accent-text: #b8400f;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --danger-soft: rgba(217, 45, 32, 0.08);
  --ok: #12804a;
  --ok-soft: rgba(18, 128, 74, 0.1);
  --warn: #b25e09;
  --warn-soft: rgba(178, 94, 9, 0.1);
  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.09);
  --chart: #e8590c;
  --chart-2: #94a3b8;
  --overlay: rgba(15, 18, 24, 0.42);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 20px 48px -12px rgba(16, 24, 40, 0.25), 0 4px 12px rgba(16, 24, 40, 0.06);
  --focus: 0 0 0 3px rgba(217, 72, 15, 0.35);
  --skeleton: linear-gradient(90deg, #eceff3 0%, #f6f7f9 40%, #eceff3 80%);
  --map-bg: #e9ecf0;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 244px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0d11;
    --surface: #13161c;
    --surface-2: #1a1e26;
    --surface-3: #232833;
    --border: #252a35;
    --border-strong: #343a47;
    --text: #e9ecf1;
    --muted: #a0a8b6;
    --faint: #6d7585;
    --accent: #ff7a32;
    --accent-hover: #ff8f52;
    --accent-fg: #1a0c03;
    --accent-soft: rgba(255, 122, 50, 0.12);
    --accent-text: #ff9a5e;
    --danger: #f2554a;
    --danger-hover: #ff6b61;
    --danger-soft: rgba(242, 85, 74, 0.13);
    --ok: #3ccf8e;
    --ok-soft: rgba(60, 207, 142, 0.12);
    --warn: #f0a33a;
    --warn-soft: rgba(240, 163, 58, 0.13);
    --info: #6ea8ff;
    --info-soft: rgba(110, 168, 255, 0.13);
    --chart: #ff7a32;
    --chart-2: #4b5563;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
    --focus: 0 0 0 3px rgba(255, 122, 50, 0.4);
    --skeleton: linear-gradient(90deg, #1a1e26 0%, #232833 40%, #1a1e26 80%);
    --map-bg: #07080b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d11;
  --surface: #13161c;
  --surface-2: #1a1e26;
  --surface-3: #232833;
  --border: #252a35;
  --border-strong: #343a47;
  --text: #e9ecf1;
  --muted: #a0a8b6;
  --faint: #6d7585;
  --accent: #ff7a32;
  --accent-hover: #ff8f52;
  --accent-fg: #1a0c03;
  --accent-soft: rgba(255, 122, 50, 0.12);
  --accent-text: #ff9a5e;
  --danger: #f2554a;
  --danger-hover: #ff6b61;
  --danger-soft: rgba(242, 85, 74, 0.13);
  --ok: #3ccf8e;
  --ok-soft: rgba(60, 207, 142, 0.12);
  --warn: #f0a33a;
  --warn-soft: rgba(240, 163, 58, 0.13);
  --info: #6ea8ff;
  --info-soft: rgba(110, 168, 255, 0.13);
  --chart: #ff7a32;
  --chart-2: #4b5563;
  --overlay: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --focus: 0 0 0 3px rgba(255, 122, 50, 0.4);
  --skeleton: linear-gradient(90deg, #1a1e26 0%, #232833 40%, #1a1e26 80%);
  --map-bg: #07080b;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img.sprite, .sprite img, canvas.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(140deg, #ff9a3d, #d9480f 60%, #9a2c06); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 2px 8px rgba(217, 72, 15, 0.35);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--faint); margin-top: -2px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500; text-decoration: none; transition: background 0.12s, color 0.12s;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
.nav a[aria-current="page"] svg { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; padding: 4px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--surface-3); color: var(--text); font-weight: 600; font-size: 12px; text-transform: uppercase;
}
.user-chip .who { min-width: 0; }
.user-chip .who b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who span { display: block; font-size: 11.5px; color: var(--faint); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar h1 { font-size: 19px; font-weight: 650; }
.topbar .crumb { color: var(--faint); font-size: 12.5px; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.search-btn {
  display: flex; align-items: center; gap: 8px; min-width: 240px; height: 36px; padding: 0 8px 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; color: var(--faint);
  cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color 0.12s;
}
.search-btn:hover { border-color: var(--border-strong); }
.search-btn svg { width: 16px; height: 16px; }
.search-btn span { flex: 1; text-align: left; }
kbd {
  font: 500 11px var(--font); padding: 2px 6px; border-radius: 5px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px;
}
.content { padding: 8px 28px 48px; max-width: 1440px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 6px 0 18px; }
.page-head p { color: var(--muted); max-width: 70ch; }
.page-head .spacer { flex: 1; }

.banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 28px; font-weight: 500;
  background: var(--danger-soft); color: var(--danger); border-bottom: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}
.banner svg { width: 18px; height: 18px; flex: none; }
.banner.mock { background: var(--info-soft); color: var(--info); border-bottom-color: color-mix(in srgb, var(--info) 25%, transparent); }

.bottom-nav { display: none; }
.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.scrim.open { opacity: 1; pointer-events: auto; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 13.5px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.btn.icon.sm { width: 30px; }
.btn.block { width: 100%; }
.btn .spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
body.world-down .needs-world { opacity: 0.5; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { height: auto; min-height: 88px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
.input-wrap > svg + .input { padding-left: 34px; }
.input-wrap .suffix { position: absolute; right: 10px; color: var(--faint); font-size: 12.5px; pointer-events: none; }
.input-wrap .suffix + .input, .input-wrap .input.has-suffix { padding-right: 34px; }
input[type="number"].input { font-variant-numeric: tabular-nums; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; transition: background 0.15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s var(--ease);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; flex-wrap: wrap; }
.segmented button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted);
  font-weight: 550; font-size: 12.5px; cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Cards, KPIs, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-head h2, .card-head h3 { font-size: 14.5px; font-weight: 620; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px 18px 18px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(142px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .label svg { flex: none; }
.kpi .label svg { width: 15px; height: 15px; color: var(--faint); }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.kpi.accent .value { color: var(--accent-text); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }

.sprite {
  width: 36px; height: 36px; border-radius: 8px; flex: none; display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.sprite img { width: 32px; height: 32px; object-fit: contain; }
.sprite.lg { width: 56px; height: 56px; border-radius: 12px; }
.sprite.lg img { width: 48px; height: 48px; }
.sprite.sm { width: 28px; height: 28px; border-radius: 6px; }
.sprite.sm img { width: 24px; height: 24px; }
.sprite > svg { width: 55%; height: 55%; color: var(--muted); }
.sprite.broken::after { content: "?"; color: var(--faint); font-weight: 600; }
.sprite.broken img { display: none; }
.name-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.name-cell .t { min-width: 0; }
.name-cell b { display: block; font-weight: 580; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name-cell small { display: block; color: var(--faint); font-family: var(--mono); font-size: 11.5px; }

/* ---------- Data table ---------- */
.dt { display: flex; flex-direction: column; }
.dt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.dt-toolbar .input-wrap { flex: 1 1 220px; max-width: 360px; }
.dt-toolbar .select { width: auto; min-width: 140px; }
.dt-toolbar .count { margin-left: auto; color: var(--faint); font-size: 12.5px; }
.dt-scroll { overflow-x: auto; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  position: sticky; top: 0; text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--faint); background: var(--surface); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.num { text-align: right; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { display: inline-block; width: 12px; margin-left: 3px; opacity: 0.9; }
.table th[aria-sort="ascending"], .table th[aria-sort="descending"] { color: var(--accent-text); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background 0.08s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.selected { background: var(--accent-soft); }
.table td.actions { text-align: right; white-space: nowrap; }
.dt-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--faint); font-size: 12.5px; }
.dt-foot .spacer { flex: 1; }

/* ---------- States ---------- */
.skel { display: block; border-radius: 6px; background: var(--skeleton); background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite; }
.skel.line { height: 12px; margin: 6px 0; }
.skel.title { height: 26px; width: 40%; margin: 8px 0; }
.skel.block { height: 120px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 48px 20px; color: var(--muted); }
.state .ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--faint); }
.state .ico svg { width: 22px; height: 22px; }
.state h3 { color: var(--text); font-size: 15px; font-weight: 620; }
.state p { max-width: 44ch; }
.state.error .ico { background: var(--danger-soft); color: var(--danger); }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70; width: min(560px, 100vw);
  display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); transform: translateX(104%); transition: transform 0.26s var(--ease);
}
.drawer.open { transform: none; }
.drawer.wide { width: min(720px, 100vw); }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head .titles { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 17px; font-weight: 650; }
.drawer-head p { color: var(--faint); font-size: 12.5px; margin-top: 2px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; overscroll-behavior: contain; }
.drawer-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.drawer-foot .spacer { flex: 1; }
.section { margin-top: 22px; }
.section:first-child { margin-top: 0; }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin-bottom: 12px; }
.section-title .spacer { flex: 1; }
.section-title .btn { text-transform: none; letter-spacing: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; font-weight: 580; color: var(--text); }
.field-label .old { margin-left: auto; font-weight: 500; font-size: 11.5px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.field.changed .field-label .old { color: var(--accent-text); }
.field.changed .field-label .old s { color: var(--faint); }
.field.changed .input, .field.changed .select { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.field-hint { font-size: 12px; color: var(--faint); }
.field-error { font-size: 12px; color: var(--danger); font-weight: 500; display: flex; gap: 5px; align-items: center; }
.field-error svg { width: 13px; height: 13px; flex: none; }
.form-error { padding: 10px 12px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-weight: 500; margin-bottom: 14px; display: flex; gap: 8px; align-items: flex-start; }
.form-error svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.readonly-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.stat .k { font-size: 11.5px; color: var(--faint); font-weight: 500; }
.stat .v { font-weight: 620; font-variant-numeric: tabular-nums; margin-top: 1px; overflow-wrap: anywhere; }

/* Repeating rows: loot, shop list */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row-edit {
  display: grid; grid-template-columns: minmax(0, 1fr) 92px 64px 64px 30px; gap: 8px; align-items: start;
  padding: 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid transparent;
}
.row-edit.invalid { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.row-edit .head { display: contents; }
.row-head { display: grid; grid-template-columns: minmax(0, 1fr) 92px 64px 64px 30px; gap: 8px; padding: 0 8px; font-size: 11.5px; color: var(--faint); font-weight: 600; }
.row-edit .input, .row-edit .select { height: 32px; font-size: 13px; }
.row-edit .field-error { grid-column: 1 / -1; }
.row-edit .tag { grid-column: 1 / -1; margin-top: -2px; }
.shop-row {
  display: grid; grid-template-columns: 22px 28px minmax(0, 1fr) 120px auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid transparent;
}
.shop-row.changed { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.shop-row .idx { color: var(--faint); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.shop-row .t b { display: block; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-row .t small { color: var(--faint); font-size: 11.5px; }
.shop-row .ctl { display: flex; gap: 2px; }
.shop-row .input { height: 32px; }

/* Combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 90; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 4px;
}
.combo-list.up { top: auto; bottom: calc(100% + 4px); }
.combo-opt { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.combo-opt[aria-selected="true"] { background: var(--accent-soft); }
.combo-opt .t { min-width: 0; flex: 1; }
.combo-opt b { display: block; font-weight: 540; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-opt small { color: var(--faint); font-size: 11.5px; }
.combo-empty { padding: 10px; color: var(--faint); font-size: 12.5px; }

.art-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; max-height: 260px; overflow-y: auto; padding: 2px; }
.art-picker button { padding: 4px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; display: grid; place-items: center; aspect-ratio: 1; }
.art-picker button img { width: 36px; height: 36px; image-rendering: pixelated; }
.art-picker button[aria-pressed="true"] { border-color: var(--accent); box-shadow: var(--focus); background: var(--accent-soft); }

/* ---------- Dialog ---------- */
.dialog-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: var(--overlay); animation: fade 0.15s; }
.dialog { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop 0.18s var(--ease); }
.dialog-body { padding: 22px 22px 6px; display: flex; gap: 14px; }
.dialog-body .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-text); }
.dialog-body .ico.danger { background: var(--danger-soft); color: var(--danger); }
.dialog-body .ico svg { width: 20px; height: 20px; }
.dialog-body h2 { font-size: 16px; font-weight: 650; }
.dialog-body p { color: var(--muted); margin-top: 4px; }
.dialog-body .extra { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 120; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px; padding: 11px 14px;
  background: var(--text); color: var(--bg); border-radius: 11px; box-shadow: var(--shadow-lg); font-weight: 520;
  animation: toast-in 0.24s var(--ease);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.ok svg { color: var(--ok); }
.toast.err { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Command palette ---------- */
.palette-wrap { position: fixed; inset: 0; z-index: 110; background: var(--overlay); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; animation: fade 0.12s; }
.palette { width: min(620px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; animation: pop 0.16s var(--ease); }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.palette-input svg { width: 18px; height: 18px; color: var(--faint); }
.palette-input input { flex: 1; border: 0; background: transparent; font-size: 15.5px; outline: none; }
.palette-list { max-height: min(420px, 60vh); overflow-y: auto; padding: 6px; }
.palette-group { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.palette-item .pi-ico { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; overflow: hidden; }
.palette-item .pi-ico svg { width: 15px; height: 15px; }
.palette-item .pi-ico img { width: 24px; height: 24px; image-rendering: pixelated; }
.palette-item .t { flex: 1; min-width: 0; }
.palette-item b { font-weight: 540; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item small { color: var(--faint); font-size: 12px; }
.palette-item[aria-selected="true"] { background: var(--accent-soft); }
.palette-item[aria-selected="true"] .pi-ico { color: var(--accent-text); }
.palette-foot { display: flex; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--border); color: var(--faint); font-size: 12px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: min(400px, 100%); padding: 32px 28px 28px; }
.login-card .brand { padding: 0 0 22px; justify-content: center; flex-direction: column; text-align: center; gap: 12px; }
.login-card .brand-mark { width: 48px; height: 48px; border-radius: 14px; }
.login-card .brand-mark svg { width: 26px; height: 26px; }
.login-card h1 { font-size: 20px; font-weight: 680; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-foot { text-align: center; color: var(--faint); font-size: 12px; margin-top: 18px; }
.login .theme-corner { position: fixed; top: 16px; right: 16px; }

/* ---------- Map ---------- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.map-wrap { position: relative; height: calc(100vh - 210px); min-height: 420px; border-radius: var(--radius-lg); overflow: hidden; background: var(--map-bg); border: 1px solid var(--border); touch-action: none; }
.map-wrap canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.map-wrap.dragging canvas { cursor: grabbing; }
.map-wrap.placing canvas { cursor: crosshair; }
.map-tools { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.map-tools > * { pointer-events: auto; }
.map-tools .spacer { flex: 1; pointer-events: none; }
.map-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.map-zoom button { width: 36px; height: 34px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.map-zoom button:hover { background: var(--surface-2); color: var(--text); }
.map-zoom button + button { border-top: 1px solid var(--border); }
.map-zoom svg { width: 16px; height: 16px; }
.map-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 8px 14px; border-radius: 99px; background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: 13px; box-shadow: var(--shadow-lg); white-space: nowrap; }
.map-tip { position: absolute; pointer-events: none; padding: 6px 9px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 550; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px)); box-shadow: var(--shadow-lg); }
.map-coords { position: absolute; left: 12px; bottom: 12px; padding: 4px 8px; border-radius: 7px; background: var(--surface); border: 1px solid var(--border); font: 12px var(--mono); color: var(--muted); }
.map-side { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 210px); min-height: 420px; }
.map-side .card { display: flex; flex-direction: column; min-height: 0; }
.map-side .list { overflow-y: auto; padding: 6px; }
.spawn-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 9px; cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; }
.spawn-item:hover { background: var(--surface-2); }
.spawn-item .t { flex: 1; min-width: 0; }
.spawn-item b { display: block; font-weight: 550; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spawn-item small { color: var(--faint); font-size: 11.5px; }
.spawn-item small.mono { font-family: var(--mono); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.legend i.safe { border-radius: 3px; background: rgba(60, 207, 142, 0.25); border: 1.5px solid #3ccf8e; }

/* ---------- Charts ---------- */
.bars { width: 100%; display: block; }
.bars text { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.bars text.val { fill: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.bars rect.bar { fill: var(--chart); }
.bars rect.track { fill: var(--surface-2); }

/* ---------- Players ---------- */
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.inv-slot { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; }
.inv-slot img { width: 36px; height: 36px; image-rendering: pixelated; }
.inv-slot .n { position: absolute; right: 4px; bottom: 2px; font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface); }
.inv-slot .slot-name { position: absolute; left: 0; right: 0; top: 3px; text-align: center; font-size: 9.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.inv-slot.named { padding-top: 12px; }
.inv-slot.named img { width: 30px; height: 30px; }
.inv-slot.empty { opacity: 0.6; }
.inv-slot.r-UNCOMMON { border-color: #4caf50; }
.inv-slot.r-RARE { border-color: #3d8bfd; }
.inv-slot.r-EPIC { border-color: #a66be0; }
.inv-slot.r-LEGENDARY { border-color: #f2b600; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pager { display: flex; align-items: center; gap: 6px; }

/* ---------- Calculator ---------- */
.calc-card .card-body { display: flex; flex-direction: column; gap: 14px; }
.calc-result { border-radius: 12px; background: var(--surface-2); padding: 14px; min-height: 92px; }
.calc-result .big { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.calc-result dl { display: grid; grid-template-columns: auto auto; gap: 4px 12px; margin: 10px 0 0; font-size: 13px; }
.calc-result dt { color: var(--muted); }
.calc-result dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.calc-note { font-size: 12px; color: var(--faint); margin-top: 8px; }

/* ---------- History ---------- */
.hist { display: flex; flex-direction: column; }
.hist-item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.hist-item:last-child { border-bottom: 0; }
.hist-item .ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.hist-item .ico svg { width: 17px; height: 17px; }
.hist-item .what b { font-weight: 600; }
.hist-item .meta { color: var(--faint); font-size: 12.5px; margin-top: 2px; }
.diff { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; font-size: 12.5px; }
.diff table { width: 100%; border-collapse: collapse; }
.diff th { text-align: left; font-weight: 600; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 10px; background: var(--surface-2); }
.diff td { padding: 6px 10px; border-top: 1px solid var(--border); font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.diff td.before { color: var(--danger); background: var(--danger-soft); }
.diff td.after { color: var(--ok); background: var(--ok-soft); }
.diff td.key { font-family: var(--font); font-weight: 550; color: var(--text); width: 30%; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-side { max-height: none; min-height: 0; }
  .map-side .list { max-height: 320px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 80; left: 0; top: 0; bottom: 0; width: min(290px, 86vw);
    transform: translateX(-104%); transition: transform 0.24s var(--ease); box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .topbar h1 { font-size: 17px; }
  .search-btn { min-width: 0; width: 36px; padding: 0; justify-content: center; }
  .search-btn span, .search-btn kbd { display: none; }
  .content { padding: 4px 16px calc(84px + env(safe-area-inset-bottom)); }
  .banner { padding: 10px 16px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border: 0; background: transparent;
    color: var(--faint); font-size: 10.5px; font-weight: 600; text-decoration: none; border-radius: 9px; cursor: pointer;
  }
  .bottom-nav svg { width: 20px; height: 20px; }
  .bottom-nav a[aria-current="page"] { color: var(--accent-text); }
  .toasts { left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
  .drawer, .drawer.wide { width: 100vw; }
  .map-wrap { height: 62vh; min-height: 340px; }
  .hide-sm { display: none; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 21px; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .row-edit, .row-head { grid-template-columns: minmax(0, 1fr) 76px 52px 52px 30px; gap: 6px; }
  .shop-row { grid-template-columns: 28px minmax(0, 1fr) 92px; }
  .shop-row .idx { display: none; }
  .shop-row .ctl { grid-column: 1 / -1; justify-content: flex-end; }
  .dt-toolbar .input-wrap { max-width: none; flex-basis: 100%; }
  .dt-toolbar .select { flex: 1; min-width: 0; }
  .hist-item { grid-template-columns: minmax(0, 1fr); }
  .hist-item .ico { display: none; }
  .dialog-body { flex-direction: column; }
  .page-head { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .skel { animation: none; }
}
