/* ============================================================
   STEWARDSHIP PLANNER v4  —  Global Stylesheet
   Mobile-first · DM Sans + DM Serif Display
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

/* ── Design Tokens ───────────────────────────────────────── */
:root {
    --ink:       #0f1923;
    --ink2:      #2d3d4e;
    --ink3:      #5c7285;
    --ink4:      #94a9ba;
    --surface:   #f4f2ee;
    --card:      #ffffff;
    --border:    #e2ddd6;
    --border2:   #ccc7be;

    --gold:      #c9922c;
    --gold-lt:   #fdf3e0;
    --gold-dk:   #8a6010;

    --teal:      #0d7c6b;
    --teal-lt:   #e0f5f0;
    --teal-dk:   #085041;

    --blue:      #1a5fa8;
    --blue-lt:   #e6f1fb;
    --blue-dk:   #0c3d70;

    --red:       #c0392b;
    --red-lt:    #fde8e6;
    --red-dk:    #82241a;

    --green:     #1a7a4a;
    --green-lt:  #e2f5eb;

    --purple:    #6d3cc7;
    --purple-lt: #eeebfd;

    --amber:     #b45309;
    --amber-lt:  #fef3c7;

    --radius:    12px;
    --radius-sm: 7px;
    --radius-xs: 4px;
    --shadow:    0 1px 8px rgba(15,25,35,.08);
    --shadow-md: 0 4px 20px rgba(15,25,35,.12);
}

