:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --text: #142126;
  --muted: #607078;
  --line: #d7e0e4;
  --brand: #1d5f6f;
  --brand-strong: #164a56;
  --danger: #b83232;
  --danger-bg: #ffe8e4;
  --warning: #ad6416;
  --warning-bg: #fff0d8;
  --watch: #776000;
  --watch-bg: #fff7c7;
  --good: #24664f;
  --good-bg: #dcf3e9;
  --verify: #6450a0;
  --verify-bg: #eee9ff;
  --shadow: 0 18px 48px rgb(16 35 43 / 10%);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1420px, calc(100% - 32px));
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0 18px;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-hint {
  margin: 0;
}

.auth-app-name { margin: 0 0 16px; color: var(--brand); font-size: 1rem; font-weight: 700; }

.auth-logo {
  display: block;
  width: 200px;
  max-width: 100%;
  height: auto;
  margin: 0 auto 24px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  gap: 18px;
  min-width: 0;
}

.header-logo {
  display: block;
  width: 112px;
  height: auto;
  flex: 0 0 112px;
  mix-blend-mode: multiply;
}

.brand-lockup h1 { font-size: 1.5rem; overflow-wrap: normal; }

@media (max-width: 600px) {
  .brand-lockup { gap: 14px; }
  .header-logo { width: 96px; flex-basis: 96px; }
  .brand-lockup h1 { font-size: 1.375rem; }
  .auth-logo { width: 180px; margin-bottom: 20px; }
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 760;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: 2rem;
}

.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.875rem;
}

.form-error, .user-table td, .worker-name { overflow-wrap: anywhere; }
#historyTableBody td { max-width: 360px; overflow-wrap: anywhere; white-space: normal; }
.shared-dialog-error:empty { display: none; }
button:disabled { cursor: wait; opacity: 0.55; }
select:disabled { opacity: 0.7; }

@media (max-width: 600px) {
  .auth-screen { padding: 16px; }
  .auth-card { padding: 20px; }
  input, select, textarea { font-size: 16px; }
  .topbar-actions { width: 100%; }
  .tabs { display: flex; overflow-x: auto; flex-wrap: nowrap; }
  .tab { flex: 0 0 auto; }
  dialog { max-width: calc(100vw - 24px); max-height: calc(100dvh - 32px); }
  .admin-grid > *, .form-grid > *, .toolbar > * { min-width: 0; }
}

h2 {
  font-size: 1.25rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 0.74rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.danger-button,
.ghost-button,
.icon-button,
.tab {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.primary-button {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
  padding: 0 18px;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
  padding: 0 18px;
}

.danger-button:hover {
  background: #942727;
}

.ghost-button {
  padding: 0 14px;
}

.user-badge {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 760;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  padding: 0;
  font-size: 0.76rem;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.register-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 0 0 18px;
  padding: 4px 0 16px;
  border-bottom: 1px solid var(--line);
}

.register-totals > div {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  min-width: 0;
}

.register-totals dt {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.register-totals dd {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  box-shadow: 0 8px 22px rgb(16 35 43 / 6%);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 2.1rem;
}

.metric-danger {
  border-left-color: var(--danger);
}

.metric-warning {
  border-left-color: var(--warning);
}

.metric-watch {
  border-left-color: #ccb02a;
}

.metric-pending {
  border-left-color: var(--verify);
}

.metric-good {
  border-left-color: var(--good);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 210px 170px;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
}

.language-control {
  width: 140px;
}

.language-control select {
  min-height: 40px;
  font-size: 0.84rem;
  font-weight: 760;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 740;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  padding: 9px 10px;
}

.readonly-field {
  display: flex;
  min-height: 40px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgb(29 95 111 / 20%);
  outline-offset: 2px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0 12px;
}

.tab {
  padding: 0 14px;
}

.tab.active {
  border-color: var(--brand);
  background: #e5f2f5;
  color: var(--brand-strong);
}

.view {
  display: none;
  padding-bottom: 36px;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 14px 0 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 13px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: #3a4b52;
  font-size: 0.78rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-overdue {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-due-7,
.status-due-30 {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-watch {
  background: var(--watch-bg);
  color: var(--watch);
}

.status-valid {
  background: var(--good-bg);
  color: var(--good);
}

.status-verify {
  background: var(--verify-bg);
  color: var(--verify);
}

.action-cell {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.small-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbfc;
  color: var(--text);
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 760;
}

.danger-text {
  color: var(--danger);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 14px;
  align-items: start;
}

.admin-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  box-shadow: 0 8px 22px rgb(16 35 43 / 6%);
}

.admin-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.checkbox-control {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
}

.checkbox-control input {
  width: 18px;
  min-height: 18px;
}

.user-table {
  min-width: 560px;
}

.worker-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.vehicle-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.vehicle-heading label { min-width: 160px; }
.vehicle-card .worker-card-header > div:first-child { min-width: 0; }
.vehicle-card .worker-name, .vehicle-card .notes { overflow-wrap: anywhere; }
.vehicle-card .worker-card-header { flex-wrap: wrap; }
#vehicleForm input[name="name"] { text-transform: uppercase; }

.worker-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 22px rgb(16 35 43 / 6%);
}

.worker-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.worker-name {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.group-chip {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  background: #e8eef0;
  color: #43545b;
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 800;
}

.component-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.component-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  border-top: 1px solid var(--line);
  padding-top: 7px;
}

.component-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 720;
}

.component-date {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.notes {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

dialog {
  width: min(720px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(20 33 38 / 50%);
}

.dialog-body {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 880px) {
  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 580px) {
  .app-shell {
    width: min(100% - 20px, 1420px);
  }

  .summary-grid,
  .form-grid,
  .worker-list {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .tab {
    white-space: nowrap;
  }
}
