/* =============================================================================
   CHURCH ERP — DESIGN TOKENS & BASE STYLES (v2 — indigo/violet SaaS theme)
   Light sidebar, white surfaces, indigo primary. Variable NAMES are kept
   stable from v1 (--gold, --coral, etc.) even though the brand moved on,
   since ~130 page files reference them inline — only the values change here,
   which is what lets a single-file edit restyle the whole app.
   ============================================================================= */

:root {
    /* Color */
    --primary:      #4F46E5; /* indigo-600 — primary actions, active states */
    --primary-dark: #4338CA; /* hover */
    --primary-soft: #EEF2FF; /* tint backgrounds: active nav, icon circles */
    --ink:        #1E1B2E; /* headings / primary text */
    --ink-soft:   #2A2640; /* hover state on dark surfaces (rare now) */
    --ink-line:   #E5E7EB; /* dividers */
    --slate:      #64748B; /* secondary text */
    --slate-soft: #98A2B3;
    --parchment:  #F7F8FC; /* app background behind cards */
    --surface:    #FFFFFF;
    --border:     #E5E7EB;
    --gold:       #4F46E5; /* legacy name -> now indigo (primary accent / CTA) */
    --gold-soft:  #EEF2FF;
    --green:      #16A34A; /* success / income / up-trend */
    --green-soft: #DCFCE7;
    --coral:      #EF4444; /* danger / expense / down-trend */
    --coral-soft: #FEE2E2;
    --amber:      #D97706; /* pending / returned */
    --amber-soft: #FEF3C7;
    --blue:       #2563EB; /* extra chart/series color */
    --blue-soft:  #DBEAFE;
    --purple:     #7C3AED; /* extra chart/series color */
    --purple-soft:#F3E8FF;

    /* Type */
    --font-display: 'Lexend', 'Inter', -apple-system, sans-serif;
    --font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:    'IBM Plex Mono', 'Courier New', monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background: var(--parchment);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    margin: 0 0 0.4em;
    letter-spacing: -0.01em;
}

.text-mono { font-family: var(--font-mono); }
.text-slate { color: var(--slate); }
.text-sm { font-size: 0.85rem; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------------------------------------------------------------------------
   APP SHELL
   --------------------------------------------------------------------------- */

.app-shell {
    display: grid;
    grid-template-columns: 264px 1fr;
    min-height: 100vh;
}

.main-col {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---------------------------------------------------------------------------
   SIDEBAR — light theme, icon + label, grouped sections
   --------------------------------------------------------------------------- */

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    color: var(--ink);
    padding: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.sidebar-brand .mark {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: linear-gradient(155deg, var(--primary), var(--purple));
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    font-size: 0.95rem;
}

.sidebar-brand .name {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--ink);
}

.sidebar-brand .name small {
    display: block;
    font-family: var(--font-body);
    font-size: 0.68rem;
    color: var(--slate-soft);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
}

.nav-group-label {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--slate-soft);
    font-weight: 600;
    padding: 16px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 16px;
    margin: 1px 10px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--slate);
    border-radius: var(--radius-sm);
}

.nav-item svg { flex-shrink: 0; opacity: 0.85; }

.nav-item:hover { background: var(--parchment); color: var(--ink); }

.nav-item.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.nav-item.active svg { opacity: 1; }

.sidebar-foot {
    margin-top: auto;
    padding: 16px;
}

.help-card {
    background: var(--parchment);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.help-card .icon-wrap {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.help-card strong { font-size: 0.82rem; display: block; }
.help-card span { font-size: 0.76rem; color: var(--slate); }

/* ---------------------------------------------------------------------------
   TOPBAR — search, icon buttons with badges, user menu
   --------------------------------------------------------------------------- */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--parchment);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 9px 14px;
    color: var(--slate-soft);
}
.topbar-search svg { flex-shrink: 0; }
.topbar-search input {
    border: none;
    background: none;
    outline: none;
    font-size: 0.86rem;
    color: var(--ink);
    flex: 1;
    width: 100%;
    padding: 0;
}
.topbar-search input::placeholder { color: var(--slate-soft); }
.topbar-search kbd {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--slate-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 6px;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--parchment);
    border: none;
    display: flex; align-items: center; justify-content: center;
    color: var(--slate);
    cursor: pointer;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); color: var(--ink); }
.icon-btn .dot-badge {
    position: absolute;
    top: -2px; right: -2px;
    min-width: 16px; height: 16px;
    border-radius: 999px;
    background: var(--coral);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--surface);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px 4px 4px;
    border-radius: var(--radius-md);
    position: relative;
}
.user-chip:hover { background: var(--parchment); }

.user-chip .avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.user-chip .role {
    display: block;
    font-size: 0.72rem;
    color: var(--slate);
    font-weight: 400;
}

.user-chip .chev { color: var(--slate-soft); flex-shrink: 0; }

