/* ChurchOS v2 — Design System */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ─── TOKENS ───────────────────────────────────────────────────────────────── */
:root {
  --gold:       #B8964A;
  --gold-light: #E2C06A;
  --gold-pale:  #F5E9CC;
  --gold-dark:  #7A5F28;
  --ink:        #1A1614;
  --ink2:       #3D322C;
  --ink3:       #6B5B52;
  --cream:      #FAF7F2;
  --cream2:     #F0E8DC;
  --cream3:     #DDD0BE;
  --navy:       #0F2340;
  --navy-mid:   #1A3A5C;
  --navy-light: #2A5285;
  --green:      #2D6A4F;
  --green-light:#E8F5EE;
  --red:        #8B2020;
  --red-light:  #FDECEA;
  --blue:       #1A56A0;
  --blue-light: #EBF2FA;
  --r:          8px;
  --rl:         14px;
  --rxl:        20px;
  --tap:        48px;
  --sidebar-w:  234px;
  --topbar-h:   56px;
  --shadow:     0 1px 3px rgba(26,22,20,.10), 0 1px 2px rgba(26,22,20,.06);
  --shadow-md:  0 4px 12px rgba(26,22,20,.12);
  --transition: .15s ease;
}

/* ─── RESET ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }
table { border-collapse: collapse; width: 100%; }

/* ─── TYPOGRAPHY ───────────────────────────────────────────────────────────── */
.serif        { font-family: 'Playfair Display', Georgia, serif; }
.mono         { font-family: 'DM Mono', monospace; }
h1,h2,h3,h4  { font-family: 'Playfair Display', Georgia, serif; line-height: 1.25; color: var(--ink); }
h1 { font-size: 1.75rem; font-weight: 600; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem;  font-weight: 600; }
h4 { font-size: .95rem;  font-weight: 600; }
.text-sm  { font-size: .8rem; }
.text-xs  { font-size: .72rem; }
.text-muted { color: var(--ink3); }
.text-gold  { color: var(--gold); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }

