:root {
  --paper: #f6f1e8;
  --paper-2: #fffaf2;
  --ink: #312b25;
  --muted: #85796d;
  --line: #e7dccd;
  --orange: #e98748;
  --orange-dark: #c9662d;
  --green: #3f8b6b;
  --red: #b45249;
  --shadow: 0 18px 50px rgba(85, 59, 34, .10);
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0, #fff8e8, var(--paper) 62%); }
.login-card { width: min(430px, 100%); background: rgba(255,250,242,.96); border: 1px solid var(--line); border-radius: 28px; padding: 42px; box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 20px; border-radius: 18px; color: white; background: var(--orange); font-size: 34px; font-weight: 700; }
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 13px; font-size: 24px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; letter-spacing: -.03em; }
h2 { margin-bottom: 0; font-size: 20px; }
.eyebrow { margin-bottom: 6px; color: var(--orange-dark); font-size: 11px; font-weight: 800; letter-spacing: .15em; }
.muted { color: var(--muted); }
.compact { font-size: 12px; }
label { display: grid; gap: 7px; margin-top: 18px; color: #665b50; font-size: 13px; font-weight: 650; }
input, select { width: 100%; min-height: 44px; padding: 0 13px; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 12px; outline: none; }
input:focus, select:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(233,135,72,.13); }
button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 11px; font-weight: 700; }
.primary { color: white; background: var(--orange); box-shadow: 0 8px 20px rgba(233,135,72,.20); }
.primary:hover { background: var(--orange-dark); }
.wide { width: 100%; margin-top: 24px; }
.ghost { color: var(--ink); background: #fffaf2; border: 1px solid var(--line); }
.danger-text { color: var(--red); }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: 13px; }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 18px; background: #312b25; color: white; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: .07em; }
.brand span { margin-top: 3px; color: #cfc4b8; font-size: 12px; }
nav { display: grid; gap: 7px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; color: #d8cec4; background: transparent; text-align: left; }
.nav-item span { width: 20px; font-size: 18px; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.10); }
.sidebar-foot { display: grid; grid-template-columns: 10px 1fr; align-items: center; gap: 8px; margin-top: auto; padding: 16px 10px 0; border-top: 1px solid rgba(255,255,255,.12); color: #d8cec4; font-size: 12px; }
.sidebar-foot small { grid-column: 1/-1; color: #978b7f; line-height: 1.5; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #69c996; box-shadow: 0 0 0 4px rgba(105,201,150,.13); }
main { min-width: 0; padding: 30px 36px 50px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.stats-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card, .panel { background: var(--paper-2); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(85,59,34,.05); }
.stat-card { padding: 22px; border-radius: 18px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 10px; font-size: 30px; letter-spacing: -.04em; }
.stat-card small { color: var(--muted); }
.panel { margin-bottom: 18px; padding: 22px; border-radius: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-actions { display: flex; align-items: center; gap: 12px; }
.trend-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.chart-panel { min-width: 0; }
.chart-canvas { min-height: 260px; overflow: hidden; }
.chart-canvas svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: #eadfd1; stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 11px; }
.chart-area { fill: rgba(233,135,72,.13); }
.chart-line { fill: none; stroke: var(--orange); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { fill: var(--paper-2); stroke: var(--orange); stroke-width: 2; }
.chart-bar { fill: #eaa06f; rx: 5; }
.chart-bar.current { fill: var(--orange); }
.map-toggle { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: white; }
.map-toggle button { min-height: 32px; padding: 0 12px; color: var(--muted); background: transparent; border-radius: 8px; font-size: 12px; }
.map-toggle button.active { color: white; background: var(--orange); box-shadow: 0 5px 12px rgba(233,135,72,.18); }
.region-layout { display: grid; grid-template-columns: minmax(0,2fr) minmax(240px,.75fr); gap: 18px; align-items: stretch; }
.region-map { min-height: 360px; display: grid; place-items: center; padding: 12px; overflow: hidden; background: #fbf4e8; border: 1px solid var(--line); border-radius: 16px; }
.region-map svg { display: block; width: 100%; height: auto; }
.map-ocean { fill: #fbf4e8; }
.map-grid-line { stroke: #eadfd1; stroke-width: 1; stroke-dasharray: 4 6; vector-effect: non-scaling-stroke; }
.map-shape { fill: #e4d9c8; fill-rule: evenodd; stroke: #fffaf2; stroke-width: .8; vector-effect: non-scaling-stroke; transition: fill .18s, fill-opacity .18s, stroke-width .18s; }
.map-shape.has-data { fill: var(--orange); fill-opacity: var(--map-intensity,.72); cursor: pointer; outline: none; }
.map-shape.has-data:hover, .map-shape.has-data:focus, .map-shape.has-data.selected { fill: var(--orange-dark); fill-opacity: .95; stroke: white; stroke-width: 1.6; }
.map-region { cursor: pointer; outline: none; }
.map-region circle { fill: rgba(233,135,72,.62); stroke: #fffaf2; stroke-width: 2.4; transition: .18s; vector-effect: non-scaling-stroke; }
.map-region:hover circle, .map-region:focus circle, .map-region.selected circle { fill: var(--orange-dark); stroke: white; stroke-width: 3.5; }
.map-region text { fill: var(--ink); font-size: 11px; font-weight: 800; paint-order: stroke; stroke: #fffaf2; stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.map-note { fill: var(--muted); font-size: 12px; }
.map-source { margin: 8px 4px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.map-source a { color: var(--orange-dark); text-underline-offset: 2px; }
.region-ranking { min-height: 360px; padding: 16px; background: white; border: 1px solid var(--line); border-radius: 16px; }
.ranking-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ranking-head strong { font-size: 14px; }
.ranking-head span { color: var(--muted); font-size: 11px; }
.ranking-list { display: grid; gap: 6px; }
.ranking-row { display: grid; grid-template-columns: 24px minmax(0,1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 43px; padding: 6px 8px; color: var(--ink); background: transparent; border-radius: 10px; text-align: left; }
.ranking-row:hover, .ranking-row.selected { background: #fff2df; }
.ranking-index { display: grid; place-items: center; width: 22px; height: 22px; color: var(--orange-dark); background: #fbe8d9; border-radius: 7px; font-size: 10px; }
.ranking-label { min-width: 0; }
.ranking-label strong, .ranking-label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-label strong { font-size: 12px; }
.ranking-label small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.ranking-count { font-size: 15px; }
.region-table { margin-top: 18px; padding-top: 4px; border-top: 1px solid var(--line); }
.two-column { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; }
.link-button { padding: 0; color: var(--orange-dark); background: transparent; }
.status-pill, .stage-pill, .oss-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 99px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-pill.active, .status-pill.published, .status-pill.activated { color: #226949; background: #dff3e8; }
.status-pill.draft, .status-pill.pending { color: #90602c; background: #f7ead3; }
.status-pill.closed, .status-pill.withdrawn { color: #756b62; background: #ebe6df; }
.stage-pill { color: #9a592d; background: #fbe8d9; }
.stage-pill.stage-A { color: #226949; background: #dff3e8; }
.oss-badge { color: #2e765b; background: #e0f2e8; }
.active-lot { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.active-lot:first-child { border-top: 0; }
.active-lot strong, .active-lot span { display: block; }
.active-lot span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.metric { text-align: right; }
.metric strong { font-size: 20px; }
.firmware-hero { display: grid; gap: 12px; }
.firmware-version { font-size: 30px; font-weight: 800; letter-spacing: -.04em; }
.firmware-meta { display: flex; flex-wrap: wrap; gap: 7px; }
.hash { display: block; max-width: 280px; overflow: hidden; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 12px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 11px; letter-spacing: .06em; text-align: left; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #eee5d9; vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fff5e8; }
.device-id { color: var(--ink); font: 700 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.filters { display: flex; align-items: center; gap: 8px; }
.filters input { width: 230px; }
.filters select { width: auto; min-width: 112px; }
.small-button { min-height: 44px; }
.list-meta { margin: -4px 0 10px; color: var(--muted); font-size: 12px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.batch-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; }
.batch-card { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.batch-card.active { border-color: #8fc5aa; box-shadow: inset 0 0 0 1px #8fc5aa; }
.batch-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.batch-title strong { font-size: 18px; }
.batch-info { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin: 18px 0; }
.batch-info span { display: block; color: var(--muted); font-size: 11px; }
.batch-info strong { display: block; margin-top: 5px; font-size: 14px; }
.batch-actions { display: flex; justify-content: flex-end; }
.callout { margin-bottom: 18px; padding: 12px 14px; color: #76593e; background: #fff2df; border: 1px solid #f1d8b6; border-radius: 12px; font-size: 12px; line-height: 1.6; }
dialog { width: min(620px,calc(100% - 30px)); padding: 24px; color: var(--ink); background: var(--paper-2); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
#deviceDialog { width: min(1040px,calc(100% - 30px)); max-height: calc(100vh - 40px); overflow: auto; }
dialog::backdrop { background: rgba(37,31,25,.48); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.icon-button { width: 34px; min-height: 34px; padding: 0; color: var(--muted); background: transparent; font-size: 25px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.full { grid-column: 1/-1; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: 18px; min-height: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.detail-item { padding: 13px; background: white; border: 1px solid var(--line); border-radius: 12px; }
.detail-item span { display: block; color: var(--muted); font-size: 11px; }
.detail-item strong { display: block; margin-top: 6px; font-size: 13px; overflow-wrap: anywhere; }
.detail-item small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.detail-item.full { grid-column: 1/-1; }
.session-history { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.session-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.session-head span { color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 360px; padding: 13px 16px; color: white; background: #312b25; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 76px minmax(0,1fr); }
  .sidebar { padding-inline: 10px; }
  .brand > div:last-child, .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item span { width: auto; }
  .sidebar-foot span:not(.live-dot), .sidebar-foot small { display: none; }
  .sidebar-foot { display: flex; justify-content: center; }
  main { padding: 25px 22px 40px; }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .trend-grid, .two-column, .batch-grid, .region-layout { grid-template-columns: 1fr; }
  .region-ranking { min-height: auto; }
  .responsive { align-items: stretch; flex-direction: column; }
  .filters { flex-wrap: wrap; }
}
@media (max-width: 620px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 5; top: auto; bottom: 0; width: 100%; height: 68px; padding: 8px; }
  .brand, .sidebar-foot { display: none; }
  nav { display: grid; grid-template-columns: repeat(4,1fr); }
  .nav-item, .nav-item:not(.active) { display: grid; place-items: center; gap: 2px; font-size: 10px; }
  .nav-item span { font-size: 18px; }
  main { padding: 20px 14px 90px; }
  .topbar { align-items: start; }
  .top-actions .compact { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 17px; }
  .stat-card strong { font-size: 25px; }
  .panel { padding: 16px; border-radius: 16px; }
  .panel-head { align-items: flex-start; }
  .panel-actions { width: 100%; align-items: flex-start; flex-direction: column; }
  .chart-canvas { min-height: 210px; margin-inline: -8px; }
  .region-map { min-height: 245px; padding: 4px; }
  .ranking-list { grid-template-columns: 1fr 1fr; }
  .filters input, .filters select { width: 100%; }
  .filters button { width: 100%; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .detail-item.full, .full { grid-column: auto; }
}
