/* ==========================================================================
   Ductos360 — design system
   Tokens → base → layout → components → pages → utilities → user preferences
   Every text/background pair meets WCAG 2.2 AA (4.5:1); check new ones too.
   ========================================================================== */

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Light surfaces (app) */
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-sunken: #eef2f6;
  --border: #e1e6ed;
  --border-strong: #cbd3de;

  --text: #0f1b2d;
  --text-muted: #4f5f76;
  --text-subtle: #5e6b7e;
  --placeholder: #687487;

  --brand: #0b5cab;
  --brand-strong: #084a8b;
  --brand-soft: #e8f1fb;
  --accent: #c8963e;
  --accent-strong: #8a611d;
  --accent-soft: #f8efdf;

  --ok: #0f7a52;        --ok-soft: #e4f5ed;
  --warn: #975a00;      --warn-soft: #fff2d9;
  --danger: #b42318;    --danger-soft: #fdeceb;
  --info: #0b5cab;      --info-soft: #e8f1fb;
  --neutral: #4f5f76;   --neutral-soft: #edf0f4;

  /* Dark surfaces (sidebar, viewer, public pages, toasts) */
  --ink-950: #0a1422;
  --ink-900: #0c1a2c;
  --ink-850: #0f1d31;
  --ink-800: #15263c;
  --ink-750: #1a2b43;
  --ink-700: #1f3a5c;
  --ink-line: #1b2b41;
  --ink-text-strong: #e6edf5;
  --ink-text: #d5deea;
  --ink-text-soft: #a9b8cc;
  --ink-muted: #8ea0b8;

  --focus: var(--brand);
  --focus-ring: 0 0 0 3px rgb(11 92 171 / 0.28);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgb(15 27 45 / 0.06);
  --shadow: 0 1px 2px rgb(15 27 45 / 0.05), 0 3px 10px rgb(15 27 45 / 0.05);
  --shadow-lg: 0 16px 40px rgb(15 27 45 / 0.16);

  --sidebar-w: 244px;
  --content-max: 1280px;
  --target: 32px; /* minimum size of small controls; 44px on touch screens */
}

/* Dark areas need a light focus indicator. */
.sidebar, .mobile-bar, .messages, .viewer, .auth-aside, .public { --focus: #8cc2ff; }

/* --- Base ----------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* The [hidden] attribute must win over component display rules (e.g. video { display: block }). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv11', 'ss01';
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img, video { max-width: 100%; display: block; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
small { font-size: 12px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Skip-link targets get focus programmatically; no ring needed there. */
[tabindex='-1']:focus { outline: none; }

.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}

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

.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 100;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--brand); color: #fff; font-weight: 600;
  box-shadow: var(--shadow-lg);
}
.skip-link:focus { top: 12px; text-decoration: none; }

/* --- App shell ------------------------------------------------------------ */

.shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--ink-900);
  color: var(--ink-text-soft);
  border-right: 1px solid var(--ink-line);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 18px;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); font-weight: 700; }
.brand-mark { width: 32px; height: 32px; flex: none; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; }
.nav-label {
  padding: 14px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-text-soft);
  font-weight: 500;
}
.nav-link:hover { background: var(--ink-800); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--ink-800); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-link .icon { opacity: 0.9; }

.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--ink-line); }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px 6px 4px; }
.user-card > div { min-width: 0; flex: 1; }
.user-card strong, .user-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card strong { color: #fff; font-weight: 500; font-size: 13px; }
.user-card small { color: var(--ink-muted); }
.avatar {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--ink-700);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--target); height: var(--target); flex: none;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: var(--ink-800); color: #fff; }

.main { margin-left: var(--sidebar-w); min-width: 0; }
.content { max-width: var(--content-max); margin: 0 auto; padding: 28px 32px 56px; }

.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
  /* visibility keeps the closed drawer out of the tab order. */
  .sidebar {
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { visibility: visible; transform: none; transition: transform 0.2s ease; }
  .sidebar-backdrop.is-open { display: block; position: fixed; inset: 0; background: rgb(12 26 44 / 0.45); z-index: 30; }
  .main { margin-left: 0; }
  .mobile-bar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    background: var(--ink-900);
    color: #fff;
  }
  .mobile-bar .brand { padding: 0; font-size: 16px; }
  .content { padding: 20px 16px 48px; }
}

