/* Shared design tokens — matches the Apex family's real spec (borrowed
   from the Core/Monitoring apps' own stylesheets, read-only, 2026-08-27),
   not an approximation. Light is the default; dark applies via an explicit
   data-theme="dark" (set by theme-toggle.js) or the OS preference when the
   user hasn't chosen. */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --text: #1c2130;
  --muted: #6b7280;
  --border: #e3e6ee;

  --primary: #005ea9;
  --primary-hover: #004a87;
  --primary-text: #ffffff;
  --primary-tint: #e7f2fb;

  --ok: #16a34a;
  --ok-tint: #ecfdf5;
  --warn: #d97706;
  --warn-tint: #fffbeb;
  --down: #dc2626;
  --down-tint: #fef2f2;

  --badge-bg: var(--primary-tint);
  --badge-text: var(--primary);

  --radius: 10px;
  --radius-lg: 16px;
  --gap: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141c;
    --surface: #1b1e29;
    --surface-2: #1e293b;
    --text: #e7e9f2;
    --muted: #9198ad;
    --border: #2e3244;

    --primary: #3fa9ff;
    --primary-hover: #6cb8ff;
    --primary-text: #0b0e15;
    --primary-tint: rgba(63, 169, 255, 0.16);

    --ok: #4ade80;
    --ok-tint: rgba(74, 222, 128, 0.14);
    --warn: #fbbf24;
    --warn-tint: rgba(251, 191, 36, 0.14);
    --down: #f87171;
    --down-tint: rgba(248, 113, 113, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg: #12141c;
  --surface: #1b1e29;
  --surface-2: #1e293b;
  --text: #e7e9f2;
  --muted: #9198ad;
  --border: #2e3244;

  --primary: #3fa9ff;
  --primary-hover: #6cb8ff;
  --primary-text: #0b0e15;
  --primary-tint: rgba(63, 169, 255, 0.16);

  --ok: #4ade80;
  --ok-tint: rgba(74, 222, 128, 0.14);
  --warn: #fbbf24;
  --warn-tint: rgba(251, 191, 36, 0.14);
  --down: #f87171;
  --down-tint: rgba(248, 113, 113, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

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

/* ---------- Top bar ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  padding: 18px 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.hamburger-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text);
  min-height: auto;
}

.hamburger-btn svg {
  width: 22px;
  height: 22px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text);
}

.brand-lockup .hex {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

.brand-lockup .product-name {
  font-family: 'Aldrich', sans-serif;
  font-weight: 400;
  letter-spacing: 2.4px;
  color: var(--primary);
  font-size: 24px;
  line-height: 1;
  text-transform: uppercase;
  -webkit-text-stroke: 0.6px currentColor;
}

/* ---------- Apex brand lockup ----------
   Matches the real spec exactly (copied from Monitoring's own base.html/
   styles.css, read-only reference): the topbar reuses the same STACKED
   layout as the login page (apex-brand-login), just narrower
   (apex-brand-topbar overrides --brand-width). Not a separate "compact
   side-by-side" variant — that was wrong in an earlier pass. */
.apex-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.apex-brand-mark {
  display: block;
  width: var(--brand-width, 180px);
  height: auto;
  flex-shrink: 0;
}

.apex-brand-text {
  display: flex;
  flex-direction: column;
}

.apex-brand-technology {
  display: flex;
  justify-content: space-between;
  width: var(--brand-width, 180px);
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
}

.apex-brand-login {
  --brand-width: 220px;
  flex-direction: column;
  align-items: center;
}

.apex-brand-login .apex-brand-text {
  /* The reference used -14px, tuned for their un-cropped logo file (which
     had empty bottom padding built in). Ours was cropped tight to the
     "APEX X" mark (see apex-logo.png), so a small positive gap is correct
     here instead — verified live at 4px. */
  margin-top: 4px;
  align-items: center;
}

.apex-brand-login .apex-brand-technology {
  font-size: 10px;
  color: #aeb1bc;
}

/* Topbar override — smaller mark than the full login page, same stacked
   layout. The reference spec uses 130px here, but that read too small
   against FieldView's own hex lockup at actual screen size — bumped up
   and confirmed visually live. */
.apex-brand-topbar {
  --brand-width: 210px;
}

.topbar-center {
  display: flex;
  justify-content: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.user-badge {
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.theme-toggle-wrap {
  position: relative;
  display: inline-flex;
}

.theme-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  min-height: auto;
}

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
}

.theme-menu {
  position: absolute;
  top: 40px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 130px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: none;
  z-index: 30;
}

.theme-menu.open {
  display: block;
}

.theme-menu button {
  width: 100%;
  /* Grid, not flex: measured a reproducible ~8px position discrepancy for
     one specific row with flexbox despite every computed style on the
     button, icon wrapper, and svg being byte-identical across rows —
     narrowed down to Chromium's flex layout itself, not any CSS property
     under our control. Explicit grid columns are unambiguous by
     construction, sidestepping whatever that quirk was. */
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  min-height: auto;
}

.theme-menu button:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.theme-menu button.active {
  background: var(--primary);
  color: var(--primary-text);
}

/* Fixed-size icon slot, not just a bare sized <svg> — some rows measured
   ~8px off from others despite every svg sharing the exact same viewBox and
   explicit width/height (confirmed even after swapping one icon's markup
   for another's, so it wasn't about the path content). Wrapping in a fixed
   fully-controlled flex box sidesteps whatever per-element quirk caused
   that instead of chasing it further. */
.theme-menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.theme-menu svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.user-info {
  text-align: right;
  line-height: 1.2;
}

.user-info .name {
  font-weight: 700;
  font-size: 0.85rem;
}

.user-info .role {
  font-size: 0.7rem;
  color: var(--muted);
}

.topbar-right a.signout {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 10px 12px;
    gap: 6px;
  }
  .user-info {
    display: none;
  }
  .brand-lockup .product-name {
    display: none;
  }
  .brand-lockup .hex {
    width: 40px;
    height: 40px;
  }
  /* Shrinks the centered Apex mark's width (and its TECHNOLOGY subtitle,
     which shares the same --brand-width) so it stops squeezing the side
     columns down to the point of clipping "Log out" — height follows the
     image's own aspect ratio via width:var(--brand-width);height:auto, so
     only the width variable needs overriding here. */
  .apex-brand-topbar {
    --brand-width: 90px;
  }
  .user-badge {
    display: none;
  }
}

.nav-dropdown {
  position: absolute;
  top: 40px;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: none;
  z-index: 30;
}

.nav-dropdown.open {
  display: block;
}

.nav-dropdown a {
  display: block;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav-dropdown a:hover {
  background: var(--surface-2);
}

.nav-dropdown a.signout-link {
  color: var(--down);
}

.nav-dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

/* ---------- Page layout ---------- */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 28px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
}

h2 {
  font-size: 1.05rem;
  color: var(--muted);
  margin: 24px 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--badge-bg);
  color: var(--badge-text);
}

