:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #dfe1e6;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #2f6fed;
  --on: #17944b;
  --off-soft: #eef0f2;
  --danger: #d13b3b;
  --warn: #b06a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1c2128;
    --border: #2b323b;
    --text: #e8eaed;
    --muted: #9aa4b2;
    --accent: #5b8dff;
    --on: #35c46f;
    --off-soft: #232931;
    --danger: #f0625f;
    --warn: #e0a33a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.view { min-height: 100vh; }
.centered { display: grid; place-items: center; padding: 24px; }
.empty-hint { padding: 30px; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- login ---- */
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-title { margin: 0 0 4px; font-size: 20px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px; color: var(--text); font-family: inherit;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.btn {
  padding: 9px 14px; font-size: 14px; font-weight: 600; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 22px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.error { color: var(--danger); font-size: 13px; margin: 10px 0 0; min-height: 1em; }
.banner { padding: 12px 16px; border: 1px solid var(--danger); border-radius: 8px; margin-bottom: 18px; }

/* ---- chrome ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 22px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.up { background: var(--on); }
.dot.down { background: var(--danger); }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 6px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; border: 0; background: transparent; color: var(--muted); }
.tab.active { background: var(--off-soft); color: var(--text); }
.user-chip { font-size: 12px; color: var(--muted); }

main { max-width: 1180px; margin: 0 auto; padding: 24px 22px 60px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-hint { margin: -6px 0 16px; }

/* ==========================================================================
   Rack faceplate — a 1U APC AP7900B seen head-on. Chassis colours are fixed
   rather than themed, because the hardware is black in any room.
   ========================================================================== */
.unit-block { margin-bottom: 26px; }

.unit-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.unit-title { font-size: 14px; font-weight: 700; }
.unit-sub { font-size: 12px; color: var(--muted); }
.unit-bar .btn-sm { margin-left: auto; }

.faceplate-wrap { overflow-x: auto; padding-bottom: 4px; }

.faceplate {
  display: flex; align-items: stretch; min-width: 940px;
  border: 1px solid #05070a; border-radius: 7px;
  background: linear-gradient(180deg, #32373e 0%, #23272d 8%, #1a1d22 55%, #141619 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .10), inset 0 -1px 0 rgba(0, 0, 0, .6), 0 6px 20px rgba(0, 0, 0, .35);
}
.faceplate.offline { filter: grayscale(.65) brightness(.72); }

/* rack mounting ears */
.ear {
  width: 28px; flex: none; display: flex; flex-direction: column;
  justify-content: space-around; align-items: center; padding: 9px 0;
  background: linear-gradient(90deg, #3a4048, #262b31);
  border-right: 1px solid #05070a;
}
.ear.right { border-right: 0; border-left: 1px solid #05070a; background: linear-gradient(270deg, #3a4048, #262b31); }
.ear .hole {
  width: 10px; height: 10px; border-radius: 50%;
  background: #0a0c0f; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .95), 0 1px 0 rgba(255, 255, 255, .07);
}

/* left branding / status block */
.fp-brand {
  width: 196px; flex: none; padding: 12px 14px; border-right: 1px solid #05070a;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.fp-name { color: #eef2f6; font-weight: 700; font-size: 13px; line-height: 1.25; word-break: break-word; }
.fp-model { color: #79838f; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }
.fp-leds { display: flex; gap: 12px; margin-top: 7px; }
.led { display: flex; align-items: center; gap: 5px; font-size: 9px; color: #6f7883; letter-spacing: .06em; text-transform: uppercase; }
.led i { width: 7px; height: 7px; border-radius: 50%; background: #333940; display: block; }
.led.ok i { background: #3ddc7f; box-shadow: 0 0 7px rgba(61, 220, 127, .85); }
.led.err i { background: #f0625f; box-shadow: 0 0 7px rgba(240, 98, 95, .85); }

/* outlet bank */
.fp-outlets { flex: 1; display: flex; padding: 9px 6px; gap: 2px; }
.outlet {
  flex: 1 1 0; min-width: 88px; display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 6px 4px 7px; border-radius: 7px; cursor: pointer;
  border: 1px solid transparent; background: transparent; font: inherit; position: relative;
}
.outlet:hover { background: rgba(255, 255, 255, .055); border-color: rgba(255, 255, 255, .12); }
.outlet:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.outlet[disabled] { cursor: default; }
.outlet[disabled]:hover { background: transparent; border-color: transparent; }

.outlet-num { font-size: 10px; font-weight: 800; color: #79838f; letter-spacing: .05em; }
.outlet-led { width: 8px; height: 8px; border-radius: 50%; background: #333940; flex: none; }
.outlet.on .outlet-led { background: #3ddc7f; box-shadow: 0 0 8px rgba(61, 220, 127, .9); }
.outlet.unknown .outlet-led { background: #f0625f; box-shadow: 0 0 8px rgba(240, 98, 95, .9); }
.outlet.busy .outlet-led { background: #f0b429; box-shadow: 0 0 8px rgba(240, 180, 41, .9); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.recep { display: block; width: 46px; height: 50px; }
.recep .face { fill: #0e1114; stroke: #05070a; stroke-width: 1; }
.recep .bezel { fill: none; stroke: #3c434b; stroke-width: 1; }
.recep .slot { fill: #04050700; }
.recep .slot { fill: #050709; }
.outlet.on .recep .face { fill: #121a15; }
.outlet.on .recep { filter: drop-shadow(0 0 5px rgba(61, 220, 127, .35)); }
.outlet.unknown .recep .face { fill: #1a1213; }

.outlet-label {
  font-size: 10px; line-height: 1.3; color: #c6ccd4; text-align: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.outlet-label.unnamed { color: #6f7883; font-style: italic; }
/* Hovering hints that the name is editable, since the faceplate otherwise
   looks like a read-only picture of the hardware. */
.outlet:hover .outlet-label { text-decoration: underline dotted; text-underline-offset: 2px; color: #eef2f6; }

/* a locked outlet is visually fenced off, not merely dimmed */
.outlet.locked { border-color: rgba(240, 180, 41, .55); background: rgba(240, 180, 41, .085); }
.outlet.locked:hover { background: rgba(240, 180, 41, .13); }
.outlet .badge-lock { font-size: 9px; color: #f0b429; font-weight: 700; letter-spacing: .04em; }
.outlet .badge-prot { font-size: 9px; color: #8a94a1; }

.unit-offline-note { font-size: 12px; color: var(--danger); margin: 8px 0 0; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log th, table.log td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.log th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); }
table.log tr:last-child td { border-bottom: 0; }
.ev-ok { color: var(--on); font-weight: 600; }
.ev-fail { color: var(--danger); font-weight: 600; }
.ev-lock { color: var(--warn); font-weight: 600; }

.inline-form { margin-top: 18px; padding: 16px; }
.inline-form h3 { margin: 0 0 12px; font-size: 14px; }
.inline-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-fields input, .inline-fields select { flex: 1 1 150px; width: auto; }
.inline-fields .btn { flex: 0 0 auto; }

/* ---- modal / sheet ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 20px; z-index: 50; overflow-y: auto; }
.modal { width: 100%; max-width: 430px; padding: 22px; }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal p { margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.sheet { max-width: 460px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0; }
.sheet-sub { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
.state-pill { font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; background: var(--off-soft); color: var(--muted); flex: none; }
.state-pill.on { background: rgba(53, 196, 111, .16); color: var(--on); }
.state-pill.busy { background: rgba(224, 163, 58, .16); color: var(--warn); }
.state-pill.unknown { background: rgba(240, 98, 95, .16); color: var(--danger); }
.sheet-section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.sheet-section h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.action-row { display: flex; gap: 8px; }
.action-row .btn { flex: 1; }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row .btn { flex: none; }
.check-row { display: flex; align-items: flex-start; gap: 9px; margin-top: 12px; font-size: 13px; }
.check-row input[type=checkbox] { width: auto; margin-top: 3px; flex: none; }
.locked-note { background: rgba(240, 180, 41, .12); border: 1px solid rgba(240, 180, 41, .4); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-top: 12px; }
