:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e8edf4;
  background: #101923;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #17232e;
  --surface-raised: #1b2a37;
  --surface-hover: #223442;
  --border: #2a3a47;
  --text: #e8edf4;
  --muted: #9baab8;
  --accent: #76c9aa;
  --accent-dark: #193e37;
  --danger: #ff8f87;
  --warning: #edc17a;
  --sidebar: #111d27;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #101923; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.hidden { display: none !important; }
.subtle { color: var(--muted); }
.eyebrow { margin: 0 0 7px; color: #86a095; font-size: 10px; font-weight: 750; letter-spacing: .14em; }

.app-shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column;
  padding: 22px 14px 16px; border-right: 1px solid var(--border); background: var(--sidebar);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 29px; color: inherit; text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .01em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.brand-mark { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; background: var(--accent); color: #10251f; font-size: 13px; font-weight: 850; }
.navigation { display: grid; gap: 5px; }
.nav-link {
  display: flex; min-height: 42px; align-items: center; gap: 12px; padding: 0 12px;
  border: 0; border-radius: 8px; background: transparent; color: #acb9c3;
  text-align: left; cursor: pointer; font-size: 13px; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.active { background: var(--accent-dark); color: #b6efda; font-weight: 650; }
.nav-icon { width: 18px; color: #87a69a; font-size: 17px; text-align: center; }
.nav-count { margin-left: auto; color: #8c9ca9; font-size: 11px; }
.sidebar-bottom { display: flex; margin-top: auto; align-items: center; justify-content: space-between; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.service-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.service-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 9px #76c9aa66; }
.sidebar-version { color: #748493; font-size: 10px; }

.workspace { min-width: 0; }
.topbar {
  position: sticky; z-index: 4; top: 0; display: flex; min-height: 82px; align-items: center;
  justify-content: space-between; gap: 20px; padding: 15px 34px; border-bottom: 1px solid var(--border);
  background: #101923ed; backdrop-filter: blur(12px);
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 680; letter-spacing: -.025em; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; color: #d3dce4; font-size: 12px; }
.user-avatar { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 50%; background: #2c403e; color: #b5ead5; font-weight: 700; }
.content { width: min(1440px, 100%); margin: 0 auto; padding: 29px 34px 50px; }
.mobile-menu { display: none !important; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 21px; }
.page-heading h2 { margin: 0 0 6px; font-size: 23px; letter-spacing: -.035em; }
.page-heading p { max-width: 720px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.heading-actions { display: flex; align-items: center; gap: 9px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-bottom: 18px; }
.metric-card, .panel {
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface);
}
.metric-card { min-height: 120px; padding: 17px 18px; }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.metric-icon { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: #263a42; color: var(--accent); font-weight: 700; }
.metric-value { margin-top: 9px; font-size: 27px; font-weight: 720; letter-spacing: -.04em; }
.metric-note { margin-top: 3px; color: #82919d; font-size: 11px; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(270px, .75fr); gap: 15px; }
.panel { min-width: 0; padding: 18px; }
.spaced-panel { margin-top: 15px; }
.panel-header { display: flex; min-height: 28px; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-header h3 { margin: 0; font-size: 14px; font-weight: 670; }
.panel-header p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.panel-link { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: 11px; }
.report-stats { display: grid; gap: 12px; }
.report-stat { display: flex; justify-content: space-between; gap: 15px; padding: 11px 0; border-bottom: 1px solid #273742; color: var(--muted); font-size: 12px; }
.report-stat:last-child { border-bottom: 0; }
.report-stat strong { color: var(--text); font-size: 13px; }

.button, .icon-button {
  display: inline-flex; min-height: 34px; align-items: center; justify-content: center; gap: 7px;
  padding: 0 12px; border: 1px solid transparent; border-radius: 7px; cursor: pointer;
  font-size: 11px; font-weight: 650; transition: background .15s, border-color .15s;
}
.button-primary { background: var(--accent); color: #10251f; }
.button-primary:hover { background: #91dbbf; }
.button-quiet { border-color: var(--border); background: transparent; color: #c3ced7; }
.button-quiet:hover { background: var(--surface-hover); }
.button-danger { border-color: #583a3a; background: #332526; color: #ffaaa3; }
.button-danger:hover { background: #492c2c; }
.button-small { min-height: 28px; padding: 0 9px; font-size: 10px; }
.button-wide { width: 100%; min-height: 42px; margin-top: 12px; font-size: 13px; }
.button:disabled { opacity: .48; cursor: wait; }
.icon-button { width: 34px; padding: 0; background: transparent; color: var(--muted); font-size: 18px; }

.table-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-bottom: 12px; }
.field, .select, .textarea {
  min-height: 36px; border: 1px solid #344652; border-radius: 7px; background: #111c25;
  color: var(--text); font-size: 12px;
}
.field, .select { padding: 0 10px; }
.field { min-width: 180px; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 10px 11px; color: #8797a4; font-size: 10px; font-weight: 700; letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; }
td { padding: 12px 11px; border-top: 1px solid #273742; color: #cad3db; font-size: 11px; vertical-align: middle; }
tbody tr:hover { background: #1b2a35; }
.primary-cell { display: block; color: #e2eaf0; font-size: 12px; font-weight: 640; }
.secondary-cell { display: block; margin-top: 4px; color: #8999a6; font-size: 10px; }
.row-actions { display: flex; flex-wrap: nowrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border: 1px solid transparent; border-radius: 999px; font-size: 10px; font-weight: 650; white-space: nowrap; }
.badge::before { width: 5px; height: 5px; border-radius: 50%; background: currentColor; content: ""; }
.badge-online, .badge-success, .badge-active { border-color: #315a4c; background: #1b352e; color: #92d9b8; }
.badge-offline, .badge-inactive { border-color: #45515b; background: #28333c; color: #abb8c2; }
.badge-error, .badge-revoked, .badge-failed { border-color: #623e3e; background: #3b292a; color: #ff9a91; }
.badge-warning, .badge-started { border-color: #5b4b37; background: #373124; color: #edc17a; }
.device-link { padding: 0; border: 0; background: none; color: #bde8d6; cursor: pointer; font-size: 12px; font-weight: 670; text-align: left; }
.device-link:hover { text-decoration: underline; }
.empty-state { padding: 32px 16px; color: var(--muted); text-align: center; font-size: 12px; }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--text); font-size: 13px; }
.event-list { display: grid; }
.event-item { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; padding: 11px 0; border-bottom: 1px solid #273742; }
.event-item:last-child { border-bottom: 0; }
.event-symbol { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 7px; background: #253942; color: var(--accent); font-size: 12px; }
.event-copy { min-width: 0; }
.event-title { color: #dbe3e9; font-size: 11px; font-weight: 620; }
.event-meta { margin-top: 4px; color: #8797a4; font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.event-detail { margin-top: 6px; color: #95a5b1; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-field { display: grid; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { color: #b8c5ce; font-size: 11px; font-weight: 620; }
.form-field .hint { margin-top: -2px; color: #81919d; font-size: 10px; line-height: 1.45; }
.textarea { min-height: 76px; resize: vertical; padding: 9px 10px; }
.upload-drop { padding: 18px; border: 1px dashed #425965; border-radius: 8px; background: #14212a; }
.upload-status { min-height: 18px; margin: 10px 0 0; color: var(--muted); font-size: 11px; }
.upload-status.error { color: var(--danger); }
.upload-status.success { color: var(--accent); }
.hash-value { display: block; max-width: 290px; color: #9eacb7; font: 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.token-callout { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px; border: 1px solid #6b5736; border-radius: 8px; background: #2d291f; }
.token-create { margin-top: 13px; }
.token-result { margin-top: 13px; }
.token-callout strong { display: block; margin-bottom: 7px; color: #f0d39d; font-size: 11px; }
.token-value { color: #f4e3bf; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; user-select: all; }
.toolbar-note { color: var(--muted); font-size: 11px; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 11px; }
.toast { position: fixed; z-index: 20; top: 18px; right: 18px; max-width: min(420px, calc(100vw - 36px)); padding: 12px 15px; transform: translateY(-12px); border: 1px solid #39604e; border-radius: 8px; background: #1d382f; color: #d2f3e2; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 12px; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: #714441; background: #3c2929; color: #ffd2cd; }
.login-screen { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(ellipse at 50% 30%, #1b302f 0, #101923 55%); }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 14px; background: #17232e; box-shadow: 0 22px 70px #0005; }
.login-card .brand-mark { width: 44px; height: 44px; margin-bottom: 24px; }
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.login-card .subtle { margin: 8px 0 25px; font-size: 12px; line-height: 1.5; }
.login-card label { display: block; margin: 14px 0 6px; color: #b8c5ce; font-size: 11px; font-weight: 620; }
.login-card input { width: 100%; height: 41px; padding: 0 11px; border: 1px solid #344652; border-radius: 7px; background: #111c25; color: var(--text); }
.login-footnote { margin: 22px 0 0; color: #81919d; font-size: 10px; line-height: 1.5; text-align: center; }

.device-dialog { width: min(720px, calc(100% - 28px)); max-width: 720px; max-height: min(88vh, 900px); padding: 0; overflow: auto; border: 1px solid #40515e; border-radius: 12px; background: #17232e; color: var(--text); box-shadow: 0 25px 100px #0009; }
.device-dialog::backdrop { background: #071018bd; backdrop-filter: blur(3px); }
.dialog-head { position: sticky; z-index: 2; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--border); background: #17232ef2; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.dialog-body { padding: 18px 20px 22px; }
.info-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.info-item { min-width: 0; padding: 10px; border: 1px solid #2a3b47; border-radius: 7px; background: #14202a; }
.info-label { color: #81919d; font-size: 9px; letter-spacing: .04em; text-transform: uppercase; }
.info-value { margin-top: 5px; color: #e0e7ed; font-size: 11px; overflow-wrap: anywhere; }
.dialog-section { margin-top: 20px; }
.dialog-section h3 { margin: 0 0 10px; font-size: 12px; }
.dialog-events { max-height: 200px; overflow: auto; }
.danger-zone { padding: 13px; border: 1px solid #553d3b; border-radius: 8px; background: #2c2324; }
.danger-zone h3 { color: #ffaaa2; }
.dialog-form { display: grid; gap: 10px; }
.loading { padding: 28px; color: var(--muted); text-align: center; font-size: 12px; }

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .topbar { padding-right: 23px; padding-left: 23px; }
  .content { padding-right: 23px; padding-left: 23px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 10; left: 0; width: 245px; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 15px 0 40px #0006; }
  .sidebar.open { transform: translateX(0); }
  .topbar { min-height: 68px; padding: 12px 15px; }
  .topbar h1 { font-size: 17px; }
  .topbar-actions { gap: 7px; }
  .topbar-actions .user-chip { display: none; }
  .mobile-menu { display: inline-flex !important; }
  .content { padding: 21px 14px 40px; }
  .metrics { gap: 8px; }
  .metric-card { min-height: 103px; padding: 13px; }
  .metric-value { font-size: 23px; }
  .page-heading { align-items: flex-start; }
  .page-heading h2 { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.full { grid-column: auto; }
  .panel { padding: 14px; }
  .hide-small { display: none; }
}
@media (max-width: 430px) {
  .topbar-actions .button { padding: 0 8px; font-size: 10px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card { padding: 11px; }
  .metric-top { font-size: 10px; }
  .metric-icon { width: 25px; height: 25px; }
  .metric-value { font-size: 21px; }
  .heading-actions .button { min-height: 31px; padding: 0 8px; }
  .info-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-card { padding: 25px; }
}
