:root {
  --ink: #13282d;
  --muted: #667a80;
  --line: #dbe5e8;
  --paper: #ffffff;
  --wash: #f2f7f7;
  --teal: #087b72;
  --teal-dark: #075e59;
  --teal-soft: #dff5f0;
  --blue: #2563eb;
  --amber: #d86f1e;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(25, 63, 70, 0.09);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--wash); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wash);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a { color: inherit; }
button, input { font: inherit; }

.app-shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 22px;
  color: #effffc;
  background:
    radial-gradient(circle at 15% 8%, rgba(82, 219, 194, 0.20), transparent 31%),
    linear-gradient(160deg, #0c3d3a 0%, #092e31 63%, #112c36 100%);
}

.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark, .login-logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  color: #063e39;
  background: #76e4cf;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.brand strong, .brand small { display: block; }
.brand small { color: #a8c5c5; font-size: 0.75rem; }

.nav-list { display: grid; gap: 8px; }
.nav-list a {
  padding: 11px 13px;
  border-radius: 11px;
  color: #bfd4d4;
  text-decoration: none;
  font-weight: 650;
}
.nav-list a:hover, .nav-list a.active { color: white; background: rgba(255,255,255,0.10); }

.sidebar-footer { margin-top: auto; display: grid; gap: 14px; }
.user-card { display: flex; align-items: center; gap: 10px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,0.12); }
.user-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: rgba(118,228,207,0.15); color: #8df0dd; font-weight: 800; }
.user-copy { min-width: 0; }
.user-copy strong, .user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { font-size: 0.85rem; }
.user-copy small { color: #9cb9ba; text-transform: capitalize; }

.main-content { min-width: 0; padding: 38px clamp(22px, 4vw, 60px) 70px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin: 0 auto 28px; max-width: 1500px; }
.page-header h1 { margin: 4px 0 5px; font-size: clamp(1.8rem, 3vw, 2.6rem); letter-spacing: -0.04em; }
.page-header p, .panel-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--teal); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.header-chip { padding: 8px 12px; border: 1px solid #b7ddd5; border-radius: 999px; color: var(--teal-dark); background: var(--teal-soft); font-size: 0.78rem; font-weight: 750; }

.stat-grid, .metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; max-width: 1500px; margin: 0 auto 20px; }
.metric-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat-card, .metric-card, .panel {
  border: 1px solid rgba(210, 224, 227, 0.9);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.stat-card, .metric-card { position: relative; overflow: hidden; padding: 21px; }
.stat-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: #607d83; }
.stat-card.accent-green::before { background: var(--teal); }
.stat-card.accent-amber::before { background: var(--amber); }
.stat-card span, .metric-card span { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.stat-card strong, .metric-card strong { display: block; margin: 7px 0 2px; font-size: 2rem; letter-spacing: -0.04em; }
.stat-card small, .metric-card small { color: #829297; }
.primary-metric { color: white; background: linear-gradient(145deg, var(--teal) 0%, var(--teal-dark) 100%); }
.primary-metric span, .primary-metric small { color: #d7fff8; }

.panel { max-width: 1500px; margin: 0 auto 20px; padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0 0 2px; font-size: 1.08rem; }
.compact-panel { margin: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; max-width: 1500px; margin: 0 auto 20px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); background: #f6f9fa; font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.06em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbfb; }
.device-link { display: grid; text-decoration: none; }
.device-link:hover strong { color: var(--teal); }
.device-link small { color: var(--muted); }
.metric-cell { color: var(--teal-dark); font-weight: 800; font-variant-numeric: tabular-nums; }

.status-pill, .state-tag, .severity { display: inline-flex; align-items: center; width: max-content; border-radius: 999px; font-size: 0.73rem; font-weight: 800; }
.status-pill { gap: 6px; padding: 5px 9px; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pill.large { padding: 9px 13px; }
.status-online { color: #05715f; background: #dff6ef; }
.status-offline { color: #7a5550; background: #f4e8e5; }
.state-tag { padding: 4px 8px; color: #4d6066; background: #edf2f3; }

.back-link { display: block; margin-bottom: 18px; color: var(--muted); text-decoration: none; font-weight: 650; }
.back-link:hover { color: var(--teal); }

.chart-panel { min-height: 370px; }
#ph-chart { display: block; width: 100%; height: 290px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 0.78rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 20px; height: 3px; border-radius: 4px; }
.legend-ph1 { background: #0f766e; }
.legend-ph2 { background: #2563eb; }
.legend-control { background: #e07a28; }
.empty-inline { padding: 70px 20px; text-align: center; color: var(--muted); }

.detail-list { display: grid; gap: 0; margin: 0; }
.detail-list div { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 1.4fr); gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; font-weight: 700; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.76rem; }

.event-list { display: grid; gap: 0; padding: 0; margin: 0; list-style: none; }
.event-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.event-list li:last-child { border-bottom: 0; }
.event-list strong, .event-list p { display: block; margin: 0; }
.event-list p, .event-list time { color: var(--muted); font-size: 0.78rem; }
.severity { padding: 4px 8px; text-transform: uppercase; }
.severity-info { color: #275da5; background: #e4edfb; }
.severity-warning { color: #9b541d; background: #fff0dc; }
.severity-critical { color: var(--danger); background: #fee9e7; }

.button { display: inline-flex; justify-content: center; align-items: center; border: 0; border-radius: 11px; padding: 10px 15px; text-decoration: none; cursor: pointer; font-weight: 800; }
.button-primary { color: white; background: var(--teal); }
.button-primary:hover { background: var(--teal-dark); }
.button-muted { color: #dceaea; background: rgba(255,255,255,0.08); }
.button-muted:hover { background: rgba(255,255,255,0.14); }
.button-full { width: 100%; }

.empty-state { padding: 45px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 5px 0 0; }
.empty-state.small { padding: 26px 10px; }

.login-body { background: #082f31; }
.login-shell { display: grid; place-items: center; min-height: 100vh; padding: 28px; background: radial-gradient(circle at 75% 20%, rgba(92, 223, 197, 0.20), transparent 32%), linear-gradient(145deg, #082f31, #112a38); }
.login-panel { width: min(1020px, 100%); display: grid; grid-template-columns: 1.15fr 0.85fr; overflow: hidden; border: 1px solid rgba(255,255,255,0.12); border-radius: 28px; background: rgba(255,255,255,0.05); box-shadow: 0 35px 90px rgba(0,0,0,0.28); }
.login-intro { position: relative; min-height: 590px; padding: clamp(38px, 7vw, 80px); color: white; overflow: hidden; }
.login-intro .eyebrow { color: #88ead7; }
.login-intro h1 { max-width: 520px; margin: 18px 0; font-size: clamp(2.4rem, 5vw, 4.5rem); line-height: 0.98; letter-spacing: -0.06em; }
.login-intro p { max-width: 470px; color: #bcd2d4; font-size: 1.05rem; }
.login-card { align-self: center; margin: 26px; padding: clamp(28px, 4vw, 42px); border-radius: 21px; background: white; box-shadow: var(--shadow); }
.login-card h2 { margin: 20px 0 3px; font-size: 1.55rem; }
.muted { color: var(--muted); }
.signal-card { position: absolute; right: -20%; bottom: -17%; width: 520px; height: 320px; transform: rotate(-8deg); }
.signal-line { position: absolute; inset: auto 0; height: 2px; border-radius: 50%; background: linear-gradient(90deg, transparent, #69e4cc, transparent); }
.signal-one { bottom: 40%; transform: rotate(-15deg); }
.signal-two { bottom: 58%; transform: rotate(8deg); opacity: 0.65; }
.signal-three { bottom: 25%; transform: rotate(19deg); opacity: 0.35; }

.form-stack { display: grid; gap: 17px; margin-top: 26px; }
.form-stack label { display: grid; gap: 7px; color: #41565c; font-size: 0.84rem; font-weight: 750; }
.form-stack input { width: 100%; border: 1px solid #cddbdd; border-radius: 11px; padding: 11px 12px; color: var(--ink); background: #fbfdfd; outline: none; }
.form-stack input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,123,114,0.12); }
.alert { margin-top: 18px; padding: 11px 13px; border-radius: 10px; font-size: 0.85rem; }
.alert-error { color: var(--danger); background: #feeceb; border: 1px solid #f8ccc8; }

.error-page { display: grid; place-items: center; gap: 16px; min-height: 380px; }
.error-code { color: var(--teal); font-size: 4rem; font-weight: 900; letter-spacing: -0.08em; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .login-panel { grid-template-columns: 1fr 0.85fr; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: relative; height: auto; padding: 18px; }
  .nav-list { display: none; }
  .sidebar-footer { margin-top: 0; grid-template-columns: 1fr auto; align-items: end; }
  .sidebar-footer form { width: 110px; }
  .main-content { padding: 25px 16px 50px; }
  .stat-grid, .metric-grid, .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-panel { display: block; }
  .login-intro { min-height: 300px; }
}

@media (max-width: 540px) {
  .page-header { display: grid; }
  .stat-grid, .metric-grid, .detail-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; border-radius: 15px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .sidebar-footer { grid-template-columns: 1fr; }
  .sidebar-footer form { width: 100%; }
  .login-shell { padding: 12px; }
  .login-panel { border-radius: 20px; }
  .login-intro { min-height: 270px; padding: 36px 28px; }
  .login-intro h1 { font-size: 2.5rem; }
  .login-card { margin: 12px; }
}
