/* ==========================================================================
   Mirch Stock  -  admin styles
   Idea: a traditional market ledger book. Ink sidebar, chilli-red accent, ledger tables
   with the classic double red margin line and pale ruled rows.
   ========================================================================== */
:root {
  --ink: #16202A;  --ink-2: #1F2C39;  --ink-3: #2C3D4F;
  --paper: #F1F3F5;  --surface: #FFFFFF;  --line: #E2E6EB;
  --muted: #5D6B78;
  --chilli: #B3202B;  --chilli-dark: #8F1922;  --chilli-soft: #FBEBEC;
  --turmeric: #B87900;  --turmeric-soft: #FFF3D2;
  --leaf: #1B7A4B;  --leaf-soft: #E2F3E9;
  --rule: #F0D3D6;
  --text: #16202A;
  --chart-2: #16202A;  --grid: #EEF0F3;
  --thead: #FAFBFC;  --mute-bg: #EDF0F3;
  --chilli-fill: rgba(179,32,43,.10);
  color-scheme: light;
  --radius: 10px;
  --side-w: 248px;

  --bs-body-font-family: 'Mukta', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-body-color: var(--text);
  --bs-body-bg: var(--paper);
  --bs-primary: var(--chilli);  --bs-primary-rgb: 179, 32, 43;
  --bs-link-color: var(--chilli);  --bs-link-hover-color: var(--chilli-dark);
  --bs-border-color: var(--line);
  --bs-border-radius: 8px;
  --bs-success: var(--leaf);  --bs-success-rgb: 27, 122, 75;
}

