:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #2d2d2d;
  --subtle: #5a6472;
  --primary: #006b4f;
  --primary-hover: #005540;
  --danger: #a61c2f;
  --border: #dce3e9;
  --header-bg: #ffffff;
  --header-ink: #2d2d2d;
  --footer-bg: #2d2d2d;
  --footer-ink: #aab0b8;
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

html, body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}

/* ── Site header ─────────────────────────────────── */

.site-header {
  background: var(--header-bg);
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.site-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-logo img {
  height: 52px;
  width: auto;
  display: block;
}

.site-header-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.billing-label {
  color: var(--header-ink);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
  text-decoration: none;
}
.billing-label:hover {
  opacity: 1;
}

/* ── Language switcher ───────────────────────────── */

.lang-switcher {
  display: flex;
  gap: 0.1rem;
  background: #f0f2f4;
  border-radius: 6px;
  padding: 0.2rem;
}

.lang-switcher a {
  color: var(--subtle);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.lang-switcher a:hover {
  color: var(--ink);
  background: #e2e6ea;
}

.lang-switcher a.active {
  background: var(--primary);
  color: #fff;
}

/* ── Site footer ─────────────────────────────────── */

.site-footer {
  margin-top: auto;
  background: var(--footer-bg);
  border-top: 1px solid rgba(255,255,255,0.06);
}

.site-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--footer-ink);
}

.site-footer-inner a {
  color: var(--footer-ink);
  text-decoration: none;
}

.site-footer-inner a:hover {
  color: #fff;
}

.version {
  font-family: monospace;
  font-size: 0.75rem;
  opacity: 0.5;
}

/* ── Layout ──────────────────────────────────────── */

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
  flex: 1;
}

.narrow {
  max-width: 640px;
}

/* ── Page header (inside main) ───────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Card ────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

h1, h2, h3, h4 {
  margin-top: 0;
  color: var(--ink);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }

/* ── Row / grid helpers ──────────────────────────── */

.row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.between {
  justify-content: space-between;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

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

/* ── Form elements ───────────────────────────────── */

label {
  display: block;
  font-weight: 600;
  color: var(--subtle);
  font-size: 0.88rem;
  margin-bottom: 0.1rem;
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,107,79,0.12);
}

button {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--primary);
  color: white;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: var(--primary-hover);
}

