/* =====================================================================
   CMMS — Option 2 UI. Mobile-first.
   Uses ONLY variables from tokens.css (no literal colours here).
   ===================================================================== */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body); font-weight: var(--fw-body); line-height: var(--lh-body); letter-spacing: var(--ls-body);
  font-variant-numeric: tabular-nums;   /* digits never jitter: numbers, timers, dates, counts */
  font-feature-settings: "tnum" 1, "cv11" 1;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-text); }
h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: var(--fs-h1); font-weight: var(--fw-h1); line-height: var(--lh-h1); letter-spacing: var(--ls-h1); }
h2 { font-size: var(--fs-h2); font-weight: var(--fw-h2); line-height: var(--lh-h2); letter-spacing: var(--ls-h2); }
h3 { font-size: var(--fs-h3); font-weight: var(--fw-h3); line-height: var(--lh-h3); letter-spacing: var(--ls-h3); }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--accent-border); }

.loading { padding: 40px var(--pad-screen); color: var(--text-2); text-align: center; }
.muted { color: var(--text-2); }
.small, .caption { font-size: var(--fs-caption); font-weight: var(--fw-caption); line-height: var(--lh-caption); letter-spacing: var(--ls-caption); }
.mono { font-variant-numeric: tabular-nums; }
.overline {
  font-size: var(--fs-micro); font-weight: var(--fw-micro); line-height: var(--lh-micro);
  letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2);
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px var(--pad-screen);
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: var(--hairline) solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: var(--fs-h3); font-weight: 700; letter-spacing: var(--ls-h3);
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border-radius: var(--r-icon); background: var(--brand-fill); color: var(--on-brand);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name small { display: block; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); letter-spacing: var(--ls-caption); }
.userbox { display: flex; align-items: center; gap: 8px; min-width: 0; }
.userbox .who { text-align: right; min-width: 0; margin-right: 4px; color: var(--text); text-decoration: none; border-radius: var(--r-control); padding: 2px 6px; }
.userbox a.who strong { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.userbox a.who:hover strong { text-decoration-color: currentColor; }
.userbox .who strong { display: block; font-size: var(--fs-button); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.userbox .who span { display: block; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); white-space: nowrap; }
.icon-btn {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: var(--r-control);
  border: var(--hairline) solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--input-border); }
.icon-btn svg { width: 20px; height: 20px; }
.userbox .btn { min-height: 44px; padding: 0 14px; }
@media (max-width: 520px) {
  /* phone: keep the short name "CMMS", drop the long subtitle so the user's name has room */
  .brand-name small { display: none; }
  .userbox { flex: 1 1 auto; justify-content: flex-end; }
  .userbox .who { flex: 1 1 auto; }
  .userbox .who strong { max-width: none; }
}

.layout { display: block; }
.content {
  max-width: var(--content-max); margin: 0 auto;
  padding: 20px var(--pad-screen) calc(var(--nav-h) + 32px + env(safe-area-inset-bottom, 0px));
}

/* Bottom navigation (phone) */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: var(--hairline) solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav a {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--nav-h);
  font-size: var(--fs-micro); font-weight: 600; letter-spacing: 0.01em; color: var(--text-2);
  text-decoration: none; position: relative;
}
.nav a > span:not(.nav-ico) {
  max-width: 100%; padding: 0 2px; text-align: center; line-height: 1.15;
  /* up to two lines so labels like "Damage count" are never cut off */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.nav a svg { width: 22px; height: 22px; }
.nav a .nav-ico { display: grid; place-items: center; width: 48px; height: 28px; border-radius: var(--r-pill); }
.nav a.active { color: var(--brand-text); }
.nav a.active .nav-ico { background: var(--accent-tint); }
.nav .count {
  position: absolute; top: 4px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--brand-fill); color: var(--on-brand);
  font-size: var(--fs-micro); line-height: 18px; text-align: center; font-weight: 700;
}
.nav .desk-only { display: none; }

