:root {
  --green-900: #0f4a26;
  --green-700: #19713b;
  --green-600: #21894a;
  --green-500: #2ea55e;
  --green-100: #e6f4ea;
  --green-50: #f3faf5;
  --red-600: #c8352b;
  --red-100: #fbe9e7;
  --amber-600: #b3760a;
  --amber-100: #fdf1de;
  --ink-900: #12201a;
  --ink-700: #38473f;
  --ink-500: #647a6d;
  --ink-300: #a9bab0;
  --line: #dce7e0;
  --surface: #ffffff;
  --bg: #f6faf7;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 74, 38, 0.06), 0 6px 20px rgba(15, 74, 38, 0.07);
  --nav-h: 64px;
  --header-h: 60px;
  --max-w: 1080px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink-900);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 4px; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 8px; color: var(--ink-700); }
a { color: var(--green-700); }

button, input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- App shell ---------- */

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: var(--green-900);
  font-size: 1.05rem;
}
.app-header .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green-600);
}

.app-header .who {
  font-size: 0.85rem;
  color: var(--ink-500);
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header .who button {
  border: none; background: none; color: var(--ink-500);
  font-size: 0.85rem; cursor: pointer; padding: 6px; text-decoration: underline;
}

.app-body {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
}

main#view {
  flex: 1;
  min-width: 0;
  padding: 16px 16px calc(var(--nav-h) + 24px);
  width: 100%;
}

/* ---------- Desktop sidebar ---------- */

.sidebar {
  display: none;
}

@media (min-width: 900px) {
  main#view { padding: 24px 24px 40px; }
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 220px;
    flex-shrink: 0;
    padding: 24px 12px;
    border-right: 1px solid var(--line);
  }
  .bottom-nav { display: none; }
  .app-body { align-items: flex-start; }
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-700);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-link:hover { background: var(--green-50); }
.nav-link.active { background: var(--green-100); color: var(--green-900); }
.nav-link .ic { font-size: 1.1rem; width: 22px; text-align: center; }

/* ---------- Bottom nav (mobile) ---------- */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav .nav-link {
  flex: 1;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  font-size: 0.68rem;
  padding: 6px 2px;
}
.bottom-nav .nav-link .ic { font-size: 1.3rem; width: auto; }
.bottom-nav .nav-link.active { background: none; color: var(--green-700); }

/* ---------- Cards & layout ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card + .card { margin-top: 0; }
.card-title-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 10px;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-500);
  font-weight: 700;
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 13px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--green-700); color: #fff; }
.btn-primary:hover { background: var(--green-900); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-outline { background: var(--surface); color: var(--ink-700); border-color: var(--line); }
.btn-outline:hover { background: var(--green-50); }
.btn-ghost { background: none; color: var(--green-700); border: none; min-height: auto; padding: 8px 10px; }
.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 0.85rem; border-radius: 10px; }
.btn-block { width: 100%; }

.choice-row { display: flex; gap: 10px; }
.choice-row .btn { flex: 1; }
.btn-attend { background: var(--green-100); color: var(--green-900); border-color: var(--green-100); }
.btn-attend.selected { background: var(--green-700); color: #fff; }
.btn-absent { background: var(--red-100); color: var(--red-600); border-color: var(--red-100); }
.btn-absent.selected { background: var(--red-600); color: #fff; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; font-weight: 700; color: var(--ink-700); }
.field input, .field select, .field textarea {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 46px;
  background: var(--surface);
  color: var(--ink-900);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green-600); box-shadow: 0 0 0 3px var(--green-100);
}
.field-checkbox { flex-direction: row; align-items: center; gap: 10px; }
.field-checkbox input { width: 22px; height: 22px; min-height: 0; accent-color: var(--green-700); }
.form { max-width: 480px; }
.hint { font-size: 0.8rem; color: var(--ink-500); }

/* ---------- Badges / status ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.badge-green { background: var(--green-100); color: var(--green-900); }
.badge-red { background: var(--red-100); color: var(--red-600); }
.badge-amber { background: var(--amber-100); color: var(--amber-600); }
.badge-gray { background: var(--bg); color: var(--ink-500); border: 1px solid var(--line); }

/* ---------- Lists as cards on mobile ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.list-row .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-row .meta .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta .sub { font-size: 0.8rem; color: var(--ink-500); }
.list-row .amount { font-weight: 800; white-space: nowrap; }
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { border-color: var(--green-500); }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
  text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 0.9rem;
}
table.data-table th { color: var(--ink-500); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }

@media (max-width: 640px) {
  table.data-table.responsive thead { display: none; }
  table.data-table.responsive, table.data-table.responsive tbody, table.data-table.responsive tr, table.data-table.responsive td {
    display: block; width: 100%;
  }
  table.data-table.responsive tr {
    border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; padding: 6px 12px;
  }
  table.data-table.responsive td {
    border: none; display: flex; justify-content: space-between; gap: 12px; padding: 8px 0;
  }
  table.data-table.responsive td::before {
    content: attr(data-label); font-weight: 700; color: var(--ink-500); font-size: 0.75rem; text-transform: uppercase;
  }
}

/* ---------- Big numbers ---------- */

.stat-hero {
  text-align: center;
  padding: 8px 0 4px;
}
.stat-hero .amount { font-size: 2.4rem; font-weight: 800; color: var(--green-900); }
.stat-hero .label { color: var(--ink-500); font-size: 0.85rem; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.stat-grid .num { font-size: 1.3rem; font-weight: 800; }
.stat-grid .lbl { font-size: 0.72rem; color: var(--ink-500); }

/* ---------- Misc ---------- */

.empty-state { text-align: center; padding: 40px 16px; color: var(--ink-500); }
.empty-state .ic { font-size: 2.2rem; margin-bottom: 8px; }

.loading { text-align: center; padding: 40px 16px; color: var(--ink-500); }

.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.88rem;
  margin-bottom: 16px;
}
.banner-error { background: var(--red-100); color: var(--red-600); }
.banner-info { background: var(--green-100); color: var(--green-900); }
.banner-offline { background: var(--amber-100); color: var(--amber-600); }

.link-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 0.82rem; word-break: break-all; color: var(--ink-700);
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 32, 26, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50; padding: 0;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 20px; } }
.modal {
  background: var(--surface); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0));
}
@media (min-width: 640px) { .modal { border-radius: var(--radius); } }

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(180deg, var(--green-50), var(--bg));
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 24px; border: 1px solid var(--line);
}
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo .dot { display: inline-block; width: 40px; height: 40px; border-radius: 50%; background: var(--green-700); margin-bottom: 10px; }

.pill-toggle { display: flex; gap: 6px; background: var(--bg); border-radius: 999px; padding: 4px; }
.pill-toggle button {
  flex: 1; border: none; background: none; padding: 8px 10px; border-radius: 999px; font-weight: 700; font-size: 0.85rem; cursor: pointer;
  color: var(--ink-500);
}
.pill-toggle button.active { background: var(--surface); color: var(--green-900); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px);
  background: var(--green-900); color: #fff; border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; align-items: center; gap: 10px; z-index: 40;
  box-shadow: var(--shadow);
}
@media (min-width: 900px) { .install-banner { bottom: 16px; max-width: 360px; left: 24px; right: auto; } }
.install-banner p { color: #eafbf0; margin: 0; font-size: 0.82rem; }
.install-banner .actions { display: flex; gap: 8px; margin-left: auto; flex-shrink: 0; }
.install-banner button { white-space: nowrap; }