.user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 190px;
    padding: 6px;
    z-index: 50;
    display: none;
}
.user-menu.open { display: block; }
.user-menu a, .user-menu button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--ink);
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-body);
}
.user-menu a:hover, .user-menu button:hover { background: var(--parchment); }
.user-menu hr { border: none; border-top: 1px solid var(--border); margin: 5px 0; }

/* breadcrumb — now lives at the top of .content, not the topbar */
.crumb-trail {
    font-size: 0.8rem;
    color: var(--slate-soft);
    margin-bottom: 6px;
}
.crumb-trail span:not(:last-child)::after { content: '/'; margin: 0 7px; color: var(--border); }
.crumb-trail span:last-child { color: var(--slate); }

/* ---------------------------------------------------------------------------
   CONTENT
   --------------------------------------------------------------------------- */

.content {
    padding: 28px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 { font-size: 1.6rem; }
.page-header p { color: var(--slate); margin: 4px 0 0; font-size: 0.92rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.grid {
    display: grid;
    gap: 18px;
}

.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------------------------------------------------------------------
   STAT CARDS — icon circle + value + trend delta
   --------------------------------------------------------------------------- */

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 14px;
}

.stat-card .icon-circle {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.icon-circle.tone-indigo { background: var(--primary-soft); color: var(--primary); }
.icon-circle.tone-green  { background: var(--green-soft); color: var(--green); }
.icon-circle.tone-blue   { background: var(--blue-soft); color: var(--blue); }
.icon-circle.tone-amber  { background: var(--amber-soft); color: var(--amber); }
.icon-circle.tone-purple { background: var(--purple-soft); color: var(--purple); }
.icon-circle.tone-coral  { background: var(--coral-soft); color: var(--coral); }

.stat-card .label {
    font-size: 0.78rem;
    color: var(--slate);
    font-weight: 500;
}

.stat-card .value {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 600;
    margin-top: 2px;
    color: var(--ink);
}

.stat-card .delta {
    font-size: 0.78rem;
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.delta.up   { color: var(--green); }
.delta.down { color: var(--coral); }
.delta.flat { color: var(--slate-soft); }

.module-placeholder {
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 36px;
    text-align: center;
    color: var(--slate);
    background: var(--surface);
}

.module-placeholder h3 { color: var(--ink); }

/* ---------------------------------------------------------------------------
   DASHBOARD WIDGETS — charts, ranked list, activity feed, insight sparklines
   --------------------------------------------------------------------------- */

.widget-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.widget-head strong { font-size: 0.98rem; font-weight: 600; }

.ranked-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
}
.ranked-row .rank-badge {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--parchment);
    color: var(--slate);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.ranked-row.is-first .rank-badge { background: var(--primary); color: #fff; }
.ranked-row .rank-info { flex: 1; min-width: 0; }
.ranked-row .rank-info .name-line {
    display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 6px;
}
.ranked-row .bar-track {
    height: 6px;
    background: var(--parchment);
    border-radius: 999px;
    overflow: hidden;
}
.ranked-row .bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
}

.activity-row {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; padding-bottom: 0; }
.activity-row .icon-circle { width: 34px; height: 34px; }
.activity-row .activity-body { flex: 1; min-width: 0; }
.activity-row .activity-title { font-size: 0.85rem; font-weight: 500; color: var(--ink); }
.activity-row .activity-sub { font-size: 0.78rem; color: var(--slate); margin-top: 2px; }
.activity-row .activity-time { font-size: 0.74rem; color: var(--slate-soft); white-space: nowrap; }

.insight-row {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.insight-row:last-child { border-bottom: none; }
.insight-row .insight-label { font-size: 0.78rem; color: var(--slate); }
.insight-row .insight-value { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; margin-top: 2px; }
.insight-row .sparkline { width: 90px; height: 36px; flex-shrink: 0; }

.chart-canvas-wrap { position: relative; height: 280px; }

/* ---------------------------------------------------------------------------
   FORMS / BUTTONS / BADGES / TABLES / ALERTS
   --------------------------------------------------------------------------- */

label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--ink);
}

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], input[type=datetime-local], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.92rem;
    background: var(--surface);
    color: var(--ink);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: var(--font-body);
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-soft); }

.btn-gold { background: var(--primary); color: #fff; }
.btn-gold:hover { background: var(--primary-dark); }

.btn-outline { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-outline:hover { background: var(--parchment); }

.btn-block { width: 100%; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
}

.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-coral  { background: var(--coral-soft);  color: var(--coral); }
.badge-amber  { background: var(--amber-soft);  color: var(--amber); }
.badge-slate  { background: #EEF0F4; color: var(--slate); }

table { width: 100%; border-collapse: collapse; }
table th {
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--slate);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
table td {
    padding: 12px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success { background: var(--green-soft); color: var(--green); border-color: #bbf0cd; }
.alert-error   { background: var(--coral-soft); color: var(--coral); border-color: #fbcaca; }
.alert-info    { background: var(--primary-soft); color: var(--primary-dark); border-color: #d7d9fb; }

@media (max-width: 880px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .topbar-search { display: none; }
}
