/* ==========================================================================
   Statement Builder — Application styles
   ========================================================================== */

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }

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

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-600) 100%);
    color: #cfe0f2;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar__brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.15rem 1.25rem;
    color: #fff; font-weight: 700; font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar__brand .logo-badge {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--secondary); color: var(--primary);
    display: grid; place-items: center; font-weight: 800;
    box-shadow: var(--shadow-sm);
}
.sidebar__nav { padding: .75rem; overflow-y: auto; flex: 1; }
.sidebar__section {
    font-size: .68rem; letter-spacing: .09em; text-transform: uppercase;
    color: rgba(255,255,255,.45); margin: 1rem .75rem .35rem;
}
.sidebar__link {
    display: flex; align-items: center; gap: .75rem;
    padding: .62rem .8rem; border-radius: var(--radius-sm);
    color: #cfe0f2; font-weight: 500; font-size: .92rem;
    margin-bottom: .12rem; transition: background .15s, color .15s;
}
.sidebar__link svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.sidebar__link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar__link.active {
    background: rgba(255,255,255,.14); color: #fff;
    box-shadow: inset 3px 0 0 var(--secondary);
}

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; position: sticky; top: 0; z-index: 1020;
}
.topbar__title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.topbar__user { display: flex; align-items: center; gap: .6rem; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--primary-050); color: var(--primary);
    display: grid; place-items: center; font-weight: 700;
}
.content { padding: 1.5rem; flex: 1; }

/* ---- Cards -------------------------------------------------------------- */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent; border-bottom: 1px solid var(--border);
    font-weight: 600; padding: 1rem 1.25rem;
}
.card-body { padding: 1.25rem; }

/* ---- Stat cards --------------------------------------------------------- */
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1.1; margin-top: .35rem; }
.stat-card .stat-icon {
    position: absolute; right: 1rem; top: 1rem;
    width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center; color: #fff;
}
.stat-icon.bg-primary-soft { background: var(--primary); }
.stat-icon.bg-gold-soft { background: var(--secondary); color: var(--primary); }
.stat-icon.bg-success-soft { background: var(--success); }
.stat-icon.bg-danger-soft { background: var(--danger); }

/* ---- Buttons ------------------------------------------------------------ */
.btn { font-weight: 600; border-radius: var(--radius-sm); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-600); border-color: var(--primary-600); }
.btn-gold { background: var(--secondary); border-color: var(--secondary); color: var(--primary); }
.btn-gold:hover { filter: brightness(.96); color: var(--primary); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }

/* ---- Badges ------------------------------------------------------------- */
.badge-soft { padding: .35em .7em; border-radius: 999px; font-weight: 600; font-size: .72rem; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-generated { background: #e0f2fe; color: #0369a1; }
.badge-finalized { background: #dcfce7; color: #15803d; }
.badge-role { background: var(--primary-050); color: var(--primary); }

/* ---- Tables ------------------------------------------------------------- */
.table { --bs-table-hover-bg: var(--primary-050); }
.table thead th {
    background: #f8fafc; color: var(--muted); text-transform: uppercase;
    font-size: .72rem; letter-spacing: .04em; border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td { vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Wizard ------------------------------------------------------------- */
.wizard-steps { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.wizard-step {
    flex: 1 1 160px; display: flex; align-items: center; gap: .65rem;
    padding: .75rem 1rem; border-radius: var(--radius-sm);
    background: var(--surface); border: 1px solid var(--border); color: var(--muted);
    font-weight: 600; font-size: .85rem;
}
.wizard-step .step-num {
    width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px;
    display: grid; place-items: center; background: #eef2f7; color: var(--muted);
    font-weight: 700; font-size: .8rem;
}
.wizard-step.active { border-color: var(--primary); color: var(--primary); box-shadow: var(--shadow-sm); }
.wizard-step.active .step-num { background: var(--primary); color: #fff; }
.wizard-step.done { color: var(--success); }
.wizard-step.done .step-num { background: var(--success); color: #fff; }
.wizard-pane { display: none; }
.wizard-pane.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Validation panel --------------------------------------------------- */
.validation-panel { border-left: 4px solid var(--border); }
.validation-panel.is-valid { border-left-color: var(--success); background: #f0fdf4; }
.validation-panel.is-invalid { border-left-color: var(--danger); background: #fef2f2; }

/* ---- Editable table cells ---------------------------------------------- */
.txn-table input, .txn-table select {
    border: 1px solid transparent; background: transparent;
    width: 100%; padding: .3rem .4rem; border-radius: 6px; font-size: .85rem;
}
.txn-table input:focus, .txn-table select:focus {
    border-color: var(--primary); background: #fff; outline: none;
    box-shadow: 0 0 0 3px var(--primary-050);
}
.txn-table td.book-balance { font-weight: 600; background: #fbfdff; }
.txn-table tr.row-invalid td { background: #fef2f2 !important; }

/* ---- Toasts ------------------------------------------------------------- */
.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast-item {
    min-width: 280px; max-width: 380px; padding: .85rem 1rem; border-radius: var(--radius-sm);
    background: var(--surface); box-shadow: var(--shadow-lg); border-left: 4px solid var(--muted);
    display: flex; align-items: flex-start; gap: .6rem; animation: slideIn .25s ease;
}
.toast-item.success { border-left-color: var(--success); }
.toast-item.error { border-left-color: var(--danger); }
.toast-item.warning { border-left-color: var(--warning); }
.toast-item.info { border-left-color: var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---- Loading overlay ---------------------------------------------------- */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,.35); backdrop-filter: blur(1px);
    display: none; align-items: center; justify-content: center; z-index: 3000;
}
.loading-overlay.show { display: flex; }
.spinner {
    width: 46px; height: 46px; border-radius: 50%;
    border: 4px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Login -------------------------------------------------------------- */
.login-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
    background: radial-gradient(1200px 500px at 10% -10%, rgba(6,57,112,.18), transparent),
                radial-gradient(900px 400px at 110% 110%, rgba(212,175,55,.18), transparent),
                var(--bg);
}
.login-card { width: 100%; max-width: 420px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-lg); }
.login-card .login-head {
    background: linear-gradient(135deg, var(--primary), var(--primary-600));
    color: #fff; padding: 1.75rem; text-align: center;
}
.login-card .login-head .logo-badge {
    width: 54px; height: 54px; border-radius: 14px; margin: 0 auto .75rem;
    background: var(--secondary); color: var(--primary);
    display: grid; place-items: center; font-weight: 800; font-size: 1.4rem;
}
.password-wrap { position: relative; }
.password-wrap .toggle-pass {
    position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: .35rem;
}

.form-label { font-weight: 600; font-size: .85rem; color: #334155; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-050); }
.input-hint { font-size: .78rem; color: var(--muted); }

.logo-preview {
    max-height: 90px; max-width: 220px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .5rem; background: #fff;
}

.sidebar-toggle { display: none; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .sidebar-toggle { display: inline-flex; }
    .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1030;
    }
    .sidebar-backdrop.show { display: block; }
}
