
:root {
  --bg-main: #f8faf9;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --auto-bg: #fef3c7;
  --auto-text: #92400e;
  --danger: #ef4444;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
}

[data-theme="dark"] {
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #064e3b;
  --auto-bg: #451a03;
  --auto-text: #fde68a;
  --danger: #f87171;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

body { background: var(--bg-main); color: var(--text-main); min-height: 100vh; transition: background 0.2s, color 0.2s; }

/* Navigation */
.navbar { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; background: var(--bg-card); border-bottom: 1px solid var(--border-color); box-shadow: var(--shadow); }
.brand { font-weight: 700; font-size: 1.25rem; color: var(--primary); text-decoration: none; display: flex; align-items: center; gap: 0.5rem; }
.nav-actions { display: flex; align-items: center; gap: 1rem; }

/* Buttons & Inputs */
.btn { background: var(--primary); color: white; border: none; padding: 0.6rem 1.2rem; border-radius: 0.5rem; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; transition: background 0.2s; }
.btn:hover { background: var(--primary-hover); }
.btn-secondary { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-secondary:hover { background: var(--bg-input); }
.theme-toggle { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; padding: 0.4rem; border-radius: 0.375rem; color: var(--text-main); }

/* Layout Containers */
.container { max-width: 1200px; margin: 2rem auto; padding: 0 1rem; }
.auth-card { max-width: 400px; margin: 4rem auto; padding: 2rem; background: var(--bg-card); border-radius: 0.75rem; border: 1px solid var(--border-color); box-shadow: var(--shadow); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; margin-top: 1.5rem; }
.card { background: var(--bg-card); padding: 1.5rem; border-radius: 0.75rem; border: 1px solid var(--border-color); box-shadow: var(--shadow); }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text-muted); }
.form-control { width: 100%; padding: 0.65rem; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: 0.375rem; color: var(--text-main); font-size: 0.95rem; }
.form-control:focus { outline: 2px solid var(--primary); }

/* Ledger Table (Page 1) */
.table-wrapper { overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 0.75rem; box-shadow: var(--shadow); margin-top: 1rem; }
.sheet-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.sheet-table th, .sheet-table td { padding: 0.75rem; border-bottom: 1px solid var(--border-color); text-align: left; font-size: 0.9rem; }
.sheet-table th { background: var(--bg-input); color: var(--text-muted); font-weight: 600; }
.col-auto { background: var(--auto-bg); color: var(--auto-text); font-weight: 600; text-align: right; }
.num-input { width: 90px; text-align: right; padding: 0.4rem; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 0.25rem; color: var(--text-main); }

/* Tabs for Worksheet Switching */
.tab-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); }
.tab-btn { padding: 0.75rem 1.25rem; border: none; background: none; color: var(--text-muted); font-weight: 600; cursor: pointer; text-decoration: none; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Add Member dialog */
dialog#addMemberModal { border: none; border-radius: 0.75rem; padding: 1.5rem; width: min(420px, 90vw); background: var(--bg-card); color: var(--text-main); box-shadow: var(--shadow); }
dialog#addMemberModal::backdrop { background: rgba(15, 23, 42, 0.5); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }

/* Read-only month badge */
.readonly-badge { display: inline-block; margin-left: 0.5rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--bg-input); color: var(--text-muted); font-size: 0.75rem; font-weight: 600; }

/* Section Summaries (Page 2) */
.summary-section { margin-bottom: 2rem; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.stat-box { background: var(--bg-card); padding: 1rem; border-radius: 0.5rem; border: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.stat-val { font-size: 1.2rem; font-weight: 700; color: var(--primary); }