/* ==========================================================================
   FWB Malawi Finance Suite — Claymorphism design system
   Palette grounded in Malawian clay/savanna tones rather than generic
   terracotta-on-cream: sandy putty base, deep forest teal, muted ochre.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=Dancing+Script:wght@600;700&display=swap');

:root {
    --clay-bg: #E7E0D2;
    --clay-surface: #EEE8DA;
    --clay-raised: #F4EFE3;
    --clay-sunken: #DFD8C9;

    --ink: #332F27;
    --ink-soft: #756E5E;
    --ink-faint: #9A927E;

    --teal: #3B6E5E;
    --teal-dark: #294F43;
    --teal-tint: #DCE8E3;

    --ochre: #BD8A34;
    --ochre-dark: #8F6923;
    --ochre-tint: #F1E4C9;

    --brick: #A8503F;
    --brick-dark: #7E3B2E;
    --brick-tint: #F1DBD5;

    --shadow-d: rgba(64, 56, 38, 0.30);
    --shadow-l: rgba(255, 255, 255, 0.85);

    --radius-lg: 28px;
    --radius-md: 18px;
    --radius-sm: 12px;

    --font-head: 'Space Grotesk', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Segoe UI', sans-serif;
    --font-signature: 'Dancing Script', cursive;
}

* { box-sizing: border-box; }

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

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

p { margin: 0 0 0.8em 0; color: var(--ink-soft); }
a { color: var(--teal-dark); }

::selection { background: var(--ochre-tint); }

/* Focus visibility (accessibility floor) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: 3px solid var(--teal);
    outline-offset: 2px;
}

/* --- Clay surface mixins (soft extruded look, dual shadow) ---------------- */
.clay {
    background: var(--clay-surface);
    border-radius: var(--radius-lg);
    box-shadow: 9px 9px 18px var(--shadow-d), -9px -9px 18px var(--shadow-l);
    border: 1px solid rgba(255,255,255,0.4);
}

.clay-sunken {
    background: var(--clay-sunken);
    border-radius: var(--radius-md);
    box-shadow: inset 4px 4px 10px var(--shadow-d), inset -4px -4px 10px var(--shadow-l);
    border: none;
}

.clay-pop {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.clay-pop:hover {
    transform: translateY(-2px);
    box-shadow: 12px 12px 22px var(--shadow-d), -8px -8px 18px var(--shadow-l);
}
.clay-pop:active {
    transform: translateY(1px);
    box-shadow: 4px 4px 10px var(--shadow-d), -4px -4px 10px var(--shadow-l);
}

/* --- App shell ------------------------------------------------------------ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--clay-surface);
    padding: 28px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 6px 0 20px rgba(64,56,38,0.12);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 22px 10px;
}

.sidebar-brand .mark {
    width: 42px; height: 42px;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--teal), var(--teal-dark));
    box-shadow: 4px 4px 10px var(--shadow-d), -3px -3px 8px var(--shadow-l);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 1.1rem;
}

.sidebar-brand .name {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.25;
}
.sidebar-brand .sub {
    font-size: 0.72rem;
    color: var(--ink-faint);
}

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}
.side-link:hover { color: var(--ink); background: var(--clay-raised); }
.side-link.active {
    background: var(--clay-sunken);
    color: var(--teal-dark);
    box-shadow: inset 3px 3px 8px var(--shadow-d), inset -3px -3px 8px var(--shadow-l);
}
.side-link .dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint);
}
.side-link.active .dot { background: var(--teal); }

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

.role-pill {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--teal-tint);
    color: var(--teal-dark);
    margin-bottom: 10px;
}

.logout-link {
    display: block;
    text-align: center;
    padding: 10px;
    border-radius: var(--radius-sm);
    background: var(--brick-tint);
    color: var(--brick-dark);
    font-weight: 700;
    font-size: 0.85rem;
    text-decoration: none;
}
.logout-link:hover { background: var(--brick); color: #fff; }

.main-area {
    flex: 1;
    min-width: 0;
    padding: 30px 36px 60px 36px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 26px;
    flex-wrap: wrap;
    gap: 14px;
}

.topbar .eyebrow-period {
    display: inline-block;
    background: var(--ochre-tint);
    color: var(--ochre-dark);
    font-weight: 700;
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: 20px;
}

/* --- Buttons ---------------------------------------------------------- */
.btn {
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.88rem;
    border: none;
    cursor: pointer;
    padding: 12px 22px;
    border-radius: var(--radius-sm);
    background: var(--clay-raised);
    color: var(--ink);
    box-shadow: 5px 5px 12px var(--shadow-d), -4px -4px 10px var(--shadow-l);
    transition: all 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: inset 3px 3px 8px var(--shadow-d), inset -3px -3px 8px var(--shadow-l); }

.btn-primary { background: linear-gradient(145deg, var(--teal), var(--teal-dark)); color: #fff; }
.btn-ochre { background: linear-gradient(145deg, var(--ochre), var(--ochre-dark)); color: #fff; }
.btn-danger { background: linear-gradient(145deg, var(--brick), var(--brick-dark)); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--clay-raised); }
.btn-sm { padding: 8px 14px; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* --- Forms -------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--ink-soft);
    margin-bottom: 6px;
}
.field input, .field select, .field textarea {
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--clay-sunken);
    box-shadow: inset 3px 3px 8px var(--shadow-d), inset -3px -3px 8px var(--shadow-l);
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--ink);
}
.field input:read-only { color: var(--ink-faint); }
.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 6px 18px;
}

