/* auth-manager — late-2000s Django-admin aesthetic.
   See $REPO_ROOT/docs/DESIGN_GUIDELINES.md.

   Shared house base styles. The accent/chrome family is expressed as tokens
   below; status colors (green/amber/red) and neutral grays stay literal and
   shared across the sibling apps. This app's accent is a muted teal/green-slate
   (identity/security register), one hue off the canonical slate blue. */

:root {
  --accent: #3E7E73;            /* panel/table headers, nav-active, primary */
  --accent-light: #498F83;      /* header + primary-button gradient top */
  --accent-dark: #234C45;       /* header/panel borders, legends */
  --accent-active: #1E5A4F;     /* link hover, active text */
  --link: #3F8378;              /* links, focus outline */
  --accent-pale: #79C8B8;       /* hover borders, info/cool accents */
  --tint: #E6F2EF;              /* row/nav hover fill */
  --focus-halo: #D3EBE4;        /* focus 2px halo */
  --header-meta: #D7E9E5;       /* header meta text, live-stamp on dark */
  --accent-hover-top: #36766B;  /* primary-button hover gradient top */
  --accent-hover-bottom: #2E665C;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Lucida Grande", "DejaVu Sans", "Bitstream Vera Sans",
               Verdana, Arial, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  color: #222;
  background: #F5F5F5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--accent-active); text-decoration: underline; }

/* Visible keyboard focus (blue outline + soft halo), per the guidelines. */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 1px;
  border-radius: 3px;
}

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 700; color: #222; }
h1 { font-size: 19px; }
h3 { font-size: 13px; }

.muted { color: #555; }
.small { font-size: 11px; }
.mono { font-family: "DejaVu Sans Mono", Menlo, Consolas, monospace; font-size: 11px; }

/* ── Header ──────────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(to bottom, var(--accent-light) 0%, var(--accent) 100%);
  color: #FFFFFF;
  border-bottom: 1px solid var(--accent-dark);
}
.app-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-title {
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.app-title:hover { color: #FFFFFF; text-decoration: none; }
.app-header-meta { font-size: 11px; color: var(--header-meta); }
.app-header-meta strong { color: #FFFFFF; }

/* ── Shell / layout ──────────────────────────────────────────────── */
.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: start;
}

/* Grid children default to min-width:auto, so a wide table would stretch the
   whole page past the viewport instead of scrolling inside its panel. */
.main-content { min-width: 0; }

.sidebar { font-size: 12px; }
.sidebar .sidebar-toggle { display: none; }
.sidebar-body {
  background: #F8F8F8;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  padding: 8px 0;
}
.nav-section { padding: 4px 0 8px; }
.nav-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #888888;
  margin: 0;
  padding: 6px 12px 4px;
}
.nav-link {
  display: block;
  padding: 6px 12px;
  color: #333;
  border-left: 3px solid transparent;
  transition: background-color 100ms linear, border-color 100ms linear;
}
.nav-link:hover { background: var(--tint); text-decoration: none; color: var(--accent-active); }
.nav-link.active {
  background: var(--tint);
  border-left-color: var(--accent);
  font-weight: 700;
  color: var(--accent-active);
}
.nav-empty { padding: 4px 12px; color: #888; }

/* ── Footer ──────────────────────────────────────────────────────── */
.app-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 16px;
  color: #888888;
  font-size: 11px;
  border-top: 1px solid #E5E5E5;
}

