/* CAPS Monitoring portal — styled to match the CAPS homepage mockup
   (modern-homepage-mockup): Barlow Condensed headings, IBM Plex Sans body,
   orange #f15a24, dark nav #101619, paper #f5f5f2, 4px radius. */
:root {
  --paper: #f5f5f2;
  --surface: #ffffff;
  --ink: #151a1d;
  --muted: #536067;
  --line: #cfd3d2;
  --orange: #f15a24;
  --orange-dark: #c73f0c;
  --nav: #101619;
  --nav-ink: #f8faf9;
  --lime: #c7dd4b;
  --green: #1e8e4e;
  --red: #c0392b;
  --amber: #b7791f;
  --radius: 4px;
  --shadow: 0 18px 45px rgba(20, 26, 29, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--orange-dark); }

h1, h2, h3 {
  font-family: "Barlow Condensed", "IBM Plex Sans", sans-serif;
  line-height: 0.94;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: -0.02em;
}

/* ---- header ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--nav);
  color: var(--nav-ink);
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  padding: 0 16px;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar .brand-logo {
  height: 58px;
  width: auto;
  flex: none;
  border-radius: 2px;
}
.topbar .nav-links {
  display: flex;
  align-items: center;
  gap: 28px;
}
.topbar .nav-links a {
  text-decoration: none;
  font-size: 0.91rem;
  font-weight: 600;
  color: #dbe0df;
  white-space: nowrap;
}
.topbar .nav-links a:hover,
.topbar .nav-links a:focus-visible { color: #fff; }
.topbar .brand {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f5b47b;
  white-space: nowrap;
  margin-left: auto;
}
.topbar .availability {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  color: #d2d8d7;
  white-space: nowrap;
}
.topbar .availability i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 0 4px rgba(199, 221, 75, 0.15);
}
.topbar .phone {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  background: var(--orange);
  color: #fff;
  padding: 12px 17px;
  font-weight: 700;
  border-radius: var(--radius);
  white-space: nowrap;
}
.topbar .phone:hover { background: #ff7440; }
.topbar .phone svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.topbar .userline {
  font-size: 13px;
  color: #c8d3dd;
  white-space: nowrap;
}
.topbar button.linklike {
  background: none;
  border: none;
  color: #f5b47b;
  font: inherit;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}

/* ---- portal sub-header: logo + page title (left), nav (center), user (right) ---- */
.subbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.subbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.subbar .brand-logo {
  height: 38px;
  width: auto;
  flex: none;
  border-radius: 2px;
}
.subbar-back {
  font-size: 13px;
  color: var(--orange-dark);
  white-space: nowrap;
}
.subbar .site-name {
  font-family: "Barlow Condensed", "IBM Plex Sans", sans-serif;
  font-size: 22px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subbar .site-picker {
  font-family: "Barlow Condensed", "IBM Plex Sans", sans-serif;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px 6px;
  max-width: 60vw;
}
.subbar .subbar-user {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  flex: 1;
  text-align: right;
}
.subbar .subbar-user a { color: var(--orange-dark); }
.subbar .subbar-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: none;
}
.subbar .subbar-nav a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--orange);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.subbar .subbar-nav a:hover { background: var(--orange-dark); }
.subbar button.linklike {
  background: none;
  border: none;
  color: var(--orange-dark);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---- layout ---- */
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}
.muted { color: var(--muted); font-size: 14px; }
.error {
  background: #fdecea;
  color: var(--red);
  border: 1px solid #f5c6c0;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 15px;
}
.okmsg {
  background: #e6f4ea;
  color: var(--green);
  border: 1px solid #b7dfc2;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 15px;
}
.hidden { display: none !important; }

/* Eyebrow label, as on the homepage (uppercase + orange dash). */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.eyebrow::before {
  content: "";
  width: 36px;
  height: 3px;
  background: var(--orange);
}

/* ---- tiles ---- */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 92px;
  box-shadow: 0 2px 8px rgba(20, 26, 29, 0.06);
}
.tile .label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.tile .value {
  font-family: "Barlow Condensed", "IBM Plex Sans", sans-serif;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}
.tile .value small { font-size: 16px; font-weight: 600; color: var(--muted); }
.tile .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tile.status-ok .value { color: var(--green); }
.tile.status-bad .value { color: var(--red); }
.tile.status-warn .value { color: var(--amber); }
.tile.status-na .value { color: var(--muted); }
.tile.clickable { cursor: pointer; }

