/* Service Accounts - one stylesheet, no frameworks */
:root {
  --ink: #1d2b3a;          /* text and top bar */
  --muted: #5b6b7c;
  --line: #d8e0e8;
  --bg: #eef2f5;
  --surface: #ffffff;
  --accent: #155e75;       /* buttons and links */
  --accent-dark: #0e4a5c;
  --danger: #b42318;
  --paid-bg: #dcf2e3;  --paid-ink: #14532d;  --paid-line: #86c79c;
  --part-bg: #fdf0c9;  --part-ink: #6b3f05;  --part-line: #e2b44e;
  --unpd-bg: #fde3e1;  --unpd-ink: #8a1c16;  --unpd-line: #e79a93;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5;
  color: var(--ink); background: var(--bg);
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }

.skip-link { position: absolute; left: -999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: .5rem; }

/* ---------- Top bar ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand:hover { color: #fff; }
.main-nav { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem; }
.main-nav a, .link-button {
  color: #dbe5ee; text-decoration: none; padding: .5rem .75rem; border-radius: 6px; font-size: .95rem;
}
.main-nav a:hover, .link-button:hover { background: rgba(255,255,255,.12); color: #fff; }
.main-nav a.active { background: #fff; color: var(--ink); font-weight: 600; }
.logout-form { margin: 0; }
.link-button { background: none; border: 0; font: inherit; cursor: pointer; }
.nav-toggle { display: none; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: .75rem; margin-bottom: 1.25rem;
}
.page-head .sub { color: var(--muted); margin: .25rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; margin-bottom: 1.25rem;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-2 > .panel { margin-bottom: 0; }
.grid-side { grid-template-columns: 1fr 2fr; }
.grid-2 > * { min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > * + * { margin-top: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.empty { color: var(--muted); padding: 1rem 0; }

/* ---------- Totals strip ---------- */
.totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 1.25rem; overflow: hidden;
}
.total { padding: 1rem 1.1rem; border-left: 1px solid var(--line); }
.total:first-child { border-left: 0; }
.total .label { color: var(--muted); font-size: .9rem; display: block; }
.total .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; display: block; margin-top: .15rem; }
.total .note { color: var(--muted); font-size: .825rem; display: block; margin-top: .2rem; }
.total.is-due .value { color: var(--unpd-ink); }
.total.is-net-neg .value { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--accent-dark); color: #fff; }
.btn-light { background: #fff; color: var(--accent); }
.btn-light:hover { background: #e8f1f4; color: var(--accent-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.req { color: var(--danger); }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=month],
input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; border: 1px solid #b9c5d1; border-radius: 6px;
  font: inherit; color: var(--ink); background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid rgba(21,94,117,.25); outline-offset: 0; }
.is-invalid { border-color: var(--danger) !important; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.25rem; }
.calc-line { background: #f4f7fa; border: 1px dashed var(--line); border-radius: 6px; padding: .6rem .8rem; font-variant-numeric: tabular-nums; }

/* Filter bar */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filters .field { flex: 1 1 160px; }
.filters .field.wide { flex: 2 1 240px; }
.filters .field label { font-size: .875rem; }
.filters .filter-actions { display: flex; gap: .5rem; }

/* ---------- Alerts ---------- */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.alert ul { margin: .35rem 0 0 1.1rem; padding: 0; }
.alert-success { background: var(--paid-bg); color: var(--paid-ink); border-color: var(--paid-line); }
.alert-error { background: var(--unpd-bg); color: var(--unpd-ink); border-color: var(--unpd-line); }
.alert-info { background: #e3eef7; color: #1e3a5f; border-color: #a9c4dd; }
.alert-warning { background: var(--part-bg); color: var(--part-ink); border-color: var(--part-line); }

/* ---------- Status badges (text + symbol, never colour alone) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap;
  padding: .15rem .6rem; border-radius: 999px; border: 1px solid; font-size: .85rem; font-weight: 600;
}
.badge-paid { background: var(--paid-bg); color: var(--paid-ink); border-color: var(--paid-line); }
.badge-partial { background: var(--part-bg); color: var(--part-ink); border-color: var(--part-line); }
.badge-unpaid { background: var(--unpd-bg); color: var(--unpd-ink); border-color: var(--unpd-line); }
.badge-inactive { background: #eceff3; color: #475467; border-color: #c4ccd6; }
.badge-active { background: #e3eef7; color: #1e3a5f; border-color: #a9c4dd; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { padding: .6rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { background: #f4f7fa; font-weight: 600; color: #344456; white-space: nowrap; }
table.data tbody tr:hover { background: #f8fafc; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 700; background: #f4f7fa; border-top: 2px solid var(--line); }
table.data .row-actions { white-space: nowrap; text-align: right; }
.due { color: var(--unpd-ink); font-weight: 600; }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; white-space: pre-line; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.page-info { color: var(--muted); font-size: .9rem; }

/* Login */
.auth-box { max-width: 420px; margin: 8vh auto 0; }
.auth-box h1 { margin-bottom: .25rem; }

/* Reports */
.period-tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.period-tabs label { display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; min-height: 40px; }
.period-tabs input:checked + span { font-weight: 700; }
.print-only { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2, .grid-side { grid-template-columns: 1fr; }
  .grid-2 > .panel { margin-bottom: 0; }
}

@media (max-width: 760px) {
  .nav-toggle {
    display: inline-flex; min-height: 44px; padding: .4rem .9rem; border-radius: 6px;
    background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); font: inherit; cursor: pointer;
  }
  .main-nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: .5rem; }
  .main-nav.open { display: flex; }
  .main-nav a, .link-button { padding: .75rem; width: 100%; text-align: left; }
  .form-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
  .total { border-left: 0; border-top: 1px solid var(--line); }
  .total:first-child { border-top: 0; }

  /* Tables become stacked cards: each cell shows its column name */
  table.data.cards thead { display: none; }
  table.data.cards, table.data.cards tbody, table.data.cards tfoot, table.data.cards tr, table.data.cards td { display: block; width: 100%; }
  table.data.cards tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; padding: .35rem .25rem; background: #fff; }
  table.data.cards td { border: 0; padding: .35rem .6rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  table.data.cards td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
  table.data.cards td.num { text-align: right; }
  table.data.cards td.row-actions { justify-content: flex-end; }
  table.data.cards td.row-actions::before { content: none; }
  table.data.cards tfoot tr { background: #f4f7fa; }
  table.data.cards tfoot td:empty { display: none; }
  .filters .field, .filters .field.wide { flex: 1 1 100%; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .no-print, .topbar, .pagination, .filters, .form-actions, .row-actions, .skip-link { display: none !important; }
  .print-only { display: block; }
  .container { max-width: none; padding: 0; }
  .panel, .totals { border: 1px solid #999; break-inside: avoid; }
  table.data th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