/* --- Cards / sections ----------------------------------------------------*/
.card { padding: 26px; margin-bottom: 24px; }
.card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}
.card-title-row h3 { margin: 0; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}
.stat-tile { padding: 22px; }
.stat-tile .label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ink-faint);
    margin-bottom: 6px;
}
.stat-tile .value {
    font-family: var(--font-head);
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--ink);
}
.stat-tile .sub { font-size: 0.78rem; color: var(--ink-soft); margin-top: 4px; }
.stat-tile.accent-teal .value { color: var(--teal-dark); }
.stat-tile.accent-ochre .value { color: var(--ochre-dark); }
.stat-tile.accent-brick .value { color: var(--brick-dark); }

.chart-card { padding: 24px; }
.chart-wrap { position: relative; height: 300px; }

/* --- Tables ----------------------------------------------------------- */
.clay-table-wrap {
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: inset 2px 2px 8px var(--shadow-d);
}
table.clay-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--clay-raised);
    font-size: 0.86rem;
}
table.clay-table th {
    background: var(--teal-tint);
    color: var(--teal-dark);
    text-align: left;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
table.clay-table td {
    padding: 11px 14px;
    border-top: 1px solid var(--clay-sunken);
    color: var(--ink);
}
table.clay-table tr:hover td { background: var(--clay-surface); }
.empty-row td { text-align: center; color: var(--ink-faint); padding: 26px; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
}
.badge-teal { background: var(--teal-tint); color: var(--teal-dark); }
.badge-ochre { background: var(--ochre-tint); color: var(--ochre-dark); }
.badge-brick { background: var(--brick-tint); color: var(--brick-dark); }

/* --- Tabs (portal navigation within a page) --------------------------- */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.tab-btn {
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--clay-surface);
    box-shadow: 4px 4px 10px var(--shadow-d), -3px -3px 8px var(--shadow-l);
    border: none;
    font-weight: 700;
    font-size: 0.84rem;
    color: var(--ink-soft);
    cursor: pointer;
}
.tab-btn.active { background: var(--teal); color: #fff; box-shadow: none; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Login page --------------------------------------------------------- */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 15% 20%, rgba(189,138,52,0.18), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(59,110,94,0.20), transparent 45%),
        var(--clay-bg);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 40px 34px;
    text-align: center;
}
.login-card .mark {
    width: 60px; height: 60px; margin: 0 auto 18px auto;
    border-radius: 20px;
    background: linear-gradient(145deg, var(--teal), var(--teal-dark));
    box-shadow: 6px 6px 14px var(--shadow-d), -5px -5px 12px var(--shadow-l);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 1.5rem;
}
.login-card h1 { font-size: 1.35rem; }
.login-card .tagline { font-size: 0.88rem; margin-bottom: 26px; }
.flash {
    background: var(--brick-tint);
    color: var(--brick-dark);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 16px;
}
.demo-accounts {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px dashed var(--clay-sunken);
    text-align: left;
    font-size: 0.76rem;
    color: var(--ink-faint);
    line-height: 1.7;
}
.demo-accounts b { color: var(--ink-soft); }

/* --- Error page ---------------------------------------------------------*/
.error-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.error-card { padding: 44px; text-align: center; max-width: 420px; }
.error-card .code {
    font-family: var(--font-head);
    font-size: 3rem;
    font-weight: 700;
    color: var(--brick);
}

/* --- Receipt / print sheets (carried over from originals) -------------- */
.workspace-actions { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.a4-sheet {
    background: #fff;
    width: 210mm;
    min-height: 148mm;
    margin: 0 auto 22px auto;
    padding: 12mm 14mm;
    border-radius: var(--radius-md);
    box-shadow: 9px 9px 18px var(--shadow-d), -9px -9px 18px var(--shadow-l);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.receipt-copy {
    border: 1.5px dashed var(--clay-sunken);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-size: 11.5px;
    color: #222;
}
.receipt-divider { border-bottom: 2px dashed var(--clay-sunken); margin: 4px 0; }
.receipt-header { text-align: center; margin-bottom: 8px; }
.receipt-header h4 { font-size: 13px; text-transform: uppercase; color: var(--teal-dark); }
.receipt-header p { font-size: 10px; color: #666; margin: 0; }
.receipt-meta { display: flex; justify-content: space-between; margin-bottom: 8px; border-bottom: 1px solid #ddd; padding-bottom: 6px; font-size: 11px; }
.receipt-tables { display: flex; gap: 10px; margin-bottom: 8px; }
.receipt-tables table { width: 100%; border-collapse: collapse; font-size: 10px; }
.receipt-tables th, .receipt-tables td { border: 1px solid #ccc; padding: 3px 6px; text-align: left; }
.receipt-tables th { background: var(--teal-tint); color: var(--teal-dark); }
.receipt-net {
    background: var(--ochre-tint);
    color: var(--ochre-dark);
    padding: 6px 10px;
    border-radius: 8px;
    display: flex; justify-content: space-between; font-weight: 700; font-size: 11px;
}
.receipt-footer { display: flex; justify-content: space-between; margin-top: 6px; font-size: 10px; color: #444; }
.signature-line { border-top: 1px solid #333; width: 130px; text-align: center; margin-top: 18px; padding-top: 4px; }

.unique-code { color: var(--teal-dark); font-weight: 900; font-family: monospace; letter-spacing: 1px; }

@media print {
    body * { visibility: hidden; }
    #print-area, #print-area * { visibility: visible; }
    #print-area { position: absolute; top: 0; left: 0; width: 100%; }
    .a4-sheet { box-shadow: none; border-radius: 0; page-break-after: always; margin: 0 auto; }
}

/* --- Responsive ---------------------------------------------------------*/
@media (max-width: 880px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; overflow-x: auto; padding: 14px; }
    .sidebar-brand { padding: 0 12px 0 0; }
    .side-link { white-space: nowrap; }
    .sidebar-footer { margin-top: 0; margin-left: auto; display: flex; align-items: center; gap: 10px; }
    .main-area { padding: 22px 16px 50px 16px; }
    .a4-sheet { width: 100%; padding: 6mm; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* --- Server-rendered receipt templates (PR model / loan) ---------------- */
.pr-model .organization-sub, .loan-model .organization-sub {
    font-size: 10px; color: #666; font-weight: 700; margin: 0;
}
table.pr-items { width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 8px; }
table.pr-items th {
    border: 1px solid #ccc; padding: 3px 6px; text-align: left;
    background: var(--teal-tint); color: var(--teal-dark);
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
table.pr-items td { border: 1px solid #ccc; padding: 3px 6px; }
.footer-section { margin-top: 8px; font-size: 10px; }
.footer-received { font-weight: 700; color: var(--teal-dark); font-size: 9.5px; margin-bottom: 6px; }
.footer-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px;
    margin-bottom: 6px; font-size: 10px;
}
.receipt-copy .receipt-meta div { font-size: 10px; }

/* --- Signature areas on printed payslips --------------------------------- */
.signature-block { display: flex; flex-direction: column; align-items: center; }
.signature-block:last-child { align-items: flex-end; }
.signature-cursive {
    font-family: var(--font-signature);
    font-size: 20px;
    color: var(--teal-dark);
    line-height: 1;
    padding: 0 10px;
    white-space: nowrap;
}
.signature-ok {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 14px;
    color: var(--teal-dark);
    background: var(--teal-tint);
    border-radius: 6px;
    padding: 2px 14px;
    letter-spacing: 1px;
}

/* --- Modal overlay (employee edit, etc.) --------------------------------- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(51, 47, 39, 0.45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-box {
    width: 100%; max-width: 560px;
    max-height: 90vh; overflow-y: auto;
    padding: 28px;
}

/* --- Live dashboard indicator --------------------------------------------- */
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--teal);
    display: inline-block;
    animation: live-pulse 2s ease-in-out infinite;
}
@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(59,110,94,0.5); }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px rgba(59,110,94,0); }
}

/* --- Super administrator badge -------------------------------------------- */
.badge-superadmin {
    background: linear-gradient(135deg, var(--teal-dark), var(--ink));
    color: #fff;
}
