:root {
  --blue: #1a73e8;
  --blue-dark: #1557b0;
  --blue-soft: #e8f0fe;
  --green: #0d9f6e;
  --green-soft: #e6f7f1;
  --amber: #f9ab00;
  --amber-soft: #fef7e0;
  --text: #202124;
  --muted: #5f6368;
  --border: #e0e3e7;
  --bg: #f8f9fa;
  --card: #ffffff;
  --danger: #d93025;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(60,64,67,.15), 0 1px 2px rgba(60,64,67,.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

.view { min-height: 100vh; }

/* Brand / login */
#view-login, #view-set-password {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-bottom));
  background: linear-gradient(180deg, #e8f0fe 0%, var(--bg) 45%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 22px; }
.logo-mark {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
}
.logo-mark.sm {
  width: 36px; height: 36px; font-size: 18px; margin: 0; border-radius: 10px; flex-shrink: 0;
}
.brand h1 { margin: 0; font-size: 1.35rem; color: var(--text); }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 14px;
}
label input, label select, .filters select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
}
label input:focus, .filters select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,.2);
}
.optional { font-weight: 400; color: #9aa0a6; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: #f1f3f4;
  color: var(--text);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-block { width: 100%; padding: 14px; margin-top: 4px; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; }

.error { color: var(--danger); font-size: 0.9rem; margin: 0 0 10px; }
.pilot-hint {
  margin-top: 18px;
  padding: 12px;
  background: var(--blue-soft);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}
.pilot-hint code {
  background: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--blue-dark);
  font-size: 0.8rem;
}

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; gap: 10px; align-items: center; }
.app-title { font-weight: 700; font-size: 1rem; }
.user-line { font-size: 0.78rem; color: var(--muted); }

.totals-scope {
  margin: 12px 12px 0;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}
.totals-scope.highlight {
  background: var(--blue-soft);
  border-color: #c5d9f7;
  color: var(--text);
  font-size: 0.95rem;
}
.totals-scope strong { color: var(--blue-dark); }

.totals-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 12px 0;
}
.total-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 10px;
  box-shadow: var(--shadow);
  text-align: center;
}
.total-card.accent { background: var(--amber-soft); }
.total-card.combined { background: var(--green-soft); }
.total-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; line-height: 1.25; }
.total-value { font-size: 1.05rem; font-weight: 700; margin-top: 2px; color: var(--text); }
.total-card.accent .total-value { color: #b06000; }
.total-card.combined .total-value { color: #0b7a55; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  min-width: 0;
  align-items: flex-end;
}
.filters select {
  width: auto;
  flex: 1 1 140px;
  min-width: 120px;
  padding: 10px 12px;
  margin: 0;
  font-size: 0.9rem;
}
.filters .date-filter {
  flex: 1 1 130px;
  min-width: 120px;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}
.filters .date-filter input[type="date"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
}
.filters .date-filter input[type="date"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,.2);
}
#btn-clear-dates {
  flex: 0 0 auto;
  align-self: flex-end;
  margin-bottom: 2px;
}
.toolbar-actions { display: flex; gap: 8px; }

.select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 0 12px 8px;
  font-size: 0.9rem;
  color: var(--muted);
}
.check-all { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; }
.check-all input { width: auto; margin: 0; }
.selected-total {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--blue-soft);
  padding: 6px 12px;
  border-radius: 8px;
  margin-left: auto;
  margin-right: 8px;
}

.receipt-list {
  padding: 0 12px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.receipt-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  cursor: pointer;
}
.receipt-card .check-cell {
  padding-top: 2px;
}
.receipt-card .check-cell input {
  width: 18px; height: 18px;
}
.receipt-main { min-width: 0; }
.receipt-vendor {
  font-weight: 700;
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.receipt-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}
.receipt-notes {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
}
.receipt-right { text-align: right; }
.receipt-amount { font-weight: 700; font-size: 1.05rem; }
.badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-submitted { background: var(--amber-soft); color: #8a5a00; }
.badge-paid { background: var(--green-soft); color: #0b7a54; }

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

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(32,33,36,.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 16px 16px 0 0;
  padding: 8px 18px calc(18px + var(--safe-bottom));
}
.modal-sheet.wide { max-width: 640px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--card);
  padding: 10px 0;
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-close { font-size: 1.5rem; line-height: 1; padding: 4px 10px; }

.detail-body { font-size: 0.95rem; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row .k { color: var(--muted); font-size: 0.85rem; }
.detail-row .v { font-weight: 600; text-align: right; }
.detail-file {
  margin-top: 14px;
}
.detail-file a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}
.detail-preview {
  margin-top: 10px;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.audit-list { font-size: 0.88rem; }
.audit-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.audit-item .when { color: var(--muted); font-size: 0.78rem; }
.audit-item .what { font-weight: 600; margin-top: 2px; }
.audit-item .who { color: var(--muted); margin-top: 2px; }

@media (min-width: 640px) {
  .modal { align-items: center; padding: 24px; }
  .modal-sheet { border-radius: 16px; max-height: 85vh; }
  .totals-row { padding: 16px 16px 0; gap: 12px; max-width: 900px; margin: 0 auto; }
  .toolbar, .select-bar, .receipt-list { max-width: 900px; margin-left: auto; margin-right: auto; }
  .total-value { font-size: 1.2rem; }
}

/* Pilot sample receipt helper */
.sample-receipt-row {
  margin: -6px 0 14px;
}
.sample-receipt-row .btn {
  margin-bottom: 6px;
}
.sample-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}
.file-status {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
}

.soft-note {
  margin: -4px 0 12px;
  padding: 10px 12px;
  background: var(--amber-soft);
  border-radius: 8px;
  color: #7a5c00;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* Manager nav + Employees panel */
.manager-nav-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}
.employees-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  max-width: 900px;
  margin: 0 auto;
}
.employees-title {
  margin: 0;
  font-size: 1.15rem;
  flex: 1;
  text-align: center;
}
.employee-list {
  padding: 0 12px calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 900px;
  margin: 0 auto;
}
.employee-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.employee-card.inactive {
  opacity: 0.72;
  background: #f1f3f4;
}
.employee-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.employee-name {
  font-weight: 700;
  font-size: 1.02rem;
}
.employee-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}
.employee-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.badge-role {
  background: var(--blue-soft);
  color: var(--blue-dark);
}
.badge-active {
  background: var(--green-soft);
  color: #0b7a54;
}
.badge-inactive {
  background: #eceff1;
  color: #5f6368;
}
.employee-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.employee-actions .btn {
  padding: 7px 10px;
  font-size: 0.8rem;
}
.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}
.reset-who {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}
#panel-employees .totals-row,
#view-app.showing-employees .totals-row,
#view-app.showing-employees .toolbar,
#view-app.showing-employees #manager-select-bar {
  display: none !important;
}

.topbar-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge-pending { background: #fff4e5; color: #9a5b00; }
#view-set-password .btn-ghost { margin-top: 10px; }

/* Keep From, To and Clear dates together on one line */
.filters .date-range {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 8px;
  flex: 2 1 340px;
  min-width: 300px;
}
.filters .date-range .date-filter { flex: 1 1 0; min-width: 0; }
@media (max-width: 420px) {
  .filters .date-range { min-width: 100%; }
}
/* Give the filters the full width so they sit in one row on wider screens */
.toolbar .filters { flex: 1 1 100%; }
.toolbar .toolbar-actions { margin-left: auto; }
.filters select { flex: 1 1 150px; }