@media (min-width: 900px) {
  .nav .desk-only { display: flex; }
  .nav .phone-only { display: none; }
  .layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
  .nav {
    position: sticky; top: var(--topbar-h); align-self: start;
    flex-direction: column; gap: 4px;
    height: calc(100vh - var(--topbar-h));
    padding: 16px 12px;
    border-top: 0; border-right: var(--hairline) solid var(--border);
  }
  .nav a {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px;
    height: var(--tap); padding: 0 12px; border-radius: var(--r-control);
    font-size: var(--fs-button); font-weight: var(--fw-button); letter-spacing: var(--ls-button);
  }
  .nav a .nav-ico { width: auto; height: auto; background: none !important; }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a.active { background: var(--accent-tint); color: var(--brand-text); }
  .nav .count { position: static; margin-left: auto; }
  .content { padding: 28px 32px 48px; margin: 0; width: 100%; max-width: calc(var(--content-max) + 64px); }
  .userbox .who strong { max-width: none; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--text-2); margin-top: 6px; }
.back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; margin-bottom: 8px;
  color: var(--text-2); text-decoration: none; font-size: var(--fs-button); font-weight: var(--fw-button);
}
.back:hover { color: var(--brand-text); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: var(--gap-section) 0 12px; }
.section-title:first-child { margin-top: 0; }
.section-title .muted { font-size: var(--fs-caption); font-weight: var(--fw-caption); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px;
  font: inherit; font-size: var(--fs-button); font-weight: var(--fw-button); line-height: var(--lh-button); letter-spacing: var(--ls-button);
  border-radius: var(--r-control); border: var(--hairline) solid var(--border);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--input-border); }
.btn:active { background: var(--border); }
.btn-primary { background: var(--brand-fill); border-color: var(--brand-fill); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-fill-hover); border-color: var(--brand-fill-hover); }
.btn-primary:active { background: var(--brand-fill-hover); }
.btn-block { display: flex; width: 100%; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 160px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 20px; max-width: 600px; }
.form-card { background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); padding: 20px var(--pad-card); }
.field { display: grid; gap: 8px; }
.field > label, .field > .label, legend.label { font-size: var(--fs-h3); font-weight: var(--fw-h3); letter-spacing: var(--ls-h3); color: var(--text); }
.field .hint { font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
.req { color: var(--text-2); font-weight: 500; } /* real text: secondary colour for readable contrast */
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 11px 14px;
  font: inherit; font-size: var(--fs-input); color: var(--text);
  background-color: var(--surface-2);
  border: var(--hairline) solid var(--input-border); border-radius: var(--r-control);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { min-height: 110px; resize: vertical; line-height: var(--lh-body); }
select {
  appearance: none; -webkit-appearance: none; padding-right: 42px; cursor: pointer;
  /* chevron drawn with token colours (no image) */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 21px) 52%, calc(100% - 16px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select option { background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-tint); }
select:disabled, input:disabled { opacity: 0.6; cursor: not-allowed; }
.readonly-value {
  min-height: var(--tap); display: flex; align-items: center;
  padding: 11px 14px; background: var(--surface-2); border: var(--hairline) dashed var(--input-border); border-radius: var(--r-control);
  color: var(--text-2); font-weight: 500;
}
.form-error {
  padding: 12px 14px; border: var(--hairline) solid var(--error); border-radius: var(--r-control);
  background: var(--error-bg); color: var(--error); font-weight: 500;
}
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 8px; }

/* Chip checkboxes (multi-select) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: var(--hairline) solid var(--border); border-radius: var(--r-pill); background: var(--surface-2);
  font-size: var(--fs-button); font-weight: var(--fw-button); user-select: none;
}
.chip input:checked + span { background: var(--accent-tint); color: var(--brand-text); border-color: var(--accent-border); }
.chip input:checked + span::before { content: "✓"; font-weight: 700; }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Segmented / range pills */
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: var(--hairline) solid var(--border); border-radius: var(--r-pill); }
.seg button {
  min-height: 40px; padding: 0 16px; border: 0; border-radius: var(--r-pill);
  font: inherit; font-size: var(--fs-button); font-weight: var(--fw-button); letter-spacing: var(--ls-button);
  background: transparent; color: var(--text-2); cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed=true] { background: var(--brand-fill); color: var(--on-brand); }