/* --- Page header ---------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head > div:first-child { min-width: 0; }
.page-sub { margin-top: 6px; color: var(--text-muted); max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-subtle);
}

.breadcrumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; color: var(--text-subtle); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs .icon { width: 14px; height: 14px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--surface-muted); border-color: var(--text-subtle); text-decoration: none; }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-sunken); border-color: transparent; color: var(--text); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); border-color: #f1b8b3; color: var(--danger); }
.btn--destructive { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--destructive:hover { background: #912018; border-color: #912018; }
.btn--sm { height: var(--target); padding: 0 10px; font-size: 13px; gap: 6px; }
.btn--block { width: 100%; }
.btn .icon { width: 16px; height: 16px; }

.inline-form { display: inline; margin: 0; }

/* --- Cards & layout ------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-head p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.card-body { padding: 20px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.layout > * { min-width: 0; }
.layout-main, .layout-aside { display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 1100px) { .layout { grid-template-columns: minmax(0, 1fr); } }

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

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-subtle);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
/* The first link of a row covers the whole row (see .row-link::after). */
.table tbody tr { position: relative; transition: background-color 0.1s; }
.table tbody tr:hover { background: var(--surface-muted); }
.table .num { text-align: right; }
.row-link { color: var(--text); font-weight: 600; }
.row-link::after { content: ''; position: absolute; inset: 0; }
.cell-sub { display: block; font-size: 12px; color: var(--text-subtle); margin-top: 1px; }
/* Secondary columns are dropped on phones instead of squeezing every cell. */
@media (max-width: 640px) {
  .col-opt { display: none; }
  .table th, .table td { padding-left: 12px; padding-right: 12px; }
}

/* --- Badges & tags -------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--plain::before { display: none; }
.badge--spin::before {
  width: 9px; height: 9px;
  background: none;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted); background: var(--surface-muted);
}

/* --- Toolbar & search ----------------------------------------------------- */

.toolbar {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.toolbar .grow { flex: 1 1 240px; }

.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
/* Same specificity as the generic input[type='search'] rule below, which would win otherwise. */
.search input[type='search'] { padding-left: 36px; }

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

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .form-grid, .form-grid--3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid--pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.field .optional { font-weight: 400; color: var(--text-subtle); }
.help { font-size: 12px; color: var(--text-subtle); }
.field-error { font-size: 12px; font-weight: 500; color: var(--danger); }
.field-error a { color: inherit; font-weight: 600; text-decoration: underline; }

input[type='text'], input[type='search'], input[type='number'], input[type='date'], input[type='email'],
input[type='password'], input[type='url'], select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
textarea { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235e6b7e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-subtle); }
/* Fields show focus with their border + ring instead of the generic outline. */
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
.field.has-error :is(input, select, textarea) { border-color: var(--danger); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }

.fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.fieldset + .fieldset { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.fieldset-head { margin-bottom: 16px; }
.fieldset-head h2 { font-size: 15px; }
.fieldset-head p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.subfieldset {
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0; margin: 0; padding: 12px 16px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-muted);
}
.subfieldset legend { display: flex; align-items: center; gap: 6px; padding: 0 6px; margin-left: -6px; font-size: 13px; font-weight: 600; }
.subfieldset legend .icon { color: var(--brand); }
.subfieldset legend small { font-weight: 400; color: var(--text-subtle); }

