:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --panel: #fffdf8;
  --panel-strong: #f7ead7;
  --text: #202124;
  --muted: #6a655d;
  --line: #ded6c9;
  --brand: #126b5d;
  --brand-dark: #0d4e45;
  --accent: #e0922f;
  --danger: #b23b3b;
  --shadow: 0 16px 40px rgba(44, 39, 31, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(18, 107, 93, 0.08), transparent 32%),
    linear-gradient(260deg, rgba(224, 146, 47, 0.1), transparent 36%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.65rem, 3vw, 2.6rem);
  line-height: 1;
}

h2 {
  font-size: 1.35rem;
}

.today-pill,
.status-badge,
.week-total {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.8);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.active {
  border-color: rgba(18, 107, 93, 0.25);
  background: rgba(18, 107, 93, 0.12);
  color: var(--brand-dark);
}

.week-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.72);
}

.tab {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: var(--brand);
  color: white;
  box-shadow: 0 8px 18px rgba(18, 107, 93, 0.22);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 18px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.summary-card span,
.detail-row span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-card strong {
  font-size: 1.45rem;
}

.mileage-layout {
  grid-template-columns: minmax(340px, 0.8fr) minmax(0, 1.2fr);
}

.history-layout {
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.clock-panel .panel-heading {
  min-height: 124px;
}

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(224, 146, 47, 0.35);
  background: rgba(224, 146, 47, 0.13);
  color: #6f4210;
}

.notice.hidden {
  display: none;
}

.notice-button,
.secondary-small {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--brand-dark);
  padding: 0 12px;
  font-weight: 900;
}

.table-actions {
  display: inline-flex;
  gap: 6px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: rgba(18, 107, 93, 0.05);
}

.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--brand-dark);
  font-weight: 900;
}

.quick-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#currentTime {
  font-size: clamp(3rem, 9vw, 6rem);
  line-height: 0.9;
}

.clock-actions {
  display: flex;
  justify-content: flex-end;
  padding: 20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.clock-actions .secondary-action {
  width: min(260px, 100%);
}

.quick-clock {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.clock-in-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 0.7fr);
  align-items: end;
  gap: 12px;
}

.primary-action,
.secondary-action,
.form-button,
.danger-action,
.danger-button {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 18px;
  font-weight: 900;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(18, 107, 93, 0.2);
  background: rgba(18, 107, 93, 0.1);
  color: var(--brand-dark);
  font-size: 0.84rem;
  font-weight: 900;
}

.status-chip.soft {
  border-color: rgba(224, 146, 47, 0.28);
  background: rgba(224, 146, 47, 0.14);
  color: #7a4a13;
}

.row-complete {
  border-left: 4px solid var(--brand);
}

.row-warning {
  border-left: 4px solid var(--accent);
}

.row-soft {
  border-left: 4px solid rgba(224, 146, 47, 0.8);
}

.day-detail {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.detail-row {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-row strong {
  font-size: 1.1rem;
}

.detail-note,
.detail-trip {
  padding: 12px;
  border-radius: 8px;
  background: rgba(18, 107, 93, 0.07);
  color: var(--muted);
  font-weight: 700;
}

.month-filter {
  min-width: 180px;
}

.primary-action,
.form-button {
  background: var(--brand);
  color: white;
}

.primary-action:hover,
.form-button:hover {
  background: var(--brand-dark);
}

.secondary-action {
  background: white;
  color: var(--brand-dark);
  border-color: var(--line);
}

.secondary-action:hover {
  border-color: var(--brand);
}

.danger-button {
  min-height: 34px;
  padding: 0 10px;
  background: rgba(178, 59, 59, 0.08);
  color: var(--danger);
  border-color: rgba(178, 59, 59, 0.18);
}

.danger-action {
  background: rgba(178, 59, 59, 0.08);
  color: var(--danger);
  border-color: rgba(178, 59, 59, 0.2);
}

.danger-action:hover {
  background: rgba(178, 59, 59, 0.14);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.stat {
  min-height: 112px;
  padding: 18px;
  background: var(--panel);
}

.stat span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
}

.stat strong {
  font-size: 1.8rem;
}

.stat.accent {
  background: var(--panel-strong);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 11px;
  text-overflow: ellipsis;
}

input:focus,
select:focus {
  outline: 3px solid rgba(18, 107, 93, 0.16);
  border-color: var(--brand);
}

.wide {
  grid-column: 1 / -1;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.checkbox-label input {
  width: 20px;
  min-height: 20px;
}

.workdays-fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.workdays-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

#tab-history th,
#tab-history td {
  padding: 12px 10px;
}

#tab-history .status-chip {
  min-height: 26px;
  padding: 0 9px;
  font-size: 0.78rem;
}

#tab-history table th:nth-child(1),
#tab-history table td:nth-child(1),
#tab-week table th:nth-child(1),
#tab-week table td:nth-child(1) {
  min-width: 150px;
}

#tab-history table th:nth-child(2),
#tab-history table td:nth-child(2),
#tab-week table th:nth-child(2),
#tab-week table td:nth-child(2) {
  min-width: 116px;
}

#tab-history table th:nth-child(3),
#tab-history table td:nth-child(3),
#tab-history table th:nth-child(4),
#tab-history table td:nth-child(4),
#tab-week table th:nth-child(3),
#tab-week table td:nth-child(3),
#tab-week table th:nth-child(4),
#tab-week table td:nth-child(4) {
  min-width: 82px;
}

#tab-history table th:nth-child(8),
#tab-history table td:nth-child(8),
#tab-week table th:nth-child(9),
#tab-week table td:nth-child(9) {
  min-width: 88px;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

td strong {
  color: var(--brand-dark);
}

#tab-mileage table th:nth-child(1),
#tab-mileage table td:nth-child(1) {
  width: 86px;
}

#tab-mileage table {
  table-layout: fixed;
}

#tab-mileage table th:nth-child(3),
#tab-mileage table td:nth-child(3) {
  width: 105px;
}

#tab-mileage table th:nth-child(4),
#tab-mileage table td:nth-child(4) {
  width: 86px;
}

#tab-mileage table th:nth-child(5),
#tab-mileage table td:nth-child(5) {
  width: 66px;
}

.route-cell {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.positive {
  color: var(--brand);
  font-weight: 900;
}

.negative {
  color: var(--danger);
  font-weight: 900;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px;
}

.import-button {
  display: inline-flex;
  align-items: center;
}

.import-button input {
  display: none;
}

.muted {
  margin: 0;
  padding: 0 20px 20px;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--text);
  color: white;
  font-weight: 800;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .dashboard-grid,
  .summary-grid,
  .mileage-layout,
  .history-layout {
    grid-template-columns: 1fr;
  }

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

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

  .clock-in-form {
    grid-template-columns: 1fr;
  }

  .workdays-fieldset {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow-x: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    margin: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 248, 0.82);
    overflow: hidden;
  }

  td,
  #tab-history td {
    display: grid;
    grid-template-columns: minmax(100px, 0.45fr) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-width: 0 !important;
    width: auto !important;
    padding: 10px 12px;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 900;
    text-transform: uppercase;
  }

  td[data-label=""]::before {
    content: "";
  }

  .route-cell {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
  }

  .table-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 460px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 12px;
  }
}
