/* ===================================================================
   Cash Management System — application styles
   Modern, responsive, mobile-first. Teal brand.
   =================================================================== */
:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1e2430;
    --ink-soft: #3b4453;
    --muted: #6b7280;
    --line: #e5e8ec;
    --line-soft: #eef1f4;
    --brand: #0f766e;
    --brand-ink: #0b5a54;
    --brand-soft: #e6f2f0;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --bad: #dc2626;
    --bad-soft: #fee2e2;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --sidebar: #0d1b2a;
    --sidebar-ink: #cbd5e1;
    --sidebar-active: #14b8a6;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
    --shadow-md: 0 4px 12px rgba(16,24,40,.08);
    --sidebar-w: 244px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    font-size: 15px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 6px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: transform .22s ease;
}
.side-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px; font-weight: 700; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.side-logo {
    display: inline-grid; place-items: center;
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--brand); color: #fff; font-size: 1rem;
}
.side-name { font-size: .98rem; }
.side-nav { padding: 12px 12px; flex: 1; overflow-y: auto; }
.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-ink); font-size: .92rem; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-ico { width: 20px; text-align: center; font-size: 1rem; }
.side-sep {
    margin: 16px 12px 6px; font-size: .68rem; text-transform: uppercase;
    letter-spacing: .8px; color: #64748b; font-weight: 600;
}
.side-foot { padding: 14px 20px; font-size: .74rem; border-top: 1px solid rgba(255,255,255,.08); }

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

.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 22px; background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
}
.hamburger { display: none; font-size: 1.4rem; cursor: pointer; user-select: none; }
.page-title { font-weight: 600; font-size: 1.05rem; flex: 1; }
.top-actions { display: flex; align-items: center; gap: 16px; }
.bell { position: relative; font-size: 1.2rem; text-decoration: none; }
.bell-count {
    position: absolute; top: -7px; right: -9px;
    background: var(--bad); color: #fff; font-size: .62rem; font-weight: 700;
    padding: 1px 5px; border-radius: 999px; line-height: 1.4;
}
.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand-ink);
    display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}
.user-info { line-height: 1.2; }
.user-name { font-size: .85rem; font-weight: 600; }
.user-role { font-size: .72rem; }
.logout-form { margin: 0; }

.content { padding: 24px; max-width: 1240px; width: 100%; }

.nav-toggle-cb, .nav-backdrop { display: none; }