.form-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* --- Alerts, toasts & confirm dialog -------------------------------------- */

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.alert .icon { margin-top: 1px; }
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }
.alert--warn { background: var(--warn-soft); border-color: #f2d49a; color: #7a4a00; }
.alert--danger { background: var(--danger-soft); border-color: #f4c2bd; color: #8f1d13; }
.alert--ok { background: var(--ok-soft); border-color: #b6e2cd; color: #0b5e3f; }
.alert pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; }
.alert details { margin-top: 6px; }
.alert summary { cursor: pointer; font-weight: 500; width: fit-content; }

.messages { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.message {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 8px 12px 14px;
  border-radius: var(--radius);
  background: var(--ink-900); color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 0.2s ease;
}
.message > .icon { margin-top: 1px; }
.message--success > .icon { color: #5fd3a2; }
.message--error > .icon { color: #ff8b80; }
.message--warning > .icon { color: #ffcc66; }
.message--info > .icon { color: #8cc2ff; }
.message p { flex: 1; }
.message .icon-btn { margin: -6px 0; color: var(--ink-muted); }
.message.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.2s ease, transform 0.2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

.confirm {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 0; border-radius: var(--radius-lg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.confirm::backdrop { background: rgb(12 26 44 / 0.5); }
.confirm p { font-size: 15px; margin-bottom: 20px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* --- Empty states & pagination -------------------------------------------- */

.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty-icon {
  width: 48px; height: 48px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
}
.empty-icon .icon { width: 22px; height: 22px; }
.empty h3 { font-size: 15px; margin-bottom: 4px; }
.empty p { max-width: 46ch; margin: 0 auto; }
.empty .btn { margin-top: 16px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.pagination-links { display: flex; gap: 6px; }

/* --- Definition lists & route --------------------------------------------- */

.meta { display: grid; gap: 14px; margin: 0; }
.meta > div { display: grid; gap: 2px; }
.meta dt { font-size: 12px; color: var(--text-subtle); }
.meta dd { margin: 0; font-weight: 500; }
.meta--grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.meta--wide { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.meta .meta-full { grid-column: 1 / -1; }

.route {
  display: flex; align-items: center; gap: 10px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}
.route-node { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 72px; text-align: center; }
.route-node strong { font-size: 13px; }
.route-node small { color: var(--text-subtle); }
.route-dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--brand); background: var(--surface); }
.route-pipe { flex: 1; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--brand), #5b9be0); position: relative; }
.route-pipe span { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--text-subtle); white-space: nowrap; }

/* --- Thumbnails & video parts --------------------------------------------- */

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--ink-800);
  color: var(--ink-text-soft);
  display: grid; place-items: center;
  flex: none;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .icon { width: 26px; height: 26px; }
.thumb-duration {
  position: absolute; right: 6px; bottom: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgb(0 0 0 / 0.72); color: #fff;
  font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums;
}

/* An inspection day: one group per manhole, each with its parts. */
.manhole-group { border-top: 1px solid var(--border); }
.manhole-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px 6px; }
.manhole-group-head h3 { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.manhole-group-head h3 .icon { color: var(--brand); }
.manhole-group.is-current .manhole-group-head h3 { color: var(--brand); }
.text-warn { color: var(--warn); }
.cinema-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.cinema-head h2 { font-size: 17px; }
.public .cinema-head h2 { color: #fff; }
.public .cinema-head .eyebrow { color: var(--ink-muted); }

.parts { display: flex; flex-direction: column; }
.part {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 8px 14px;
  align-items: start;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.part:last-child { border-bottom: 0; }
.part.is-current { background: var(--brand-soft); }
.part-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.part-meta { font-size: 12px; color: var(--text-subtle); margin-top: 2px; overflow-wrap: anywhere; }
.part-error { grid-column: 2 / -1; }
.part-actions { display: flex; gap: 6px; }
@media (max-width: 640px) {
  .part { grid-template-columns: 96px minmax(0, 1fr); }
  .part-actions, .part-error { grid-column: 1 / -1; }
}

/* --- Upload --------------------------------------------------------------- */

.dropzone {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 20px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone.is-dragover { border-color: var(--brand); background: var(--brand-soft); }
/* The real file input is invisible on top of the zone: show its keyboard focus on the zone. */
.dropzone:has(input:focus-visible) { border-color: var(--brand); box-shadow: var(--focus-ring); }
.dropzone-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface); color: var(--brand);
  box-shadow: var(--shadow-sm);
}
.dropzone strong { color: var(--text); font-size: 14px; }
.dropzone input[type='file'] { max-width: 100%; }
.is-enhanced .dropzone input[type='file'] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.is-enhanced [data-upload-fallback] { display: none; }

.upload-manhole { margin-bottom: 14px; }
.upload-form > .field-error { display: block; margin-bottom: 12px; }

.upload-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.upload-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.upload-item-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.upload-item-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.upload-item-status { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.upload-item.is-error .upload-item-status { color: var(--danger); }
.upload-item.is-done .upload-item-status { color: var(--ok); }
.progress { height: 6px; margin-top: 8px; border-radius: 3px; background: var(--surface-sunken); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 3px; transition: width 0.2s; }
.upload-item.is-done .progress > span { background: var(--ok); }
.upload-item.is-error .progress > span { background: var(--danger); }

/* --- 360° viewer ---------------------------------------------------------- */

.viewer { background: var(--ink-950); border-radius: var(--radius); overflow: hidden; }
.viewer-stage { position: relative; aspect-ratio: 16 / 9; }
/* z-index creates a stacking context so PSV's internal layers stay below the flat video. */
.viewer-canvas { position: absolute; inset: 0; z-index: 0; }
.viewer-host { position: absolute; inset: 0; }
/* Above Photo Sphere Viewer's own layers (navbar, overlays). */
.viewer-flat { position: absolute; inset: 0; z-index: 20; width: 100%; height: 100%; background: #000; object-fit: contain; }
.viewer-message {
  position: absolute; left: 12px; right: 12px; bottom: 60px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgb(10 20 34 / 0.85); color: #fff;
  font-size: 13px;
  z-index: 21;
}
/* Discreet controls over the video; above the flat <video> (z 20) so they work in both modes. */
.viewer-overlay {
  position: absolute; top: 12px; right: 12px; z-index: 22;
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end;
  max-width: calc(100% - 24px);
}
.viewer-overlay .segmented { background: rgb(10 20 34 / 0.72); backdrop-filter: blur(6px); }
.viewer-hint {
  position: absolute; left: 50%; top: 14px; z-index: 22; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: rgb(10 20 34 / 0.72); color: var(--ink-text);
  font-size: 12px; white-space: nowrap; pointer-events: none;
}
.viewer-empty {
  display: grid; place-items: center;
  min-height: clamp(220px, 32vh, 320px);
  padding: 24px;
  color: var(--ink-text-soft); text-align: center;
}
.viewer-empty .icon { width: 30px; height: 30px; margin: 0 auto 10px; color: var(--ink-muted); }
.viewer-empty strong { display: block; color: #fff; font-size: 15px; margin-bottom: 4px; }
.viewer-empty a { color: #8cc2ff; }
.viewer-empty .spinner { margin: 0 auto 12px; }

/* Cinema mode: the viewer spans the page width and most of the screen height. */
.cinema { margin-bottom: 24px; }
.viewer--cinema .viewer-stage { aspect-ratio: auto; height: clamp(320px, 72vh, 900px); }
@media (max-width: 640px) {
  .viewer--cinema .viewer-stage { aspect-ratio: 16 / 9; height: auto; }
  .viewer-hint { display: none; }
}

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--ink-750); }
.segmented button {
  min-height: 28px;
  border: 0; border-radius: 6px;
  padding: 5px 11px;
  background: transparent; color: var(--ink-text-soft);
  font: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer;
}
.segmented button:hover { color: #fff; }
.segmented button.is-active { background: #fff; color: var(--ink-900); }

.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 0.2); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}

/* Photo Sphere Viewer tweaks */
.viewer .psv-container { background: var(--ink-950); }
.viewer .psv-navbar { background: linear-gradient(transparent, rgb(0 0 0 / 0.65)); }

/* --- Share links ---------------------------------------------------------- */

.links { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.link-row { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.link-row:last-child { border-bottom: 0; }
.link-row.is-new { background: var(--ok-soft); }
.link-row.is-inactive { opacity: 0.6; }
.link-row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.link-row-head strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row-meta { font-size: 12px; color: var(--text-subtle); margin-top: 6px; }
.link-row-actions { display: inline-flex; gap: 4px; margin-left: auto; }
.link-row-head strong a { color: inherit; }
.link-row-head .icon { color: var(--brand); }
.link-credentials { margin-bottom: 10px; }
.link-credentials p + p { margin-top: 2px; }
.link-credentials .btn { margin-top: 8px; }
.field--mono input { font-family: var(--mono); }

/* Radio choices shown as cards (what a share link shares). */
.choice-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.choice-card {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.choice-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.choice-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice-card input { margin-top: 3px; accent-color: var(--brand); }
.choice-card strong { display: block; font-weight: 600; }
.choice-card small { color: var(--text-muted); font-size: 12px; }
.copy-field { display: flex; flex-wrap: wrap; gap: 6px; }
.copy-field input { flex: 1 1 100%; height: 32px; font-size: 12px; background: var(--surface-muted); font-family: var(--mono); }
.copy-field .btn { flex: 1; }

/* --- Map ------------------------------------------------------------------ */

.page-map .content { max-width: none; padding: 0; }
.map-page { position: relative; height: 100vh; height: 100dvh; }
/* isolation keeps Leaflet's high z-indexes (400–1000) below the floating cards and the sidebar. */
.map-canvas { position: absolute; inset: 0; isolation: isolate; background: var(--surface-sunken); }

/* Floating cards over the map; the zoom buttons sit on the top right. */
.map-toolbar, .map-legend {
  position: absolute; z-index: 2;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.map-toolbar { top: 16px; left: 16px; width: min(340px, calc(100% - 88px)); padding: 14px 16px; border-radius: var(--radius-lg); }
.map-toolbar-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.map-toolbar h1 { font-size: 17px; }
.map-toolbar-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.map-toolbar-note { display: flex; gap: 6px; align-items: flex-start; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.map-toolbar-note .icon { flex: none; margin-top: 1px; }
.map-missing { display: block; }
.map-missing summary { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
.map-missing ul { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0 0 20px; padding: 0; list-style: none; max-height: 120px; overflow-y: auto; }
.map-search { margin-top: 12px; }
.map-search-status { margin-top: 8px; font-size: 13px; color: var(--danger); }
.map-search-status:empty { display: none; }
.map-legend { left: 16px; bottom: 24px; display: flex; gap: 14px; flex-wrap: wrap; margin: 0; padding: 8px 14px; list-style: none; border-radius: var(--radius); font-size: 12px; color: var(--text-muted); }
.map-legend li { display: flex; align-items: center; gap: 6px; }
.map-legend-pin { width: 11px; height: 11px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: #7b889a; }
.map-legend-pin--inspected { background: var(--brand); }

/* Manhole pin: a teardrop (rotated square with three round corners) with the inspection count. */
.map-pin-anchor { background: none; border: 0; } /* Leaflet's default divIcon is a white box */
.map-pin {
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  background: #7b889a;
  box-shadow: 0 2px 6px rgb(15 27 45 / 0.35);
  transform: rotate(-45deg);
  transition: transform 0.12s, background-color 0.12s;
  cursor: pointer;
}
.map-pin--inspected { background: var(--brand); }
.map-pin-label { transform: rotate(45deg); color: #fff; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.map-pin-anchor:hover .map-pin, .map-pin-anchor.is-selected .map-pin { transform: rotate(-45deg) scale(1.15); }
.map-pin-anchor.is-selected .map-pin { background: var(--accent-strong); }
.map-pin-anchor:focus { outline: none; }
.map-pin-anchor:focus-visible .map-pin { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Dialog: a manhole's inspections, then the viewer of the chosen one. */
.map-dialog {
  width: min(560px, calc(100vw - 32px)); max-width: none; max-height: min(86dvh, 900px);
  padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.map-dialog[open] { display: flex; flex-direction: column; }
.map-dialog.is-playing { width: min(1400px, 96vw); max-height: 96dvh; }
.map-dialog::backdrop { background: rgb(5 12 22 / 0.6); }
.map-dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.map-dialog-head .icon-btn { color: var(--text-muted); }
.map-dialog-head .icon-btn:hover { background: var(--surface-sunken); color: var(--text); }
.map-dialog-titles { flex: 1; min-width: 0; }
.map-dialog-titles .eyebrow { margin-bottom: 2px; }
.map-dialog-titles h2 { font-size: 19px; }
.map-dialog-sub { color: var(--text-muted); font-size: 13px; }
.map-dialog-body { flex: 1; min-height: 0; overflow-y: auto; }
.map-dialog-player .viewer { border-radius: 0; }
.map-dialog-player .viewer--cinema .viewer-stage { height: min(78dvh, 860px); }

.map-manhole-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px 6px; font-size: 13px; color: var(--text-muted); }
.map-list { list-style: none; margin: 0; padding: 4px 12px 16px; }
.map-item {
  display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; align-items: center;
  width: 100%; padding: 8px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: inherit; font: inherit; text-align: left;
  cursor: pointer;
}
.map-item:hover { background: var(--surface-muted); border-color: var(--border); text-decoration: none; }
.map-item-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.map-item-text strong { font-size: 15px; font-weight: 600; }
.map-item-text small { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-item-play { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--brand); }

@media (max-width: 960px) {
  /* 52px = sticky mobile bar. */
  .map-page { height: calc(100dvh - 52px); }
  .map-toolbar { top: 12px; left: 12px; width: calc(100% - 76px); }
  .map-legend { left: 12px; bottom: 20px; gap: 10px; }
}
@media (max-width: 640px) {
  .map-dialog-head { flex-wrap: wrap; }
  .map-dialog-player .viewer--cinema .viewer-stage { height: auto; }
}

/* --- Dashboard ------------------------------------------------------------ */

.attention-list { list-style: none; margin: 0; padding: 0; }
.attention-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.attention-list li:last-child { border-bottom: 0; }
.attention-list a { font-weight: 500; }

.map-shortcut { display: flex; align-items: center; gap: 14px; padding: 18px 20px; color: var(--text); transition: border-color 0.12s, box-shadow 0.12s; }
.map-shortcut:hover { border-color: var(--brand); box-shadow: var(--shadow-lg); text-decoration: none; }
.map-shortcut > .icon { flex: none; color: var(--brand); }
.map-shortcut-art { width: 48px; height: 48px; flex: none; display: grid; place-items: center; border-radius: var(--radius); background: var(--brand-soft); color: var(--brand); }
.map-shortcut-art .icon { width: 24px; height: 24px; }
.map-shortcut-text { flex: 1; min-width: 0; }
.map-shortcut-text strong { display: block; font-weight: 600; }
.map-shortcut-text small { color: var(--text-muted); }

/* --- Auth ----------------------------------------------------------------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); background: var(--surface); }
.auth-aside {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 40px 48px;
  background: radial-gradient(1200px 600px at 110% 110%, #16365e 0%, transparent 60%), var(--ink-900);
  color: var(--ink-text);
}
.auth-aside .brand { padding: 0; font-size: 20px; }
.auth-aside .brand-mark { width: 38px; height: 38px; }
.auth-pitch { position: relative; z-index: 1; max-width: 440px; }
.auth-pitch h1 { color: #fff; font-size: 32px; line-height: 1.2; letter-spacing: -0.02em; }
.auth-pitch p { margin-top: 14px; font-size: 15px; color: var(--ink-text-soft); }
.auth-points { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 10px; }
.auth-points li { display: flex; gap: 10px; align-items: center; }
.auth-points .icon { color: var(--accent); }
.auth-rings { position: absolute; right: -140px; top: 50%; transform: translateY(-50%); width: 520px; height: 520px; opacity: 0.35; }
.auth-foot { position: relative; z-index: 1; font-size: 12px; color: var(--ink-muted); }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 22px; font-weight: 700; }
.auth-card > p { color: var(--text-muted); margin: 6px 0 24px; }
.auth-card > p.help { margin-top: -12px; margin-bottom: 8px; }
.auth-card > .alert { margin-bottom: 16px; }
.auth-card form { display: grid; gap: 16px; }
.auth-card .btn { height: 42px; }
.auth-card .empty-icon { margin: 0 0 16px; }
.auth-card .help ul { margin: 2px 0 0; padding-left: 18px; }
.auth-alt { margin-top: 20px; font-size: 13px; }
.auth-alt a { display: inline-flex; align-items: center; gap: 4px; }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-label-row label, .field-label-row a { font-size: 13px; }
.field-label-row label { font-weight: 500; }
@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-aside { padding: 24px; }
  .auth-pitch, .auth-foot, .auth-rings { display: none; }
}

/* --- Public (shared link) pages ------------------------------------------- */

.public { background: var(--ink-950); color: var(--ink-text); min-height: 100vh; }
.public-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px;
  border-bottom: 1px solid var(--ink-line);
  background: var(--ink-900);
}
.public-header .brand { padding: 0; }
.public-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-muted); }
.public-main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.public-title { margin-bottom: 18px; }
.public-title .eyebrow { color: var(--ink-muted); }
.public-title h1 { color: #fff; font-size: 26px; }
.public-title p { color: var(--ink-text-soft); margin-top: 6px; }
/* The history (side) comes first in the DOM so phones show it right under the video. */
.public-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: 'main side';
  gap: 20px; align-items: start;
}
.public-layout > * { min-width: 0; }
.public-layout-main { grid-area: main; }
.public-layout-side { grid-area: side; }
@media (max-width: 1000px) {
  .public-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'side' 'main'; }
}
.public-panel { border: 1px solid var(--ink-line); border-radius: var(--radius); background: var(--ink-850); }
.public-panel-head { padding: 14px 16px; border-bottom: 1px solid var(--ink-line); }
.public-panel-head h2 { color: #fff; font-size: 14px; }
.public-panel-body { padding: 16px; }
.public .meta dt { color: var(--ink-muted); }
.public .meta dd { color: var(--ink-text-strong); }
.public .viewer { border: 1px solid var(--ink-line); }
.public-footer { padding: 24px; text-align: center; font-size: 12px; color: var(--ink-muted); }
.public-history { list-style: none; margin: 0; padding: 6px; max-height: 560px; overflow-y: auto; }
.public-history a {
  display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius-sm);
  color: var(--ink-text);
}
.public-history a:hover { background: var(--ink-800); text-decoration: none; }
.public-history a.is-selected { background: var(--ink-700); box-shadow: inset 3px 0 0 var(--accent); }
.public-history strong { display: block; color: #fff; font-size: 13px; }
.public-history small { color: var(--ink-muted); }
.public-history .thumb { border-radius: 5px; }
.public-notes { white-space: pre-line; color: var(--ink-text); font-size: 13px; }
.public--map { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.public--map .public-main { flex: 1; min-height: 0; width: 100%; max-width: none; padding: 0; }
.public--map .map-page { height: 100%; }
.public .map-toolbar, .public .map-legend, .public .map-dialog { color: var(--text); --focus: var(--brand); }
.public .map-dialog .viewer { --focus: #8cc2ff; }

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

.unavailable { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.unavailable .card { max-width: 440px; padding: 36px 28px; }
.unavailable h1 { font-size: 20px; margin: 4px 0 8px; }
.unavailable p { color: var(--text-muted); }
.share-password { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.share-password .empty-icon, .share-password h1 { align-self: center; }
.share-password h1 { margin: 0; }
.share-password > p { text-align: center; }

/* --- Accounts ------------------------------------------------------------- */

.readonly-value { display: flex; align-items: center; height: 38px; color: var(--text-muted); }
.narrow { max-width: 560px; }

/* --- Utilities ------------------------------------------------------------ */

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row--center { justify-content: center; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.pre-line { white-space: pre-line; }
.only-coarse-pointer { display: none; }

/* --- User preferences & devices ------------------------------------------- */

/* Touch screens: bigger targets (WCAG 2.5.8 asks ≥ 24px; 44px is the comfortable size). */
@media (pointer: coarse) {
  :root { --target: 40px; }
  .btn { height: 44px; }
  .btn--sm { height: var(--target); }
  .segmented button { min-height: 36px; padding: 8px 14px; }
  .only-fine-pointer { display: none; }
  .only-coarse-pointer { display: inline; }
}

/* Phones: 16px text in fields avoids the automatic zoom of iOS Safari on focus. */
@media (max-width: 640px) {
  input[type='text'], input[type='search'], input[type='number'], input[type='date'], input[type='email'],
  input[type='password'], input[type='url'], select, textarea { font-size: 16px; height: 42px; }
  textarea { height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
