/*
 * Kite Bill — one calm, standard look (front office and back office).
 *
 * One accent colour (indigo) for the main button, links and the active menu item. Text, amounts and headings use the
 * normal text colour and one font (tabular figures for money). Colour is kept only where it carries meaning: small
 * icons, status badges (paid / unpaid / overdue) and alerts. Buttons other than the main one are plain outlines.
 */

/* ---------------------------------------------------------------- palette */
:root, html.dark, html.medium, html.light {
  --mbb-purple-gradient: var(--mbb-purple);
  --kt-accent: #6366f1;
  --kt-accent-soft: rgba(99, 102, 241, .14);
}
html.light { --kt-accent: #4f46e5; --kt-accent-soft: rgba(79, 70, 229, .1); }

/* ---------------------------------------------------------------- figures: one font, one colour */
.mbb-main .metric-val,
.mbb-main .num-dr, .mbb-main .num-cr,
.mbb-main [style*="JetBrains Mono"]:not(.kbg-mono),
.mbb-main td[style*="font-family"], .mbb-main strong[style*="font-family"],
.mbb-main table td, .mbb-main table td * {
  font-family: inherit !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0 !important;
}
.mbb-main .metric-val, .mbb-main .num-dr, .mbb-main .num-cr { color: var(--text) !important; font-weight: 800 !important; }

/* coloured words inside the screens (invoice nos., amounts, prices, stock) → normal text; badges and chips keep theirs */
.mbb-main :is(strong, b, span, div, td, p, h3, h4)[style*="color: #"]:not([class*="badge"]):not([class*="chip"]):not([style*="background"]):not(.metric-icon-box),
.mbb-main :is(strong, b, span, div, td, p, h3, h4)[style*="color:#"]:not([class*="badge"]):not([class*="chip"]):not([style*="background"]):not(.metric-icon-box),
.mbb-main :is(strong, b, span, div, td)[style*="color: var(--mbb-green)"]:not([style*="background"]),
.mbb-main :is(strong, b, span, div, td)[style*="color: var(--mbb-red)"]:not([style*="background"]),
.mbb-main :is(strong, b, span, div, td)[style*="color: var(--mbb-amber)"]:not([style*="background"]),
.mbb-main :is(strong, b, span, div, td)[style*="color: var(--mbb-blue)"]:not([style*="background"]) {
  color: var(--text) !important;
}
/* links stay the one accent */
.mbb-main a[style*="color"]:not(.btn):not([class*="badge"]) { color: var(--kt-accent) !important; }

/* ---------------------------------------------------------------- cards: no coloured edges */
.mbb-main .metric-card[style*="border-left"],
.mbb-main .card[style*="border-left"],
.mbb-main [class*="card"][style*="border-color: #"],
.mbb-main [class*="card"][style*="border: 1px solid rgba(245"] {
  border: 1px solid var(--card-border) !important;
}

/* ---------------------------------------------------------------- buttons: one filled accent, the rest plain */
.btn-primary, .mbb-quick-create-btn, .sidebar-create-bill-btn {
  background: var(--kt-accent) !important; border-color: var(--kt-accent) !important; color: #fff !important; box-shadow: none !important;
}
.btn-primary:hover, .sidebar-create-bill-btn:hover { filter: brightness(1.08); }
.mbb-main .table-btn[style*="color"], .mbb-main .table-btn[style*="border-color"],
.mbb-main .btn-secondary[style*="color"], .mbb-main .btn-secondary[style*="border"],
.mbb-main .btn:not(.btn-primary):not(.btn-danger)[style*="color"],
.mbb-main button[style*="border-color: #"]:not(.btn-primary),
.mbb-main button[style*="color: #"]:not(.btn-primary):not([class*="badge"]) {
  color: var(--text) !important; border-color: var(--card-border) !important; background: transparent !important; box-shadow: none !important;
}
.mbb-main .table-btn:hover, .mbb-main .btn-secondary:hover { background: rgba(148, 163, 184, .12) !important; }
/* the few number badges on buttons (held bills) keep a small amber dot */
.mbb-main button [id$="HeldCount"], .mbb-main button [id$="HeldBadge"] { color: #f59e0b !important; }

/* ---------------------------------------------------------------- menu and top bar */
.mbb-nav-item.active { color: var(--mbb-sidebar-active-text, #fff) !important; background: var(--kt-accent-soft) !important; box-shadow: inset 3px 0 0 var(--kt-accent) !important; }
.mbb-section-label, .kbp-grp-h { color: var(--text-muted) !important; }
.kb-top .kb-branch-tag { color: var(--text-muted) !important; background: rgba(148, 163, 184, .14) !important; }
.kbp-hubtabs button.on, .kbp-hubtabs button.active { background: var(--kt-accent) !important; color: #fff !important; }

/* ---------------------------------------------------------------- back office (same rules) */
.app-shell .content-area :is(h1, h2, h3) { color: var(--text, #e5e7eb); }
.app-shell .nav-item.active { color: var(--text, #e5e7eb) !important; background: rgba(99, 102, 241, .14) !important; border-left-color: #6366f1 !important; box-shadow: inset 3px 0 0 #6366f1 !important; }
.app-shell .nav-item.active .nav-symbol { color: #a5b4fc !important; }
.app-shell .btn.primary, .app-shell .btn.green, .app-shell .btn.outline-green:hover { background: #6366f1 !important; border-color: #6366f1 !important; color: #fff !important; box-shadow: none !important; }
.app-shell .btn.outline-green { color: inherit !important; border-color: var(--card-border) !important; background: transparent !important; }
.app-shell .kpi-val, .app-shell .stat-value, .app-shell .kpi-value, .app-shell [class*="stat"] [style*="color"] { color: var(--text, #e5e7eb) !important; font-family: inherit !important; font-variant-numeric: tabular-nums; }
.kb-top .kb-sync { color: var(--muted, #94a3b8) !important; }

/* ---------------------------------------------------------------- Unified Invoice Studio & Modal Aesthetics */
#modalInvoice .modal-box {
  background: var(--card-bg, #0b1120) !important;
  border: 1px solid var(--card-border, #1e293b) !important;
}

#modalInvoice .modal-box-header {
  background: var(--card-inner, #0f172a) !important;
  border-bottom: 1px solid var(--card-border, #1e293b) !important;
}

#modalInvoice .modal-box-footer {
  background: var(--card-inner, #0f172a) !important;
  border-top: 1px solid var(--card-border, #1e293b) !important;
}

#modalInvoice input:focus,
#modalInvoice select:focus,
#modalInvoice textarea:focus {
  border-color: var(--kt-accent) !important;
  box-shadow: 0 0 0 2px var(--kt-accent-soft) !important;
  outline: none !important;
}

#modalInvoice .inv-item-margin {
  color: var(--kt-accent) !important;
  background: var(--kt-accent-soft) !important;
  border-color: rgba(99, 102, 241, 0.3) !important;
}

/* Responsive Studio Behavior for Screens <= 900px */
@media (max-width: 900px) {
  #modalInvoice .modal-box {
    width: 98vw !important;
    max-width: 98vw !important;
    height: 96vh !important;
    max-height: 96vh !important;
    margin: 2vh auto !important;
  }

  .inv-meta-grid,
  #modalInvoice .modal-box-body > div[style*="grid-template-columns: 1.45fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
    padding: 1rem !important;
  }

  .inv-bottom-settlement-grid,
  #modalInvoice .modal-box-body > div[style*="grid-template-columns: 1fr 340px"] {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .inv-paymode-selector,
  #modalInvoice .modal-box-body div[style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
}

/* Deep Mobile Responsiveness for Phones <= 768px */
@media (max-width: 768px) {
  #modalInvoice .modal-box,
  #modalInvoicePreview .modal-box,
  #modalItem .modal-box,
  #modalParty .modal-box,
  #modalPurchase .modal-box {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
  }

  #modalInvoice .modal-box-header,
  #modalInvoice .modal-box-footer {
    padding: 0.75rem 1rem !important;
  }

  #modalInvoice .modal-box-body {
    padding: 1rem !important;
  }

  .inv-items-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 0.75rem !important;
  }

  .inv-paymode-selector {
    grid-template-columns: 1fr 1fr !important;
  }

  #invItemQuickSearchWrapper {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  #invItemQuickSearchWrapper > div {
    min-width: 100% !important;
  }

  #invItemQuickSearchWrapper button {
    width: 100% !important;
    justify-content: center !important;
  }

  #modalInvoice .modal-box-footer {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  #modalInvoice .modal-box-footer .btn {
    flex: 1 1 calc(50% - 8px) !important;
    justify-content: center !important;
    text-align: center !important;
  }

  #modalInvoice .modal-box-footer .btn-primary {
    flex: 1 1 100% !important;
  }
}

/* ---- layout polish: top bar, dashboard cards, floating buttons (all screen widths) ---- */
.mbb-header.kb-top .kb-right{flex-wrap:nowrap;white-space:nowrap}
.kb-top #kiteBillConnectPill{flex:0 0 auto;height:28px!important}
@media (max-width:1100px){.kb-top #kiteBillConnectPill>span:nth-child(2){display:none}.kb-top #kiteBillConnectPill{padding:0 .5rem!important}}
/* the calculator button sits at the bottom right so it never covers the side menu */
.kx-fab{left:auto!important;right:16px!important;bottom:16px!important}
/* dashboard cards: four in a row on a wide window, two and two on a tablet or phone (never one orphan) */
@media (min-width:641px) and (max-width:1100px){.metrics-row{grid-template-columns:repeat(2,minmax(0,1fr))!important}}
@media (max-width:640px){
  .metrics-row{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:.6rem!important}
  .metrics-row .metric-card{padding:.7rem .75rem!important}
  .metrics-row .metric-card [class*=value],.metrics-row .metric-card .metric-value{font-size:1.2rem!important}
  .metrics-row .metric-label{font-size:.62rem!important}
}
/* tables scroll inside their card instead of cutting off */
.table-scroll{overflow-x:auto;-webkit-overflow-scrolling:touch}

/* ---- phone ---- */
@media (max-width:640px){
  /* top bar: the shop name box stays, the extra chips go (they have no room) */
  .kb-top #kiteGuardSecBadge,.kb-top #kiteBillConnectPill{display:none!important}
  /* floating buttons small and above the bottom edge so they do not sit on the content */
  .kx-fab{display:none!important}
  .kb-top .kb-cmd-name{inset:0 .5rem 0 1.7rem!important;justify-content:flex-start!important;overflow:hidden;text-overflow:ellipsis;display:block!important;line-height:26px}
  /* report window buttons wrap instead of running off the screen */
  #modalReportView .modal-box-footer,#modalReportView .modal-box-footer>div{display:flex!important;flex-wrap:wrap!important;gap:.4rem!important;width:100%}
  #modalReportView .modal-box-footer .btn{flex:1 1 calc(50% - .4rem);min-width:0;white-space:normal;justify-content:center}
  /* sales panel (POS) bar: the title goes, the Retail / Wholesale switch gets the full width */
  .ksp-bar{flex-wrap:wrap!important;gap:.5rem!important}
  .ksp-bar-title{display:none!important}
  .ksp-bar-mid{width:100%;flex-wrap:wrap}.ksp-seg{width:100%;max-width:100%}
  .ksp-seg-btn{font-size:.7rem!important}
  .ksp-seg-btn{flex:1 1 0;justify-content:center;min-width:0;padding:.35rem .3rem!important}
}

/* the calculator button hides while a window is open (it sat on the Save buttons) */
body:has(.modal-overlay.open) .kx-fab{display:none!important}
@media (max-width:640px){
  /* the customer box and its list stay inside the window */
  #modalInvoice .modal-box-body div:has(>#invPartyInputWrapper),#modalInvoice #invPartyInputWrapper{min-width:0!important;max-width:100%!important;width:100%!important}
  #modalInvoice .modal-box-body :has(>label>#invPartyInputWrapper),#modalInvoice .modal-box-body div:has(>#invPartyInputWrapper){grid-column:1/-1}
  #invPartyAutocompleteDropdown{left:0!important;right:0!important;width:auto!important;max-width:100%!important}
  #invPartyAutocompleteDropdown .autocomplete-item{flex-wrap:wrap;gap:.25rem}
  #invPartySearchInput{font-size:.9rem!important;text-overflow:ellipsis}
}
@media (max-width:760px){.inv-meta-grid{grid-template-columns:minmax(0,1fr)!important;padding:.8rem!important}.inv-meta-grid>*{min-width:0}}
@media (max-width:760px){.inv-meta-grid [style*="grid-template-columns"]{grid-template-columns:repeat(2,minmax(0,1fr))!important}.inv-meta-grid select,.inv-meta-grid input{max-width:100%;min-width:0}}
@media (max-width:760px){#modalInvoice .inv-meta-grid div[style*="grid-template-columns"]{grid-template-columns:repeat(2,minmax(0,1fr))!important}#modalInvoice .inv-meta-grid div[style*="grid-template-columns"]>div{min-width:0}}

/* Kite Bill: no festive garland strip under the top bar (the corner drawing at the bottom stays, still) */
.mbb-header::after, .pos-header::after, .hd::after, body > header::after { content: none !important; display: none !important; }
#kiteFestArt svg { animation: none !important; }
