/* Site chrome for server-rendered pages — built entirely on tokens.css
 * custom properties. Page-specific stylesheets (e.g. the dashboard island's
 * dashboard.css) layer on top of this, not instead of it.
 *
 * Layout: an app shell — persistent sidebar (collapses to a drawer under
 * 880px) + slim top bar + scrolling content column. Anonymous pages
 * (login/register/invite links) get the same top bar without the sidebar. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
}

/* ================= App shell ================= */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.brand {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--color-text);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--color-primary);
  color: var(--color-primary-text);
  display: grid;
  place-items: center;
  flex: none;
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.01em;
}

.nav {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-section {
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-muted);
  padding: var(--space-4) var(--space-3) var(--space-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-left: 2px solid transparent;
}

.nav-link svg {
  flex: none;
  opacity: 0.85;
}

.nav-link:hover {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-text);
}

.nav-link.active {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
}

.sidebar-foot {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 0.75rem;
  flex: none;
}

.sidebar-foot .who {
  min-width: 0;
}

.sidebar-foot .who-name {
  display: block;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot .who-meta {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.sidebar-foot .who-meta form {
  display: inline;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  margin: 0;
}

.topbar-spacer {
  flex: 1;
}

.topbar-links {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  font-size: var(--font-size-sm);
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: var(--space-1);
  cursor: pointer;
  color: var(--color-text-muted);
  display: grid;
  place-items: center;
  font-size: var(--font-size-base);
  line-height: 1;
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--color-primary) 8%, transparent);
  color: var(--color-text);
}

#hamburger {
  display: none;
}

#backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}

.content {
  padding: var(--space-6);
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
}

.shell-anonymous .content {
  max-width: 960px;
}

.page-intro {
  margin: 0 0 var(--space-6);
}

.page-intro h2 {
  margin: 0 0 2px;
  font-size: 1.375rem;
  font-weight: 650;
  text-wrap: balance;
}

.page-intro p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ================= Cards, forms, buttons (pre-shell classes) ============ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
}

.card-narrow {
  max-width: 360px;
  width: 100%;
  margin: 0 auto;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.card-head h3 {
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.card-head .sub {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.card-head .link {
  margin-left: auto;
  font-size: var(--font-size-sm);
  text-decoration: none;
  white-space: nowrap;
}

.form-field {
  margin-bottom: var(--space-4);
}

.form-field label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}

.button {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-size: var(--font-size-base);
  cursor: pointer;
  text-decoration: none;
}

.button-secondary {
  background: transparent;
  color: var(--color-primary);
}

.error-list {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  padding-left: var(--space-4);
  margin: 0 0 var(--space-4);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--color-primary);
  cursor: pointer;
}

/* ================= Status indicators ================= */

.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.status-dot-sm {
  width: 8px;
  height: 8px;
  flex: none;
}

.status-on {
  background: var(--color-success);
}

.status-off {
  background: var(--color-muted);
}

.status-badge {
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-border);
  font-size: 0.75rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 550;
  border-radius: 999px;
  padding: 2px var(--space-3);
  white-space: nowrap;
}

.pill.online {
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  color: var(--color-success);
}

.pill.offline {
  background: color-mix(in srgb, var(--color-muted) 18%, transparent);
  color: var(--color-text-muted);
}

.pill.attention {
  background: color-mix(in srgb, var(--color-warning) 14%, transparent);
  color: var(--color-warning);
}

.sev {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  white-space: nowrap;
}

.sev.warning {
  background: color-mix(in srgb, var(--color-warning) 15%, transparent);
  color: var(--color-warning);
}

.sev.critical {
  background: color-mix(in srgb, var(--color-danger) 13%, transparent);
  color: var(--color-danger);
}

.sev.ok {
  background: color-mix(in srgb, var(--color-success) 13%, transparent);
  color: var(--color-success);
}

/* ================= Stat tiles & card grids ================= */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  padding: var(--space-4);
}

.stat .label {
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}

.stat .value {
  font-size: 1.625rem;
  font-weight: 650;
  line-height: 1.25;
  margin-top: 2px;
}

