:root {
  color-scheme: light;
  --bg: #f2f6f4;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --text: #16231f;
  --muted: #687873;
  --line: #dce7e2;
  --primary: #176b57;
  --primary-dark: #0d5444;
  --danger: #b43a40;
  --shadow: 0 16px 44px rgba(20, 59, 48, 0.09);
  font-family: "Noto Sans Khmer", "Khmer OS Battambang", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 5% 0%, rgba(23, 107, 87, 0.12), transparent 30rem),
    var(--bg);
}

button, input { font: inherit; }

button { cursor: pointer; }

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 440px);
  padding: 38px;
  border: 1px solid rgba(23, 107, 87, 0.14);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand-mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 21px;
  color: white;
  background: var(--primary);
  box-shadow: 0 10px 24px rgba(23, 107, 87, 0.28);
  font-size: 38px;
  font-weight: 900;
}

.brand-mark.small {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 24px;
}

.eyebrow {
  margin: 18px 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 { margin-bottom: 8px; font-size: clamp(24px, 5vw, 34px); }

h2 { margin-bottom: 0; font-size: 21px; }
h3 { margin: 0; font-size: 19px; }
h4 { margin: 0; font-size: 17px; }

.muted, .tiny { color: var(--muted); }

.tiny { margin: 20px 0 0; font-size: 12px; line-height: 1.7; }

label { display: grid; gap: 7px; font-weight: 700; }

.login-card form { display: grid; gap: 16px; margin-top: 28px; }

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid #c9d8d2;
  border-radius: 12px;
  outline: none;
  color: var(--text);
  background: white;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 87, 0.13);
}

.password-row { position: relative; }
.password-row input { padding-right: 52px; }
.password-row .icon-button { position: absolute; inset: 5px 5px 5px auto; }