/* ---------- Cards & lists ---------- */
.card {
  background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow-card); padding: var(--pad-card);
}
.card + .card { margin-top: var(--gap-card); }
.list { display: grid; gap: var(--gap-card); }
.ticket-card {
  display: grid; gap: 6px;
  padding: var(--pad-card); background: var(--surface);
  border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card);
  color: var(--text); text-decoration: none;
  transition: border-color 0.12s;
}
.ticket-card:hover { border-color: var(--accent-border); }
.ticket-card.mine { border-color: var(--accent-border); box-shadow: inset 3px 0 0 var(--brand), var(--shadow-card); }
.tc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tc-no { font-size: var(--fs-caption); font-weight: 600; color: var(--text-2); letter-spacing: var(--ls-caption); }
.tc-title { font-size: var(--fs-h3); font-weight: var(--fw-h3); line-height: var(--lh-h3); letter-spacing: var(--ls-h3); }
.tc-meta { font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); line-height: var(--lh-caption); }
.tc-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

/* Tags (small pills) */
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 10px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--text-2); border: var(--hairline) solid var(--border);
  font-size: var(--fs-caption); font-weight: 600; letter-spacing: var(--ls-caption); white-space: nowrap;
}
.tag-accent { background: var(--accent-tint); color: var(--brand-text); border-color: var(--accent-border); }
.tag-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.tag-error { background: var(--error-bg); color: var(--error); border-color: transparent; }
.tag-success { background: var(--success-bg); color: var(--success); border-color: transparent; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); white-space: nowrap;
  font-size: var(--fs-micro); font-weight: var(--fw-micro); line-height: var(--lh-micro); letter-spacing: var(--ls-micro); text-transform: uppercase;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-OPEN { background: var(--accent-tint); color: var(--brand-text); }
.badge-WAITING_VERIFICATION { background: var(--warning-bg); color: var(--warning); }
.badge-NEEDS_CORRECTION { background: var(--error-bg); color: var(--error); }
.badge-VERIFIED { background: var(--success-bg); color: var(--success); }

/* ---------- Timers ---------- */
.timer {
  font-size: var(--fs-display); font-weight: var(--fw-display); line-height: var(--lh-display); letter-spacing: var(--ls-display);
  font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap;
}
.timer-lg { font-size: calc(var(--fs-display) + 2px); }
.timer-sm { font-size: var(--fs-h2); font-weight: 700; letter-spacing: -0.01em; }
.timer-label { font-size: var(--fs-micro); font-weight: var(--fw-micro); letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2); margin-bottom: 2px; }
.downtime { font-size: var(--fs-h2); font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-fill); margin-right: 6px; vertical-align: middle; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* ---------- Detail ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail-head h1 { margin-top: 2px; }
.timer-box {
  margin: 16px 0; padding: 20px var(--pad-card); text-align: center;
  background: var(--surface); border: var(--hairline) solid var(--accent-border); border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.timer-box.stopped { border-color: var(--border); background: var(--surface-2); box-shadow: none; }
.timer-box.stopped .timer { color: var(--text-2); }
dl.facts { display: grid; grid-template-columns: 1fr; margin: 0; }
dl.facts > div { display: grid; grid-template-columns: 136px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-bottom: var(--hairline) solid var(--border); }
dl.facts > div:first-child { padding-top: 0; }
dl.facts > div:last-child { border-bottom: 0; padding-bottom: 0; }
dl.facts dt { color: var(--text-2); font-size: var(--fs-caption); font-weight: var(--fw-caption); padding-top: 2px; }
dl.facts dd { margin: 0; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 420px) { dl.facts > div { grid-template-columns: 1fr; gap: 2px; } }
.callout {
  padding: 14px 16px; border-radius: var(--r-card);
  background: var(--error-bg); color: var(--text); border: var(--hairline) solid var(--error);
}
.callout strong { display: block; margin-bottom: 4px; color: var(--error); font-size: var(--fs-h3); }
.callout-attached { margin-top: -10px; padding-top: 18px; border-top-left-radius: 0; border-top-right-radius: 0; border-top: 0; font-size: var(--fs-caption); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 20px; bottom: 0; width: var(--hairline); background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
.timeline .comment { margin-top: 6px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--r-control); white-space: pre-wrap; }
.actions-bar { margin-top: 24px; }
.verify-box { display: grid; gap: 14px; border-color: var(--accent-border); }
.confirm-text { margin-bottom: 12px; }

/* ---------- Stats / KPI cards ---------- */
.stat-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-card); }
@media (min-width: 760px) { .stat-row { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } }
.stat {
  padding: var(--pad-card); background: var(--surface);
  border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card);
  min-width: 0;
}
.stat-label { font-size: var(--fs-micro); font-weight: var(--fw-micro); letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2); }
.stat-value {
  font-size: var(--fs-display); font-weight: var(--fw-display); line-height: var(--lh-display); letter-spacing: var(--ls-display);
  margin-top: 8px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.stat-sub { font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); margin-top: 4px; }

