:root {
  --bg: #0a0d10;
  --sidebar: #07090b;
  --panel: #11161b;
  --panel-soft: #0e1317;
  --border: #252c32;
  --border-strong: #343d45;
  --text: #f4f6f8;
  --muted: #9aa5ae;
  --green: #62e985;
  --green-dark: #163c24;
  --green-border: #286b3e;
  --blue: #a7c7ff;
  --blue-bg: #15253a;
  --blue-border: #2b4668;
  --amber: #f6cf75;
  --amber-bg: #2d2614;
  --amber-border: #5b4b20;
  --danger: #ff8f8f;
  --danger-bg: #2c1518;
  --danger-border: #5a292e;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.portal-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
}
.brand img { width: 72px; height: auto; display: block; }
.brand-copy { min-width: 0; }
.brand-copy strong,
.brand-copy span { display: block; }
.brand-copy strong { font-size: 1rem; line-height: 1.2; }
.brand-copy span {
  margin-top: 4px;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: grid;
  gap: 4px;
  padding-top: 18px;
}
.nav-btn,
.technician-link,
.logout {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  text-align: left;
  text-decoration: none;
  font-weight: 650;
  cursor: pointer;
}
.nav-btn {
  color: #c6cdd3;
  background: transparent;
}
.nav-btn:hover { background: #10151a; color: #fff; }
.nav-btn.active {
  color: #fff;
  background: #151c21;
  box-shadow: inset 3px 0 0 var(--green);
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.technician-link { color: #dce3e8; background: #10151a; }
.technician-link:hover { background: #151c21; }
.logout { color: #d0d5d9; background: transparent; }
.logout:hover { color: #fff; background: #171b1f; }

.main {
  min-width: 0;
  padding: 28px 30px 42px;
}
.topbar {
  min-height: 62px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.72rem;
  line-height: 1.1;
  letter-spacing: -.025em;
}
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .94rem;
}
.user-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-top: 4px;
  white-space: nowrap;
}
.user-summary strong { font-size: .9rem; }
.user-summary span { color: var(--muted); font-size: .8rem; }
.hidden { display: none !important; }

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.primary,
.secondary,
.table-action,
.button-link {
  min-height: 38px;
  border-radius: 6px;
  padding: 8px 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.primary {
  border: 1px solid #4fd572;
  background: var(--green);
  color: #071109;
}
.primary:hover { background: #79f195; }
.secondary {
  border: 1px solid var(--border-strong);
  background: #151a1f;
  color: #f3f5f6;
}
.secondary:hover { background: #1a2025; }
.full { width: 100%; text-align: center; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  background: var(--panel);
  margin-bottom: 18px;
}
.metric {
  min-width: 0;
  padding: 18px 20px 17px;
  border-right: 1px solid var(--border);
}
.metric:last-child { border-right: 0; }
.metric-label {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .045em;
}
.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 1.9rem;
  line-height: 1;
  letter-spacing: -.035em;
}
.metric-meta {
  display: block;
  margin-top: 8px;
  color: #b2bbc2;
  font-size: .78rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr);
  gap: 18px;
  margin-bottom: 18px;
}
.panel {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 20px;
}
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.section-head h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}
.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .82rem;
}
.section-count {
  min-width: 26px;
  padding: 3px 7px;
  border: 1px solid var(--border-strong);
  background: var(--panel-soft);
  color: #d8dde1;
  text-align: center;
  font-size: .76rem;
  font-weight: 750;
}

.work-list { border-top: 1px solid var(--border); }
.work-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.5fr) minmax(120px, .7fr) 100px 115px;
  gap: 14px;
  align-items: center;
  min-height: 62px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.work-row:last-child { border-bottom: 0; padding-bottom: 0; }
.work-vehicle strong,
.work-tech strong,
.work-date strong { display: block; font-size: .86rem; }
.work-vehicle span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: .78rem;
}
.cell-label {
  display: block;
  margin-bottom: 3px;
  color: #78838c;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.team-list { border-top: 1px solid var(--border); }
.team-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px 66px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.team-row:last-child { border-bottom: 0; padding-bottom: 0; }
.team-person strong,
.team-person span { display: block; }
.team-person strong { font-size: .86rem; }
.team-person span { margin-top: 2px; color: var(--muted); font-size: .74rem; }
.team-numbers { text-align: right; }
.team-numbers strong,
.team-numbers span { display: block; }
.team-numbers strong { font-size: .92rem; }
.team-numbers span { margin-top: 2px; color: var(--muted); font-size: .66rem; }

.table-wrap { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}
.table th {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-strong);
  color: #89949d;
  text-align: left;
  font-size: .69rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .055em;
}
.table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  color: #dfe4e8;
  vertical-align: middle;
  font-size: .84rem;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #13191e; }
.table td strong { color: #fff; font-size: .86rem; }
.subline {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: .74rem;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.action-col { width: 78px; text-align: right !important; }
.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  background: #151b20;
  color: #fff;
  font-size: .78rem;
}
.table-action:hover { border-color: #4c5963; background: #1a2127; }
.button-link { appearance: none; }
.action-muted { color: #59636b; }
.report-state {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: .72rem;
}

.status {
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--border-strong);
  background: #151a1f;
  color: #cbd2d7;
  font-size: .68rem;
  font-weight: 750;
  line-height: 1.2;
}
.status-good { color: #a9f7b8; border-color: var(--green-border); background: var(--green-dark); }
.status-active { color: var(--blue); border-color: var(--blue-border); background: var(--blue-bg); }
.status-waiting { color: var(--amber); border-color: var(--amber-border); background: var(--amber-bg); }
.status-neutral { color: #c5cbd0; }

.inspection-actions .filters {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex: 1 1 460px;
  justify-content: flex-end;
}
.search-input { max-width: 360px; }
.filter-select { width: 170px; }

.form { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
label {
  display: grid;
  gap: 6px;
  color: #b4bdc4;
  font-size: .78rem;
  font-weight: 650;
}
.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 9px 10px;
  outline: none;
  background: #0c1014;
  color: #fff;
}
.input:focus,
.select:focus,
.textarea:focus { border-color: #4a8060; box-shadow: 0 0 0 2px rgba(98, 233, 133, .08); }
.select option { color: #111; }
.textarea { min-height: 110px; resize: vertical; }
.uppercase { text-transform: uppercase; }
.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
}
.check-row input { width: 16px; height: 16px; }
.form-actions { padding-top: 4px; }
.settings-panel { max-width: 980px; }

.notice,
.error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  font-size: .82rem;
  line-height: 1.45;
}
.notice { color: #bff6ca; border-color: var(--green-border); background: #10271a; }
.error { color: #ffc3c3; border-color: var(--danger-border); background: var(--danger-bg); }

.empty-state {
  display: grid;
  gap: 4px;
  padding: 24px 6px;
  color: var(--muted);
  text-align: center;
}
.empty-state strong { color: #dfe4e8; font-size: .9rem; }
.empty-state span { font-size: .8rem; }
.loading-state {
  padding: 22px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}

.login-wrap {
  min-height: calc(100vh - 150px);
  display: grid;
  place-items: center;
}
.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 28px;
}
.login-card img { width: 130px; height: auto; }
.login-card h2 { margin: 20px 0 6px; font-size: 1.45rem; }
.login-card p { margin: 0 0 20px; color: var(--muted); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, .72);
}
.modal-card {
  width: min(820px, 100%);
  max-height: 92vh;
  overflow: auto;
  border: 1px solid var(--border-strong);
  background: #0d1115;
  padding: 20px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.28rem; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: .82rem; }
.close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: #151a1f;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}
.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 16px;
  margin-top: 18px;
  border-top: 1px solid var(--border);
}

@media (max-width: 1150px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .portal-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding-bottom: 12px; }
  .nav {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding-top: 10px;
  }
  .nav-btn { width: auto; min-width: max-content; }
  .nav-btn.active { box-shadow: inset 0 -3px 0 var(--green); }
  .sidebar-actions {
    margin-top: 10px;
    padding-top: 10px;
    display: flex;
  }
  .technician-link, .logout { width: auto; }
  .main { padding: 20px 16px 32px; }
  .work-row { grid-template-columns: minmax(180px, 1fr) minmax(120px, .8fr) 90px; }
  .work-date { display: none; }
}

@media (max-width: 620px) {
  .topbar { flex-direction: column; min-height: auto; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--border); }
  .metric:last-child { border-bottom: 0; }
  .work-row { grid-template-columns: 1fr auto; gap: 8px; }
  .work-tech { grid-column: 1 / 2; }
  .work-status { grid-row: 1 / 3; grid-column: 2; align-self: center; }
  .two, .three { grid-template-columns: 1fr; }
  .inspection-actions .filters {
    width: 100%;
    flex-basis: 100%;
    justify-content: stretch;
    flex-direction: column;
  }
  .search-input, .filter-select { width: 100%; max-width: none; }
  .login-card { padding: 22px; }
}

/* v1.04 inspection management + native dark select fixes */
.select {
  color-scheme: dark;
}
.select option,
.select optgroup {
  background: #10151a;
  color: #f4f6f8;
}
.inspection-actions .filters {
  flex: 0 1 590px;
  min-width: 420px;
}
.inspection-actions .search-input {
  flex: 1 1 330px;
  width: auto;
  max-width: none;
}
.inspection-actions .filter-select {
  flex: 0 0 190px;
  width: 190px;
}
.action-col {
  width: 160px;
  white-space: nowrap;
}
.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.status-cancelled {
  color: #ffb0b0;
  border-color: var(--danger-border);
  background: var(--danger-bg);
}
.inspection-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  background: var(--panel-soft);
  margin-bottom: 18px;
}
.inspection-summary > div {
  min-width: 0;
  padding: 12px 14px;
  border-right: 1px solid var(--border);
}
.inspection-summary > div:last-child { border-right: 0; }
.inspection-summary span,
.inspection-summary strong { display: block; }
.inspection-summary span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .67rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .045em;
}
.inspection-summary strong {
  color: #f4f6f8;
  font-size: .79rem;
  font-weight: 650;
  line-height: 1.35;
}
.inspection-summary strong .status { display: inline-block; }
.form-section-title {
  margin-top: 4px;
  padding: 12px 0 7px;
  border-bottom: 1px solid var(--border);
  color: #f3f5f6;
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .045em;
}
.field-help {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 500;
  line-height: 1.35;
}
.compact-textarea { min-height: 78px; }
.modal-inline-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 16px;
}
.compact-button { min-height: 34px; padding: 6px 10px; font-size: .78rem; }
.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--danger-border);
}
.danger-zone > div:first-child { min-width: 0; }
.danger-zone strong,
.danger-zone span { display: block; }
.danger-zone strong { font-size: .82rem; }
.danger-zone span {
  max-width: 520px;
  margin-top: 4px;
  color: var(--muted);
  font-size: .74rem;
  line-height: 1.4;
}
.danger-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}
.danger-button,
.danger-outline {
  min-height: 36px;
  border-radius: 5px;
  padding: 7px 11px;
  font-weight: 750;
  cursor: pointer;
}
.danger-button {
  border: 1px solid #8a333a;
  background: #6b2229;
  color: #fff;
}
.danger-button:hover { background: #7b2931; }
.danger-outline {
  border: 1px solid var(--danger-border);
  background: transparent;
  color: #ffb4b4;
}
.danger-outline:hover { background: var(--danger-bg); }
.select:disabled {
  color: #7d878f;
  background: #0a0e11;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .inspection-summary { grid-template-columns: 1fr 1fr; }
  .inspection-summary > div:nth-child(2) { border-right: 0; }
  .inspection-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .inspection-actions .filters { min-width: 0; flex-basis: 100%; }
}

@media (max-width: 620px) {
  .inspection-actions .filters { min-width: 0; }
  .inspection-actions .search-input,
  .inspection-actions .filter-select { width: 100%; flex: 1 1 auto; }
  .inspection-summary { grid-template-columns: 1fr; }
  .inspection-summary > div { border-right: 0; border-bottom: 1px solid var(--border); }
  .inspection-summary > div:last-child { border-bottom: 0; }
  .danger-zone { align-items: flex-start; flex-direction: column; }
  .danger-actions { width: 100%; justify-content: flex-start; }
}
