:root {
  color-scheme: light;
  --ink: #17221d;
  --muted: #6c7971;
  --line: #d8e0db;
  --paper: #f6f8f5;
  --surface: #ffffff;
  --accent: #1c8b59;
  --accent-dark: #0d6039;
  --accent-soft: #e0f2e8;
  --danger: #b74842;
  --shadow: 0 22px 50px rgba(26, 47, 35, .08);
  font-family: Inter, "Segoe UI", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.shell { max-width: 1320px; margin: 0 auto; padding: 34px 28px 54px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; font-size: 11px; letter-spacing: .12em; font-weight: 800; color: var(--accent-dark); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.02em; }
h2 { margin-bottom: 0; font-size: 21px; }
.server-status { display: inline-flex; align-items: center; gap: 8px; padding: 10px 13px; color: var(--muted); font-size: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ba69e; }
.server-status.online .status-dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.login-panel, .workspace { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-panel { display: flex; align-items: center; justify-content: space-between; gap: 28px; padding: 26px 28px; border-radius: 10px; }
.login-panel p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.inline-form { display: flex; gap: 10px; align-items: center; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 11px 12px; color: var(--ink); background: #fcfdfc; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button { border: 0; border-radius: 6px; padding: 11px 16px; font-weight: 700; white-space: nowrap; }
button.primary { color: #fff; background: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.secondary { color: var(--accent-dark); background: var(--accent-soft); }
button.danger { color: var(--danger); background: #fbeceb; }
.form-error { min-height: 18px; color: var(--danger); font-size: 13px; }
.login-panel .form-error { position: absolute; margin-top: 76px; }
.workspace { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 690px; border-radius: 10px; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; padding: 24px 18px; background: #f1f5f1; border-right: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2 { font-size: 20px; }
.icon-button { width: 38px; height: 38px; padding: 0; color: var(--accent-dark); font-size: 22px; background: var(--surface); border: 1px solid var(--line); }
.device-list { display: grid; gap: 8px; margin: 22px 0; }
.device-item { width: 100%; padding: 13px 14px; text-align: left; color: var(--ink); background: transparent; border: 1px solid transparent; border-radius: 7px; }
.device-item:hover { background: var(--surface); }
.device-item.selected { background: var(--surface); border-color: #abd9bc; box-shadow: 0 6px 16px rgba(26, 47, 35, .06); }
.device-item strong, .device-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-item strong { margin-bottom: 5px; font-size: 14px; }
.device-item small { color: var(--muted); font-size: 11px; }
.new-device-form { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); }
.new-device-form label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 800; }
.new-device-form .inline-form { align-items: stretch; }
.new-device-form button { padding: 10px 13px; }
.content { min-width: 0; padding: 34px 38px; }
.empty-state { display: grid; place-items: center; align-content: center; min-height: 610px; text-align: center; }
.empty-state p { max-width: 390px; margin: 12px 0 0; color: var(--muted); line-height: 1.7; font-size: 14px; }
.empty-mark { display: grid; place-items: center; width: 66px; height: 66px; margin-bottom: 18px; color: var(--accent); font-size: 36px; background: var(--accent-soft); border-radius: 50%; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.detail-header h2 { font-size: 29px; }
.muted { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 24px 0 30px; }
.metric { padding: 17px; background: #f7faf7; border: 1px solid var(--line); border-radius: 7px; }
.metric span, .metric strong { display: block; }
.metric span { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.metric strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.policy-form { max-width: 850px; }
.form-heading { margin-bottom: 19px; }
.policy-switches { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.switch-label { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; cursor: pointer; }
.switch-label input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { position: relative; width: 38px; height: 22px; background: #cbd4ce; border-radius: 999px; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch-label input:checked + .switch { background: var(--accent); }
.switch-label input:checked + .switch::after { transform: translateX(16px); }
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 22px; }
.mode-option { display: flex; align-items: flex-start; gap: 11px; padding: 15px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; }
.mode-option:has(input:checked) { border-color: #8bcba3; background: #f3fbf5; }
.mode-option input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.mode-option strong, .mode-option small { display: block; }
.mode-option strong { margin-bottom: 5px; font-size: 14px; }
.mode-option small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.field-label { display: block; margin-bottom: 18px; font-size: 13px; font-weight: 800; }
.field-label span { margin-left: 8px; color: var(--muted); font-size: 11px; font-weight: 400; }
.field-label textarea, .field-label input { display: block; margin-top: 8px; font-weight: 400; }
.two-columns { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 14px; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 8px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 5; max-width: 360px; padding: 13px 17px; color: #fff; background: #1e3026; border-radius: 6px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.token-dialog { width: min(460px, calc(100% - 32px)); padding: 28px; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.token-dialog::backdrop { background: rgba(19, 35, 26, .4); }
.token-dialog p:not(.eyebrow) { color: var(--muted); line-height: 1.6; font-size: 14px; }
.token-dialog code { display: block; overflow-wrap: anywhere; margin: 20px 0; padding: 14px; color: var(--accent-dark); background: var(--accent-soft); border-radius: 6px; font-size: 12px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.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; }
@media (max-width: 820px) {
  .shell { padding: 22px 14px 34px; }
  .topbar, .login-panel, .detail-header { align-items: stretch; flex-direction: column; }
  .login-panel .form-error { position: static; margin: -12px 0 0; }
  .login-panel .inline-form { flex-direction: column; align-items: stretch; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .device-list { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .new-device-form { margin-top: 16px; }
  .content { padding: 26px 18px; }
  .header-actions { justify-content: flex-start; }
  .metrics, .mode-grid, .two-columns { grid-template-columns: 1fr; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
}