/* ---------- Filters ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.inline-field { display: flex; align-items: center; gap: 10px; }
.inline-field label { font-size: var(--fs-caption); font-weight: 600; color: var(--text-2); }
.inline-field select { width: auto; min-width: 150px; flex: 1 1 auto; max-width: 260px; min-height: 44px; }

/* ---------- Repeat failures ---------- */
tr.repeat-warning td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
tr.repeat-error td:first-child { box-shadow: inset 3px 0 0 var(--error); }

/* ---------- Knowledge tree ---------- */
.search-box { position: relative; margin-bottom: 12px; }
.search-box input { padding-left: 46px; background-color: var(--surface); }
.search-box svg { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--text-3); pointer-events: none; }
.tree { display: grid; gap: var(--gap-card); }
.tree details { min-width: 0; }
.tree .lvl-line { background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); padding: 4px 4px 8px; }
.tree .lvl-line:not([open]) { padding-bottom: 4px; }
.tree summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: var(--tap); padding: 8px 12px;
  cursor: pointer; list-style: none; user-select: none; border-radius: var(--r-control);
  font-size: var(--fs-h3); font-weight: var(--fw-h3); letter-spacing: var(--ls-h3);
}
.tree summary:hover { background: var(--scrim-hover); }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before {
  content: ""; flex: 0 0 auto; width: 7px; height: 7px;
  border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2);
  transform: rotate(-45deg); transition: transform 0.15s; margin-right: 2px;
}
.tree details[open] > summary::before { transform: rotate(45deg); }
.tree .lvl-line > summary { font-size: var(--fs-h2); font-weight: var(--fw-h2); letter-spacing: var(--ls-h2); }
.tree summary .n { margin-left: auto; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
/* indented levels with hairline connectors */
.tree .lvl-machine, .tree .lvl-comp { position: relative; margin-left: 20px; padding-left: 12px; }
.tree .lvl-machine::before, .tree .lvl-comp::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: var(--hairline); background: var(--border);
}
.tree .lvl-machine > summary::after, .tree .lvl-comp > summary::after {
  content: ""; position: absolute; left: 0; top: 24px; width: 10px; height: var(--hairline); background: var(--border);
}
.tree .lvl-comp > summary { font-weight: 600; color: var(--text); }
.issues { display: grid; gap: 10px; padding: 4px 8px 12px 20px; }
.issue {
  padding: 14px; display: grid; gap: 10px;
  background: var(--surface-2); border: var(--hairline) solid var(--border); border-radius: var(--r-control);
}
.issues.flat { padding: 0; }
.issues.flat .issue { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.issue-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.issue-head .date { font-weight: 600; }
.issue .lbl, .tf-history .lbl { font-size: var(--fs-micro); font-weight: var(--fw-micro); letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2); margin-bottom: 2px; }
.issue .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.issue-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.issue-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
.issue-foot a { min-height: 40px; display: inline-flex; align-items: center; font-weight: 600; color: var(--brand-text); text-decoration: none; }
mark { background: var(--accent-tint); color: var(--brand-text); padding: 0 3px; border-radius: 4px; box-shadow: inset 0 0 0 var(--hairline) var(--accent-border); }

