:root {
  color: #182126;
  background: #f4f6f7;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #182126;
  --muted: #68767c;
  --line: #dfe5e7;
  --surface: #ffffff;
  --soft: #f4f6f7;
  --accent: #137a62;
  --accent-dark: #0f624f;
  --accent-soft: #e6f3ef;
  --danger: #b43e45;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--soft); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(19, 122, 98, .22); outline-offset: 2px; }
.is-hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--accent-dark); font-size: 12px; font-weight: 750; text-transform: uppercase; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #eef4f2, #f8f9f9 60%); }
.auth-panel { width: min(100%, 420px); padding: 42px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 18px 60px rgba(24, 33, 38, .10); }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 28px; color: white; background: var(--accent); border-radius: 12px; }
.brand-mark svg { width: 27px; fill: currentColor; }
.brand-mark-small { width: 34px; height: 34px; margin: 0; border-radius: 8px; }
.brand-mark-small svg { width: 20px; }
.auth-panel h1 { margin: 0; font-size: 30px; letter-spacing: -.03em; }
.auth-copy { margin: 12px 0 28px; color: var(--muted); line-height: 1.55; }
.auth-form, #device-form { display: grid; gap: 10px; }
label { color: #354248; font-size: 13px; font-weight: 650; }
input, select { width: 100%; height: 42px; padding: 0 12px; color: var(--ink); background: var(--surface); border: 1px solid #cfd8db; border-radius: 7px; }
input:hover, select:hover { border-color: #9eabad; }
input:focus, select:focus { border-color: var(--accent); outline: 3px solid rgba(19, 122, 98, .12); }
.form-error { min-height: 18px; margin: 2px 0 0; color: var(--danger); font-size: 13px; }

.button { height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid transparent; border-radius: 7px; font-size: 14px; font-weight: 700; text-decoration: none; transition: background .15s, border-color .15s, color .15s; }
.button:disabled { cursor: wait; opacity: .6; }
.button-primary { color: white; background: var(--accent); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { color: #334147; background: var(--surface); border-color: #cfd8db; }
.button-secondary:hover { background: #f6f8f8; border-color: #aebabc; }
.button-full { width: 100%; margin-top: 10px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 16px; color: #dfe8e6; background: #172724; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; color: white; font-size: 15px; font-weight: 750; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 12px; color: #aebdb9; border-radius: 7px; text-decoration: none; font-size: 14px; font-weight: 650; }
.nav-item svg { width: 19px; fill: currentColor; }
.nav-item:hover { color: white; background: rgba(255, 255, 255, .06); }
.nav-item.is-active { color: white; background: rgba(85, 199, 166, .14); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 12px; color: #92a49f; font-size: 12px; }
.privacy-dot { width: 7px; height: 7px; background: #57c7a7; border-radius: 50%; box-shadow: 0 0 0 4px rgba(87, 199, 167, .12); }

.main-content { width: min(100%, 1440px); padding: 34px 40px 64px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: 28px; letter-spacing: -.03em; }
.page-header .muted { margin: 7px 0 0; font-size: 13px; }
.header-actions { display: flex; gap: 8px; }
.alert { margin-bottom: 16px; padding: 12px 14px; color: #812e34; background: #fbecee; border: 1px solid #f0c6ca; border-radius: 7px; font-size: 14px; }

.filters { display: flex; align-items: end; gap: 10px; margin-bottom: 16px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; }
.filters label { width: 190px; display: grid; gap: 6px; }
.filters label:nth-child(2) { width: 230px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; }
.kpi { min-width: 0; padding: 20px 22px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi > span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 650; }
.kpi strong { display: block; overflow: hidden; color: #1e2d31; font-size: 25px; letter-spacing: -.03em; text-overflow: ellipsis; white-space: nowrap; }
.kpi .kpi-domain { font-size: 20px; }
.kpi small { display: block; margin-top: 8px; color: #899397; font-size: 11px; }

.panel { margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.panel-heading { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-size: 17px; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.count-badge { min-width: 30px; height: 26px; display: grid; place-items: center; padding: 0 9px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 20px; font-size: 12px; font-weight: 750; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { height: 42px; padding: 0 20px; color: #7a878b; background: #fafbfb; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; }
td { height: 56px; padding: 8px 20px; border-bottom: 1px solid #edf0f1; color: #465359; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
td strong { color: #253238; font-weight: 700; }
td small { display: block; margin-top: 4px; color: #8c979b; font-size: 11px; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table-state { height: 130px; color: var(--muted); text-align: center; }
.table-state strong, .table-state span { display: block; }
.table-state span { margin-top: 7px; color: #929ca0; font-size: 12px; }
.spinner { width: 16px; height: 16px; display: inline-block !important; margin: 0 auto 10px !important; border: 2px solid #d7dfdf; border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 650; }
.status i { width: 7px; height: 7px; border-radius: 50%; }
.status-online { color: #176b57; }
.status-online i { background: #36a884; box-shadow: 0 0 0 3px #e1f2ed; }
.status-neutral { color: #748085; }
.status-neutral i { background: #aeb7ba; }
.tabs { display: flex; padding: 3px; background: #eef2f2; border-radius: 7px; }
.tab { height: 30px; padding: 0 14px; color: #68767b; background: transparent; border: 0; border-radius: 5px; font-size: 12px; font-weight: 700; }
.tab.is-active { color: #27353a; background: white; box-shadow: 0 1px 3px rgba(24, 33, 38, .10); }
.usage-bar { width: 130px; height: 6px; appearance: none; border: 0; border-radius: 10px; overflow: hidden; }
.usage-bar::-webkit-progress-bar { background: #e8eded; border-radius: 10px; }
.usage-bar::-webkit-progress-value { background: #51ab91; border-radius: 10px; }
.usage-bar::-moz-progress-bar { background: #51ab91; border-radius: 10px; }

dialog { width: min(92vw, 480px); padding: 0; color: var(--ink); background: var(--surface); border: 0; border-radius: 12px; box-shadow: 0 22px 80px rgba(13, 25, 23, .25); }
dialog::backdrop { background: rgba(16, 28, 26, .48); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 21px; }
.icon-button { width: 34px; height: 34px; color: #758186; background: transparent; border: 0; border-radius: 6px; font-size: 26px; line-height: 1; }
.icon-button:hover { background: var(--soft); }
#device-form { padding: 24px 26px 26px; }
.field-hint { margin: 0; color: var(--muted); font-size: 12px; }
.token-row { display: flex; gap: 8px; }
.token-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.success-mark { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 12px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 50%; font-size: 22px; font-weight: 800; }
#device-token-step h3 { margin: 0 0 8px; }
#device-token-step .muted { margin: 0 0 20px; font-size: 13px; line-height: 1.5; }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(2) { border-right: 0; }
  .kpi:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: 1fr auto; padding: 12px 16px; }
  .sidebar-brand { padding: 0; }
  .sidebar nav { display: flex; }
  .nav-item { width: 42px; padding: 0; justify-content: center; font-size: 0; }
  .sidebar-footer { display: none; }
  .main-content { padding: 24px 16px 48px; }
  .page-header { display: grid; }
  .header-actions { width: 100%; flex-wrap: wrap; }
  .header-actions .button { flex: 1; min-height: 44px; height: auto; padding-top: 7px; padding-bottom: 7px; line-height: 1.25; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters label, .filters label:nth-child(2) { width: auto; }
  .filters .button { grid-column: 1 / -1; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 16px; }
  .kpi strong { font-size: 21px; }
  .kpi .kpi-domain { font-size: 16px; }
  .panel-heading { align-items: flex-start; }
  .tabs-heading { display: grid; }
  th, td { padding-left: 14px; padding-right: 14px; }
  .auth-panel { padding: 30px 24px; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi, .kpi:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .kpi:last-child { border-bottom: 0; }
  .filters { grid-template-columns: 1fr; }
  .filters .button { grid-column: auto; }
  .token-row { display: grid; }
}