/* ── Base ────────────────────────────────────────────────── */
body {
    font-family: 'DM Sans', sans-serif;
    background: var(--surface);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3, h4, .serif { font-family: 'DM Serif Display', serif; font-weight: 400; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1.2; }
h2 { font-size: 1.3rem; line-height: 1.3; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.9rem; font-family: 'DM Sans', sans-serif; font-weight: 600; }
p  { line-height: 1.65; }
a  { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navigation ──────────────────────────────────────────── */
.app-nav {
    background: var(--ink);
    position: sticky; top: 0; z-index: 200;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.nav-inner {
    max-width: 1200px; margin: 0 auto;
    display: flex; align-items: center;
    padding: 0 16px; height: 56px; gap: 8px;
}
.nav-brand { display: flex; align-items: center; gap: 10px; margin-right: 8px; flex-shrink: 0; }
.nav-logo  { width: 34px; height: 34px; background: var(--teal); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; }
.nav-title { display: block; color: #fff; font-weight: 600; font-size: 14px; line-height: 1.2; }
.nav-sub   { display: block; color: var(--ink4); font-size: 11px; }

.nav-links { display: flex; align-items: center; gap: 2px; flex: 1; flex-wrap: nowrap; overflow-x: auto; }
.nav-link  { display: flex; align-items: center; gap: 6px; color: var(--ink4);
    padding: 6px 10px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
    white-space: nowrap; transition: background .15s, color .15s; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav-link i { font-size: 16px; }

.nav-user { display: flex; align-items: center; gap: 8px; margin-left: 8px; flex-shrink: 0; }
.nav-user-info { display: flex; flex-direction: column; }
.nav-user-name { color: #fff; font-size: 13px; font-weight: 500; }
.nav-logout    { color: var(--ink4); font-size: 11px; display: flex; align-items: center; gap: 3px; }
.nav-logout:hover { color: var(--red-lt); text-decoration: none; }

.avatar { width: 32px; height: 32px; border-radius: 50%;
    background: var(--teal); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; flex-shrink: 0; }

.nav-hamburger { display: none; background: none; border: none; color: var(--ink4);
    font-size: 22px; cursor: pointer; padding: 4px; margin-left: auto; }

@media (max-width: 768px) {
    .nav-hamburger { display: flex; }
    .nav-links {
        display: none; flex-direction: column; align-items: flex-start;
        position: absolute; top: 56px; left: 0; right: 0;
        background: var(--ink); padding: 8px 16px 16px;
        border-bottom: 1px solid rgba(255,255,255,.08);
        gap: 2px; z-index: 199;
    }
    .nav-links.open { display: flex; }
    .nav-user-info  { display: none; }
}

/* ── Page Layout ─────────────────────────────────────────── */
.page-body { }
.page-main { min-height: calc(100vh - 56px); }
.page-container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    margin-bottom: 16px;
}
.card-header {
    display: flex; align-items: center; gap: 12px;
    padding-bottom: 14px; border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}
.card-header h2, .card-header h3 { margin: 0; }
.card-header .ch-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-icon {
    width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.ci-gold   { background: var(--gold-lt);   color: var(--gold); }
.ci-teal   { background: var(--teal-lt);   color: var(--teal); }
.ci-blue   { background: var(--blue-lt);   color: var(--blue); }
.ci-red    { background: var(--red-lt);    color: var(--red); }
.ci-green  { background: var(--green-lt);  color: var(--green); }
.ci-purple { background: var(--purple-lt); color: var(--purple); }
.ci-amber  { background: var(--amber-lt);  color: var(--amber); }
.ci-ink    { background: #e8edf2;           color: var(--ink2); }

/* ── Stat Grid ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px; margin-bottom: 20px;
}
.stat-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
}
.stat-card .sl { font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .07em; color: var(--ink3); margin-bottom: 4px; }
.stat-card .sv { font-size: 1.15rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stat-card .ss { font-size: 11px; color: var(--ink3); margin-top: 3px; }
.stat-card.sc-teal  { border-left: 3px solid var(--teal); }
.stat-card.sc-gold  { border-left: 3px solid var(--gold); }
.stat-card.sc-green { border-left: 3px solid var(--green); }
.stat-card.sc-red   { border-left: 3px solid var(--red); }
.stat-card.sc-blue  { border-left: 3px solid var(--blue); }
.stat-card.sc-amber { border-left: 3px solid var(--amber); }

/* ── Form Elements ───────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.g1 { grid-template-columns: 1fr; }
.form-grid.full { grid-column: 1/-1; }
@media (max-width: 540px) {
    .form-grid, .form-grid.g3 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 500; color: var(--ink2); }
.field .hint  { font-size: 11px; color: var(--ink3); }

input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="date"], input[type="tel"],
select, textarea {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border2); border-radius: var(--radius-sm);
    font-size: 15px; font-family: 'DM Sans', sans-serif;
    background: var(--card); color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(13,124,107,.14);
}
input.money { font-weight: 600; letter-spacing: .01em; }
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235c7285' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background: #c8d0d8; border-radius: 24px; transition: .2s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px;
    left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
    transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.switch input:checked + .slider { background: var(--teal); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-text { font-size: 14px; font-weight: 500; flex: 1; line-height: 1.4; }
.toggle-sub  { font-size: 12px; color: var(--ink3); display: block; margin-top: 1px; }

/* Sub-fields panel */
.sub-fields {
    background: #faf9f7; border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px; margin-top: 8px;
}
.sub-fields.hidden { display: none; }

/* Checkbox group */
.check-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 0; cursor: pointer;
}
.check-row input[type="checkbox"] {
    width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0;
    cursor: pointer; accent-color: var(--teal);
}
.check-row label { font-size: 14px; cursor: pointer; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 7px; padding: 10px 18px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: opacity .15s, transform .1s, background .15s;
    line-height: 1;
}
.btn:active { transform: scale(.98); }
.btn i { font-size: 16px; }
.btn-primary  { background: var(--teal);  color: #fff; border-color: var(--teal-dk); }
.btn-gold     { background: var(--gold);  color: #fff; border-color: var(--gold-dk); }
.btn-blue     { background: var(--blue);  color: #fff; border-color: var(--blue-dk); }
.btn-red      { background: var(--red);   color: #fff; border-color: var(--red-dk); }
.btn-ghost    { background: transparent; color: var(--ink2); border-color: var(--border2); }
.btn-ghost:hover { background: var(--surface); }
.btn-sm       { padding: 7px 13px; font-size: 13px; }
.btn-xs       { padding: 4px 10px; font-size: 12px; }
.btn-full     { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-group    { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-primary:hover  { opacity: .9; }
.btn-gold:hover     { opacity: .9; }
.btn-blue:hover     { opacity: .9; }
.btn-red:hover      { opacity: .9; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-lt); color: var(--green); }
.badge-amber  { background: var(--amber-lt); color: var(--amber); }
.badge-red    { background: var(--red-lt);   color: var(--red); }
.badge-blue   { background: var(--blue-lt);  color: var(--blue); }
.badge-teal   { background: var(--teal-lt);  color: var(--teal); }
.badge-gray   { background: var(--surface);  color: var(--ink3); border: 1px solid var(--border); }
.badge-gold   { background: var(--gold-lt);  color: var(--gold); }
.badge-purple { background: var(--purple-lt); color: var(--purple); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
thead th {
    background: var(--ink); color: #fff; padding: 10px 14px;
    text-align: left; font-size: 11px; font-weight: 500;
    text-transform: uppercase; letter-spacing: .05em;
    position: sticky; top: 0; z-index: 2;
}
thead th.r { text-align: right; }
tbody td {
    padding: 10px 14px; border-bottom: 1px solid #f0ece6;
    font-variant-numeric: tabular-nums; color: var(--ink2);
}
tbody td.r { text-align: right; }
tbody td.bold { font-weight: 600; color: var(--ink); }
tbody tr:hover td { background: #faf9f7; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { padding: 10px 14px; font-weight: 600; background: #f4f2ee; }
tfoot td.r { text-align: right; }

.col-num   { color: var(--ink3); }
.col-pos   { color: var(--teal); font-weight: 600; }
.col-neg   { color: var(--red); }
.col-gold  { color: var(--gold); font-weight: 600; }
.col-dim   { color: var(--ink4); font-size: 12px; }

/* Projection table special rows */
.row-ff    td { background: #fffbee !important; }
.row-goal  td { background: var(--green-lt) !important; }
.row-final td { background: var(--red-lt) !important; }
.row-annual td { background: #1a2d3d !important; color: #dce9f5 !important;
    font-weight: 600; border-top: 2px solid #2d4a63 !important; }

.tag { display: inline-block; padding: 1px 5px; border-radius: 3px;
    font-size: 10px; font-weight: 700; vertical-align: middle; margin-left: 3px; }
.tag-ff   { background: var(--gold-lt);  color: var(--gold); }
.tag-exit { background: var(--red-lt);   color: var(--red); }
.tag-goal { background: var(--green-lt); color: var(--green); }
.tag-act  { background: var(--blue-lt);  color: var(--blue); }

/* ── Flash Messages ──────────────────────────────────────── */
.flash {
    padding: 12px 16px; border-radius: var(--radius-sm);
    margin-bottom: 16px; font-size: 14px; font-weight: 500;
    display: flex; align-items: flex-start; gap: 10px;
}
.flash::before { font-family: 'tabler-icons'; font-size: 18px; flex-shrink: 0; }
.flash-success { background: var(--green-lt); color: var(--green); border-left: 3px solid var(--green); }
.flash-error   { background: var(--red-lt);   color: var(--red);   border-left: 3px solid var(--red);   }
.flash-warn    { background: var(--amber-lt); color: var(--amber); border-left: 3px solid var(--amber); }
.flash-info    { background: var(--blue-lt);  color: var(--blue);  border-left: 3px solid var(--blue);  }

/* ── Breadcrumb ──────────────────────────────────────────── */
.breadcrumb { margin-bottom: 16px; }
.breadcrumb ol { display: flex; align-items: center; gap: 6px;
    list-style: none; flex-wrap: wrap; font-size: 13px; }
.breadcrumb li a { color: var(--ink3); }
.breadcrumb li a:hover { color: var(--teal); text-decoration: none; }
.breadcrumb li + li::before { content: '/'; color: var(--ink4); margin-right: 6px; }
.bc-current { color: var(--ink2); font-weight: 500; }

/* ── Auth Pages ──────────────────────────────────────────── */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--ink); padding: 24px 16px;
}
.auth-card {
    background: var(--card); border-radius: var(--radius);
    padding: 36px 32px; width: 100%; max-width: 400px;
    box-shadow: var(--shadow-md);
}
.auth-logo {
    width: 52px; height: 52px; background: var(--teal); border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 26px; margin-bottom: 20px;
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.auth-card .sub { color: var(--ink3); font-size: 14px; margin-bottom: 28px; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 500; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--card); border-radius: var(--radius);
    padding: 24px; width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-md);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.modal-close { background: none; border: none; cursor: pointer; font-size: 22px; color: var(--ink3); padding: 2px; }
.modal-footer { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px; }

/* ── Dashboard ──────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 700px) { .dash-grid, .dash-grid.g3 { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; height: 260px; margin: 8px 0; }

/* Progress tracking */
.progress-bar-wrap { background: var(--border); border-radius: 20px; height: 8px; overflow: hidden; margin: 6px 0; }
.progress-bar      { height: 100%; border-radius: 20px; background: var(--teal); transition: width .4s; }

/* ── Timeline / Activity Feed ───────────────────────────── */
.timeline { padding: 0; }
.tl-item  { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-dot   { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; margin-top: 2px;
    display: flex; align-items: center; justify-content: center; font-size: 15px; }
.tl-dot.d-teal   { background: var(--teal-lt);  color: var(--teal); }
.tl-dot.d-gold   { background: var(--gold-lt);  color: var(--gold); }
.tl-dot.d-green  { background: var(--green-lt); color: var(--green); }
.tl-dot.d-red    { background: var(--red-lt);   color: var(--red); }
.tl-dot.d-blue   { background: var(--blue-lt);  color: var(--blue); }
.tl-body .tl-title { font-weight: 600; font-size: 14px; }
.tl-body .tl-meta  { font-size: 12px; color: var(--ink3); margin-top: 2px; }

/* ── Empty States ────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 48px 24px; color: var(--ink3);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 14px; margin-top: 6px; }

/* ── Allocation Bar ──────────────────────────────────────── */
.alloc-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--border); }
.alloc-seg { height: 100%; }
.alloc-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 11px; color: var(--ink3); }

/* ── Utilities ───────────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.muted  { color: var(--ink3); }
.bold   { font-weight: 600; }
.right  { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.flex   { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center  { display: flex; align-items: center; gap: 8px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.mono    { font-family: 'DM Mono', monospace; }

.section-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .07em; color: var(--ink3); margin: 20px 0 10px;
    display: flex; align-items: center; gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Contribution status colours ─────────────────────────── */
.contrib-paid    { color: var(--green); }
.contrib-pending { color: var(--amber); }
.contrib-overdue { color: var(--red); }

/* ── Print ───────────────────────────────────────────────── */
@media print {
    .app-nav, .btn-group, .modal-backdrop, .no-print { display: none !important; }
    body { background: #fff; font-size: 12px; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; page-break-inside: avoid; }
    .page-container { padding: 0; max-width: 100%; }
    table { font-size: 10px; }
    thead th { background: #333 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .app-nav { display: none !important; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
    .card { padding: 14px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .auth-card  { padding: 24px 20px; }
    h1 { font-size: 1.3rem; }
    .btn-group.wrap { flex-direction: column; }
}
@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr; }
}