/* ---- chart card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(20, 26, 29, 0.06);
}
.card h2 {
  margin: 0 0 8px;
  font-size: 22px;
}
#chart { width: 100%; min-height: 220px; }
.chart-empty { color: var(--muted); font-size: 14px; padding: 40px 0; text-align: center; }

/* ---- log tables (fault / acknowledgement / reset history) ---- */
table.log { width: 100%; border-collapse: collapse; font-size: 15px; }
table.log th, table.log td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.log th {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
table.log tr:last-child td { border-bottom: none; }

/* ---- link-style buttons (sign out, cancel) ---- */
button.linklike {
  background: none;
  border: none;
  color: var(--orange-dark);
  font: inherit;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}

/* ---- scrollable log tables (CAPS admin landing) ---- */
.log-scroll { max-height: 440px; overflow-y: auto; }

/* ---- admin navigation (CAPS admin landing) ---- */
.admin-nav { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; }
.admin-nav a {
  display: inline-block;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--orange);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  font-size: 15px;
}
.admin-nav a:hover { background: var(--orange-dark); }
label.fld { display: block; margin: 0 0 12px; font-weight: 600; font-size: 15px; }
label.fld input[type="text"], label.fld input[type="email"],
label.fld input[type="tel"], label.fld input[type="password"],
label.fld input[type="number"], label.fld textarea, select.fld-select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; font-weight: 400; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
label.fld textarea { min-height: 88px; resize: vertical; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row label.fld { flex: 1; min-width: 140px; }
label.fld input:disabled { background: #f0f0ee; color: var(--muted); }
fieldset.fld { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; }
fieldset.fld legend { font-weight: 600; font-size: 15px; padding: 0 4px; }
label.chk { display: block; margin: 6px 0; font-weight: 400; font-size: 15px; }
label.chk input { margin-right: 6px; }
.access-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 15px; }
.access-row input[type="checkbox"] { width: 18px; height: 18px; }
.access-row label { flex: 1; }
.access-row select { padding: 6px 8px; font: inherit; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

/* ---- forms ---- */
form.card label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin: 12px 0 4px;
}
form.card label:first-child { margin-top: 0; }
input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 12px;
  border: 1px solid #b9c4cd;
  border-radius: var(--radius);
  background: #fff;
}
input:focus { outline: 2px solid var(--orange); outline-offset: 0; border-color: var(--orange); }
button.primary {
  width: 100%;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: var(--orange);
  border: none;
  border-radius: var(--radius);
  padding: 13px;
  margin-top: 16px;
  cursor: pointer;
}
button.primary:hover { background: #ff7440; }
button.primary:active { background: var(--orange-dark); }
button.primary:disabled { opacity: 0.55; cursor: default; }
button.danger {
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
}
button.danger:active { opacity: 0.85; }
.divider {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 18px 0 4px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.center { text-align: center; }
.logo { font-size: 22px; font-weight: 800; margin: 28px 0 4px; }
.logo span { color: var(--orange); }
.logo-img {
  display: block;
  width: min(360px, 85vw);
  height: auto;
  margin: 28px auto 4px;
}
.tagline { color: var(--muted); margin: 0 0 20px; }

footer.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0 24px;
}

@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .subbar .site-name { font-size: 26px; }
  }

@media (max-width: 850px) {
  .topbar .nav-links a:nth-child(2) { display: none; }
  .topbar .availability { display: none; }
  .topbar .phone { padding: 10px 12px; }
}

@media (max-width: 520px) {
  .topbar .nav-links { display: none; }
  .topbar .phone span { display: none; }
  .topbar .phone { padding: 10px 12px; }
}

/* ---- users/admin tables: stop the wrapping, one badge per site ---- */
table.users-table th { white-space: nowrap; }
table.users-table td { vertical-align: top; }
table.users-table td.nowrap { white-space: nowrap; }
table.users-table td.actions { white-space: nowrap; }
.site-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.site-badge {
  display: inline-block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
}
.site-badge .badge-site { display: block; font-weight: 600; white-space: nowrap; }
.site-badge .badge-level { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; }
tr.sites-row td { border-top: none; padding-top: 0; padding-bottom: 14px; }
/* A bolder line between one user and the next (the contact row that
   follows a sites row). */
table.users-table tr.sites-row + tr td { border-top: 2px solid #9aa0a3; }

/* ---- low oil temp setpoint, below the oil-temp chart ---- */
.setpoint { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.setpoint-label { font-weight: 600; }
.setpoint input[type="number"] { width: 90px; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: var(--radius); }
.setpoint button { font: inherit; font-size: 15px; font-weight: 700; color: #fff; background: var(--orange); border: none; border-radius: var(--radius); padding: 8px 16px; cursor: pointer; }
.setpoint button:hover { background: #ff7440; }
.setpoint button:disabled { opacity: 0.55; cursor: default; }

/* ---- site header pulled from the main website ---- */
/* The portal's top header is fetched from the real site (see
   app/site_header.py). The site header wraps its links in a <nav>,
   carries a Monitoring link and a Facebook link, so those need rules
   the built-in header did not. The nav-links margin pushes the
   social/availability/phone items to the right edge.
   The nav also carries the site's "wrap" class, which on the portal
   means the 720px content column — that would squeeze the header into
   a narrow centered strip. Override it here to the site's own wrap
   width (1180px, centered) so the header looks exactly like the
   website's. */
.topbar .nav { display: flex; align-items: center; gap: 28px; flex: 1; min-width: 0; max-width: 1180px; margin-inline: auto; padding: 0; }
.topbar .nav-links { margin-right: auto; }
.nav-links a.monitoring { color: #fff; border: 1px solid rgba(255,255,255,.45); border-radius: 4px; padding: 6px 12px; }
.nav-links a.monitoring:hover { border-color: #fff; background: rgba(255,255,255,.08); }
.social-link { display: flex; align-items: center; color: #dbe0df; text-decoration: none; flex: none; }
.social-link:hover, .social-link:focus-visible { color: #fff; }
.social-link svg { width: 22px; height: 22px; fill: currentColor; }

/* ---- login page logo ---- */
.login-logo { display: block; margin: 12px auto 4px; max-width: 300px; width: 100%; height: auto; }