/* Secondary / ghost button (used for logout, back links) */
.btn-secondary {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn-secondary:hover {
  border-color: var(--primary);
  background: #f0faf6;
}

form.inline { display: inline; }

/* ── Danger button ───────────────────────────────── */

.btn-danger {
  display: inline-block;
  width: auto;
  padding: 0.25rem 0.65rem;
  margin-top: 0;
  border: 1px solid #f0bec5;
  border-radius: 6px;
  background: #fff2f4;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ── Cycle list row ──────────────────────────────── */

.cycle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.2rem 0;
}

.cycle-delete-form {
  flex-shrink: 0;
}

/* ── Alerts ──────────────────────────────────────── */

.alert {
  background: #eef8f3;
  border: 1px solid #b9dfcc;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.93rem;
}

.alert.error {
  background: #fff2f4;
  border-color: #f0bec5;
  color: var(--danger);
}

/* ── Status badges ───────────────────────────────── */

.status {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status.paid {
  background: #dff5eb;
  color: #0b6e48;
}

.status.unpaid {
  background: #ffe8ec;
  color: #8e1a2e;
}

/* ── Tables ──────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 0.5rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--subtle);
  border-bottom: 2px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td {
  border-bottom: none;
}

/* ── Billing cycles list ─────────────────────────── */

.cycles {
  margin: 0;
  padding-left: 1.2rem;
  line-height: 2;
}

/* ── Invoice payment block ───────────────────────── */

.payment-block {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.qr {
  width: 220px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  margin-top: 0.5rem;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #1a2230;
  color: #c8dff7;
  padding: 0.85rem;
  border-radius: 8px;
  font-size: 0.75rem;
  line-height: 1.5;
}

code {
  font-size: 0.8rem;
  color: var(--subtle);
  word-break: break-all;
}

/* ── Utility ─────────────────────────────────────── */

/* ── Two-action choice (index page) ─────────────────────────────── */

.action-choice {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.action-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  flex: 1;
  min-width: 180px;
}

.action-divider {
  font-size: 0.9rem;
  color: var(--subtle);
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Tabs ─────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--subtle);
  text-decoration: none;
  border-radius: 8px 8px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  margin-bottom: -2px;
  transition: color 0.15s, background 0.15s;
}

.tab-btn:hover {
  color: var(--ink);
  background: #f0faf6;
}

.tab-btn.active {
  color: var(--primary);
  background: var(--card);
  border-color: var(--border);
  border-bottom-color: var(--card);
}

/* ── Utility ─────────────────────────────────────────────────────── */

.small {
  color: var(--subtle);
  font-size: 0.86rem;
}

/* ── Email template editor ───────────────────────────────────────────────────── */

.template-editor {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.template-editor:last-child {
  margin-bottom: 0;
}

.template-editor-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.template-editor textarea {
  width: 100%;
  resize: vertical;
}

/* ── Invoice cycle collapsible sections ──────────────────────────── */

details.invoice-cycle {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

details.invoice-cycle > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  user-select: none;
}

details.invoice-cycle > summary::-webkit-details-marker { display: none; }

.invoice-cycle-title {
  flex: 1;
}

.invoice-cycle-meta {
  flex-shrink: 0;
}

.summary-chevron {
  font-size: 0.7rem;
  color: var(--subtle);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.invoice-cycle-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Sortable table headers ───────────────────────────────────────── */

th.sortable {
  cursor: pointer;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--primary);
}

.sort-icon {
  font-style: normal;
  opacity: 0.5;
  font-size: 0.75rem;
}

/* ── Small action buttons (inside table rows) ─────────────────────── */

.btn-small {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  border-radius: 6px;
  white-space: nowrap;
}

/* ── Table pagination ────────────────────────────────────────────── */

.pagination-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.pagination-bar .billing-items-pagination,
.pagination-bar .members-pagination,
.pagination-bar #cycles-pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.page-size-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--subtle);
  white-space: nowrap;
}

.page-size-select {
  padding: 0.2rem 0.4rem;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.table-pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0;
  font-size: 0.85rem;
}

.table-pagination .btn-page,
.pagination-bar .btn-page {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 6px;
}

.table-pagination .btn-page:disabled,
.pagination-bar .btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  color: var(--subtle);
}

/* ── Send-all bar ────────────────────────────────────────────────── */

.cycle-send-all-bar {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.btn-send-all {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0.4rem 1rem;
  font-size: 0.88rem;
}

/* ── Progress modal ─────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--card);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.modal h3 {
  margin-bottom: 1.25rem;
}

.progress-bar-track {
  background: var(--border);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.4s ease;
  width: 0%;
}

.modal #modal-status {
  margin-bottom: 1.25rem;
}

.modal #modal-cancel-btn {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0.45rem 1.1rem;
}

/* ── Link-style button (e.g. clickable member name in table) ─────── */

.btn-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  color: var(--primary);
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-align: left;
}

.btn-link:hover {
  background: none;
  color: var(--primary-hover);
}

/* ── Wide / scrollable modal variant ────────────────────────────── */

.modal--wide {
  max-width: min(900px, 96vw);
}

/* Overlay that scrolls when modal content is taller than the viewport */
.modal-overlay--scroll {
  align-items: flex-start;
  overflow-y: auto;
  padding: 3vh 1rem;
}

/* Scrollable region inside a modal (e.g. member resolution table) */
.modal-scroll-body {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.member-detail-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem 2rem;
  margin: 1rem 0 1.5rem;
}

.member-detail-section h4 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--subtle);
  margin: 0 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.member-detail-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.4rem;
}

.member-detail-label {
  font-size: 0.75rem;
  color: var(--subtle);
  font-weight: 600;
}

.member-detail-value {
  font-size: 0.9rem;
  color: var(--ink);
  word-break: break-word;
}

/* ── Collapsible form sections ───────────────────────────────────── */

.collapsible-form summary.collapsible-form__toggle {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  padding: 0.3rem 0;
  list-style: none;
  user-select: none;
}

.collapsible-form summary.collapsible-form__toggle::-webkit-details-marker { display: none; }

.collapsible-form .collapsible-form__body {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  margin-top: 0.25rem;
  background: var(--surface);
}

/* ── Filter bar ─────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-input {
  flex: 1 1 140px;
  min-width: 100px;
  max-width: 220px;
  margin-top: 0;
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}

/* ── Status badges ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge--grey { background: #e8e8e8; color: #555; }
.badge--blue { background: #dbeafe; color: #1e40af; }

/* ── Billing items table group separator ─────────────────────────── */

tr.group-start td {
  border-top: 2px solid var(--border);
}

/* ── Danger button variant ───────────────────────────────────────── */

.btn-danger {
  background: var(--danger, #c0392b);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #a93226;
}

/* ── Generic data table ─────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table thead th {
  background: var(--surface);
  font-weight: 700;
  font-size: 0.82rem;
}

/* ── Flash messages ─────────────────────────────────────────────── */

.flash {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash--ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.flash--err {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* ── Form rows (two-column grid) ────────────────────────────────── */

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

/* ── Subtle text ────────────────────────────────────────────────── */

.subtle {
  color: var(--subtle);
  font-size: 0.88rem;
}

/* ── Primary button variant ─────────────────────────────────────── */

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
}

.btn-primary:hover {
  background: var(--primary-hover, #1a5e3a);
}

/* ── Billing items action bar ────────────────────────────────────── */

.bi-action-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  margin-top: 0.75rem;
  background: var(--primary, #1e7a4a);
  color: #fff;
  border-radius: 8px;
}

.bi-action-label {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
}