/* ---- Dark mode ---- (html[data-bs-theme="dark"]) */
:root[data-bs-theme="dark"] {
  --ink: #0A0F14;  --ink-2: #151E28;  --ink-3: #243240;
  --paper: #0F151C;  --surface: #17212B;  --line: #29373F;
  --muted: #9AABBA;  --text: #E5ECF3;
  --chilli: #E04A57;  --chilli-dark: #C13845;  --chilli-soft: rgba(224,74,87,.15);
  --turmeric: #EDB04A;  --turmeric-soft: rgba(237,176,74,.15);
  --leaf: #45C48A;  --leaf-soft: rgba(69,196,138,.14);
  --rule: rgba(224,74,87,.25);
  --chart-2: #8FA3B6;  --grid: #24323D;
  --thead: #1B2732;  --mute-bg: #243240;
  --chilli-fill: rgba(224,74,87,.14);
  color-scheme: dark;

  --bs-body-color: var(--text);  --bs-body-bg: var(--paper);
  --bs-border-color: var(--line);  --bs-secondary-color: var(--muted);
  --bs-link-color: #F06B77;  --bs-link-hover-color: #FF8F99;
  --bs-primary-rgb: 224, 74, 87;  --bs-success-rgb: 69, 196, 138;
}
:root[data-bs-theme="dark"] .btn-primary,
:root[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-focus-shadow-rgb: 224,74,87; }
:root[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #fff; --bs-btn-hover-color: #fff; }
:root[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: #F06B77; --bs-btn-hover-color: #fff; }
:root[data-bs-theme="dark"] .btn-outline-success { --bs-btn-color: var(--leaf); --bs-btn-hover-color: #0F151C; }
:root[data-bs-theme="dark"] .form-control,
:root[data-bs-theme="dark"] .form-select { background-color: #101820; border-color: var(--line); color: var(--text); }
:root[data-bs-theme="dark"] .form-control::placeholder { color: #6F8192; }
:root[data-bs-theme="dark"] .input-group-text { background: var(--ink-2); border-color: var(--line); color: var(--muted); }
:root[data-bs-theme="dark"] .modal-content { background: var(--surface); }
:root[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(1) brightness(1.6); }
:root[data-bs-theme="dark"] .form-check-input:not(:checked) { background-color: #101820; border-color: #4A5C6B; }
:root[data-bs-theme="dark"] .dropdown-menu { background: var(--surface); }
:root[data-bs-theme="dark"] .pagination { --bs-pagination-bg: var(--surface); --bs-pagination-border-color: var(--line); --bs-pagination-hover-bg: var(--ink-2); --bs-pagination-disabled-bg: var(--surface); }

body { font-size: 15.5px; line-height: 1.5; }
h1, h2, h3, h4, h5, .display-num, .brand-name { font-family: 'Bricolage Grotesque', 'Mukta', sans-serif; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3, h4, h5 { font-weight: 600; }
a { text-decoration: none; }
:focus-visible { outline: 2px solid var(--chilli); outline-offset: 2px; }
.text-muted, .text-secondary { color: var(--muted) !important; }

/* ---- Bootstrap colour overrides ---- */
.btn-primary { --bs-btn-bg: var(--chilli); --bs-btn-border-color: var(--chilli); --bs-btn-hover-bg: var(--chilli-dark); --bs-btn-hover-border-color: var(--chilli-dark);
  --bs-btn-active-bg: var(--chilli-dark); --bs-btn-active-border-color: var(--chilli-dark); --bs-btn-disabled-bg: var(--chilli); --bs-btn-disabled-border-color: var(--chilli); --bs-btn-focus-shadow-rgb: 179,32,43; }
.btn-outline-primary { --bs-btn-color: var(--chilli); --bs-btn-border-color: var(--chilli); --bs-btn-hover-bg: var(--chilli); --bs-btn-hover-border-color: var(--chilli);
  --bs-btn-active-bg: var(--chilli-dark); --bs-btn-active-border-color: var(--chilli-dark); --bs-btn-focus-shadow-rgb: 179,32,43; }
.btn-success { --bs-btn-bg: var(--leaf); --bs-btn-border-color: var(--leaf); --bs-btn-hover-bg: #14603a; --bs-btn-hover-border-color: #14603a; }
.btn-outline-success { --bs-btn-color: var(--leaf); --bs-btn-border-color: var(--leaf); --bs-btn-hover-bg: var(--leaf); --bs-btn-hover-border-color: var(--leaf); }
.form-control:focus, .form-select:focus { border-color: var(--chilli); box-shadow: 0 0 0 .2rem rgba(179,32,43,.15); }
.form-check-input:checked { background-color: var(--chilli); border-color: var(--chilli); }
.form-label { font-weight: 600; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.nav-tabs { --bs-nav-tabs-link-active-color: var(--chilli); --bs-nav-link-color: var(--muted); --bs-nav-link-hover-color: var(--text); border-bottom-color: var(--line); }
.nav-tabs .nav-link { font-weight: 600; }
.nav-tabs .nav-link.active { border-color: var(--line) var(--line) var(--surface); }
.modal-content { border: 0; border-radius: 14px; }
.modal-header { border-bottom-color: var(--line); }
.modal-footer { border-top-color: var(--line); }
.table { --bs-table-bg: transparent; --bs-table-hover-bg: var(--thead); }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-weight: 600; font-size: .84rem; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--thead); }
.pagination { --bs-pagination-active-bg: var(--chilli); --bs-pagination-active-border-color: var(--chilli); --bs-pagination-color: var(--text); }

/* ---- App shell ---- */
.app-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--ink); color: #C3CEDA; overflow-y: auto; z-index: 1030; transition: transform .22s ease; }
.side-inner { display: flex; flex-direction: column; min-height: 100%; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.15rem 1.2rem 1rem; color: #fff; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--chilli); display: grid; place-items: center; font-size: 1.15rem; font-weight: 700; color: #fff; flex: none; }
.brand-name { font-size: 1.02rem; font-weight: 700; line-height: 1.15; color: #fff; }
.brand-sub { font-size: .76rem; color: #8FA0B2; }
.side-group { font-size: .78rem; color: #7F91A4; padding: 1rem 1.3rem .3rem; }
.side-link { display: flex; align-items: center; gap: .75rem; padding: .55rem 1.3rem; color: #C3CEDA; font-weight: 500; border-left: 3px solid transparent; }
.side-link i { font-size: 1.05rem; opacity: .8; width: 1.2rem; }
.side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-link.active { background: rgba(224,74,87,.20); color: #fff; border-left-color: var(--chilli); font-weight: 600; }
.side-link.active i { opacity: 1; color: #FF8C96; }
.side-foot { margin-top: auto; padding: 1rem 1.3rem; border-top: 1px solid var(--ink-3); font-size: .86rem; }
.side-foot a { color: #C3CEDA; }
.side-foot a:hover { color: #fff; }
.theme-btn { display: inline-flex; align-items: center; gap: .5rem; background: transparent; border: 1px solid var(--ink-3); color: #C3CEDA; border-radius: 8px; padding: .3rem .7rem; font-size: .86rem; }
.theme-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.theme-btn .t-sun { display: none; }
:root[data-bs-theme="dark"] .theme-btn .t-sun { display: inline; }
:root[data-bs-theme="dark"] .theme-btn .t-moon { display: none; }
.side-backdrop { display: none; }
.app-main { margin-left: var(--side-w); min-height: 100vh; }
.app-top { display: none; background: var(--ink); color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 1020; align-items: center; gap: .8rem; }
.app-top .theme-btn { margin-left: auto; padding: .3rem .55rem; }
.app-content { padding: 1.6rem 1.8rem 3rem; max-width: 1400px; }
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: none; }
  body.side-open .app-sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.45); }
  body.side-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1025; }
  .app-main { margin-left: 0; }
  .app-top { display: flex; }
  .app-content { padding: 1.1rem .9rem 3rem; }
}
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1.2rem; }
.page-head p { margin: 0; color: var(--muted); }

/* ---- Panels ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 1.05rem; }
.panel-body { padding: 1.1rem; }
.panel .table { margin-bottom: 0; }
.panel .table-responsive { border-radius: 0 0 var(--radius) var(--radius); }

/* ---- numbers ---- */
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.display-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.due { color: var(--chilli); font-weight: 600; }
.adv { color: var(--leaf); font-weight: 600; }
.zero { color: var(--muted); }
.pill { display: inline-block; padding: .12rem .6rem; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.pill-due { background: var(--chilli-soft); color: var(--chilli-dark); }
.pill-ok { background: var(--leaf-soft); color: var(--leaf); }
.pill-warn { background: var(--turmeric-soft); color: var(--turmeric); }
.pill-mute { background: var(--mute-bg); color: var(--muted); }

/* ---- Dashboard strip ---- */
.strip { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.strip > div { padding: 1.1rem 1.3rem; border-left: 1px solid var(--line); }
.strip > div:first-child { border-left: 0; }
.strip .lbl { color: var(--muted); font-size: .88rem; }
.strip .val { font-size: 1.75rem; line-height: 1.15; margin-top: .15rem; }
.strip .sub { font-size: .84rem; color: var(--muted); margin-top: .1rem; }
.strip .hot .val { color: var(--chilli); }
@media (max-width: 991.98px) {
  .strip { grid-template-columns: 1fr 1fr; }
  .strip > div:nth-child(3) { border-left: 0; }
  .strip > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .strip .val { font-size: 1.4rem; }
}

/* ---- Rate board ---- */
.rate-row { display: flex; align-items: baseline; justify-content: space-between; padding: .7rem 1.1rem; border-bottom: 1px dashed var(--line); }
.rate-row:last-child { border-bottom: 0; }
.rate-row .r { font-family: 'Bricolage Grotesque', sans-serif; font-size: 1.35rem; font-weight: 700; }
.rate-row .r small { font-size: .78rem; color: var(--muted); font-weight: 500; font-family: 'Mukta', sans-serif; }

/* ---- Ledger book (double red margin, ruled rows) ---- */
.ledger-book { border: 1px solid var(--rule); border-left: 5px double var(--chilli); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; overflow: hidden; }
.ledger-book .table { margin: 0; }
.ledger-book thead th { background: var(--chilli-soft); color: var(--chilli-dark); border-bottom: 2px solid var(--chilli); font-size: .86rem; }
.ledger-book td, .ledger-book th { border-bottom: 1px solid var(--rule); }
.ledger-book .rule { border-left: 1px solid var(--rule); }
.ledger-book tfoot td { background: var(--chilli-soft); font-weight: 700; border-top: 2px solid var(--chilli); border-bottom: 0; }
.ledger-book tbody tr:hover { background: var(--chilli-soft); }

/* ---- Bill / invoice ---- */
.invoice { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-width: 820px; margin: 0 auto; padding: 2rem 2.2rem; }
.invoice .biz { font-family: 'Bricolage Grotesque', sans-serif; font-size: 1.6rem; font-weight: 700; }
.invoice table { width: 100%; }
.invoice .lines th { border-top: 1px solid var(--text); border-bottom: 1px solid var(--text); padding: .4rem .5rem; font-size: .88rem; background: transparent; color: var(--text); }
.invoice .lines td { padding: .45rem .5rem; border-bottom: 1px dashed var(--line); }
.invoice .totals td { padding: .2rem .5rem; }
.invoice .grand td { border-top: 1px solid var(--text); border-bottom: 3px double var(--text); font-weight: 700; font-size: 1.15rem; padding: .5rem; }
@media (max-width: 575.98px) { .invoice { padding: 1.1rem; } }

/* ---- Bill form ---- */
.lines-table th { font-size: .8rem; }
.lines-table td { padding: .35rem .4rem; vertical-align: middle; }
.lines-table .form-control, .lines-table .form-select { padding: .35rem .5rem; }
.lines-table .amt { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals-box { background: var(--thead); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.totals-box .row-t { display: flex; justify-content: space-between; align-items: center; padding: .25rem 0; }
.totals-box .grand { border-top: 2px solid var(--text); margin-top: .4rem; padding-top: .55rem; font-size: 1.35rem; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; }
.party-hint { font-size: .86rem; margin-top: .25rem; }

/* ---- misc ---- */
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty i { font-size: 1.8rem; display: block; margin-bottom: .4rem; opacity: .6; }
.avatar { width: 46px; height: 46px; border-radius: 12px; background: var(--chilli-soft); color: var(--chilli-dark); display: grid; place-items: center; font-weight: 700; font-family: 'Bricolage Grotesque', sans-serif; font-size: 1.2rem; flex: none; }
.row-link { cursor: pointer; }
.chart-wrap { position: relative; height: 290px; }
.kv { display: flex; justify-content: space-between; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-art { background: var(--ink); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art .big { font-weight: 700; font-size: clamp(4.5rem, 12vw, 9.5rem); font-family: 'Bricolage Grotesque', sans-serif; letter-spacing: -.03em; line-height: .9; color: var(--chilli); opacity: .95; }
.login-form { display: grid; place-items: center; padding: 2rem; background: var(--paper); }
@media (max-width: 767.98px) { .login-wrap { grid-template-columns: 1fr; } .login-art { padding: 1.6rem; } .login-art .big { font-size: 4.5rem; } }

/* ---- Print ---- */
@media print {
  .app-sidebar, .app-top, .no-print, .btn, .pagination { display: none !important; }
  .app-main { margin: 0 !important; }
  .app-content { padding: 0 !important; max-width: none; }
  body { background: #fff; font-size: 13px; }
  .invoice, .panel, .ledger-book { border: 0 !important; }
  .invoice { padding: 0; max-width: none; }
  .ledger-book { border-left: 5px double #000 !important; }
  a { color: inherit; }
}

@media (prefers-reduced-motion: reduce) { .app-sidebar { transition: none; } }