/* ── Breadcrumbs (Django-admin strip) ────────────────────────────── */
.breadcrumbs {
  background: #EEEEEE;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  padding: 5px 10px;
  margin-bottom: 14px;
  font-size: 11px;
  color: #888;
}
.breadcrumbs a { color: var(--link); }
.breadcrumbs .current { color: #555; font-weight: 700; }

/* ── Page title ──────────────────────────────────────────────────── */
.page-title { margin-bottom: 14px; }
.page-title h1 { margin-bottom: 2px; }
.subtitle { margin: 0; color: #555; font-size: 12px; }
.subtitle code {
  font-family: "DejaVu Sans Mono", Menlo, Consolas, monospace;
  background: #EEEEEE;
  border: 1px solid #DDDDDD;
  border-radius: 2px;
  padding: 0 4px;
}

/* ── Status list + dots ──────────────────────────────────────────── */
.status-list { list-style: none; margin: 0; padding: 0; }
.status-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #EEEEEE;
}
.status-list li:last-child { border-bottom: none; }
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
  flex: 0 0 auto;
}
.status-dot.ok { background: #70BF2B; }
.status-dot.warn { background: #EFB80B; }
.status-dot.crit { background: #BA2121; }
.status-dot.unknown { background: #BBBBBB; }

/* ── Panels ──────────────────────────────────────────────────────── */
.panel {
  background: #FFFFFF;
  border: 1px solid #CCCCCC;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  margin-bottom: 16px;
}
.panel-header {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--accent-dark);
  border-radius: 3px 3px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.panel-body { padding: 12px; }
.panel-header-title { display: inline-flex; align-items: center; gap: 6px; }
.panel-header-title a { color: #FFFFFF; }
.panel-header-title a:hover { color: #FFFFFF; }
.panel-header-meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* ── Tables (changelist) ─────────────────────────────────────────── */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
  padding: 6px 8px;
  text-align: left;
  border: 1px solid var(--accent-dark);
}
table.data td {
  background: #FFFFFF;
  padding: 6px 8px;
  border: 1px solid #DDDDDD;
}
table.data tr:nth-child(even) td { background: #F8F8F8; }
table.data tr:hover td { background: var(--tint); }

/* key/value table: row headers on the left, no slate header row */
table.data.kv th[scope="row"] {
  background: #F8F8F8;
  color: #222;
  border: 1px solid #DDDDDD;
  width: 160px;
  font-weight: 700;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
button, .btn {
  font-family: inherit;
  font-size: 12px;
  background: linear-gradient(to bottom, #FFFFFF 0%, #EEEEEE 100%);
  border: 1px solid #CCC;
  border-radius: 3px;
  padding: 4px 12px;
  color: #222;
  box-shadow: 0 1px 0 #FFFFFF inset;
  cursor: pointer;
  transition: background-color 100ms linear, border-color 100ms linear;
}
button:hover, .btn:hover { background: linear-gradient(to bottom, #F4F4F4 0%, #E4E4E4 100%); }
.btn-primary {
  background: linear-gradient(to bottom, var(--accent-light) 0%, var(--accent) 100%);
  border-color: var(--accent-dark);
  color: #FFFFFF;
}
.btn-primary:hover { background: linear-gradient(to bottom, var(--accent-hover-top) 0%, var(--accent-hover-bottom) 100%); }
.btn-mini { padding: 2px 8px; font-size: 11px; }
button:disabled, .btn:disabled,
button[disabled], .btn[disabled] {
  opacity: 0.6;
  cursor: default;
  background: #EEEEEE;
  box-shadow: none;
}

/* ── Forms ───────────────────────────────────────────────────────── */
input, select, textarea {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #CCC;
  border-radius: 3px;
  background: #FFFFFF;
  color: #222;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--link);
  outline: 2px solid var(--focus-halo);
}
label { font-weight: 700; display: block; margin-bottom: 3px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
/* min-width:0 lets fields shrink below their content (a <select> with long
   options otherwise forces the bar — and the page — past the viewport);
   the flex-basis shares the row evenly on desktop and wraps cleanly on
   narrow screens. */
.filter-field {
  display: flex;
  flex-direction: column;
  flex: 1 1 150px;
  min-width: 0;
  max-width: 320px;
}
.filter-field > select, .filter-field > input { width: 100%; max-width: 100%; min-width: 0; }
.filter-field.filter-search { flex: 2 1 200px; }
.filter-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.stacked-action-form {
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  background: #F8F8F8;
  padding: 10px;
  max-width: 360px;
}
.stacked-action-form .filter-field { max-width: 320px; }
.form-actions { margin-top: 10px; }

.input-group { display: inline-flex; align-items: center; gap: 4px; }
.input-group input { width: 80px; }
.input-suffix { color: #555; }

/* iLO fan control */
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.control-block {
  border-top: 1px solid #E5E5E5;
  padding-top: 12px;
  margin-top: 12px;
}
.control-grid .control-block:first-child,
.control-grid .control-block { border-top: none; padding-top: 0; margin-top: 0; }
.fan-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.fan-control-item label { font-weight: 400; color: #555; }

/* iLO fan quick settings (overview) */
.quick-fan-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #E5E5E5;
}
.quick-fan-row:first-of-type { border-top: none; }
.quick-fan-name { font-weight: 700; min-width: 120px; }
.quick-fan-presets { display: inline-flex; gap: 4px; }
.quick-fan-custom { display: inline-flex; align-items: center; gap: 4px; }
.quick-fan-custom .input-group input { width: 64px; }

/* ── Stats (MikroTik) ────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-grid.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat {
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  background: #F8F8F8;
  padding: 10px;
}
.stat-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 20px; font-weight: 700; color: #222; }
.stat-value.small { font-size: 13px; }
.stat-detail { font-size: 11px; color: #555; margin-top: 2px; }
.meter {
  margin-top: 6px;
  height: 8px;
  background: #E5E5E5;
  border: 1px solid #CCCCCC;
  border-radius: 2px;
  overflow: hidden;
}
.meter-bar {
  height: 100%;
  background: linear-gradient(to bottom, var(--accent-pale) 0%, var(--link) 100%);
}
.meter-bar.warn { background: linear-gradient(to bottom, #F0C53C 0%, #EFB80B 100%); }
.meter-bar.crit { background: linear-gradient(to bottom, #D14B4B 0%, #BA2121 100%); }

/* ── Chart ───────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.sparkline { height: 130px; }

/* ── Temperatures (iLO) ──────────────────────────────────────────── */
.temps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}
.temp-item {
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  background: #F8F8F8;
  padding: 8px 10px;
}
.temp-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.temp-name { font-weight: 700; }
.temp-sensor-id { color: #888; font-weight: 400; }
.temp-pill-group { display: inline-flex; gap: 4px; align-items: center; }
.temp-pill, .temp-pill-threshold {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 11px;
  border: 1px solid #CCC;
}
.temp-pill.cool { background: var(--tint); border-color: var(--accent-pale); color: var(--accent-active); }
.temp-pill.warm { background: #FBF0CC; border-color: #EFB80B; color: #6b5300; }
.temp-pill.hot { background: #F6D9D9; border-color: #BA2121; color: #BA2121; }
.temp-pill-threshold.warning { color: #6b5300; }
.temp-pill-threshold.critical { color: #BA2121; }
.temp-bar {
  height: 8px;
  background: #E5E5E5;
  border: 1px solid #CCCCCC;
  border-radius: 2px;
  overflow: hidden;
}
.temp-bar-inner { height: 100%; }
.temp-bar-inner.cool { background: linear-gradient(to bottom, var(--accent-pale), var(--link)); }
.temp-bar-inner.warm { background: linear-gradient(to bottom, #F0C53C, #EFB80B); }
.temp-bar-inner.hot { background: linear-gradient(to bottom, #D14B4B, #BA2121); }

/* ── Badges / status ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 11px;
  border: 1px solid #CCC;
}
.badge.ok { background: #E7F4D8; border-color: #70BF2B; color: #3d6b13; }
.badge.info { background: var(--tint); border-color: var(--accent-pale); color: var(--accent-active); }
.badge.warning { background: #FBF0CC; border-color: #EFB80B; color: #6b5300; }
.badge.critical { background: #F6D9D9; border-color: #BA2121; color: #BA2121; }

/* ── Flash messages ──────────────────────────────────────────────── */
.flash, .inline-flash {
  border-radius: 3px;
  padding: 8px 12px;
  border: 1px solid #CCC;
  margin: 0 0 10px;
}
.flash { max-width: 1180px; margin: 8px auto 0; }
.inline-flash { margin-bottom: 0; }
.flash.info, .inline-flash.info { background: var(--tint); border-color: var(--accent-pale); color: var(--accent-active); }
.flash.warning, .inline-flash.warning { background: #FBF0CC; border-color: #EFB80B; color: #6b5300; }
.flash.error, .inline-flash.error { background: #F6D9D9; border-color: #BA2121; color: #BA2121; }

/* ── Live refresh (htmx) ─────────────────────────────────────────── */
.live-region { transition: opacity 120ms linear; }
.live-region.htmx-request { opacity: 0.6; }
.live-stamp { font-size: 11px; color: var(--header-meta); font-weight: 400; }
.panel-body .live-stamp, .filter-actions .live-stamp { color: #888; }

/* ── Sea of Sensors ──────────────────────────────────────────────── */
#sea-of-sensors-container {
  position: relative;
  width: 100%;
  height: 420px;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  background: #FFFFFF;
  overflow: hidden;
}
#sea-of-sensors-legend {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  padding: 4px 6px;
}
.sos-legend-label { font-size: 10px; color: #555; }
.sos-legend-gradient {
  width: 90px;
  height: 8px;
  border: 1px solid #CCC;
  background: linear-gradient(to right, #00d933, #f2f200, #f2a200, #e60000);
}
.sos-tooltip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: #FFFFFF;
  border: 1px solid #999;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 11px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.sos-tt-warn { color: #6b5300; }
.sos-tt-crit { color: #BA2121; }

/* ── Mobile (≤720px) ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .app-header-inner, .shell, .app-footer, .flash { padding-left: 12px; padding-right: 12px; }

  .sidebar .sidebar-toggle {
    display: block;
    background: var(--accent);
    color: #FFFFFF;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid var(--accent-dark);
    border-radius: 3px;
    list-style: none;
    cursor: pointer;
  }
  .sidebar .sidebar-toggle::-webkit-details-marker { display: none; }
  .mobile-menu[open] .sidebar-toggle { border-radius: 3px 3px 0 0; }
  .nav-link { padding: 10px 12px; }

  /* Tables scroll horizontally inside their panel instead of crushing (or
     stretching the page): natural column widths + panel-scoped scroll. */
  .panel-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .panel-body table.data { min-width: max-content; }
  .filter-field, .stacked-action-form { max-width: none; }

  /* 16px on every form control stops iOS Safari from zooming on focus. */
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 480px) {
  .stat-value { font-size: 18px; }
  .app-header-meta { display: none; }
}

/* ============================================================== */
/* auth-manager additions — login portal + service dashboard      */
/* ============================================================== */

/* ── Centered auth layout (login / totp) ─────────────────────────── */
.auth-wrap {
  max-width: 380px;
  margin: 48px auto;
  padding: 0 16px;
}
.auth-wrap .panel { margin-bottom: 12px; }
.auth-logo {
  text-align: center;
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
}
.auth-field { margin-bottom: 10px; }
.auth-field input[type="text"],
.auth-field input[type="password"],
.auth-field input[type="email"] { width: 100%; }
.auth-actions { margin-top: 12px; }
.auth-actions .btn { width: 100%; padding: 6px 12px; }
.auth-remember { font-weight: 400; display: flex; align-items: center; gap: 6px; }
.auth-remember input { width: auto; }
.auth-meta { text-align: center; font-size: 11px; color: #888; margin-top: 8px; }

/* TOTP enrolment */
.totp-qr {
  display: block;
  margin: 8px auto;
  width: 180px;
  height: 180px;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  background: #FFFFFF;
}
.totp-secret {
  font-family: "DejaVu Sans Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.08em;
  background: #F8F8F8;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  padding: 6px 8px;
  text-align: center;
  word-break: break-all;
}
.code-input { text-align: center; font-size: 18px; letter-spacing: 0.3em; }

/* ── Service dashboard (lab.bluehat.cc) ──────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.tile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #FFFFFF;
  border: 1px solid #CCCCCC;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  color: #222;
  transition: background-color 100ms linear, border-color 100ms linear;
}
.tile:hover { background: var(--tint); border-color: var(--accent-pale); text-decoration: none; color: var(--accent-active); }
.tile .icon { width: 32px; height: 32px; flex: 0 0 auto; }
.tile .icon-fallback {
  width: 32px; height: 32px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #FFFFFF; border-radius: 3px; font-weight: 700;
}
.tile-body { min-width: 0; }
.tile-body h3 { margin: 0 0 1px; font-size: 13px; }
.tile-body p { margin: 0; color: #555; font-size: 11px; }
.tile-body .host { color: #888; font-size: 11px; }
.dash-empty { color: #555; padding: 12px 0; }