/* ---- Cards / panels ----------------------------------------------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; margin-bottom: 18px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 14px;
}
.card-head h2, .card-head h1 { margin: 0; }

/* ---- KPI tiles ---------------------------------------------------- */
.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px; margin-bottom: 18px;
}
.kpi {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 18px; position: relative; overflow: hidden;
}
.kpi-label { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin-top: 6px; letter-spacing: -.3px; }
.kpi-sub { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.kpi-accent { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.kpi.k-in  .kpi-accent { background: var(--ok); }
.kpi.k-out .kpi-accent { background: var(--bad); }
.kpi.k-card .kpi-accent { background: #7c3aed; }
.kpi.k-bank .kpi-accent { background: var(--info); }
.kpi.k-warn .kpi-accent { background: var(--warn); }

/* ---- Tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); font-size: .9rem; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.table tbody tr:hover { background: #fafbfc; }
.table td.amount, .table th.amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .empty { text-align: center; color: var(--muted); padding: 34px 12px; }

/* ---- Badges / pills ----------------------------------------------- */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-ok   { background: var(--ok-soft); color: #14532d; }
.badge-bad  { background: var(--bad-soft); color: #991b1b; }
.badge-warn { background: var(--warn-soft); color: #92400e; }
.badge-info { background: var(--info-soft); color: #075985; }
.badge-muted{ background: #eef1f4; color: #475569; }
.badge-brand{ background: var(--brand-soft); color: var(--brand-ink); }

/* ---- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: var(--brand); color: #fff;
    font-size: .9rem; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--brand-ink); text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: .82rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: #f1f3f5; color: var(--ink); }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #b91c1c; }
.btn-ok { background: var(--ok); }
.btn-ok:hover { background: #15803d; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- Forms -------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.field label { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: .76rem; color: var(--muted); }
.field.req label::after { content: " *"; color: var(--bad); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
    width: 100%; padding: 9px 12px; font-size: .92rem;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: #fff; color: var(--ink); font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; min-height: 84px; }
.input-group { display: flex; }
.input-group > select { max-width: 110px; border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-right: 0; }
.input-group > input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ---- Alerts ------------------------------------------------------- */
.alert { padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .9rem; border: 1px solid transparent; }
.alert-danger  { background: var(--bad-soft); color: #991b1b; border-color: #fecaca; }
.alert-success { background: var(--ok-soft); color: #14532d; border-color: #bbf7d0; }
.alert-info    { background: var(--info-soft); color: #075985; border-color: #bae6fd; }
.alert-warning { background: var(--warn-soft); color: #92400e; border-color: #fde68a; }

/* ---- Filters bar -------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 140px; flex: 1 1 140px; }
.filters .field.grow { flex: 2 1 220px; }

/* ---- Balance / branch chips --------------------------------------- */
.bal-list { display: flex; flex-wrap: wrap; gap: 8px; }
.bal-chip {
    background: var(--brand-soft); color: var(--brand-ink);
    border-radius: var(--radius-sm); padding: 6px 12px; font-weight: 600; font-size: .9rem;
    font-variant-numeric: tabular-nums;
}
.bal-chip.neg { background: var(--bad-soft); color: #991b1b; }

.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.branch-tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; background: var(--card); }
.branch-tile h4 { margin: 0 0 10px; font-size: .95rem; }

/* ---- Charts ------------------------------------------------------- */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.chart-box { position: relative; height: 280px; }

/* ---- Card (corporate) tiles --------------------------------------- */
.cc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.cc {
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; background: linear-gradient(135deg, #0f766e 0%, #134e4a 100%);
    color: #fff; box-shadow: var(--shadow-md); position: relative;
}
.cc.low { background: linear-gradient(135deg, #b91c1c 0%, #7f1d1d 100%); }
.cc.blocked { background: linear-gradient(135deg, #475569 0%, #1e293b 100%); }
.cc-top { display: flex; justify-content: space-between; align-items: flex-start; }
.cc-name { font-weight: 700; font-size: 1.02rem; }
.cc-type { font-size: .72rem; opacity: .85; text-transform: uppercase; letter-spacing: .5px; }
.cc-num { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; margin: 18px 0 4px; font-size: 1.02rem; }
.cc-bal { font-size: 1.7rem; font-weight: 700; margin-top: 12px; }
.cc-meta { display: flex; justify-content: space-between; margin-top: 12px; font-size: .78rem; opacity: .9; }
.cc-foot { margin-top: 14px; display: flex; gap: 8px; }
.cc .btn { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.25); }
.cc .btn:hover { background: rgba(255,255,255,.28); }

/* ---- Misc --------------------------------------------------------- */
.stack > * + * { margin-top: 16px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.spacer { flex: 1; }
.tag { font-size: .78rem; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--line); border-radius: 7px; font-size: .85rem; color: var(--ink-soft); }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 6px; font-size: .88em; }
.attach-link { display: inline-flex; align-items: center; gap: 5px; font-size: .84rem; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: 8px; }

/* ---- Login -------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: linear-gradient(135deg, #0f766e 0%, #0d1b2a 100%); }
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.28);
    padding: 34px 30px; width: 100%; max-width: 400px; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo { display: inline-grid; place-items: center; width: 52px; height: 52px;
    border-radius: 14px; background: var(--brand); color: #fff; font-size: 1.5rem; margin-bottom: 12px; }
.login-brand h1 { font-size: 1.25rem; margin: 0; }
.login-brand p { color: var(--muted); font-size: .88rem; margin: 4px 0 0; }
.login-foot { text-align: center; margin-top: 18px; font-size: .78rem; color: var(--muted); }

/* Demo one-click role logins */
.demo-roles { display: flex; flex-direction: column; gap: 10px; }
.demo-role-form { margin: 0; }
.demo-role-btn {
    width: 100%; text-align: left; cursor: pointer;
    display: flex; flex-direction: column; gap: 3px;
    padding: 13px 16px; border-radius: 12px;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    transition: border-color .15s, box-shadow .15s, transform .05s;
}
.demo-role-btn:hover { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.demo-role-btn:active { transform: translateY(1px); }
.demo-role-name { font-weight: 700; font-size: .98rem; color: var(--brand-ink); }
.demo-role-desc { font-size: .8rem; color: var(--muted); }
.demo-manual { margin-top: 16px; }
.demo-manual > summary {
    cursor: pointer; text-align: center; font-size: .84rem; color: var(--muted);
    list-style: none;
}
.demo-manual > summary::-webkit-details-marker { display: none; }
.demo-manual > summary:hover { color: var(--brand); }

/* ---- Responsive --------------------------------------------------- */
@media (max-width: 900px) {
    .form-grid, .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-md); }
    .main { margin-left: 0; }
    .hamburger { display: block; }
    .nav-toggle-cb:checked ~ .shell .sidebar { transform: translateX(0); }
    .nav-toggle-cb:checked ~ .shell .nav-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35;
    }
    .user-info { display: none; }
    .content { padding: 16px; }
}
@media (max-width: 520px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .kpi-value { font-size: 1.25rem; }
    .card { padding: 16px; }
}
@media print {
    .sidebar, .topbar, .btn, .filters, .no-print { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; max-width: 100%; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    body { background: #fff; font-size: 12px; }
}