/* ---------- Manage lists ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 16px; scrollbar-width: thin; }
.tabs button {
  flex: 0 0 auto; min-height: 44px; padding: 0 16px; border-radius: var(--r-pill);
  border: var(--hairline) solid var(--border); background: var(--surface); color: var(--text-2);
  font: inherit; font-size: var(--fs-button); font-weight: var(--fw-button); cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected=true] { background: var(--brand-fill); color: var(--on-brand); border-color: var(--brand-fill); }
.add-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.add-row .field { flex: 1 1 220px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand-fill); }
.items { display: grid; background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); overflow: hidden; }
.item { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-bottom: var(--hairline) solid var(--border); min-height: 64px; }
.item:last-child { border-bottom: 0; }
.item.inactive { background: var(--surface-2); }
.item.inactive .item-name { color: var(--text-2); text-decoration: line-through; text-decoration-color: var(--text-3); }
.item-name { flex: 1 1 160px; font-weight: 600; overflow-wrap: anywhere; }
.item-name small { display: block; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
.item .btn { min-height: 44px; padding: 0 14px; }
.item input[type=text] { flex: 1 1 160px; }
.menu-list { display: grid; gap: var(--gap-card); }
.menu-list a {
  display: flex; align-items: center; gap: 14px; min-height: 72px; padding: 12px var(--pad-card);
  background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card);
  color: var(--text); text-decoration: none; font-weight: 600;
}
.menu-list a small { display: block; font-size: var(--fs-caption); font-weight: var(--fw-caption); color: var(--text-2); }
.icon-well { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: var(--r-icon); background: var(--accent-tint); color: var(--brand-text); }
.icon-well svg { width: 22px; height: 22px; }

/* ---------- Dashboard ---------- */
.chart-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap-card); margin-top: var(--gap-card); }
@media (min-width: 1100px) { .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .chart-grid.one { grid-template-columns: minmax(0, 1fr); } }
.chart-card { display: grid; gap: 12px; align-content: start; min-width: 0; }
.chart-card + .chart-card { margin-top: 0; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chart-head h2 { font-size: var(--fs-h3); font-weight: var(--fw-h3); letter-spacing: var(--ls-h3); line-height: var(--lh-h3); }
.chart-head .muted { font-size: var(--fs-caption); font-weight: var(--fw-caption); }
.chart-box { position: relative; height: 220px; min-width: 0; }
.chart-box-trend { height: 240px; }
.chart-box-sm { height: 170px; }

.split-bar { display: flex; height: 14px; border-radius: var(--r-pill); overflow: hidden; gap: 3px; background: var(--surface); }
.split-bar span { display: block; height: 100%; min-width: 3px; }
.split-bar span:first-child { border-radius: var(--r-pill) 0 0 var(--r-pill); }
.split-bar span:last-child { border-radius: 0 var(--r-pill) var(--r-pill) 0; }
.split-bar span:only-child { border-radius: var(--r-pill); }
.seg-warning { background: var(--warning); }
.seg-brand { background: var(--chart-1); }
.seg-grey { background: var(--chart-2); }
.split-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.split-legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 40px; align-items: center; gap: 10px; }
.split-legend strong { font-size: var(--fs-h3); }
.split-legend .muted { text-align: right; }
.sw { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

.live-card { display: grid; gap: 8px; }
.live-list { list-style: none; margin: 0; padding: 0; }
.live-list li + li { border-top: var(--hairline) solid var(--border); }
.live-list a { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 8px 0; color: var(--text); text-decoration: none; }
.live-list a > span:first-child { display: grid; min-width: 0; gap: 2px; }
.live-list a:hover strong { color: var(--brand-text); }
.live-list .timer { font-size: var(--fs-display); }
@media (max-width: 420px) { .live-list .timer { font-size: calc(var(--fs-display) - 6px); } }

/* ---------- Damage count ---------- */
.count-card { display: grid; gap: 16px; }
.count-main { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.count-num {
  display: grid; place-items: center; min-width: 96px; height: 96px; padding: 0 16px;
  border-radius: var(--r-card); background: var(--accent-tint); color: var(--brand-text);
  font-size: var(--fs-count-hero); font-weight: var(--fw-display); line-height: 1; letter-spacing: var(--ls-display);
}
.count-what { font-size: var(--fs-h2); font-weight: 500; letter-spacing: var(--ls-h2); }
.count-main .tag { margin-top: 8px; }

/* ---------- Tables (desktop) / stacked cards (phone) ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: var(--hairline) solid var(--border); vertical-align: middle; }
.table th { font-size: var(--fs-micro); font-weight: var(--fw-micro); letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table td a { color: var(--text); text-decoration: none; }
.table td a:hover { color: var(--brand-text); }
.table td.num, .table th.num { text-align: right; }
@media (max-width: 699px) {
  .table-wrap.stack { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .stack table.table, .stack .table tbody, .stack .table tr, .stack .table td { display: block; width: 100%; }
  .stack .table thead { display: none; }
  .stack .table tr {
    background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card);
    box-shadow: var(--shadow-card); padding: 6px var(--pad-card); margin-bottom: var(--gap-card); overflow: hidden;
  }
  .stack .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; text-align: right; }
  .stack .table td:first-child { display: block; text-align: left; padding-top: 10px; }
  .stack .table td::before {
    content: attr(data-label); text-align: left; flex: 0 0 auto;
    font-size: var(--fs-micro); font-weight: var(--fw-micro); letter-spacing: var(--ls-micro); text-transform: uppercase; color: var(--text-2);
  }
  .stack .table td:first-child::before { display: none; }
  .stack .table tr:last-child td { border-bottom: var(--hairline) solid var(--border); }
  .stack .table tr td:last-child { border-bottom: 0; }
  .stack tr.repeat-warning td:first-child, .stack tr.repeat-error td:first-child { box-shadow: none; }
  .stack tr.repeat-warning { box-shadow: inset 3px 0 0 var(--warning), var(--shadow-card); }
  .stack tr.repeat-error { box-shadow: inset 3px 0 0 var(--error), var(--shadow-card); }
}

/* ---------- Empty state ---------- */
.empty {
  padding: 32px var(--pad-card); text-align: center; color: var(--text-2);
  background: var(--surface); border: var(--hairline) dashed var(--input-border); border-radius: var(--r-card);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; font-size: var(--fs-h3); font-weight: var(--fw-h3); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--pad-screen); }
.login-card {
  width: 100%; max-width: 420px; padding: 28px 24px;
  background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.login-head { display: flex; flex-direction: column; align-items: center; text-align: center; }
.login-card .brand-mark { width: 48px; height: 48px; margin-bottom: 16px; }
.login-card .brand-mark svg { width: 26px; height: 26px; }
.login-card h1 { font-size: var(--fs-display); letter-spacing: var(--ls-display); line-height: var(--lh-display); }
.login-sub { margin: 4px 0 12px; font-size: var(--fs-caption); font-weight: 600; letter-spacing: var(--ls-caption); color: var(--brand-text); }
.login-top { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: var(--pad-screen); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: var(--pad-screen); right: var(--pad-screen); z-index: 50;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
  max-width: 480px; margin: 0 auto;
  padding: 14px 16px; border-radius: var(--r-control);
  background: var(--toast-bg); color: var(--toast-text); font-weight: 500; box-shadow: var(--shadow-float);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ---------- Grouped chips (Also helped) ---------- */
.chip-group-label { margin: 6px 0 6px; font-weight: 600; }


/* ---------- Insights, Smart search, Settings (design tokens only) ---------- */
.note {
  padding: 12px 16px; border-radius: var(--r-card); margin: 0 0 16px;
  background: var(--accent-tint); color: var(--text); border: var(--hairline) solid var(--accent-border);
}
.note a { color: var(--brand-text); font-weight: 600; }
.ins-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.ins-controls .seg { flex-wrap: wrap; }
.delta { font-size: var(--fs-caption); color: var(--text-2); font-weight: var(--fw-caption); }
.table td .delta { white-space: nowrap; }
.row-vital td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
@media (max-width: 699px) { .stack tr.row-vital { box-shadow: inset 3px 0 0 var(--brand), var(--shadow-card); } .stack tr.row-vital td:first-child { box-shadow: none; } }
.vital-list { margin: 8px 0 0; padding-left: 22px; display: grid; gap: 6px; }
.vital-list li { padding-left: 4px; }
.vital-list .muted { margin-left: 6px; }
.chart-legend { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: var(--fs-caption); color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 8px; }
.lg { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.lg-bar { background: var(--chart-1); }
.lg-dim { background: var(--chart-3); }
.lg-line { height: 0; border-top: 2px solid var(--text); border-radius: 0; }
.lg-mark { height: 0; border-top: 2px dashed var(--chart-2); border-radius: 0; }
.chart-card .note, .card .note { margin-top: 8px; }

.search-filters { margin-top: 12px; }
.empty .tips { text-align: left; margin: 12px auto 0; max-width: 460px; padding-left: 20px; display: grid; gap: 4px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager .btn[disabled] { opacity: 0.5; cursor: default; }
.issues.flat + .pager { margin-top: 16px; }

.tf-list { display: grid; gap: var(--gap-card); margin-top: 12px; }
.tf-item {
  background: var(--surface); border: var(--hairline) solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow-card); min-width: 0;
}
.tf-item > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px var(--pad-card); min-height: var(--tap); border-radius: var(--r-card);
}
.tf-item > summary::-webkit-details-marker { display: none; }
.tf-item > summary:hover { background: var(--scrim-hover); }
.tf-main { display: grid; gap: 2px; min-width: 0; }
.tf-main .muted { overflow-wrap: anywhere; }
.tf-side { display: grid; justify-items: end; gap: 4px; flex: 0 0 auto; text-align: right; }
.tf-body { padding: 0 var(--pad-card) var(--pad-card); border-top: var(--hairline) solid var(--border); }
.tf-tickets { list-style: none; margin: 0; padding: 0; display: grid; }
.tf-tickets li { padding: 12px 0; border-bottom: var(--hairline) solid var(--border); display: grid; gap: 4px; }
.tf-tickets .issue-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-start; }
.tf-tickets a { color: var(--brand-text); font-weight: 600; }
.tf-resolve { display: grid; gap: 10px; margin-top: 14px; }
.tf-resolve textarea { width: 100%; }
.tf-history { margin-top: 14px; }
.tf-history ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.tf-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: var(--gap-card);
  color: var(--text); text-decoration: none; padding: 14px var(--pad-card);
}
.tf-card:hover { background: var(--scrim-hover); }
.settings-form { max-width: 520px; display: grid; gap: 12px; }
.cellv { display: grid; justify-items: end; gap: 2px; text-align: right; }
.val { white-space: nowrap; font-weight: 600; }
.filter-panel { margin-top: 12px; }
.filter-panel > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap);
  padding: 0 14px; border: var(--hairline) solid var(--border); border-radius: var(--r-pill); background: var(--surface);
  font-weight: 600;
}
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s;
}
.filter-panel[open] > summary::before { transform: rotate(45deg); }
.filter-panel[open] > summary { margin-bottom: 4px; }
.stat-row + p.muted { margin-top: 12px; }
.dept-field { max-width: 360px; margin-bottom: 16px; }
.item select[name=dept] { max-width: 260px; }
