/* ============================================================
   Accounting System — app.css
   Mobile-first, no external dependencies. CSS custom properties
   drive the palette; everything scales from 360px up.
   ============================================================ */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #0f766e;          /* teal-700 */
    --primary-hover: #115e59;
    --primary-soft: #ccfbf1;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
    --shadow-lg: 0 10px 30px rgba(15,23,42,.12);
    --topbar-h: 56px;
    --maxw: 960px;
    font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow);
}
.topbar .brand {
    color: #fff; font-weight: 700; font-size: 1.05rem;
    text-decoration: none; letter-spacing: -.01em;
}
.topbar .spacer { flex: 1; }
.userchip { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.userchip-name { font-weight: 600; font-size: .9rem; }
.userchip-role { font-size: .72rem; opacity: .8; }
.hamburger {
    background: none; border: 0; cursor: pointer; padding: 8px;
    display: inline-flex; flex-direction: column; gap: 4px;
}
.hamburger span {
    display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px;
    transition: transform .2s, opacity .2s;
}

/* ---------- Sidenav ---------- */
.sidenav {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 84vw;
    background: var(--surface); box-shadow: var(--shadow-lg);
    padding: 16px 12px; z-index: 60;
    transform: translateX(-105%); transition: transform .22s ease;
    display: flex; flex-direction: column; gap: 2px;
    overflow-y: auto;
}
.sidenav.open { transform: translateX(0); }
.sidenav a {
    color: var(--text); padding: 12px 14px; border-radius: var(--radius-sm);
    text-decoration: none; font-weight: 500; font-size: .95rem;
    display: flex; align-items: center; gap: 10px;
}
.sidenav a:hover { background: var(--surface-2); text-decoration: none; }
.sidenav a.is-active { background: var(--primary-soft); color: var(--primary-hover); }
.sidenav hr { border: 0; border-top: 1px solid var(--border); margin: 10px 6px; }
.sidenav .nav-logout { margin-top: auto; color: var(--danger); }
.sidenav form { margin-top: auto; }
.sidenav button.nav-logout { margin-top: auto; color: var(--danger); }
.sidenav button.nav-logout:hover { background: var(--danger-soft); }
.backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 50;
}

@media (min-width: 900px) {
    .hamburger { display: none; }
    .sidenav {
        transform: none; width: 230px;
        box-shadow: 1px 0 0 var(--border);
    }
    .content { margin-left: 230px; }
    .topbar { left: 230px; }
}

/* ---------- Content ---------- */
.content {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 16px 14px 48px;
}
.content.centered {
    min-height: 60vh; display: flex; align-items: center; justify-content: center;
}

.page-head { margin-bottom: 18px; }
.page-title { margin: 0; font-size: 1.4rem; letter-spacing: -.02em; }
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: .92rem; }
.page-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards & sections ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: repeat(3,1fr);} }
@media (min-width: 760px) { .grid.cols-4 { grid-template-columns: repeat(4,1fr);} }

/* ---------- Stat cards ---------- */
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.stat .stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat .stat-meta { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.stat.negative .stat-value { color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 480px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-2); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.balance-pos { color: var(--success); font-weight: 600; }
.balance-neg { color: var(--danger); font-weight: 600; }

/* ---------- Chips / badges ---------- */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface-2); color: var(--text-muted); }
.chip.t-fiscal_sponsor { background: #ede9fe; color: #6d28d9; }
.chip.t-bank { background: #dbeafe; color: #1d4ed8; }
.chip.t-cash { background: #fef3c7; color: #b45309; }
.chip.t-expense { background: #fee2e2; color: #b91c1c; }
.chip.t-income { background: #dcfce7; color: #15803d; }
.chip.t-asset { background: #e0f2fe; color: #0369a1; }
.chip.t-liability { background: #fce7f3; color: #be185d; }
.chip.t-equity { background: var(--primary-soft); color: var(--primary-hover); }
.chip.t-transfer { background: #e0e7ff; color: #4338ca; }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; color: var(--text); }
.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
    width: 100%; padding: 10px 12px; font-size: 1rem; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary);
}
.form-grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; font-size: .92rem; font-weight: 600;
    background: var(--primary); color: #fff; border: 0; border-radius: var(--radius-sm);
    cursor: pointer; text-decoration: none; transition: background .15s;
    min-height: 42px;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: .82rem; min-height: 32px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Flash ---------- */
.flash {
    padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .9rem;
    border: 1px solid transparent;
}
.flash-info { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.flash-success { background: var(--success-soft); color: #15803d; border-color: #86efac; }
.flash-error { background: var(--danger-soft); color: #b91c1c; border-color: #fca5a5; }
.flash-warning { background: var(--warning-soft); color: #b45309; border-color: #fcd34d; }

/* ---------- Auth (login) ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-card .logo { font-size: 2rem; margin-bottom: 4px; }
.auth-card p.lead { margin: 0 0 18px; color: var(--text-muted); font-size: .92rem; }

/* ---------- Dropzone / uploads ---------- */
.dropzone {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 22px 16px; text-align: center; color: var(--text-muted);
    background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .dz-label { font-weight: 600; color: var(--text); }
.dropzone input[type=file] { display: none; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.thumb {
    position: relative; width: 96px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    overflow: hidden; background: var(--surface-2);
}
.thumb img { display: block; width: 100%; height: 80px; object-fit: cover; }
.thumb .pdf-ic { display:flex; align-items:center; justify-content:center; height:80px; font-weight:700; color:#b91c1c; }
.thumb .thumb-meta { font-size: .68rem; padding: 4px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .thumb-remove {
    position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.55); color: #fff;
    border: 0; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1;
}
.upload-progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.upload-progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }

/* ---------- Misc ---------- */
.doc-preview { width: 80px; height: 80px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.doc-icon { display:inline-flex; align-items:center; justify-content:center; width:80px; height:80px; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); font-weight: 700; }
.list-empty { padding: 30px 16px; text-align: center; color: var(--text-muted); }
.list-empty .ico { font-size: 1.8rem; margin-bottom: 6px; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filter-bar .field { flex: 1 1 140px; min-width: 0; }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.text-mono { font-variant-numeric: tabular-nums; }
.hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.balance-indicator {
    padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600;
    background: var(--danger-soft); color: var(--danger); border: 1px solid #fca5a5;
    text-align: center; margin-top: 8px;
}
.balance-indicator.balanced { background: var(--success-soft); color: #15803d; border-color: #86efac; }
.journal-row { display: grid; grid-template-columns: 2fr 1fr 1fr 40px; gap: 8px; align-items: end; margin-bottom: 8px; }
.journal-row .rm-btn { background: none; border: 0; color: var(--danger); font-size: 1.2rem; cursor: pointer; }
.error-card { text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); }
.footer { text-align: center; color: var(--text-muted); font-size: .78rem; padding: 24px 12px; }
.tag-serial { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; color: var(--primary-hover); font-weight: 600; }
.iconbtn { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; cursor: pointer; color: var(--text-muted); }
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.detail-grid dt { font-weight: 600; color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.detail-grid dd { margin: 0 0 10px; }
.detail-grid { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; }
@media (max-width: 480px) { .detail-grid { grid-template-columns: 1fr; } .journal-row { grid-template-columns: 1fr 80px 80px 36px; } }
