:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #697785;
  --line: #dce2e8;
  --line-strong: #c8d0d8;
  --sidebar: #20262d;
  --sidebar-muted: #9ea8b2;
  --accent: #237a57;
  --accent-dark: #185c40;
  --blue: #276ca9;
  --warning: #a86516;
  --danger: #b23b3b;
  --shadow: 0 14px 40px rgba(28, 40, 51, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-width: 320px; background: var(--bg); }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef1f4;
}

.login-panel {
  width: min(100%, 390px);
  padding: 34px 36px 38px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.brand-lockup, .sidebar-brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 5px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 18px;
}
.brand-lockup h1 { margin: 0; font-size: 21px; line-height: 1.2; }
.brand-lockup p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 18px; margin-top: 30px; }
.login-form label { display: grid; gap: 7px; color: #394652; font-size: 13px; font-weight: 600; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(35, 122, 87, 0.12); }
.button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 650;
}
.button-primary { background: var(--accent); color: white; }
.button-primary:hover { background: var(--accent-dark); }
.button:disabled { cursor: not-allowed; opacity: 0.5; }
.button-secondary { background: white; border-color: var(--line-strong); color: #33404c; }
.button-secondary:hover { border-color: #8f9ba6; }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover { background: #edf0f2; color: var(--ink); }
.login-button { margin-top: 2px; min-height: 42px; }
.form-error { min-height: 18px; margin: -7px 0 0; color: var(--danger); font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 226px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px 18px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: white;
}
.sidebar-brand { padding: 0 8px 22px; border-bottom: 1px solid rgba(255, 255, 255, 0.09); }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand div > span { margin-top: 2px; color: var(--sidebar-muted); font-size: 11px; text-transform: uppercase; }
.main-nav { display: grid; gap: 4px; margin-top: 20px; overflow-y: auto; scrollbar-width: thin; }
.main-nav button {
  height: 40px;
  padding: 0 13px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #c7cdd3;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
}
.main-nav button:hover { background: rgba(255, 255, 255, 0.06); color: white; }
.main-nav button.active { background: #303a43; color: white; box-shadow: inset 3px 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: grid; gap: 7px; padding: 14px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.09); color: var(--sidebar-muted); font-size: 11px; }
.connection-state { display: flex; align-items: center; gap: 7px; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.connection-state.connected i { background: #4dc68b; }
.connection-state.disconnected i { background: #dd6f6f; }

.workspace { min-width: 0; }
.topbar {
  min-height: 82px;
  padding: 17px clamp(20px, 3vw, 38px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: white;
  border-bottom: 1px solid var(--line);
}
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 9px; font-weight: 750; }
.topbar h2 { margin: 0; font-size: 20px; line-height: 1.25; }
.user-tools { display: flex; align-items: center; gap: 9px; }
#current-user { margin-right: 4px; color: #4b5966; font-size: 13px; font-weight: 600; }
.content { padding: 28px clamp(20px, 3vw, 38px) 48px; }
.view { display: none; }
.view.active-view { display: block; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  overflow: hidden;
}
.metric { min-width: 0; min-height: 125px; padding: 20px 22px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.metric strong { display: block; margin: 8px 0 4px; font-size: 31px; line-height: 1; }
.metric small { color: #8a969f; font-size: 11px; }
.metric-online strong { color: var(--accent); }
.metric-alert strong { color: var(--danger); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr); gap: 22px; margin-top: 22px; }

.data-section { background: white; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.section-heading { min-height: 66px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.section-heading h3 { margin: 0; font-size: 14px; }
.section-heading span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.text-button { border: 0; background: transparent; color: var(--blue); font-size: 12px; font-weight: 650; }
.text-button:hover { text-decoration: underline; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 40px; padding: 0 14px; color: #64717d; background: #f7f8f9; font-size: 10px; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { height: 52px; padding: 9px 14px; border-top: 1px solid #edf0f2; vertical-align: middle; }
tbody tr:hover { background: #fafbfb; }
.compact-table td { height: 49px; }
.primary-cell { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; color: #26323d; }
.secondary-cell { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10px; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.badge-online, .badge-completed { color: #176441; background: #e7f5ee; }
.badge-offline { color: #69747e; background: #edf0f2; }
.badge-queued, .badge-dispatched { color: #8a5615; background: #fbf0df; }
.badge-failed { color: #982f2f; background: #fae8e8; }
.row-action { min-height: 30px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: white; color: #34414c; font-size: 11px; }
.row-action:hover { border-color: var(--accent); color: var(--accent); }
.row-actions { display: flex; align-items: center; gap: 6px; }
.empty-cell { height: 130px; text-align: center; color: var(--muted); }

.activity-list { min-height: 280px; margin: 0; padding: 8px 18px 12px; list-style: none; }
.activity-list li { position: relative; padding: 12px 0 12px 20px; border-bottom: 1px solid #edf0f2; }
.activity-list li:last-child { border-bottom: 0; }
.activity-list li::before { content: ""; position: absolute; top: 18px; left: 1px; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.activity-list strong { display: block; font-size: 11px; }
.activity-list span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

.section-toolbar { margin-bottom: 14px; display: flex; align-items: end; justify-content: space-between; gap: 18px; }
.filter-group { width: min(100%, 340px); }
.filter-group label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 650; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 5px; background: #e9edf0; }
.segmented button { min-width: 56px; height: 30px; border: 0; border-radius: 3px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 650; }
.segmented button.active { background: white; color: var(--ink); box-shadow: 0 1px 3px rgba(24, 35, 44, 0.12); }
.adb-panel { margin-bottom: 14px; }
.adb-pair-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(130px, 0.55fr) auto;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.adb-pair-form label { display: grid; gap: 6px; color: #4f5d68; font-size: 11px; font-weight: 650; }
.adb-pair-form .button { height: 40px; white-space: nowrap; }
.adb-pair-form .form-error { grid-column: 1 / -1; margin: 0; min-height: 0; }
.adb-device-list { display: grid; }
.adb-device-row { min-height: 58px; padding: 10px 16px; display: grid; grid-template-columns: minmax(0, 1fr) 110px 100px; align-items: center; gap: 12px; border-top: 1px solid var(--line); font-size: 11px; }
.adb-device-row:first-child { border-top: 0; }
.adb-device-row strong, .adb-device-row span { overflow-wrap: anywhere; }
.adb-device-empty { min-height: 72px; padding: 22px 16px; color: var(--muted); font-size: 11px; text-align: center; }
.error-text { color: var(--danger); }

.split-layout { display: grid; grid-template-columns: minmax(280px, 0.62fr) minmax(0, 1.38fr); gap: 20px; align-items: start; }
.form-section { overflow: visible; }
.stack-form { display: grid; gap: 14px; padding: 18px; }
.build-primary-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.build-primary-actions .button { display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.stack-form label, .config-body label { display: grid; gap: 6px; color: #4f5d68; font-size: 11px; font-weight: 650; }
.stack-form select, .config-body select { width: 100%; height: 40px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 4px; background: white; color: var(--ink); outline: none; }
.config-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.asset-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.asset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 18px; }
.asset-item { min-height: 76px; padding: 12px; display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 5px; }
.asset-item strong, .asset-item small { display: block; overflow-wrap: anywhere; }
.asset-item strong { font-size: 12px; }
.asset-item small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.asset-swatch, .asset-splash-preview { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 5px; color: white; font-size: 14px; font-weight: 800; }
.asset-splash-preview { background: #eef1f4; border: 1px solid var(--line-strong); }
.asset-empty { padding: 28px; color: var(--muted); font-size: 11px; text-align: center; }
.config-body { display: grid; gap: 15px; padding: 18px; }
.check-row { min-height: 36px; display: flex !important; align-items: center; gap: 9px !important; }
.check-row input { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }

.drawer { position: fixed; inset: 0; z-index: 20; display: none; }
.drawer.open { display: block; }
.drawer-scrim { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(23, 32, 42, 0.36); }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(100%, 470px); height: 100%; background: white; box-shadow: -14px 0 40px rgba(20, 30, 38, 0.16); overflow: auto; }
.drawer-header { position: sticky; top: 0; z-index: 1; min-height: 78px; padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; background: white; border-bottom: 1px solid var(--line); }
.drawer-header p { margin: 0 0 4px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.drawer-header h3 { margin: 0; font-size: 18px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 4px; background: white; color: var(--muted); font-size: 24px; line-height: 1; }
.icon-button:hover { color: var(--ink); border-color: var(--line-strong); }
.drawer-content { padding: 20px; }
.share-dialog { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; }
.share-scrim { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(23, 32, 42, 0.42); }
.share-panel { position: relative; width: min(100%, 420px); max-height: calc(100vh - 36px); overflow: auto; background: white; border-radius: 6px; box-shadow: 0 18px 50px rgba(20, 30, 38, 0.2); }
.share-header { min-height: 64px; padding: 14px 16px 14px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.share-header h3 { margin: 0; font-size: 16px; }
.share-body { display: grid; justify-items: center; gap: 16px; padding: 22px; }
.share-qr { width: min(240px, 100%); height: auto; aspect-ratio: 1; border: 1px solid var(--line); background: white; image-rendering: pixelated; }
.share-url-label { width: 100%; display: grid; gap: 6px; color: #4f5d68; font-size: 11px; font-weight: 650; }
.share-url-label input { width: 100%; font-family: var(--mono); font-size: 11px; }
.share-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.unavailable-screen, .real-screen {
  position: relative;
  width: min(100%, 280px);
  aspect-ratio: 9 / 16;
  margin: 0 auto 20px;
  border: 1px solid #12171c;
  border-radius: 6px;
  overflow: hidden;
  background: #27313a;
  color: white;
}
.unavailable-screen { display: grid; place-items: center; align-content: center; gap: 7px; }
.unavailable-screen strong { max-width: 80%; text-align: center; font-size: 16px; }
.screen-status { position: absolute; top: 0; left: 0; right: 0; height: 32px; padding: 0 10px; display: flex; align-items: center; justify-content: space-between; background: rgba(10, 14, 17, 0.35); font-size: 9px; }
.real-screen img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #090b0d;
  cursor: crosshair;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
}
.screen-actions { width: min(100%, 280px); margin: -10px auto 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.screen-actions button { min-height: 32px; border: 1px solid var(--line-strong); border-radius: 4px; background: white; color: #34414c; font-size: 10px; }
.device-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 5px; }
.summary-item { min-height: 70px; padding: 13px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-item:nth-child(2n) { border-right: 0; }
.summary-item:nth-last-child(-n + 2) { border-bottom: 0; }
.summary-item span { display: block; color: var(--muted); font-size: 10px; }
.summary-item strong { display: block; margin-top: 7px; overflow-wrap: anywhere; font-size: 12px; }
.drawer-section { margin-top: 24px; }
.drawer-section h4 { margin: 0 0 10px; font-size: 12px; }
.command-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.command-group { margin-top: 14px; }
.command-group:first-child { margin-top: 0; }
.command-group h5 { margin: 0 0 7px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.command-button { min-height: 44px; padding: 7px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line-strong); border-radius: 4px; background: #f8f9fa; color: #34414c; font-size: 11px; font-weight: 650; text-align: left; }
.command-button span { min-width: 0; overflow-wrap: anywhere; }
.command-button small { flex: 0 0 auto; color: var(--muted); font-size: 8px; font-weight: 750; }
.command-button:hover { border-color: var(--accent); color: var(--accent); background: #f3faf7; }
.command-button:disabled { cursor: not-allowed; opacity: 0.5; }
.inventory-table { width: 100%; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.inventory-row { display: grid; grid-template-columns: 140px minmax(0, 1fr); border-top: 1px solid var(--line); }
.inventory-row:first-child { border-top: 0; }
.inventory-row span, .inventory-row strong { padding: 9px 11px; font-size: 10px; overflow-wrap: anywhere; }
.inventory-row span { color: var(--muted); background: #f7f8f9; }
.drawer-form { display: grid; gap: 9px; }
.drawer-form textarea { width: 100%; min-height: 88px; padding: 9px 11px; resize: vertical; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); font: inherit; font-size: 11px; outline: none; }
.drawer-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(35, 122, 87, 0.12); }
.inline-drawer-form { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.inline-drawer-form .check-row { min-height: 40px; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; max-width: min(360px, calc(100vw - 44px)); padding: 11px 14px; border-radius: 4px; background: #24313a; color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 150ms, transform 150ms; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8f3030; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 188px minmax(0, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .activity-list { min-height: 0; }
  .metric { padding: 18px; }
  .split-layout { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr 1fr; }
  .asset-grid { grid-template-columns: 1fr; }
  .adb-pair-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { display: block; padding-top: 112px; }
  .sidebar { position: fixed; z-index: 10; width: 100%; height: 112px; padding: 10px 14px; display: block; }
  .sidebar-brand { height: 43px; padding: 0 2px 8px; border: 0; }
  .sidebar-brand .brand-mark { width: 30px; height: 30px; }
  .sidebar-brand div > span { display: none; }
  .main-nav { display: flex; gap: 3px; margin: 0; overflow-x: auto; overflow-y: hidden; }
  .main-nav button { min-width: 70px; height: 38px; padding: 0 8px; text-align: center; flex: 0 0 auto; }
  .main-nav button.active { box-shadow: inset 0 -3px var(--accent); }
  .sidebar-foot { display: none; }
  .topbar { min-height: 76px; padding: 13px 16px; align-items: flex-start; }
  .eyebrow, #current-user { display: none; }
  .topbar h2 { margin-top: 8px; font-size: 17px; }
  .user-tools { gap: 5px; }
  .button { min-height: 34px; padding: 0 10px; }
  .content { padding: 18px 14px 34px; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 104px; border-bottom: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n + 2) { border-bottom: 0; }
  .metric strong { font-size: 26px; }
  .section-toolbar { align-items: stretch; flex-direction: column; }
  .filter-group { width: 100%; }
  .segmented { align-self: flex-start; }
  .adb-device-row { grid-template-columns: 1fr; gap: 5px; }
  .adb-pair-form { grid-template-columns: minmax(0, 1fr); }
  .adb-pair-form .form-error { grid-column: 1; }
  .drawer-panel { width: 100%; }
  .share-dialog { padding: 12px; }
  .share-panel { max-height: calc(100vh - 24px); }
  .share-actions { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr; }
  .asset-layout { grid-template-columns: 1fr; }
}

@media (max-width: 440px) {
  .login-panel { padding: 28px 22px 31px; }
  .topbar .button-secondary { display: none; }
  .device-summary { grid-template-columns: 1fr; }
  .summary-item { border-right: 0; }
  .summary-item:nth-last-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .summary-item:last-child { border-bottom: 0; }
  .inventory-row { grid-template-columns: 105px minmax(0, 1fr); }
}
