/* Ourael dues — one stylesheet, no build step.
   Tokens first; everything below uses them. */

:root {
  --brand: #6b3410;
  --brand-strong: #4a2208;
  --brand-soft: #f6ede4;
  --accent: #b8860b;
  --bg: #faf7f3;
  --surface: #ffffff;
  --surface-2: #f4efe8;
  --border: #e6ddd2;
  --text: #2a1a10;
  --muted: #7a6656;
  --paid: #2e7d32;
  --paid-bg: #e7f4e8;
  --paid-border: #a9d5ac;
  --due: #b45309;
  --due-bg: #fdf3e7;
  --due-border: #f2cf9d;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --info-bg: #eef4fb;
  --info: #1f4e79;
  --focus: #c97a2b;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(42, 26, 16, .06), 0 2px 8px rgba(42, 26, 16, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Ethiopic", sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #e0a26b;
    --brand-strong: #f0bb88;
    --brand-soft: #3a2a1f;
    --bg: #17120e;
    --surface: #211a14;
    --surface-2: #2a211a;
    --border: #3b3027;
    --text: #f3ebe3;
    --muted: #b4a191;
    --paid: #7ccf82;
    --paid-bg: #1d2e1e;
    --paid-border: #2f5a33;
    --due: #f0a75a;
    --due-bg: #33241450;
    --due-border: #6b4a25;
    --danger: #f28b82;
    --danger-bg: #3a1d1a;
    --info-bg: #1b2735;
    --info: #9cc3ea;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
input, select, textarea { accent-color: var(--brand); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* --- Top bar --------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem;
  padding-top: calc(.5rem + env(safe-area-inset-top));
  background: linear-gradient(135deg, #4a2208, #7a3d12);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; min-width: 0; flex: 1; }
.brand-logo { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.7); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: .75rem; opacity: .8; }
.account { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.account-name small { color: rgba(255,255,255,.75); }
.account .btn-link { color: #fff; }
.nav-top { display: none; gap: .25rem; }
.nav-top a { color: rgba(255,255,255,.85); text-decoration: none; padding: .4rem .8rem; border-radius: 999px; font-weight: 500; }
.nav-top a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-top a.active { background: #fff; color: #4a2208; }

/* --- Bottom nav (phones) --------------------------------------------- */
.nav-bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav-bottom a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 500;
}
.nav-bottom a.active { color: var(--brand); }
.nav-icon { width: 24px; height: 24px; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.nav-icon-lookup  { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); }
.nav-icon-reports { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); }
.nav-icon-cashier { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='20' height='13' rx='2'/%3E%3Ccircle cx='12' cy='12.5' r='2.5'/%3E%3Cpath d='M6 9.5v6M18 9.5v6'/%3E%3C/svg%3E"); }
.nav-icon-admin   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1'/%3E%3C/svg%3E"); }
.nav-icon-login   { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4M10 17l5-5-5-5M15 12H3'/%3E%3C/svg%3E"); }

@media (min-width: 760px) {
  body { padding-bottom: 2rem; }
  .nav-bottom { display: none; }
  .nav-top { display: flex; }
  .brand { flex: 0 1 auto; }
  .topbar { justify-content: space-between; }
}

/* --- Page ------------------------------------------------------------ */
.page { max-width: 760px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.page-head h1 { margin: 0; }
.stack > * + * { margin-top: 1rem; }

/* Sub-navigation: one scrollable row, never wraps */
.subnav { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; margin: 0 -1rem 1rem; padding: 0 1rem; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  flex: 0 0 auto; padding: .45rem .9rem; border-radius: 999px; text-decoration: none; font-size: .9rem; font-weight: 500;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); white-space: nowrap;
}
.subnav a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .subnav a.active { color: #1a120c; } }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75rem; text-align: center; margin-left: .25rem; }

/* --- Cards ----------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }

/* --- Forms ----------------------------------------------------------- */
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: .9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
input:not([type]), input[type=text], input[type=password], input[type=number], input[type=search], input[type=tel], input[type=email], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .75rem; min-height: 44px;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; inset: 0; }
.check-pill span { display: inline-block; padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: .9rem; cursor: pointer; }
.check-pill input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.check-pill input:disabled + span { opacity: .45; cursor: not-allowed; text-decoration: line-through; }
.check-pill input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* --- Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1.1rem; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-primary:hover { color: #1a120c; } }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn[disabled], .btn.htmx-request { opacity: .6; cursor: progress; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* --- Alerts ---------------------------------------------------------- */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--paid-bg); border-color: var(--paid-border); color: var(--paid); }
.alert-error { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert-warning { background: var(--due-bg); border-color: var(--due-border); color: var(--due); }
.alert-info { background: var(--info-bg); color: var(--info); }

/* --- Member search --------------------------------------------------- */
.search { position: relative; }
.search-results { list-style: none; margin: .25rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow); max-height: 50vh; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a, .search-results .empty { display: block; padding: .7rem .9rem; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border); }
.search-results li:last-child a { border-bottom: 0; }
.search-results a:hover, .search-results a:focus { background: var(--surface-2); }
.search-results .empty { color: var(--muted); }

/* --- Member summary -------------------------------------------------- */
.member-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.member-name { font-size: 1.25rem; font-weight: 700; margin: 0; }
.progress { height: 10px; border-radius: 999px; background: var(--due-bg); overflow: hidden; margin: .5rem 0 .25rem; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, #4caf50, var(--paid)); border-radius: inherit; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 1rem 0; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: .6rem; text-align: center; }
.stat b { display: block; font-size: 1.3rem; color: var(--brand); }
.stat span { font-size: .8rem; color: var(--muted); }
.stats-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .stats-4 { grid-template-columns: repeat(4, 1fr); } }

/* --- Month grid ------------------------------------------------------ */
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
@media (min-width: 560px) { .months { grid-template-columns: repeat(4, 1fr); } }
.month {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 64px; padding: .4rem; border-radius: var(--radius-sm); border: 1px solid; text-align: center;
}
.month .m { font-weight: 700; font-size: .85rem; }
.month .a { font-size: .9rem; }
.month.paid { background: var(--paid-bg); border-color: var(--paid-border); color: var(--paid); }
.month.due { background: var(--due-bg); border-color: var(--due-border); color: var(--due); }
.month-toggle { cursor: pointer; }
.month-toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.month-toggle:has(input:checked) { outline: 3px solid var(--brand); outline-offset: -1px; box-shadow: 0 0 0 4px var(--brand-soft); }
.month-toggle:has(input:checked)::after { content: "✓"; position: absolute; top: 4px; right: 6px; font-weight: 700; color: var(--brand); font-size: .8rem; }
.month-toggle:has(input:focus-visible) { outline: 3px solid var(--focus); }
.total-bar { margin-top: .75rem; padding: .6rem; text-align: center; font-weight: 600; background: var(--surface-2); border-radius: var(--radius-sm); }
.action-panel { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.action-panel:empty { display: none; }

/* --- Tables ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Lists ----------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .7rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag-paid { background: var(--paid-bg); color: var(--paid); }
.tag-due { background: var(--due-bg); color: var(--due); }
.tag-danger { background: var(--danger-bg); color: var(--danger); }

details.card > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸ "; color: var(--muted); }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: .75rem; }

/* --- Charts ---------------------------------------------------------- */
.chart { width: 100%; min-height: 280px; }

/* --- Toast ----------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); z-index: 50;
  max-width: min(92vw, 480px); padding: .75rem 1rem; border-radius: var(--radius-sm);
  background: #2a1a10; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: .95rem;
}
.toast.error { background: var(--danger); }
@media (min-width: 760px) { .toast { bottom: 1.5rem; } }

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.list details > summary::-webkit-details-marker { display: none; }
.list details > summary::after { content: "▾"; color: var(--muted); margin-left: .5rem; }
.list details[open] > summary::after { content: "▴"; }

/* --- Feedback button + dialog ----------------------------------------- */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 30;
  width: 52px; height: 52px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1.4rem;
  background: linear-gradient(135deg, #4a2208, #7a3d12); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
@media (min-width: 760px) { .fab { bottom: 24px; } }
.dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; width: min(92vw, 440px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(20, 12, 6, .45); }

/* --- Assistant chat ----------------------------------------------------- */
.chat-msg { padding: .6rem .8rem; border-radius: var(--radius-sm); }
.chat-msg > strong { display: block; font-size: .8rem; color: var(--muted); }
.chat-user { background: var(--brand-soft); margin-left: 2rem; }
.chat-bot { background: var(--surface-2); margin-right: 2rem; }
.chat-msg ul { margin: .25rem 0; padding-left: 1.2rem; }
