:root {
  --bg: #f2f5f9; --panel: #ffffff; --line: #e4e9f0; --line-soft: #eef2f7;
  --ink: #17233b; --muted: #66748c;
  --brand: #2545d3; --brand-dark: #1c37a8; --brand-soft: #eef1fe; --brand-border: #d8dffc;
  --green: #0e9f6e; --green-soft: #e3f6ee;
  --red: #d64545; --red-soft: #fceaea;
  --amber: #b7791f; --amber-soft: #fdf3e3;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(23, 35, 59, .05), 0 1px 6px rgba(23, 35, 59, .04);
  --shadow-md: 0 4px 14px rgba(23, 35, 59, .08);
  --shadow-lg: 0 24px 70px rgba(15, 25, 55, .28);
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-font-smoothing: antialiased; }
body { font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin-top: 10px; font-size: 13px; text-align: center; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- Home / Login ---------- */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px;
  background: radial-gradient(1100px 500px at 20% -10%, #dfe6ff 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #dcf3ea 0%, transparent 55%), var(--bg); }
.hero { display: flex; gap: 0; max-width: 940px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg); overflow: hidden; }
.hero-brand { flex: 1.2; background: linear-gradient(160deg, #101a31 0%, #1b2a52 70%, #23368c 100%); color: #cdd7ec; padding: 48px 44px; display: flex; flex-direction: column; }
.hero-logo { width: 52px; height: 52px; background: var(--brand); color: #fff; border-radius: 13px; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; box-shadow: 0 8px 24px rgba(37,69,211,.5); margin-bottom: 18px; }
.hero-brand h1 { color: #fff; font-size: 30px; letter-spacing: -.02em; }
.hero-brand h1 span { color: #8da4f5; }
.hero-tag { margin: 10px 0 28px; font-size: 14.5px; line-height: 1.6; color: #aab9d8; }
.hero-features { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.hero-features li { display: flex; gap: 13px; align-items: flex-start; }
.hero-features svg { width: 20px; height: 20px; flex-shrink: 0; color: #8da4f5; margin-top: 2px; }
.hero-features b { display: block; color: #eef2fb; font-size: 13.5px; }
.hero-features span { font-size: 12.5px; color: #93a5c8; }
.hero-foot { margin-top: auto; padding-top: 28px; font-size: 11.5px; color: #6f81a6; letter-spacing: .04em; }
#login-form { flex: 1; padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
#login-form h2 { font-size: 22px; letter-spacing: -.02em; }
.brand span { color: var(--brand); }
#login-form p { margin: 4px 0 24px; }
#login-form input { width: 100%; padding: 11px 13px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; transition: border-color .15s, box-shadow .15s; }
#login-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
#login-form button { width: 100%; padding: 11px; background: var(--brand); color: #fff; border: 0; border-radius: 10px; font-weight: 600; transition: background .15s, transform .05s; }
#login-form button:hover { background: var(--brand-dark); }
#login-form button:active { transform: translateY(1px); }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }
#sidebar { width: 216px; background: linear-gradient(180deg, #101a31 0%, #0d1526 100%); color: #c3cde0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 22px 20px 18px; letter-spacing: -.01em; }
#sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
#sidebar nav a { display: flex; align-items: center; gap: 11px; color: #aab7d0; text-decoration: none; padding: 9px 12px; border-radius: 9px; font-weight: 500; transition: background .12s, color .12s; }
#sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .8; }
#sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #e8edf7; }
#sidebar nav a.active { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(37, 69, 211, .4); }
#sidebar nav a.active svg { opacity: 1; }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12.5px; }
#whoami { color: #e8edf7; margin-bottom: 2px; }
.link-btn { background: none; border: 0; color: #8fa2c4; padding: 3px 0; text-decoration: underline; text-underline-offset: 2px; }
#content { flex: 1; min-width: 0; }
#topbar { display: flex; justify-content: space-between; align-items: center; padding: 15px 28px; background: rgba(255, 255, 255, .85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
#page-title { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
#currency-toggle { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 6px 15px; font-weight: 600; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
#currency-toggle:hover { border-color: var(--brand); color: var(--brand); }
#main { padding: 26px 28px 70px; max-width: 1180px; }

/* ---------- Cards / panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: var(--shadow-md); }
.card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 6px; white-space: nowrap; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.value.pos { color: var(--green); } .value.neg { color: var(--red); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.panel h3 { margin-bottom: 14px; font-size: 15px; letter-spacing: -.01em; }
.warn-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--amber-soft); color: var(--amber); border: 1px solid #f0dcb8; padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform .1s; }
.warn-chip:hover { transform: translateY(-1px); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; }
td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f6f8fd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 12px; letter-spacing: .02em; }
.badge.PAID { background: var(--green-soft); color: var(--green); }
.badge.AUTHORISED { background: var(--brand-soft); color: var(--brand); }
.badge.DRAFT { background: var(--line-soft); color: var(--muted); }
.badge.VOIDED, .badge.DELETED { background: var(--red-soft); color: var(--red); }
.badge.in { background: var(--green-soft); color: var(--green); } .badge.out { background: var(--red-soft); color: var(--red); }

/* ---------- Toolbar / tabs / buttons / forms ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar input, .toolbar select, .modal input, .modal select, .modal textarea, .panel input, .panel select, .panel textarea {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; font: inherit; background: #fff; transition: border-color .15s, box-shadow .15s; }
.toolbar input:focus, .toolbar select:focus, .modal input:focus, .modal select:focus, .modal textarea:focus, .panel input:focus, .panel select:focus, .panel textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 9px; padding: 9px 17px; font-weight: 600; box-shadow: 0 2px 8px rgba(37, 69, 211, .25); transition: background .15s, transform .05s, box-shadow .15s; }
.btn:hover { background: var(--brand-dark); box-shadow: 0 4px 12px rgba(37, 69, 211, .3); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { border-color: #c9d2e0; background: #fafbfd; }
.btn.danger { background: var(--red); box-shadow: 0 2px 8px rgba(214, 69, 69, .25); }
.btn.danger:hover { background: #b93a3a; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.spacer { flex: 1; }
.viewer .writeonly { display: none !important; }
.tabs { display: flex; gap: 2px; }
.tabs button { background: none; border: 0; padding: 8px 14px; color: var(--muted); font-weight: 600; border-radius: 8px; transition: background .12s, color .12s; }
.tabs button:hover { background: var(--line-soft); }
.tabs button.active { color: var(--brand); background: var(--brand-soft); }

/* ---------- Modal (centered — the global margin reset must not win) ---------- */
dialog.modal { margin: auto; border: 0; border-radius: 16px; padding: 0; width: min(700px, 94vw); box-shadow: var(--shadow-lg); animation: modal-in .18s ease-out; }
dialog.modal::backdrop { background: rgba(13, 21, 38, .5); backdrop-filter: blur(2px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.modal-body { padding: 22px; max-height: 68vh; overflow-y: auto; }
.modal-foot { padding: 15px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fafbfd; border-radius: 0 0 16px 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label, .form-col label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.form-grid input, .form-grid select { width: 100%; }
.lines-table input, .lines-table select { width: 100%; padding: 6px 8px; }
.close-x { background: none; border: 0; font-size: 22px; color: var(--muted); line-height: 1; padding: 2px 6px; border-radius: 6px; transition: background .12s, color .12s; }
.close-x:hover { background: var(--line-soft); color: var(--ink); }

/* ---------- Inline category select ---------- */
select.cat-inline { max-width: 220px; padding: 4px 6px; font-size: 13px; border: 1px solid transparent; background: transparent; border-radius: 6px; }
select.cat-inline:hover { border-color: var(--line); background: #fff; }
select.cat-inline.empty { color: var(--amber); font-weight: 600; }

/* ---------- Report bars ---------- */
.bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--brand), #5a75e8); display: inline-block; vertical-align: middle; }
.bar.expense { background: linear-gradient(90deg, var(--red), #e57373); }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px); background: #101a31; color: #fff; padding: 11px 22px; border-radius: 12px; opacity: 0; transition: opacity .22s, transform .22s; pointer-events: none; z-index: 50; max-width: 80vw; box-shadow: var(--shadow-lg); font-weight: 500; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Invoice document (print + preview) ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .invoice-doc { font-size: 13px; color: #111; max-width: 720px; margin: 0 auto; }
}
.invoice-doc { padding: 34px 8px; }
.invoice-doc .brand-strip { height: 8px; background: var(--brand); border-radius: 4px; margin-bottom: 30px; }
.invoice-doc .doc-head { display: flex; justify-content: space-between; margin-bottom: 34px; }
.invoice-doc .logo-mark { width: 42px; height: 42px; background: var(--brand); color: #fff; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; margin-bottom: 12px; }
.invoice-doc h1 { font-size: 32px; letter-spacing: .08em; }
.invoice-doc .org { text-align: right; font-size: 12.5px; line-height: 1.55; color: #444; }
.invoice-doc .org b { font-size: 14px; color: #111; }
.invoice-doc .meta-row { display: flex; justify-content: space-between; margin-bottom: 26px; }
.invoice-doc .bill-to { font-size: 12.5px; line-height: 1.55; }
.invoice-doc .inv-meta td { border: 0; padding: 3px 8px; font-size: 13px; }
.invoice-doc .inv-meta .due td { background: var(--brand-soft); font-weight: 700; color: var(--brand); }
.invoice-doc table.items { margin: 10px 0 18px; }
.invoice-doc table.items th { background: var(--brand); color: #fff; padding: 9px 10px; position: static; }
.invoice-doc .totals { text-align: right; font-size: 14px; }
.invoice-doc .totals .grand { font-size: 16px; font-weight: 700; border-top: 2px solid var(--line); padding-top: 8px; margin-top: 6px; }
.invoice-doc .thanks { text-align: center; font-style: italic; color: #666; margin-top: 34px; }
.invoice-doc .doc-foot { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; display: flex; justify-content: space-between; font-size: 11px; color: #888; }

/* ---------- Responsive ---------- */
/* ---------- Settings tabs / Documentation / Copilot ---------- */
.settings-tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.docs h4 { margin: 18px 0 8px; font-size: 14px; }
.docs p, .docs li { font-size: 13.5px; line-height: 1.65; color: #3b4a63; }
.docs ol, .docs ul { padding-left: 20px; margin: 6px 0; }
.docs .flow { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.docs .flow-card { flex: 1; min-width: 200px; background: var(--brand-soft); border: 1px solid var(--brand-border); border-radius: 10px; padding: 12px 14px; font-size: 12.5px; }
.docs .flow-card.expense { background: var(--red-soft); border-color: #f0cccc; }
.docs .flow-card b { display: block; font-size: 13px; margin-bottom: 3px; }
.docs code { background: var(--line-soft); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.copilot-preview td { font-size: 13px; }
.copilot-note { background: var(--brand-soft); border: 1px solid var(--brand-border); border-radius: 10px; padding: 10px 14px; font-size: 13px; margin: 12px 0; }

@media (max-width: 860px) {
  .hero { flex-direction: column; }
  .hero-brand { padding: 32px 28px; }
  #sidebar { width: 62px; }
  .brand { font-size: 13px; padding: 16px 8px; text-align: center; }
  #sidebar nav { padding: 0 7px; }
  #sidebar nav a { justify-content: center; padding: 11px 8px; }
  #sidebar nav a span { display: none; }
  .sidebar-foot { display: none; }
  #main, #topbar { padding-left: 16px; padding-right: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