button {
  min-height: 43px;
  padding: 9px 15px;
  border: 0;
  border-radius: 11px;
  font-weight: 800;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:active { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: 0.58; }

.primary { color: white; background: var(--primary); box-shadow: 0 8px 18px rgba(23, 107, 87, 0.2); }
.primary:hover { background: var(--primary-dark); }
.secondary { color: var(--primary); background: #e7f2ee; }
.ghost { color: var(--muted); background: transparent; }
.danger-button { color: white; background: var(--danger); }
.danger-button:hover { background: #922b31; }
.icon-button { min-width: 40px; min-height: 38px; padding: 4px; background: transparent; }
.full { width: 100%; }
.nav-button {
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  padding: 9px 15px;
  border-radius: 11px;
  font-weight: 800;
  text-decoration: none;
}

.error-message { min-height: 22px; margin: 12px 0 0; color: var(--danger); font-weight: 700; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px max(18px, calc((100vw - 1280px) / 2));
  border-bottom: 1px solid rgba(23, 107, 87, 0.12);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(18px);
}

.brand-row, .top-actions, .section-heading, .toolbar, .toolbar-controls, .search-row {
  display: flex;
  align-items: center;
}

.brand-row { gap: 12px; }
.brand-row h1 { margin: 0; font-size: 20px; }
.brand-row .eyebrow { margin: 0 0 2px; }
.top-actions { gap: 8px; }

.sync-status {
  padding: 8px 11px;
  border-radius: 999px;
  color: #176b57;
  background: #e6f4ef;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.sync-status[data-state="busy"] { color: #8b5a00; background: #fff1cf; }
.sync-status[data-state="error"] { color: #9b2930; background: #fde9eb; }

.device-mode {
  padding: 7px 10px;
  border: 1px solid rgba(23, 107, 87, 0.18);
  border-radius: 999px;
  color: var(--primary);
  background: #f4fbf8;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.content {
  width: min(1280px, calc(100% - 32px));
  margin: 24px auto;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(20, 59, 48, 0.055);
}

.section-heading, .toolbar { justify-content: space-between; gap: 18px; }
.section-heading .eyebrow, .toolbar .eyebrow { margin-top: 0; }

.record-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 13px;
  align-items: end;
  margin-top: 20px;
}

.record-form label span, .compact-label span { color: var(--muted); font-size: 13px; }
.save-button { grid-column: span 2; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 16px 0;
}

.stat-card {
  position: relative;
  overflow: hidden;
  min-height: 112px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}
.stat-card::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--accent); }
.stat-card span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 12px; font-size: clamp(24px, 4vw, 32px); }
.stat-card.green { --accent: #2d9478; }
.stat-card.amber { --accent: #e0a22e; }
.stat-card.blue { --accent: #3c7fbb; }
.stat-card.violet { --accent: #8358b1; }
.stat-card.rose { --accent: #b84a60; }
.stat-card.teal { --accent: #258d91; }

.toolbar-controls { gap: 10px; }
.compact-label { display: flex; align-items: center; gap: 8px; }
.compact-label input { width: auto; min-height: 43px; }
.search-row { gap: 9px; margin: 18px 0 12px; }
.search-row input { max-width: 360px; }
.month-delete-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #f0c9cc;
  border-radius: 13px;
  background: #fff7f7;
}
.month-delete-row small { color: #8a4b4f; }

.monthly-report-panel {
  margin: 16px 0;
  border-color: rgba(23, 107, 87, 0.24);
  background: linear-gradient(145deg, #ffffff, #f5fbf8);
}
.report-close-row { display: flex; justify-content: flex-end; }
.report-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 4px;
}
.combined-report-section {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.subreport-heading .eyebrow { margin-top: 0; }
.driver-summary-section {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.combined-report-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.combined-report-summary .stat-card { min-height: 96px; padding: 14px; }
.combined-report-summary .stat-card strong { font-size: clamp(19px, 2.5vw, 26px); }
.driver-sum-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 22px 0 12px; }
.driver-sum-table { min-width: 1050px; }
.driver-sum-table td { font-size: 14px; white-space: nowrap; }
.driver-sum-table .summary-vet-row { background: #edf5fc; }
.driver-sum-table .summary-combined-row { background: #e3f3ed; font-weight: 900; }
.driver-name-label {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 10px;
  color: var(--primary);
  background: #e7f2ee;
  font-size: 13px;
  font-weight: 800;
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { padding: 14px 12px; border-bottom: 1px solid var(--line); text-align: center; }
th { position: sticky; top: 0; color: #42534d; background: #edf4f1; font-size: 14px; }
td { font-size: 16px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: var(--surface-2); }
.date-cell { font-size: 17px; font-weight: 900; white-space: nowrap; }
.actions { display: flex; justify-content: center; gap: 7px; }
.table-button { min-height: 36px; padding: 6px 10px; font-size: 12px; }
.edit-button { color: #245c9c; background: #e9f1fb; }
.delete-button { color: #a2262d; background: #fcebed; }
.empty-state { padding: 48px 18px; color: var(--muted); text-align: center; }
.footer-note { margin: 17px 4px 0; color: var(--muted); font-size: 12px; text-align: center; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  color: white;
  background: #18342c;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: 180ms ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .record-form { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .combined-report-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topbar { padding-inline: 14px; }
  .top-actions .sync-status { display: none; }
}

@media (max-width: 768px) {
  .vet-page .topbar { align-items: center; flex-wrap: wrap; padding: 10px 12px; }
  .vet-page .brand-row { flex: 1 1 auto; min-width: 0; }
  .vet-page .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  .vet-page .top-actions .device-mode,
  .vet-page .top-actions .nav-button,
  .vet-page .top-actions button { width: 100%; min-height: 40px; justify-content: center; text-align: center; }
  .vet-page .top-actions .sync-status { display: none; }
  .content { width: min(100% - 20px, 1280px); margin-top: 12px; }
  .panel { padding: 16px; border-radius: 16px; }
  .login-card { padding: 28px 22px; }
  .brand-row h1 { font-size: 16px; }
  .brand-row .eyebrow { display: none; }
  .brand-mark.small { width: 40px; height: 40px; }
  .top-actions { gap: 2px; }
  .top-actions button { padding-inline: 9px; font-size: 12px; }
  .top-actions .nav-button { padding-inline: 9px; font-size: 12px; }
  .record-form { grid-template-columns: 1fr; }
  .save-button { grid-column: auto; min-height: 52px; }
  .summary-grid { gap: 8px; }
  .stat-card { min-height: 96px; padding: 14px; border-radius: 14px; }
  .stat-card strong { font-size: 22px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-controls { width: 100%; }
  .vet-page .toolbar-controls { align-items: stretch; flex-wrap: wrap; }
  .vet-page .toolbar-controls .compact-label { flex: 1 1 100%; }
  .vet-page .toolbar-controls button { flex: 1 1 calc(50% - 6px); }
  .compact-label { flex: 1; }
  .compact-label input { flex: 1; min-width: 0; }
  .monthly-only.toolbar-controls { align-items: stretch; flex-direction: column; }
  .monthly-only .compact-label { width: 100%; }
  .monthly-only button { width: 100%; }
  .search-row { align-items: stretch; flex-wrap: wrap; }
  .search-row input { max-width: none; flex: 1 1 100%; }
  .search-row button { flex: 1; }
  .month-delete-row { align-items: stretch; flex-direction: column; }
  .month-delete-row .compact-label { width: 100%; }
  .month-delete-row button { width: 100%; }
  .report-actions { align-items: stretch; flex-direction: column; }
  .report-actions .compact-label,
  .report-actions button { width: 100%; }
  .driver-sum-heading { align-items: stretch; flex-direction: column; }
  .driver-sum-heading button { width: 100%; }
  .combined-report-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .combined-report-summary .stat-card { min-height: 88px; padding: 12px; }
  .combined-report-summary .stat-card strong { font-size: 19px; overflow-wrap: anywhere; }
  .vet-page .driver-sum-table { min-width: 0; }
  .vet-page .driver-sum-table td { white-space: normal; }
  .vet-page .driver-sum-table .summary-vet-row { background: #edf5fc !important; }
  .vet-page .driver-sum-table .summary-combined-row { background: #e3f3ed !important; }
  .table-wrap { overflow: visible; border: 0; }
  table, thead, tbody, tr, th, td { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 11px; }
  tbody tr { padding: 10px 13px; border: 1px solid var(--line); border-radius: 14px; background: white !important; }
  td { display: grid; grid-template-columns: minmax(105px, 42%) 1fr; gap: 10px; padding: 8px 2px; border-bottom: 1px dashed var(--line); text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; }
  td:last-child { border-bottom: 0; }
  .actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}


.nav-button[aria-current="page"] {outline:2px solid currentColor;outline-offset:-2px;}
