:root {
  --navy: #0b1f3a;
  --navy-2: #122c4e;
  --navy-3: #1a3a64;
  --copper: #c45c26;
  --copper-2: #a74b1d;
  --canvas: #f3f5f8;
  --card: #ffffff;
  --text: #172033;
  --muted: #5b6b82;
  --line: #e3e8ef;
  --open: #2563eb;
  --material: #d97706;
  --impediment: #dc2626;
  --field: #0f9d8e;
  --backoffice: #7c3aed;
  --closed: #64748b;
  --danger: #b42318;
  --ok: #157347;
  --soon: #b45309;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .06);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --sidebar: 248px;
  --bottom: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--canvas);
  line-height: 1.45;
}
a { color: var(--navy-3); }
a:hover { color: var(--copper); }
code { font-size: .92em; background: #eef2f7; padding: .1em .35em; border-radius: 6px; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  background: linear-gradient(180deg, var(--navy) 0%, #081628 100%);
  color: #dbe7f5;
  padding: 22px 16px 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  flex-shrink: 0;
}
.brand { display: flex; gap: 12px; align-items: center; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 1.05rem; letter-spacing: .02em; }
.brand small { display: block; color: #9fb3cc; font-size: .78rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--copper); color: #fff; display: grid; place-items: center;
  font-weight: 800; letter-spacing: .04em;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a, .bottom-nav a {
  display: flex; align-items: center; gap: 10px;
  color: #c5d4e6; text-decoration: none; padding: 10px 12px; border-radius: 10px;
}
.side-nav a svg, .bottom-nav a svg { width: 20px; height: 20px; flex-shrink: 0; }
.side-nav a.active, .side-nav a:hover { background: var(--navy-3); color: #fff; }
.side-sub { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.side-sub p { margin: 0 0 8px; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #8aa0bb; padding: 0 12px; }
.side-sub a { display: block; color: #b7c7da; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: .9rem; }
.side-sub a:hover { background: var(--navy-3); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 28px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.who { text-align: right; }
.who strong { display: block; font-size: .95rem; }
.who small { color: var(--muted); font-size: .78rem; }
.content { padding: 22px 28px 96px; max-width: 1200px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 650;
  cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn-primary { background: var(--copper); color: #fff; }
.btn-primary:hover { background: var(--copper-2); color: #fff; }
.btn-secondary { background: var(--navy); color: #fff; }
.btn-ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn-block { width: 100%; }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }
.flash-ok { background: #e8f6ee; color: var(--ok); }
.flash-err { background: #fdecec; color: var(--danger); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 18px 16px; margin-bottom: 18px;
}
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-h h2 { margin: 0; font-size: 1.02rem; }
.card-list { display: flex; flex-direction: column; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 10px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  text-decoration: none; color: inherit; border-top: 3px solid var(--open);
}
.stat-n { display: block; font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; }
.stat span:last-child { color: var(--muted); font-size: .85rem; }
.stat-material { border-top-color: var(--material); }
.stat-impediment { border-top-color: var(--impediment); }
.stat-field { border-top-color: var(--field); }
.stat-back { border-top-color: var(--backoffice); }
.stat-closed { border-top-color: var(--closed); }

.callout {
  display: block; background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; text-decoration: none;
}
.callout strong { display: block; }
.callout-warn { background: #fff7ed; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lede { color: var(--muted); max-width: 52rem; }
.muted { color: var(--muted); }
.tiny { font-size: .85rem; }
.empty, .empty-block { color: var(--muted); padding: 12px 0; }
.empty-block { background: #fff; border: 1px dashed var(--line); border-radius: 14px; padding: 28px 18px; text-align: center; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input, .filters select, label input, label select, label textarea, .file input {
  font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%;
}
.filters input[type="search"] { min-width: 220px; flex: 1; }
.filters select { width: auto; min-width: 160px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .88rem; margin-bottom: 12px; }
.chk { flex-direction: row; align-items: center; font-weight: 550; gap: 8px; width: auto; }
.chk input { width: auto; }
.chk.big { min-height: 44px; font-size: 1rem; }
.help { margin: -8px 0 14px; color: var(--muted); font-size: .85rem; font-weight: 400; }

.wo-cards { display: none; flex-direction: column; gap: 10px; }
.stack-cards { display: flex; flex-direction: column; gap: 10px; }
.wo-card {
  display: block; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.wo-card-main { display: block; text-decoration: none; color: inherit; }
.mini-stats {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
}
.mini-stats a {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; text-decoration: none; color: inherit; font-size: .88rem;
}
.mini-stats a strong { margin-right: 4px; }
.status-quick { margin: 0 0 8px; }
.status-quick select,
.gf-assign { margin: 0; }
.gf-assign select,
.status-quick select {
  min-width: 132px; width: 100%; padding: 8px 10px; min-height: 40px;
  font: inherit; font-weight: 650; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.gf-assign select.is-saved,
.status-quick select.is-saved { border-color: var(--ok); background: #e8f6ee; }
.gf-assign select.is-error,
.status-quick select.is-error { border-color: var(--danger); background: #fdecec; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
table.data .gf-assign select,
table.data .status-quick select { min-height: 36px; padding: 6px 8px; }
table.data .status-quick { margin: 0; }
table.data tr.is-picked td { background: #fff4ec; }
.wo-card.is-picked { border-color: var(--copper); box-shadow: 0 0 0 2px rgba(196,92,38,.25); }
.pole-form .facts { margin-bottom: 12px; }
table.data .btn { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.wo-card.is-overdue { border-left: 4px solid var(--danger); }
.wo-card.is-soon { border-left: 4px solid var(--soon); }
.wo-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.wo-addr, .wo-addr-lg { margin: 6px 0; color: var(--text); }
.wo-meta { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .85rem; }

.badge {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px;
  font-size: .75rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
}
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-material-issues { background: #ffedd5; color: #c2410c; }
.badge-impediment { background: #fee2e2; color: #b91c1c; }
.badge-field-complete { background: #ccfbf1; color: #0f766e; }
.badge-back-office { background: #ede9fe; color: #6d28d9; }
.badge-closed { background: #e2e8f0; color: #475569; }

.chip { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: .78rem; background: #eef2f7; }
.chip-overdue { background: #fee2e2; color: #991b1b; font-weight: 700; }
.chip-soon { background: #ffedd5; color: #9a3412; font-weight: 700; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; background: #f8fafc; padding: 10px 12px; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
table.data td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.data .clip { max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-tabs { display: flex; gap: 8px; overflow: auto; margin-bottom: 12px; padding-bottom: 4px; }
.flow-tabs a {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); text-decoration: none; color: var(--text); font-weight: 600; font-size: .88rem;
}
.flow-tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.flow-tabs a.active .tab-count { background: rgba(255,255,255,.2); }
.th-sort { color: inherit; text-decoration: none; }
.th-sort.is-on { color: var(--navy); }
.filter-row th { background: #fff; padding: 6px 8px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.filter-row input, .filter-row select {
  width: 100%; min-width: 70px; font: inherit; font-size: .8rem; font-weight: 500;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff;
}
table.data td.note-cell-wrap {
  min-width: 280px; width: 26%; white-space: normal;
  word-break: break-word; overflow-wrap: anywhere;
}
.note-area, .note-text {
  width: 100%; min-width: 220px; font: inherit; font-size: .95rem; font-weight: 500;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; line-height: 1.45;
}
.note-area { resize: vertical; min-height: 6.2em; max-height: 60vh; overflow: auto; }
.note-area.is-open { min-height: 10em; }
.note-area-lg { min-height: 10em; }
.note-area.is-saved { border-color: var(--ok); background: #e8f6ee; }
.note-area.is-error { border-color: var(--danger); }
.note-text { background: #f7f9fc; max-height: 7.2em; overflow: hidden; cursor: pointer; }
.note-text.is-open, .note-text.can-expand.is-open { max-height: none; }
.note-text.can-expand::after { content: " · tap to expand"; color: var(--muted); font-size: .75rem; }
.note-text.can-expand.is-open::after { content: ""; }
.note-block { margin-top: 14px; }
.back-row { margin: 0 0 12px; }
.advance-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 12px 0 0; }
.cell-date { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.card-field { margin-top: 8px; }
.card-label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 16px; color: var(--muted); }

.wo-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); margin: 0 0 4px; }
.wo-num { margin: 0; font-size: 1.7rem; }
.wo-num a { color: inherit; text-decoration: none; }
.wo-num a:hover { color: var(--copper); }
.wo-head-side { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; }
.ro { font-weight: 500; background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
.ro.pre { white-space: pre-wrap; min-height: 72px; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 8px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0; }
.facts div { background: #f7f9fc; border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.facts dd { margin: 4px 0 0; }
.save-bar {
  position: sticky; bottom: calc(var(--bottom) + 8px); background: rgba(243,245,248,.94);
  padding: 10px 0; margin-top: 8px; backdrop-filter: blur(8px);
}
.queue-tabs { display: flex; gap: 8px; overflow: auto; margin-bottom: 14px; padding-bottom: 4px; }
.queue-tabs a {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); text-decoration: none; color: var(--text); font-weight: 600; font-size: .88rem;
}
.queue-tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab-count {
  display: inline-block; min-width: 1.4em; margin-left: 6px; padding: 0 6px;
  border-radius: 999px; background: rgba(15,23,42,.08); font-size: .78rem; font-weight: 800;
}
.queue-tabs a.active .tab-count { background: rgba(255,255,255,.2); }
.prose h2 { margin-top: 0; }
.prose p, .prose li { color: #334155; }

.bottom-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom);
  background: #fff; border-top: 1px solid var(--line); z-index: 30;
  justify-content: space-around; padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { flex-direction: column; gap: 2px; font-size: .68rem; padding: 8px 4px; color: var(--muted); }
.bottom-nav a.active { color: var(--copper); }

.modal {
  position: fixed; inset: 0; background: rgba(8,16,32,.5); display: grid; place-items: center;
  z-index: 50; padding: 18px;
}
.modal[hidden] { display: none !important; }
.modal-card { background: #fff; border-radius: 16px; padding: 22px; max-width: 460px; width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.auth-body { min-height: 100vh; background: var(--navy); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.auth-hero { padding: 64px 56px; color: #e7eef8; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.15; margin: 28px 0 12px; color: #fff; }
.auth-hero p { color: #b7c7da; max-width: 28rem; font-size: 1.05rem; }
.auth-panel { background: var(--canvas); display: grid; place-items: center; padding: 32px 20px; }
.auth-form { width: min(420px, 100%); background: #fff; padding: 28px; border-radius: 18px; box-shadow: var(--shadow); }
.auth-form h2 { margin: 0 0 8px; }
.login-hints { color: var(--muted); font-size: .85rem; padding-left: 18px; }
.brand-lg .brand-mark { width: 48px; height: 48px; }

@media (max-width: 960px) {
  .who small { display: none; }
  .sidebar { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px 16px 110px; }
  .topbar { padding: 14px 16px; }
  .bottom-nav { display: flex; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 22px 12px; }
  .desktop-table { display: none; }
  .wo-cards { display: flex; }
  .save-bar { bottom: calc(var(--bottom) + 8px); }
}
@media (min-width: 961px) {
  .wo-cards { display: none; }
  .desktop-table { display: block; }
  .dashboard .wo-cards, .card-list { display: flex; }
  .card-list .wo-card { display: block; }
}
@media (min-width: 961px) {
  .card-list { display: flex; }
}
