*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #0a66c2;
  --brand-dark: #004182;
  --brand-light: #e8f1fb;
  --bg: #f3f2ef;
  --surface: #ffffff;
  --border: #e0ddd8;
  --text-primary: #000000e0;
  --text-secondary: #00000099;
  --text-muted: #00000060;
  --green: #057642;
  --green-bg: #e8f5ee;
  --red: #b24020;
  --red-bg: #fdf0ec;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --topbar-h: 56px;
  --max-w: 1128px;
  --radius: 8px;
  --shadow: 0 0 0 1px var(--border), 0 2px 6px rgba(0,0,0,.06);
  --font-sans: "Source Sans 3", system-ui, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.topbar-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  min-height: var(--topbar-h);
  flex-wrap: wrap;
}
.topbar-logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; flex-shrink: 0;
}
.logo-mark {
  width: 32px; height: 32px;
  background: var(--brand); color: #fff;
  border-radius: 6px;
  display: grid; place-items: center;
  font-weight: 700; font-size: .75rem;
}
.logo-text { font-weight: 700; color: var(--text-primary); }

.nav-toggle {
  margin-left: auto;
  width: 44px; height: 44px;
  border: 0; background: transparent;
  display: grid; place-content: center; gap: 5px;
  cursor: pointer;
}
.nav-toggle span {
  display: block; width: 20px; height: 2px;
  background: var(--text-primary); border-radius: 1px;
}

.topbar-nav {
  display: none;
  width: 100%;
  flex-direction: column;
  padding-bottom: 12px;
  gap: 2px;
}
.topbar-nav.is-open { display: flex; }
.nav-link {
  display: block;
  padding: 12px 10px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  min-height: 44px;
}
.nav-link:hover, .nav-link.is-active {
  background: var(--brand-light);
  color: var(--brand-dark);
  text-decoration: none;
}
.nav-logout { display: contents; }
.btn-link {
  border: 0; background: transparent; width: 100%;
  text-align: left; font: inherit; cursor: pointer;
}

.page-body { flex: 1; }
.page-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.login-body { background: linear-gradient(165deg, #e8f1fb 0%, var(--bg) 45%, #fff 100%); }
.login-wrap {
  display: grid; place-items: center;
  padding: 32px 16px;
  min-height: 100vh;
}
.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px 22px;
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .logo-mark { margin: 0 auto 12px; }
.login-brand h1 { font-size: 1.4rem; }
.login-brand p { color: var(--text-secondary); }

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
.field input, .field select, .field textarea,
.search-form input, .search-form select, .inline-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px;
  font: inherit;
  background: #fff;
  min-height: 44px;
}
.field textarea { min-height: 96px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text-primary); }
.btn-block { width: 100%; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.search-form {
  display: flex; flex-wrap: wrap; gap: 8px;
  flex: 1; min-width: min(100%, 280px);
}
.search-form input[type="search"] { flex: 1; min-width: 160px; }
.inline-field {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: .9rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-decoration: none;
  color: inherit;
}
.stat:hover { outline: 2px solid var(--brand-light); text-decoration: none; }
.stat-label { display: block; color: var(--text-secondary); font-size: .85rem; font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 700; }

.dash-grid, .form-grid, .detail-grid {
  display: grid;
  gap: 14px;
}
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.panel-head h2, .section-title {
  font-size: 1rem; font-weight: 700;
}
.list { list-style: none; display: grid; gap: 8px; }
.list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list a { display: grid; gap: 2px; color: inherit; text-decoration: none; flex: 1; }
.list a:hover strong { color: var(--brand); }
.list span { color: var(--text-secondary); font-size: .9rem; }

.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th {
  font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-secondary); background: #fafaf8;
}
.data-table tbody tr:last-child td { border-bottom: 0; }

.form-grid { margin-top: 8px; }
.form-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  grid-column: 1 / -1;
  margin-top: 4px;
}
.detail-grid {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 18px;
}
.detail-grid div { display: grid; gap: 4px; }
.detail-grid dt { color: var(--text-secondary); font-size: .85rem; font-weight: 600; }
.detail-grid dd { font-weight: 600; }
.span-2 { grid-column: 1 / -1; }

.pill {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: .78rem; font-weight: 700;
  background: var(--brand-light); color: var(--brand-dark);
  white-space: nowrap;
}
.pill-paid, .pill-approved { background: var(--green-bg); color: var(--green); }
.pill-overdue, .pill-declined { background: var(--red-bg); color: var(--red); }
.pill-sent, .pill-open { background: var(--amber-bg); color: var(--amber); }

.flash {
  padding: 12px 14px; border-radius: var(--radius);
  margin-bottom: 14px; font-weight: 600;
}
.flash-ok { background: var(--green-bg); color: var(--green); }
.flash-err { background: var(--red-bg); color: var(--red); }
.empty { color: var(--text-secondary); padding: 18px 0; }
.pager {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-top: 14px;
}
.pager-label { color: var(--text-secondary); font-size: .9rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

.event-list { list-style: none; display: grid; gap: 10px; }
.event-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.event-card a {
  display: flex; gap: 14px; padding: 14px;
  color: inherit; text-decoration: none; min-height: 64px;
}
.event-date {
  min-width: 72px; font-weight: 700; color: var(--brand-dark);
}
.event-card strong { display: block; }
.event-card span { color: var(--text-secondary); font-size: .9rem; }

@media (max-width: 720px) {
  .data-table thead { display: none; }
  .data-table tr {
    display: block;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .data-table td {
    display: flex; justify-content: space-between; gap: 12px;
    border: 0; padding: 4px 0;
  }
  .data-table td::before {
    content: attr(data-label);
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
  }
}

@media (min-width: 860px) {
  .nav-toggle { display: none; }
  .topbar-inner { flex-wrap: nowrap; }
  .topbar-nav {
    display: flex; flex-direction: row; align-items: center;
    width: auto; margin-left: auto; padding: 0; gap: 2px;
  }
  .nav-link { padding: 8px 10px; min-height: auto; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
