/* =========================
   Design Tokens
========================= */
:root {
    --bg: #f3f6fa;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dde5ef;
    --line-soft: #e8eef5;

    --ok: #15803d;
    --bad: #b91c1c;
    --warn: #b45309;
    --primary: #1d4f8c;
    --primary-bright: #2563eb;
    --primary-dark: #13243f;
    --primary-soft: #eff6ff;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 12px 28px rgba(15, 23, 42, 0.08);
}

/* =========================
   Global Reset + Base
========================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background: radial-gradient(1000px 380px at 12% -8%, #e6eefc 0%, transparent 58%), var(--bg);
    margin: 28px;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
    margin: 0 0 10px;
    color: var(--text);
}

a {
    color: #1f2937;
    text-decoration: none;
}
a:hover { text-decoration: underline; }

/* =========================
   Layout
========================= */
.topbar {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card {
    background: var(--surface);
    padding: 18px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.section-title {
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: .15px;
    color: var(--text);
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    padding: 14px;
}

.panel-title {
    font-weight: 900;
    font-size: 16px;
    margin-bottom: 8px;
}

.row-space {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* =========================
   Form Controls
========================= */
select,
input,
button,
textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 8px 10px;
    border: 1px solid #d1d9e5;
    border-radius: 8px;
    background: #fff;
    height: 36px;
}

textarea {
    height: auto;
}

input[type="date"],
input[type="number"] {
    -moz-appearance: textfield;
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%),
                      linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position: calc(100% - 16px) 14px,
                         calc(100% - 10px) 14px;
    background-size: 6px 6px;
    background-repeat: no-repeat;
    padding-right: 30px;
}

button {
    cursor: pointer;
    background: #1f2937;
    color: #fff;
    border: none;
    font-weight: 800;
    transition: background .15s ease;
}
button:hover {
    background: #334155;
}

/* =========================
   KPI + Charts
========================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 12px;
}

.kpi {
    padding: 14px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
}
.kpi .label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .45px;
}
.kpi .value {
    font-size: 22px;
    font-weight: 900;
    color: var(--text);
}

.green { color: var(--ok); font-weight: 800; }
.red { color: var(--bad); font-weight: 800; }
.orange { color: var(--warn); font-weight: 800; }

.grid-3 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 16px;
}

.chart-wrap { height: 320px; }
.chart-wrap.tall { height: 380px; }

hr {
    border: none;
    border-top: 1px solid var(--line-soft);
    margin: 14px 0;
}

/* =========================
   Tables
========================= */
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid #eef2f7;
    font-size: 14px;
}
.table th {
    color: #334155;
    font-weight: 900;
    background: #f7f9fc;
}

/* =========================
   Badges
========================= */
.badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    border: 1px solid var(--line);
    background: #fff;
}
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }

/* =========================
   Utilities
========================= */
.text-success {
    color: var(--ok);
    font-weight: 800;
}
.text-warn {
    color: var(--warn);
    font-weight: 800;
}
.text-muted {
    color: var(--muted);
    font-weight: 700;
}

.stack-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.form-grid-ministry {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr 1fr 1fr auto;
    gap: 10px;
}

.card-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.ministry-item {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--surface-soft);
}

.ministry-item-title {
    font-weight: 900;
    font-size: 16px;
    margin-bottom: 8px;
}

.inline-budget-form {
    display: flex;
    gap: 8px;
}

.grow {
    flex: 1;
}

.row-links {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}

.login-card {
    max-width: 420px;
    margin: 60px auto;
}

/* =========================
   Login
========================= */
.login-page {
    min-height: 100svh;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, var(--primary-soft) 0%, var(--surface-soft) 58%, var(--bg) 100%);
    color: var(--text);
}

.login-shell {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 18px 42px rgba(31, 41, 55, .12);
    animation: login-rise .55s ease both;
}

.login-brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 42px;
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 900;
}

.login-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--primary-bright);
    color: #ffffff;
    font-size: 13px;
    letter-spacing: .4px;
}

.login-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--surface);
    color: var(--text);
    padding: 42px;
}

.login-panel-header p {
    margin: 10px 0 28px;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.45;
    font-weight: 700;
}

.login-panel-header h1 {
    margin: 0;
    color: var(--text);
    font-size: 36px;
    line-height: 1;
    letter-spacing: 0;
}