/* ─── LAYOUT ───────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition);
}
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--cream3);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.page-content {
  flex: 1;
  padding: 1.75rem 1.75rem 3rem;
  max-width: 1400px;
}

/* ─── SIDEBAR ──────────────────────────────────────────────────────────────── */
.sidebar-brand {
  padding: 1.1rem 1.25rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.sidebar-brand-icon {
  width: 34px; height: 34px;
  background: var(--gold);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-brand-name {
  font-family: 'Playfair Display', serif;
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar-brand-sub {
  font-size: .68rem;
  color: rgba(255,255,255,.45);
  margin-top: .1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-section-label {
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: .9rem 1.25rem .3rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1.25rem;
  color: rgba(255,255,255,.65);
  font-size: .84rem;
  font-weight: 400;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.nav-item.active { background: rgba(184,150,74,.18); color: var(--gold-light); font-weight: 500; }
.nav-item .nav-icon { width: 18px; text-align: center; opacity: .75; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-divider { height: 1px; background: rgba(255,255,255,.07); margin: .4rem 1.25rem; }
.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,.08);
  padding: .75rem 1.25rem;
}
.sidebar-user {
  display: flex; align-items: center; gap: .6rem;
}
.sidebar-avatar {
  width: 32px; height: 32px;
  background: var(--navy-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--gold-light);
  flex-shrink: 0;
}
.sidebar-user-name { font-size: .8rem; color: rgba(255,255,255,.8); font-weight: 500; line-height: 1.2; }
.sidebar-user-role { font-size: .68rem; color: rgba(255,255,255,.35); }

/* ─── TOPBAR ───────────────────────────────────────────────────────────────── */
.topbar-page-title { font-family: 'Playfair Display', serif; font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.topbar-badge {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}
.topbar-badge.offline { background: var(--cream3); }
.topbar-status { font-size: .75rem; color: var(--ink3); display: flex; align-items: center; gap: .35rem; }

/* ─── PAGES ────────────────────────────────────────────────────────────────── */
.erp-page { display: none; }
.erp-page.active { display: block; }

/* ─── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem;
  font-size: .84rem; font-weight: 500;
  border-radius: var(--r);
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--tap);
}
.btn-sm { padding: .35rem .75rem; font-size: .78rem; min-height: 34px; }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-dark); }
.btn-outline { background: transparent; border: 1.5px solid var(--cream3); color: var(--ink2); }
.btn-outline:hover { background: var(--cream2); }
.btn-ghost { background: transparent; color: var(--ink2); }
.btn-ghost:hover { background: var(--cream2); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #6b1818; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-mid); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── CARDS ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--cream3);
  border-radius: var(--rl);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.stat-card {
  background: #fff;
  border: 1px solid var(--cream3);
  border-radius: var(--rl);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-card-label { font-size: .75rem; color: var(--ink3); font-weight: 500; letter-spacing: .02em; }
.stat-card-value { font-family: 'Playfair Display', serif; font-size: 1.85rem; font-weight: 700; color: var(--ink); line-height: 1.1; margin: .25rem 0 .1rem; }
.stat-card-sub   { font-size: .75rem; color: var(--ink3); }
.stat-card-icon  { font-size: 1.4rem; margin-bottom: .5rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ─── TABLES ───────────────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border-radius: var(--rl); border: 1px solid var(--cream3); background: #fff; }
.dtable { width: 100%; }
.dtable thead th {
  background: var(--cream2);
  padding: .65rem 1rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink3);
  text-align: left;
  border-bottom: 1px solid var(--cream3);
  white-space: nowrap;
}
.dtable tbody tr { border-bottom: 1px solid var(--cream2); transition: background var(--transition); }
.dtable tbody tr:last-child { border-bottom: none; }
.dtable tbody tr:hover { background: var(--cream); }
.dtable td { padding: .7rem 1rem; font-size: .84rem; color: var(--ink2); vertical-align: middle; }
.dtable .td-name { font-weight: 500; color: var(--ink); }
.dtable .td-actions { white-space: nowrap; text-align: right; }
.tbl-empty { padding: 3rem; text-align: center; color: var(--ink3); font-size: .88rem; }

/* ─── FORMS ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--ink2); margin-bottom: .35rem; }
.form-control {
  width: 100%;
  padding: .6rem .85rem;
  border: 1.5px solid var(--cream3);
  border-radius: var(--r);
  font-size: .88rem;
  color: var(--ink);
  background: #fff;
  transition: border-color var(--transition);
  min-height: var(--tap);
}
.form-control:focus { outline: none; border-color: var(--gold); }
.form-control::placeholder { color: var(--ink3); }
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.25rem; }
.search-box {
  display: flex; align-items: center; gap: .5rem;
  background: var(--cream2);
  border: 1.5px solid var(--cream3);
  border-radius: var(--r);
  padding: .4rem .85rem;
}
.search-box input {
  border: none; background: transparent; font-size: .84rem; color: var(--ink);
  width: 200px;
}
.search-box input:focus { outline: none; }
.search-box .search-icon { color: var(--ink3); font-size: .9rem; }

/* ─── BADGES ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-red    { background: var(--red-light);   color: var(--red); }
.badge-gold   { background: var(--gold-pale);   color: var(--gold-dark); }
.badge-blue   { background: var(--blue-light);  color: var(--blue); }
.badge-gray   { background: var(--cream2);      color: var(--ink3); }

/* ─── MODALS ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,35,64,.5);
  z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4rem 1rem;
  overflow-y: auto;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: var(--rxl);
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 520px;
  padding: 1.75rem;
  position: relative;
}
.modal-lg { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal-title { font-family: 'Playfair Display', serif; font-size: 1.15rem; font-weight: 600; }
.modal-close { color: var(--ink3); padding: .25rem; border-radius: 4px; }
.modal-close:hover { background: var(--cream2); color: var(--ink); }

/* ─── TOASTS ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 500; display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  display: flex; align-items: center; gap: .65rem;
  padding: .75rem 1rem;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r);
  font-size: .84rem;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
  min-width: 240px; max-width: 380px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--gold-dark); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } }

/* ─── PAGE HEADER ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap; gap: .75rem;
}
.page-header-left h2 { margin-bottom: .15rem; }
.page-header-left p  { font-size: .82rem; color: var(--ink3); }
.page-actions { display: flex; gap: .5rem; align-items: center; }

/* ─── TABS ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--cream3); margin-bottom: 1.25rem; }
.tab-btn {
  padding: .6rem 1.1rem;
  font-size: .84rem; font-weight: 500;
  color: var(--ink3);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition), border-color var(--transition);
  cursor: pointer;
}
.tab-btn.active { color: var(--gold-dark); border-color: var(--gold); }
.tab-btn:hover:not(.active) { color: var(--ink2); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── FILTER BAR ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 1rem; flex-wrap: wrap;
}

/* ─── SECTION DIVIDER ──────────────────────────────────────────────────────── */
.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1rem; font-weight: 600;
  color: var(--ink);
  margin-bottom: .85rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--cream3);
}

/* ─── ONLINE INDICATOR ─────────────────────────────────────────────────────── */
.offline-banner {
  background: var(--gold-pale);
  border-bottom: 1px solid var(--gold);
  padding: .4rem 1.5rem;
  font-size: .78rem;
  color: var(--gold-dark);
  display: none;
  align-items: center;
  gap: .5rem;
}
.offline-banner.show { display: flex; }

/* ─── EMPTY STATE ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem;
  color: var(--ink3);
  text-align: center;
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .4; }
.empty-state h3 { font-family: 'Playfair Display', serif; font-size: 1.05rem; color: var(--ink2); margin-bottom: .35rem; }
.empty-state p { font-size: .83rem; max-width: 300px; }

/* ─── CHART WRAPPER ────────────────────────────────────────────────────────── */
.chart-card { background: #fff; border: 1px solid var(--cream3); border-radius: var(--rl); padding: 1.25rem; box-shadow: var(--shadow); }
.chart-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.chart-card-title { font-size: .88rem; font-weight: 600; color: var(--ink2); }
.chart-wrap { position: relative; }

/* ─── AVATAR ───────────────────────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--cream2);
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 600; color: var(--ink3);
  flex-shrink: 0;
}
.avatar-gold { background: var(--gold-pale); color: var(--gold-dark); }

/* ─── FINANCE SPECIFICS ────────────────────────────────────────────────────── */
.finance-tabs { background: var(--cream2); border-radius: var(--r); padding: .3rem; display: inline-flex; gap: .2rem; margin-bottom: 1.25rem; }
.finance-tab { padding: .4rem .85rem; border-radius: 6px; font-size: .82rem; font-weight: 500; color: var(--ink3); cursor: pointer; transition: background var(--transition), color var(--transition); }
.finance-tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ─── SPINNER ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--cream3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: 3rem; color: var(--ink3); font-size: .85rem; }

/* ─── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── PRINT ────────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-actions, .btn { display: none !important; }
  .main-wrap { margin-left: 0; }
  body { background: #fff; }
}

/* ─── AUTH PAGES ───────────────────────────────────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 2rem;
}
.auth-card {
  background: #fff;
  border-radius: var(--rxl);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  padding: 2.5rem;
  width: 100%;
  max-width: 440px;
}
.auth-logo {
  display: flex; align-items: center; gap: .75rem; margin-bottom: 2rem;
}
.auth-logo-icon {
  width: 44px; height: 44px;
  background: var(--gold);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.auth-logo-text h1 { font-size: 1.25rem; color: var(--ink); margin: 0; }
.auth-logo-text p  { font-size: .78rem; color: var(--ink3); margin: 0; }
.auth-tabs { display: flex; margin-bottom: 1.75rem; border-bottom: 2px solid var(--cream3); }
.auth-tab { flex: 1; text-align: center; padding: .6rem; font-size: .88rem; font-weight: 500; color: var(--ink3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all var(--transition); }
.auth-tab.active { color: var(--gold-dark); border-color: var(--gold); }
.auth-panel { display: none; }
.auth-panel.active { display: block; }
.auth-divider { text-align: center; color: var(--ink3); font-size: .78rem; margin: 1rem 0; position: relative; }
.auth-divider::before, .auth-divider::after { content: ''; position: absolute; top: 50%; width: 42%; height: 1px; background: var(--cream3); }
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }
