:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --ink: #17212b;
  --muted: #64717d;
  --navy: #15293d;
  --navy-soft: #223f5b;
  --blue: #176b87;
  --blue-dark: #0e5269;
  --paper: #ffffff;
  --canvas: #f1f4f6;
  --line: #dce3e8;
  --success: #247052;
  --warning: #9b6515;
  --danger: #a43838;
  --shadow: 0 18px 45px rgba(21, 41, 61, 0.08);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.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; }

.app-shell { min-height: 100vh; }
.topbar { min-height: 92px; padding: 20px clamp(20px, 4vw, 64px); color: white; background: var(--navy); display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.topbar h1 { margin: 0; font-size: clamp(1.45rem, 2vw, 2rem); letter-spacing: -0.02em; }
.eyebrow { margin: 0 0 5px; color: #7d8a96; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.topbar .eyebrow { color: #8fc5d8; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.connection-state { padding: 7px 11px; border: 1px solid rgba(255,255,255,0.22); border-radius: 999px; font-size: 0.82rem; }

.primary-nav { padding: 0 clamp(20px, 4vw, 64px); background: var(--paper); border-bottom: 1px solid var(--line); display: flex; gap: 4px; overflow-x: auto; }
.nav-item { appearance: none; padding: 17px 18px 14px; color: var(--muted); background: transparent; border: 0; border-bottom: 3px solid transparent; font-weight: 700; white-space: nowrap; }
.nav-item:hover, .nav-item:focus-visible { color: var(--navy); }
.nav-item.active { color: var(--blue-dark); border-bottom-color: var(--blue); }

main { width: min(1320px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 72px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { margin-bottom: 24px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.55rem); letter-spacing: -0.035em; }
.section-heading p:not(.eyebrow) { max-width: 720px; margin: 8px 0 0; color: var(--muted); }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.metric-card, .panel { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.metric-card { padding: 24px; display: grid; gap: 4px; }
.metric-card span { color: var(--muted); font-weight: 700; }
.metric-card strong { margin: 8px 0 2px; color: var(--navy); font-size: 2.4rem; }
.metric-card small { color: var(--muted); }
.panel { padding: clamp(18px, 3vw, 28px); }
.next-step-panel { margin-top: 22px; display: flex; align-items: center; justify-content: space-between; gap: 30px; }
.next-step-panel h3 { margin: 0; font-size: 1.4rem; }
.next-step-panel p:not(.eyebrow) { max-width: 750px; margin: 8px 0 0; color: var(--muted); }

.button { min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 750; transition: 140ms ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: 0.55; cursor: wait; transform: none; }
.button-primary { color: white; background: var(--blue); }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { color: var(--navy); background: white; border-color: #bac7d1; }
.button-quiet { min-height: 36px; color: white; background: transparent; border-color: rgba(255,255,255,0.3); }
.full-width { width: 100%; }

.toolbar { margin-bottom: 22px; display: flex; gap: 10px; }
.search-field { flex: 1; }
input, select, textarea { width: 100%; padding: 10px 12px; color: var(--ink); background: white; border: 1px solid #b9c6cf; border-radius: 9px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14); }
label { display: grid; gap: 7px; color: #394957; font-size: 0.88rem; font-weight: 720; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 14px; color: white; background: var(--navy-soft); text-align: left; font-size: 0.8rem; letter-spacing: 0.03em; }
th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }
td { padding: 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7f9fa; }
.code-cell { color: var(--blue-dark); font-family: "Cascadia Mono", Consolas, monospace; font-weight: 700; }
.status-pill { display: inline-flex; padding: 5px 9px; color: var(--success); background: #e7f4ee; border-radius: 999px; font-size: 0.76rem; font-weight: 800; }
.empty-state { margin: 26px 0 0; padding: 28px; color: var(--muted); background: #f7f9fa; border-radius: 12px; text-align: center; }

.scan-panel { margin-bottom: 18px; background: linear-gradient(135deg, white, #f1f8fa); }
.scan-form { max-width: 820px; }
.scan-form > div { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 8px; }
.scan-form input { min-height: 50px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 1.05rem; }
.device-title { display: flex; justify-content: space-between; gap: 20px; }
.device-title h3 { margin: 0; font-size: 1.55rem; }
.detail-grid { margin: 26px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.detail-grid div { padding: 15px; background: #f6f8fa; border-radius: 11px; }
.detail-grid dt { color: var(--muted); font-size: 0.76rem; font-weight: 800; text-transform: uppercase; }
.detail-grid dd { margin: 7px 0 0; overflow-wrap: anywhere; font-weight: 700; }
.move-form { padding: 20px; background: #eef4f6; border-radius: 13px; display: grid; grid-template-columns: 1fr 1fr 2fr auto; align-items: end; gap: 12px; }
.movement-section { margin-top: 28px; }
.movement-section h4 { margin-bottom: 14px; }
.movement-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.movement-list li { padding: 12px 14px; border-left: 3px solid var(--blue); background: #f7f9fa; }
.movement-list small { display: block; margin-top: 4px; color: var(--muted); }

.dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 32px 90px rgba(10, 28, 43, 0.28); }
.dialog::backdrop { background: rgba(13, 29, 43, 0.62); backdrop-filter: blur(3px); }
.dialog form { padding: 28px; }
.login-dialog { width: min(430px, calc(100% - 32px)); }
.login-dialog form { display: grid; gap: 16px; }
.login-dialog h2 { margin: 0; font-size: 2rem; }
.login-dialog p:not(.eyebrow):not(.form-error) { margin: -8px 0 4px; color: var(--muted); }
.dialog-heading { margin-bottom: 24px; display: flex; justify-content: space-between; gap: 18px; }
.dialog-heading h2 { margin: 0; }
.icon-button { width: 38px; height: 38px; color: var(--muted); background: #eef2f4; border: 0; border-radius: 50%; font-size: 1.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.wide-field { grid-column: 1 / -1; }
.dialog-actions { margin-top: 24px; display: flex; justify-content: end; gap: 10px; }
.form-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: 0.86rem; }
.message { margin-bottom: 22px; padding: 13px 16px; color: var(--navy); background: #dff0f5; border-left: 4px solid var(--blue); border-radius: 7px; }
.message.error { color: #752424; background: #fbe9e9; border-left-color: var(--danger); }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .move-form { grid-template-columns: 1fr 1fr; }
  .move-form .wide-field { grid-column: 1 / -1; }
  .move-form button { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  main { width: min(100% - 24px, 1320px); padding-top: 25px; }
  .topbar { min-height: 78px; padding: 15px 16px; }
  .connection-state { display: none; }
  .primary-nav { padding: 0 8px; }
  .section-heading, .next-step-panel { align-items: stretch; flex-direction: column; }
  .section-heading .button, .next-step-panel .button { width: 100%; }
  .form-grid, .detail-grid, .move-form { grid-template-columns: 1fr; }
  .wide-field, .move-form .wide-field, .move-form button { grid-column: auto; }
  .scan-form > div { grid-template-columns: 1fr; }
  .dialog form { padding: 22px 18px; }
}