.login-error {
    margin: 0 0 16px;
    padding: 10px 12px;
    border-left: 4px solid #dc2626;
    border-radius: 6px;
    background: #fef2f2;
    color: #991b1b;
    font-weight: 900;
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-form label {
    color: #374151;
    font-size: 13px;
    font-weight: 900;
}

.login-form input {
    width: 100%;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: #111827;
    font-size: 16px;
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.password-wrap {
    position: relative;
}

.password-wrap input {
    padding-right: 76px;
}

.password-toggle {
    position: absolute;
    top: 7px;
    right: 7px;
    width: auto;
    height: 34px;
    min-width: 58px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-size: 12px;
    font-weight: 900;
    transition: background .16s ease, border-color .16s ease, color .16s ease;
}

.password-toggle:hover {
    background: #eef2f7;
    border-color: #94a3b8;
    color: #0f172a;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-bright);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .14);
}

.caps-warning {
    margin: -2px 0 0;
    color: #b45309;
    font-size: 12px;
    font-weight: 900;
}

.login-form .login-submit {
    height: 50px;
    margin-top: 8px;
    border-radius: 8px;
    background: var(--primary-bright);
    color: #ffffff;
    font-size: 15px;
    transition: background .16s ease, transform .16s ease, box-shadow .16s ease;
}

.login-form .login-submit:hover {
    background: var(--primary);
    box-shadow: 0 12px 24px rgba(37, 99, 235, .22);
    transform: translateY(-2px);
}

.login-form .login-submit:active {
    transform: translateY(0);
    box-shadow: none;
}

.login-form .login-submit:disabled {
    cursor: wait;
    opacity: .76;
    transform: none;
    box-shadow: none;
}

.login-form .password-toggle,
.login-form .password-toggle:hover,
.login-form .password-toggle:active {
    margin-top: 0;
    box-shadow: none;
    transform: none;
}

.login-remember-note {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.35;
}

.login-foot {
    margin: 24px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-align: center;
}

@keyframes login-rise {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 860px) {
    .login-shell {
        width: min(480px, 100%);
    }

    .login-panel {
        padding: 32px;
    }

    .login-brand {
        margin-bottom: 42px;
    }
}

@media (max-width: 420px) {
    .login-page {
        padding: 12px;
    }

    .login-panel {
        padding: 24px;
    }

    .login-panel-header h1 {
        font-size: 31px;
    }

    .login-brand {
        margin-bottom: 34px;
    }
}

/* =========================
   Expenses
========================= */
.expense-box {
    background: #fafafa;
    border: 1px solid var(--line);
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 8px;
}

/* =========================
   Receipts UI
========================= */
.receipt-area {
    margin-top: 10px;
    border-top: 1px dashed var(--line);
    padding-top: 10px;
}

.receipt-drop {
    border: 2px dashed #cbd5e1;
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    font-weight: 800;
    color: #475569;
    text-align: center;
    user-select: none;
    cursor: pointer;
    transition: border .2s ease;
}
.receipt-drop.dragover {
    border-color: #1f2937;
}

.receipt-gallery {
    display: grid;
    grid-template-columns: repeat(6, minmax(90px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.receipt-thumb {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 6px;
    position: relative;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.receipt-thumb img {
    max-width: 100%;
    max-height: 80px;
    object-fit: contain;
    display: block;
}

.receipt-thumb .xbtn {
    position: absolute;
    top: 6px;
    right: 6px;
    border: none;
    border-radius: 999px;
    width: 24px;
    height: 24px;
    background: rgba(31, 41, 55, .9);
    color: #fff;
    font-weight: 900;
    cursor: pointer;
}
.receipt-thumb .xbtn:hover {
    background: rgba(55, 65, 81, .95);
}

/* =========================
   Save State
========================= */
.save-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}
.save-state {
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
}
.save-state.saved { color: var(--ok); }
.save-state.saving { color: var(--warn); }
.save-state.error { color: var(--bad); }

/* =========================
   Responsive
========================= */
@media (max-width: 1100px) {
    body { margin: 18px; }
    .topbar { align-items: flex-start; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: 1fr; }
    .chart-wrap, .chart-wrap.tall { height: 300px; }
    .receipt-gallery { grid-template-columns: repeat(3, minmax(90px, 1fr)); }
    .form-grid-ministry { grid-template-columns: 1fr; }
}

/* =========================
   Shared App Shell
========================= */
.app-wrap {
    max-width: 1320px;
    margin: 0 auto;
}

.app-hero {
    border: 1px solid #294768;
    border-radius: 22px;
    padding: 20px 22px;
    background: linear-gradient(145deg, #0b1327 0%, #15375f 60%, #2e67c7 100%);
    color: #fff;
    box-shadow: 0 16px 34px rgba(15, 23, 42, .24);
}

.app-hero h1 {
    margin: 0;
    color: #fff;
    font-size: 34px;
    line-height: 1.08;
    letter-spacing: -.4px;
}

.app-hero-sub {
    margin-top: 8px;
    color: #cfe0ff;
    font-size: 15px;
    font-weight: 700;
}

.app-toolbar {
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.app-card {
    margin-top: 14px;
    border: 1px solid #dbe3ef;
    border-radius: 18px;
    background: #f8fbff;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .07);
    padding: 18px;
}