.badge.badge-neutral {
  background: var(--surface-2);
  color: var(--muted);
}

.badge.badge-warn {
  background: var(--warn-tint);
  color: var(--warn);
}

.badge.badge-ok {
  background: var(--ok-tint);
  color: var(--ok);
}

.breadcrumb {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 8px;
}

.breadcrumb:hover {
  color: var(--primary);
}

.status-text {
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-text.ok { color: var(--ok); }
.status-text.warn { color: var(--warn); }
.status-text.down { color: var(--down); }

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

.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.down { background: var(--down); }

/* ---------- Buttons ---------- */

button,
input[type="submit"],
.btn {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:active,
.btn:active {
  opacity: 0.85;
}

.btn-dark {
  background: #475569;
  color: #ffffff;
}

.btn-dark:hover {
  background: #3f4a5c;
}

.btn-primary,
button[type="submit"] {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover,
button[type="submit"]:hover {
  background: var(--primary-hover);
}

/* ---------- Cards / stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--gap);
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card .label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 4px;
}

.stat-card .value.value-text {
  font-size: 1.1rem;
}

/* ---------- Project card grid ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: block;
}

.project-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.project-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.project-card-top h3 {
  margin: 0;
  font-size: 16px;
}

.project-card-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

/* ---------- Lists / rows ---------- */

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li,
.list-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 12px;
  padding: 14.4px 17.6px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.list-row:hover {
  border-top-color: #475569;
  border-right-color: #475569;
  border-bottom-color: #475569;
}

.list-row.ok { border-left-color: var(--ok); }
.list-row.warn { border-left-color: var(--warn); }
.list-row.down { border-left-color: var(--down); }

.list-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.list-row-title {
  font-weight: 700;
}

.list-row-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.list-row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.list-row form {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
}

/* ---------- Forms ---------- */

input[type="text"],
input[type="date"],
input[type="email"],
select {
  font-size: 16px; /* prevents iOS auto-zoom on focus */
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 4px 0;
}

/* iOS WebKit's native date picker control (Safari and Chrome-on-iOS both —
   Apple requires every iOS browser to render through WebKit) enforces its
   own minimum content width for the day/month/year segments + calendar
   icon — confirmed by the user it physically overflows past the form
   card's own right edge, so width:100%/max-width/min-width:0 alone weren't
   enough (min-width:0 didn't help either). -webkit-appearance:none strips
   the native OS chrome that carries that enforced minimum size, handing
   full control back to normal CSS box sizing — the standard fix for this
   class of WebKit bug. Trade-off: the calendar icon glyph may disappear
   since it's part of that native appearance; tapping the field still opens
   the native date picker regardless. Not reproducible in this session's
   Chromium-based tooling — still unverified on a real device as of this
   attempt. */
input[type="date"] {
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 8px 0 2px;
}

form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
}

/* Filter/search bar: fields stack on phones, sit in a row on wider screens */
.filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-field {
  min-width: 0; /* lets the date input shrink to fit instead of overflowing
                   its flex/grid track — some browsers' native date control
                   otherwise ignores width:100% and forces its own min size */
}

.filter-field label {
  margin: 0 0 2px;
}

@media (min-width: 640px) {
  .filters {
    flex-direction: row;
    align-items: flex-end;
    flex-wrap: wrap;
  }
  .filters > * {
    flex: 1;
    min-width: 140px;
  }
}

input[type="file"] {
  display: block;
  width: 100%;
  margin: 8px 0;
  font-size: 15px;
}

/* ---------- Pill tabs ---------- */

.pill-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.pill-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  min-height: auto;
}

.pill-tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--badge-bg);
}

/* ---------- Media gallery ---------- */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

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

.media-card img,
.media-card video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
  display: block;
}

.media-card .media-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-card form {
  padding: 0;
  border: none;
  margin: 0;
  background: none;
}

.media-card input[type="text"] {
  font-size: 14px;
  padding: 6px 8px;
}

/* ---------- Upload picker/preview ---------- */

.upload-form {
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-preview {
  margin-top: 12px;
}

.upload-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.upload-preview-grid img,
.upload-preview-grid video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: block;
}

.upload-preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

th {
  background: var(--surface-2);
  color: var(--muted);
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
}

.inline-form select {
  width: auto;
  margin: 0;
}

.page-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -8px 0 16px;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px 20px;
  z-index: 100;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  left: 16px;
}

/* ---------- Error pages ---------- */

.error-page {
  text-align: center;
  padding: 60px 20px;
}

.error-code {
  font-family: 'Aldrich', sans-serif;
  font-size: 4rem;
  color: var(--primary);
  line-height: 1;
}

.error-page h1 {
  margin: 8px 0 4px;
}

.error-page .page-hint {
  margin: 0 auto 20px;
  max-width: 420px;
}
