:root {
  --navy: #102b4e;
  --navy-2: #173c68;
  --blue: #1677d2;
  --blue-soft: #e8f3fd;
  --teal: #13a99a;
  --ink: #17263a;
  --muted: #64758a;
  --line: #dce5ed;
  --surface: #ffffff;
  --background: #f3f7fa;
  --danger: #b42336;
  --success: #147a55;
  --shadow: 0 10px 32px rgba(22, 52, 82, 0.07);
  --radius: 14px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--background); }
a { color: #0967b7; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.85rem, 3vw, 2.5rem); letter-spacing: -0.035em; color: var(--navy); }
h2 { margin-bottom: 6px; font-size: 1.1rem; color: var(--navy); }
p { color: var(--muted); line-height: 1.55; }
small { display: block; color: var(--muted); line-height: 1.45; }
code, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 20; width: 252px; padding: 24px 16px;
  display: flex; flex-direction: column; color: #dcecff; background: linear-gradient(180deg, #0d315b 0%, #0b2442 100%);
}
.brand, .mobile-brand, .auth-brand { display: flex; align-items: center; gap: 11px; font-weight: 800; letter-spacing: -0.02em; }
.brand { padding: 2px 10px 24px; color: #fff; font-size: 1.22rem; }
.brand:hover, .mobile-brand:hover, .auth-brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; color: #073463; background: #68e2ce; box-shadow: inset 0 -8px 14px rgba(15, 124, 141, .18); }
.project-link { display: block; padding: 11px 13px; margin-bottom: 15px; color: #dcecff; border-radius: 9px; font-weight: 700; }
.project-link:hover, .project-link.active { text-decoration: none; color: #fff; background: rgba(255,255,255,.1); }
.site-label { padding: 16px 13px 13px; margin: 0 -2px 10px; border-top: 1px solid rgba(255,255,255,.12); border-bottom: 1px solid rgba(255,255,255,.12); }
.site-label span { display: block; margin-bottom: 6px; color: #8fb6dd; font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.site-label strong, .site-label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-label strong { color: #fff; }
.site-label small { color: #9fc1e2; }
.main-nav { display: grid; gap: 4px; }
.main-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 11px; color: #c3d8ed; border-radius: 9px; font-size: .91rem; font-weight: 650; }
.main-nav a:hover, .main-nav a.active { color: #fff; background: rgba(77, 173, 255, .18); text-decoration: none; }
.nav-icon { display: grid; place-items: center; min-width: 29px; height: 25px; border-radius: 7px; color: #80d8fb; background: rgba(255,255,255,.08); font-size: .62rem; letter-spacing: .04em; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding: 16px 10px 0; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer a, .sidebar-footer .link-button { color: #bed4e9; }
.main-content { min-height: 100vh; margin-left: 252px; padding: 38px clamp(24px, 5vw, 72px) 24px; }
.mobile-header { display: none; }
.app-footer { display: flex; justify-content: space-between; gap: 20px; padding: 30px 4px 0; color: #8795a5; font-size: .78rem; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 auto 25px; max-width: 1440px; }
.page-heading p { max-width: 760px; margin: 0; }
.heading-actions { flex: none; }
.range-form select { min-width: 165px; padding: 10px 34px 10px 12px; border: 1px solid #b9ccdc; border-radius: 9px; color: var(--navy); background: #fff; font-weight: 700; }
.toolbar { display: flex; justify-content: flex-end; max-width: 1440px; margin: -70px auto 25px; }
.flash { max-width: 1440px; margin: 0 auto 20px; padding: 13px 16px; border: 1px solid; border-radius: 10px; font-weight: 650; }
.flash.success { color: #116044; border-color: #b7e1cf; background: #eaf8f2; }
.flash.error { color: #8f1e31; border-color: #f1bdc5; background: #fff0f2; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 8px 15px; border: 1px solid #b8cad9; border-radius: 9px; color: var(--navy); background: #fff; font-weight: 750; text-decoration: none; }
.button:hover { border-color: #7799b6; text-decoration: none; }
.button.primary { color: #fff; border-color: var(--blue); background: var(--blue); }
.button.primary:hover { background: #0c69ba; }
.button.danger { color: var(--danger); border-color: #efb7c0; background: #fff4f5; }
.button.small { min-height: 34px; padding: 6px 13px; font-size: .86rem; }
.button.full { width: 100%; }
.link-button { padding: 0; border: 0; color: #0967b7; background: transparent; }
.danger-text { color: var(--danger); }

.panel, .project-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel { max-width: 1440px; margin: 0 auto 22px; padding: 22px; }
.panel.narrow { max-width: 720px; margin-left: 0; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.panel-heading p { margin-bottom: 0; font-size: .9rem; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 20px; max-width: 1440px; margin: 0 auto; }
.project-card { padding: 22px; }
.project-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.project-top h2 { display: inline; font-size: 1.16rem; }
.project-top p { margin: 5px 0 0 15px; font-size: .86rem; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(19,169,154,.12); }
.status-dot.off { background: #99a5b2; box-shadow: none; }
.spark-chart { display: block; width: 100%; height: 85px; margin: 18px 0 10px; }
.project-metrics, .inline-stats { display: grid; margin: 0; }
.project-metrics { grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.project-metrics div { padding: 15px 10px 0; border-left: 1px solid var(--line); }
.project-metrics div:first-child { border-left: 0; padding-left: 0; }
.project-metrics dt, .inline-stats dt { color: var(--muted); font-size: .71rem; }
.project-metrics dd, .inline-stats dd { margin: 3px 0 0; color: var(--navy); font-size: 1.25rem; font-weight: 800; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; max-width: 1440px; margin: 0 auto 22px; }
.metric-grid article, .session-summary article { padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.metric-grid span, .session-summary span { display: block; color: var(--muted); font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .055em; }
.metric-grid strong { display: block; margin: 9px 0 2px; color: var(--navy); font-size: 2rem; letter-spacing: -.04em; }
.chart-panel { overflow: hidden; }
.inline-stats { grid-template-columns: repeat(3, minmax(90px,1fr)); gap: 26px; }
.inline-stats dd { font-size: 1.35rem; }
.line-chart { display: block; width: 100%; height: 280px; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; max-width: 1440px; margin: 0 auto; }
.two-columns .panel { width: 100%; }
.rank-list { padding: 0; margin: 0; list-style: none; }
.rank-list li { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid #edf1f5; }
.rank-list li:last-child { border-bottom: 0; }
.rank-list span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list b { color: var(--navy); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 11px 12px; color: #65768a; background: #f7fafc; border-bottom: 1px solid var(--line); font-size: .72rem; letter-spacing: .055em; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 12px; border-bottom: 1px solid #e9eef2; vertical-align: top; font-size: .88rem; line-height: 1.45; }
tbody tr:last-child td { border-bottom: 0; }
td small { margin-top: 3px; }
td a { word-break: break-word; }
.activity-table td:nth-child(1) { min-width: 190px; }
.activity-table td:nth-child(2) { min-width: 230px; }
.activity-table td:nth-child(3) { min-width: 340px; }
.activity-table td:nth-child(4) { min-width: 250px; }
.activity-table td:nth-child(5) { min-width: 150px; }
.detail-link { display: block; margin-top: 7px; font-weight: 750; }
.location-pill { display: inline-flex; align-items: center; gap: 7px; }
.location-pill b { padding: 3px 6px; border-radius: 5px; color: #0a5c91; background: var(--blue-soft); font-size: .68rem; }
.current-ip { color: var(--muted); font-size: .86rem; }

.tabs { display: flex; gap: 5px; max-width: 1440px; margin: -5px auto 18px; padding: 5px; overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; background: #e9f0f5; }
.tabs a { padding: 9px 14px; border-radius: 8px; color: #50667c; font-size: .88rem; font-weight: 750; white-space: nowrap; }
.tabs a:hover { text-decoration: none; }
.tabs a.active { color: var(--navy); background: #fff; box-shadow: 0 3px 9px rgba(16,43,78,.08); }
.report-panel { padding: 0; overflow: hidden; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; max-width: 1440px; margin: 0 auto; }
.settings-grid .panel { width: 100%; }
.stack-form { display: grid; gap: 16px; }
.stack-form label, .inline-form label { display: grid; gap: 7px; color: var(--navy); font-size: .86rem; font-weight: 750; }
input, textarea, select { width: 100%; padding: 10px 11px; border: 1px solid #bdcbd7; border-radius: 8px; color: var(--ink); background: #fff; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgba(22,119,210,.23); outline-offset: 2px; border-color: var(--blue); }
textarea { resize: vertical; line-height: 1.45; }
.code-box { min-height: 300px; margin: 4px 0 12px; color: #d6e9ff; border-color: #173d66; background: #0e2948; font: .78rem/1.55 "SFMono-Regular", Consolas, monospace; white-space: pre; }
.check-row { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
.check-row input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: end; gap: 13px; margin-bottom: 20px; }
.key-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 12px; border-radius: 8px; background: #f2f6f9; }
.key-box span { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.danger-form { display: grid; justify-items: start; gap: 8px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

.session-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; max-width: 1440px; margin: 0 auto 22px; }
.session-summary strong { display: block; margin: 10px 0 4px; word-break: break-word; }
.journey { position: relative; display: grid; gap: 0; }
.journey:before { content: ""; position: absolute; top: 22px; bottom: 22px; left: 18px; width: 2px; background: #d8e7f2; }
.journey-item { position: relative; display: grid; grid-template-columns: 38px 1fr; gap: 16px; padding: 11px 0 22px; }
.journey-number { z-index: 1; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: #fff; background: var(--blue); font-weight: 800; }
.journey-item strong, .journey-item a, .journey-item small { display: block; }
.journey-item a { margin: 5px 0; word-break: break-word; }

.empty-state { padding: 46px 20px; text-align: center; }
.empty-mark { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 18px; color: var(--blue); background: var(--blue-soft); font-size: 2rem; }
.empty-state h2 { font-size: 1.12rem; }
.empty-state p { max-width: 480px; margin: 0 auto; }
.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; }

.auth-body { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dff5f0, transparent 35%), radial-gradient(circle at 90% 90%, #dbeeff, transparent 38%), #edf4f8; }
.auth-card { width: min(100%, 430px); padding: 36px; border: 1px solid #d7e3ec; border-radius: 18px; background: #fff; box-shadow: 0 22px 70px rgba(23,60,104,.14); }
.auth-brand { margin-bottom: 35px; color: var(--navy); font-size: 1.2rem; }
.auth-card h1 { font-size: 2rem; }
.installer-card { width: min(100%, 720px); margin: 30px 0; }
.installer-card fieldset { display: grid; gap: 15px; margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: 11px; }
.installer-card legend { padding: 0 7px; color: var(--navy); font-weight: 800; }
.installer-card fieldset > label { display: grid; gap: 7px; color: var(--navy); font-size: .86rem; font-weight: 750; }
.install-note { margin: 20px 0 0; padding: 12px; border-radius: 8px; background: #f3f7fa; font-size: .86rem; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .session-summary { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .mobile-header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; color: #fff; background: var(--navy); }
  .mobile-brand { color: #fff; }
  .nav-toggle { padding: 7px 11px; border: 1px solid rgba(255,255,255,.35); border-radius: 7px; color: #fff; background: transparent; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0,0,0,.2); }
  .main-content { margin-left: 0; padding: 26px 17px 20px; }
  .page-heading { align-items: flex-start; }
  .two-columns { grid-template-columns: 1fr; gap: 0; }
  .toolbar { margin: 0 auto 20px; justify-content: flex-start; }
  .project-metrics { grid-template-columns: repeat(2,1fr); }
  .project-metrics div:nth-child(3) { padding-left: 0; border-left: 0; }
  .panel-heading { flex-direction: column; gap: 10px; }
  .inline-stats { width: 100%; gap: 12px; }
  .line-chart { height: 220px; }
}

@media (max-width: 570px) {
  .page-heading { flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-grid article { padding: 16px; }
  .metric-grid strong { font-size: 1.55rem; }
  .project-grid { grid-template-columns: 1fr; }
  .project-card, .panel { padding: 17px; }
  .report-panel { padding: 0; }
  .inline-form { grid-template-columns: 1fr; }
  .auth-card { padding: 27px 22px; }
  .app-footer { flex-direction: column; }
}
