:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --good: #1a7f37;
  --good-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 2px 8px rgb(16 24 40 / .05);
  /* club color (Settings → Club); blue unless a theme below overrides it */
  --brand: #1f5fbf;
  --brand-2: #3b82f6;
  --accent-soft: #e8f0fc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b2027;
    --text: #e8ecf1;
    --muted: #9aa6b5;
    --line: #2e3640;
    --accent: #6ea8ff;
    --accent-text: #0b1220;
    --good: #5bd17d;
    --good-bg: #173322;
    --warn: #f0c35a;
    --warn-bg: #3a2f14;
    --bad: #ff8a80;
    --bad-bg: #3d1b1b;
    --shadow: none;
    --accent-soft: #1a2740;
  }
}

/* Club colors: --brand/--brand-2 paint the header band (white text on top);
   --accent is for buttons and links, lighter in dark mode; --accent-soft is a tint */
[data-theme="green"]  { --brand: #1e7a4c; --brand-2: #34a36b; --accent: #1e7a4c; --accent-soft: #e6f4ec; }
[data-theme="maroon"] { --brand: #7f1d2d; --brand-2: #b0334a; --accent: #8a1c2b; --accent-soft: #f8e9ec; }
[data-theme="purple"] { --brand: #4f2f99; --brand-2: #7c5cd6; --accent: #5b3aa6; --accent-soft: #efeafb; }
[data-theme="teal"]   { --brand: #0f6b64; --brand-2: #14a39a; --accent: #0f766e; --accent-soft: #e3f4f2; }
[data-theme="navy"]   { --brand: #1b2541; --brand-2: #3a4f86; --accent: #2b3d6b; --accent-soft: #e9edf6; }
[data-theme="rose"]   { --brand: #a3305e; --brand-2: #dc6a98; --accent: #a8325f; --accent-soft: #fbeaf1; }
[data-theme="gold"]   { --brand: #85590a; --brand-2: #c9921c; --accent: #8a5f00; --accent-soft: #fbf3df; }
@media (prefers-color-scheme: dark) {
  [data-theme="green"]  { --accent: #5fd39a; --accent-soft: #16301f; }
  [data-theme="maroon"] { --accent: #ff8fa0; --accent-soft: #3a1a20; }
  [data-theme="purple"] { --accent: #b9a2ff; --accent-soft: #2a2140; }
  [data-theme="teal"]   { --accent: #5eead4; --accent-soft: #12302d; }
  [data-theme="navy"]   { --accent: #9db4ff; --accent-soft: #1d2438; }
  [data-theme="rose"]   { --accent: #ff9cc4; --accent-soft: #3a1c29; }
  [data-theme="gold"]   { --accent: #f0c35a; --accent-soft: #3a2f14; }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header, main { max-width: 860px; margin: 0 auto; padding: 0 16px; }
main { padding-bottom: 40px; }

/* Header band in the club color; the cards below overlap its bottom edge */
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; padding: 22px 0 58px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
  flex: none; width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center;
  font-size: 1.8rem; background: rgb(255 255 255 / .18); box-shadow: inset 0 0 0 1px rgb(255 255 255 / .25);
}
.logo.letter { font-weight: 800; font-size: 1.5rem; }
h1 { font-size: 1.55rem; margin: 0; line-height: 1.2; }
.tagline { margin: 2px 0 0; opacity: .85; font-size: .9rem; }
.hero button { background: rgb(255 255 255 / .15); color: #fff; border-color: rgb(255 255 255 / .4); }
.hero button:hover { background: rgb(255 255 255 / .25); }
.hero .muted { color: rgb(255 255 255 / .85); }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: -40px 0 16px; position: relative; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card.balance strong { color: var(--accent); }
.meter { height: 6px; border-radius: 99px; background: var(--bg); margin-top: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--good); transition: width .4s; }
.card .label { display: block; color: var(--muted); font-size: .85rem; }
.card strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

nav#tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; margin-top: 22px; }
nav#tabs button {
  background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted);
  padding: 10px 12px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
nav#tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

a.button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; }
button, .button {
  font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 9px 14px; cursor: pointer; min-height: 42px;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-height: 42px;
}
textarea { min-height: 70px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row > .auto { flex: 0 0 auto; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; min-height: 0; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .main { min-width: 0; flex: 1; }
.item .name { font-weight: 600; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.in { color: var(--good); }
.out { color: var(--bad); }

.chip { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.chip.paid { background: var(--good-bg); color: var(--good); }
.chip.part { background: var(--warn-bg); color: var(--warn); }
.chip.unpaid { background: var(--bad-bg); color: var(--bad); }

/* Events bulletin */
.panel.events { box-shadow: var(--shadow); }
.events h2 { margin: 0; }
.events-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.event-list { display: flex; flex-direction: column; }
.event { display: flex; gap: 14px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.event-list > .event:first-child { border-top: 0; }
.event .main { flex: 1; min-width: 0; }
.event .title { font-weight: 600; }
.event .details { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.date-badge {
  flex: none; width: 52px; text-align: center; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface); line-height: 1.1;
}
.date-badge .mon { display: block; background: var(--accent); color: var(--accent-text); font-size: .75rem; font-weight: 700; text-transform: uppercase; padding: 3px 0; }
.date-badge .day { display: block; font-size: 1.35rem; font-weight: 700; padding: 4px 0 5px; }
.event.next { background: var(--accent-soft); border: 0; border-radius: 10px; padding: 12px; margin-bottom: 4px; }
.event.next + .event { border-top: 0; }
.event.next .date-badge { width: 60px; }
.event.next .date-badge .day { font-size: 1.6rem; }
.event.next .title { font-size: 1.1rem; }
.next-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 2px; }
.next-label .soon { margin-left: 8px; padding: 1px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-text); text-transform: none; letter-spacing: 0; }
.event-list.past .event { opacity: .7; }
.events details { margin-top: 6px; }

/* Members: cards, 3-4 across on desktop, one column on phones */
.members { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 10px; margin: 12px 0; }
.members.admin { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.member {
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius);
}
.member.paid { border-left-color: var(--good); }
.member.part { border-left-color: var(--warn); }
.member.unpaid { border-left-color: var(--bad); }
.member .top { display: flex; align-items: center; gap: 10px; }
.member .main { min-width: 0; }
.member .name { font-weight: 600; overflow-wrap: anywhere; }
.member .chip { margin-top: 3px; }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: .9rem; background: var(--bg); color: var(--muted);
}
.member.paid .avatar { background: var(--good-bg); color: var(--good); }
.member.part .avatar { background: var(--warn-bg); color: var(--warn); }
.member.unpaid .avatar { background: var(--bad-bg); color: var(--bad); }
.member .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.member .actions button:not(.link) { flex: 1 1 auto; min-height: 36px; padding: 6px 10px; }

.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 14px; }
.toolbar > div { flex: 1 1 150px; }
.toolbar label { margin-top: 0; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--line); }
th { color: var(--muted); font-size: .85rem; font-weight: 600; border-top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }

/* Settings: club color and icon */
.icon-input { width: 110px; font-size: 1.3rem; text-align: center; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; min-height: 42px; align-items: center; }
.swatch {
  width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--surface);
  background: linear-gradient(135deg, var(--sw), var(--sw2)); box-shadow: 0 0 0 1px var(--line);
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--text); }
.t-blue { --sw: #1f5fbf; --sw2: #3b82f6; }  .t-green { --sw: #1e7a4c; --sw2: #34a36b; }
.t-maroon { --sw: #7f1d2d; --sw2: #b0334a; } .t-purple { --sw: #4f2f99; --sw2: #7c5cd6; }
.t-teal { --sw: #0f6b64; --sw2: #14a39a; }  .t-navy { --sw: #1b2541; --sw2: #3a4f86; }
.t-rose { --sw: #a3305e; --sw2: #dc6a98; }  .t-gold { --sw: #85590a; --sw2: #c9921c; }
.segmented { display: flex; gap: 0; }
.segmented button { flex: 1; border-radius: 0; }
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  transition: transform .2s, visibility .2s; max-width: calc(100% - 32px); z-index: 10; visibility: hidden;
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
#toast.error { background: var(--bad); color: #fff; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(460px, calc(100% - 32px)); padding: 18px;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin-top: 0; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.error-text { color: var(--bad); margin: 10px 0 0; }

@media (max-width: 520px) {
  .card strong { font-size: 1.3rem; }
  .hero { padding: 16px 0 52px; }
  .logo { width: 46px; height: 46px; font-size: 1.5rem; border-radius: 13px; }
  h1 { font-size: 1.3rem; }
  .item { flex-wrap: wrap; }
  .item .actions { width: 100%; justify-content: stretch; }
  .item .actions button { flex: 1; }
  .hide-narrow { display: none; }
  .members, .members.admin { grid-template-columns: 1fr; gap: 8px; }
}
