:root {
  --wine: #7a1f2b; --wine-dark: #591620; --wine-deep: #3f0f16;
  --gold: #b8894a; --gold-soft: #d8b483;
  --bg: #f6f2ec; --surface: #ffffff; --surface-2: #faf7f2;
  --ink: #241d1b; --muted: #8a817a; --line: #ece4da;
  --ok: #1f7a3d; --ok-bg: #e7f3ea; --err: #b3261e; --err-bg: #fbe9e7;
  --warn: #9a6b1f; --warn-bg: #f7edda;
  --shadow: 0 1px 2px rgba(40,20,10,.04), 0 6px 24px rgba(40,20,10,.06);
  --radius: 14px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 var(--sans); color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* buttons */
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#loginBtn, #creditBtn, #recBtn, .btn-primary {
  padding: 11px 18px; font-weight: 600; color: #fff; background: var(--wine);
}
#loginBtn:hover, #creditBtn:hover, #recBtn:hover, .btn-primary:hover { background: var(--wine-dark); }
.btn-ghost { padding: 9px 14px; background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { padding: 9px 16px; background: var(--err); color: #fff; font-weight: 600; }
.btn-danger:hover { filter: brightness(.94); }
.btn-sm { padding: 8px 14px; font-size: 14px; }
.icon-btn { padding: 6px; background: transparent; color: var(--muted); border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { padding: 6px 12px; background: var(--surface-2); color: var(--wine); border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.link-btn:hover { background: #fff; border-color: var(--gold-soft); }

/* inputs */
label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
input {
  width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,137,74,.15); }
.error { color: var(--err); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }

/* ===================== LOGIN ===================== */
.login {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #8a2632 0%, var(--wine-deep) 55%, #2c0a10 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px;
  padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-foot { color: rgba(255,255,255,.6); font-size: 13px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--wine); color: var(--gold-soft); flex: none; }
.brand strong { display: block; font-family: var(--serif); font-size: 18px; letter-spacing: .2px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.brand--login { margin-bottom: 22px; }
#loginForm label { margin-top: 14px; }
#loginBtn { width: 100%; margin-top: 20px; }

/* ===================== APP SHELL ===================== */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100%; }
.sidebar {
  display: flex; flex-direction: column; gap: 6px; padding: 20px 14px;
  background: linear-gradient(180deg, var(--wine-dark), var(--wine-deep));
  color: #f3e7d8; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 4px 8px 18px; }
.sidebar .brand strong { color: #fff; }
.sidebar .brand span { color: var(--gold-soft); }
.sidebar .brand-mark { background: rgba(255,255,255,.1); color: var(--gold-soft); }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 11px 12px;
  background: transparent; color: rgba(243,231,216,.72); border-radius: 10px;
  font-size: 14.5px; font-weight: 500; text-align: left; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--gold); }
.nav-item .ic { width: 19px; height: 19px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.who { font-size: 12.5px; color: rgba(243,231,216,.7); margin-bottom: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn-ghost { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; color: #f3e7d8; border-color: rgba(255,255,255,.18); background: transparent; }
.sidebar-foot .btn-ghost:hover { background: rgba(255,255,255,.08); }

.content { padding: 30px clamp(18px, 4vw, 40px); max-width: 1100px; width: 100%; }
.view-head { margin-bottom: 22px; }
.view-head h1 { font-family: var(--serif); font-size: 26px; font-weight: 600; }
.view-head p { margin: 4px 0 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { display: block; font-size: 12.5px; color: var(--muted); }
.kpi strong { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi-ic { width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center; }
.kpi-ic .ic { width: 20px; height: 20px; }
.i-users { background-color: #f3e7e9; color: var(--wine); }
.i-wallet { background-color: #f7edda; color: var(--warn); }
.i-up { background-color: #e7f3ea; color: var(--ok); }
.i-down { background-color: #fbe9e7; color: var(--err); }

/* panels & grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 16px 18px 0; }
.panel-head h2 { font-size: 15px; font-weight: 600; }

/* lists (expiring / activity / history) */
.list { padding: 8px 6px 10px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; }
.list-item:hover { background: var(--surface-2); }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 12.5px; color: var(--muted); }
.li-amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.li-amount.pos { color: var(--ok); } .li-amount.neg { color: var(--err); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.warn { background: var(--gold); } .dot.pos { background: var(--ok); } .dot.neg { background: var(--err); }
.list-empty, .table-empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.bal { font-weight: 600; }

/* search */
.searchbar { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 6px 14px; margin-bottom: 16px; max-width: 520px; box-shadow: var(--shadow); }
.searchbar .search-ic { color: var(--muted); display: grid; place-items: center; }
.searchbar input { border: 0; margin: 0; padding: 6px 4px; box-shadow: none; }
.searchbar input:focus { box-shadow: none; }

/* forms */
.form { padding: 22px; max-width: 560px; }
.form label { margin-bottom: 14px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row label { flex: 1; min-width: 140px; }
.form button[type=submit] { margin-top: 6px; }
.preview { margin: -4px 0 14px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; }
.preview.found { background: var(--ok-bg); border-color: #cfe6d6; }
.preview strong { font-weight: 600; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(30,15,12,.42); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(440px, 92vw);
  background: var(--surface); box-shadow: -12px 0 40px rgba(0,0,0,.2); display: flex; flex-direction: column;
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 22px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-family: var(--serif); font-size: 20px; }
.drawer-balance { display: flex; align-items: baseline; justify-content: space-between; padding: 18px 22px; background: var(--surface-2); }
.drawer-balance span { color: var(--muted); font-size: 13px; }
.drawer-balance strong { font-size: 26px; font-weight: 700; color: var(--wine); }
.drawer-body { padding: 16px 16px 24px; overflow-y: auto; }
.drawer-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 6px 6px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-box { position: relative; background: var(--surface); border-radius: 16px; padding: 24px; width: min(400px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-box h3 { font-family: var(--serif); font-size: 19px; margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px; animation: toastIn .2s ease-out; max-width: 360px; }
.toast.ok { background: #1c6b37; } .toast.err { background: #a01f18; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* skeleton */
.skeleton { color: transparent; background: linear-gradient(90deg, #eee 25%, #f5f5f5 37%, #eee 63%); background-size: 400% 100%; border-radius: 6px; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ===================== responsive ===================== */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; gap: 4px; padding: 10px 12px; z-index: 20; overflow-x: auto; }
  .sidebar .brand { padding: 0 10px 0 4px; }
  .sidebar .brand div { display: none; }
  .nav { flex-direction: row; }
  .nav-item { border-left: 0; border-bottom: 3px solid transparent; padding: 9px 12px; white-space: nowrap; }
  .nav-item.active { border-left: 0; border-bottom-color: var(--gold); }
  .nav-item span { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; display: flex; align-items: center; }
  .who { display: none; }
  .sidebar-foot .btn-ghost { width: auto; padding: 8px 12px; }
  .content { padding: 20px 16px 40px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 13px; } .kpi strong { font-size: 19px; }
  .view-head h1 { font-size: 22px; }
}