.stat .delta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.stat .delta .up {
  color: var(--color-success);
  font-weight: 600;
}

.stat .delta .down {
  color: var(--color-danger);
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  align-items: start;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  align-items: start;
}

.card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ================= Lists (devices, alerts, dashboards) ================= */

.device-list {
  display: flex;
  flex-direction: column;
}

.device-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.device-row:first-child {
  border-top: none;
}

.device-row .name {
  font-weight: 550;
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.device-row .name a {
  color: inherit;
  text-decoration: none;
}

.device-row .meta {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  margin-top: 1px;
}

.device-metric {
  text-align: right;
}

.device-metric .reading {
  font-weight: 600;
  font-size: var(--font-size-base);
  font-variant-numeric: tabular-nums;
}

.device-metric .metric-name {
  color: var(--color-text-muted);
  font-size: 0.6875rem;
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.simple-list li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.simple-list li:first-child {
  border-top: none;
}

.simple-list .grow {
  flex: 1;
  min-width: 0;
}

.simple-list .title {
  font-weight: 550;
}

.simple-list .title a {
  color: inherit;
  text-decoration: none;
}

.simple-list .muted {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.simple-list .when {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.empty-note {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  margin: 0;
}

/* ================= Tables ================= */

.console-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.console-table th,
.console-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.console-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.console-table .cell-strong {
  font-weight: 550;
}

.console-table .cell-muted {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.console-table .cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .console-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}

.toolbar .form-field {
  margin-bottom: 0;
}

/* ================= Charts (fleet overview / overview) ================= */

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-svg text {
  font-family: var(--font-family);
  font-size: 11px;
  fill: var(--color-text-muted);
}

.chart-svg .endpoint-label {
  fill: var(--color-text);
  font-weight: 650;
}

.gridline {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.axisline {
  stroke: var(--chart-axis);
  stroke-width: 1;
}

.series-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.series-area {
  fill: var(--chart-line);
  opacity: 0.1;
}

.series-end {
  fill: var(--chart-line);
  stroke: var(--color-surface);
  stroke-width: 2;
}

.crosshair {
  stroke: var(--color-muted);
  stroke-width: 1;
  visibility: hidden;
}

.hover-dot {
  fill: var(--chart-line);
  stroke: var(--color-surface);
  stroke-width: 2;
  visibility: hidden;
}

.hbar-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.hbar-row {
  display: grid;
  grid-template-columns: 130px 1fr 40px;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
}

.hbar-row .cat {
  color: var(--color-text-muted);
}

.hbar-track {
  height: 12px;
  position: relative;
}

.hbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--chart-line);
  border-radius: 0 4px 4px 0;
}

.hbar-row .val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.vbars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-top: 14px;
  border-bottom: 1px solid var(--chart-axis);
}

.vbar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.vbar {
  width: 100%;
  max-width: 24px;
  background: var(--chart-bad);
  border-radius: 4px 4px 0 0;
}

.vbar-col .day {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.vbar-col .peak {
  font-size: 0.6875rem;
  font-weight: 650;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.rank-table td {
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
  vertical-align: middle;
}

.rank-table tr:first-child td {
  border-top: none;
}

.rank-table .dev {
  font-weight: 550;
}

.rank-table .owner {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.rank-table .n {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  padding-left: var(--space-3);
}

.rank-table .barcell {
  width: 34%;
  padding-left: var(--space-3);
}

.rank-bar {
  height: 8px;
  background: var(--chart-line);
  border-radius: 0 3px 3px 0;
  min-width: 3px;
}

.spark .line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark .end {
  fill: var(--chart-line);
}

#chart-tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.75rem;
  font-weight: 550;
  padding: 5px 9px;
  border-radius: 6px;
  visibility: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ================= Responsive ================= */

@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(15, 23, 42, 0.25);
  }

  .shell.drawer-open .sidebar {
    transform: translateX(0);
  }

  .shell.drawer-open #backdrop {
    display: block;
  }

  #hamburger {
    display: grid;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .device-row {
    grid-template-columns: 1fr auto;
  }

  .device-row .spark-cell {
    display: none;
  }
}

@media (max-width: 640px) {
  .content {
    padding: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
