/* =============================================================================
   PXBilling — app.css
   "Private-banking ledger" design system.
   Signature: every monetary figure is set in a tabular monospace face, and
   the three regions (Asia / EU / Americas) carry functional accent colors.
   ========================================================================== */

:root {
  /* Brand + neutrals */
  --ink:        #0F1729;   /* sidebar, primary text          */
  --ink-soft:   #1B2536;
  --canvas:     #F6F7F9;   /* app background (cool paper)     */
  --surface:    #FFFFFF;
  --surface-2:  #FBFBFC;
  --line:       #E7E9EE;   /* hairline borders               */
  --line-strong:#D8DCE3;
  --text:       #131B2B;
  --muted:      #5B6472;
  --faint:      #8A93A6;

  /* Brand accents — used with restraint */
  --jade:       #0B7A6B;
  --jade-deep:  #086153;
  --jade-tint:  #E6F3F0;
  --gold:       #C8922A;
  --gold-tint:  #F8EFD9;

  /* Region accents — functional, only in tags + charts */
  --asia:       #E0533D;
  --eu:         #2E6BD6;
  --americas:   #7C5CE0;

  /* Status */
  --paid:       #0B7A6B;
  --pending:    #C8922A;
  --overdue:    #D14343;
  --draft:      #8A93A6;

  --radius:     14px;
  --radius-sm:  9px;
  --shadow:     0 1px 2px rgba(15,23,41,.04), 0 8px 24px rgba(15,23,41,.06);
  --shadow-lg:  0 24px 60px rgba(15,23,41,.18);

  --font-ui:   "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-num:  "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.num { font-family: var(--font-num); font-feature-settings: "tnum" 1; letter-spacing: -.01em; }

/* ============================== Layout ================================== */

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  color: #C5CCDA;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 22px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(150deg, var(--jade), var(--jade-deep));
  color: #fff; font-weight: 800; font-size: 15px;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.brand-name { color: #fff; font-weight: 700; letter-spacing: -.01em; font-size: 16px; }
.brand-name span { color: var(--gold); }
.brand-sub { font-size: 11px; color: #7C8699; letter-spacing: .06em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav-label {
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: #59647A; padding: 16px 12px 7px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 9px; color: #AEB7C7;
  font-weight: 500; font-size: 13.5px; position: relative;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: rgba(11,122,107,.16); color: #fff; }
.nav-item.active::before {
  content: ""; position: absolute; left: -16px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--jade);
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .9; }

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.07); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(150deg,#2E3A52,#1B2536);
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.side-user .meta { line-height: 1.2; }
.side-user .meta b { color: #fff; font-size: 13px; font-weight: 600; }
.side-user .meta small { color: #7C8699; font-size: 11px; }

/* ============================== Topbar ================================= */

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 30px; background: var(--canvas);
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.topbar .spacer { flex: 1; }

.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  width: 240px; color: var(--faint);
}
.search input { border: 0; outline: 0; background: none; width: 100%; font-size: 13.5px; color: var(--text); }
.search svg { width: 16px; height: 16px; flex: none; }

.select {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--text);
  font-family: var(--font-ui); outline: none;
}
.select:focus-visible { border-color: var(--jade); box-shadow: 0 0 0 3px var(--jade-tint); }

.content { padding: 26px 30px 60px; }

/* ============================== Buttons =============================== */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: var(--jade); border-color: var(--jade); color: #fff;
  box-shadow: 0 1px 2px rgba(11,122,107,.25), 0 6px 16px rgba(11,122,107,.18);
}
.btn-primary:hover { background: var(--jade-deep); border-color: var(--jade-deep); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-danger { color: var(--overdue); border-color: var(--line); }
.btn-danger:hover { background: #FCEDED; border-color: #F3CACA; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--jade-tint); }

/* ============================== Cards ================================= */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

.grid { display: grid; gap: 18px; }

/* KPI strip ------------------------------------------------------------ */
.kpis { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600;
  letter-spacing: .02em; display: flex; align-items: center; gap: 7px; }
.kpi .icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.kpi .icon svg { width: 15px; height: 15px; }
.kpi .value { font-size: 27px; font-weight: 700; margin-top: 10px; color: var(--ink);
  letter-spacing: -.02em; }
.kpi .delta { font-size: 12px; margin-top: 5px; color: var(--muted); }
.kpi .delta b { color: var(--jade); font-weight: 700; }
.kpi .delta b.down { color: var(--overdue); }

/* ============================== Badges =============================== */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  letter-spacing: .01em; line-height: 1.6;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid    { color: var(--paid);    background: var(--jade-tint); }
.badge-pending { color: #9A6E12;        background: var(--gold-tint); }
.badge-overdue { color: var(--overdue); background: #FCEDED; }
.badge-draft   { color: #5C657A;        background: #EEF0F4; }

.region-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--text);
}
.region-tag .swatch { width: 8px; height: 8px; border-radius: 2px; }

/* ============================== Tables =============================== */

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); font-weight: 700; padding: 11px 18px; border-bottom: 1px solid var(--line);
}
.table th.right, .table td.right { text-align: right; }
.table td { padding: 13px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .primary { font-weight: 600; color: var(--ink); }
.table .muted { color: var(--muted); font-size: 12.5px; }
.row-click { cursor: pointer; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

.client-cell { display: flex; align-items: center; gap: 11px; }
.client-avatar {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff;
}

/* ============================== Charts =============================== */

.chart-wrap { padding: 8px 4px 0; }
.bar-track { fill: var(--line); }
.bar-fill { transition: height .6s cubic-bezier(.2,.7,.2,1), y .6s cubic-bezier(.2,.7,.2,1); }
.axis-label { font-family: var(--font-num); font-size: 10px; fill: var(--faint); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 4px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend-item b { color: var(--ink); font-family: var(--font-num); }

.region-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.region-row .name { width: 92px; font-weight: 600; font-size: 13px; }
.region-row .meter { flex: 1; height: 9px; border-radius: 6px; background: var(--line); overflow: hidden; }
.region-row .meter span { display: block; height: 100%; border-radius: 6px;
  transition: width .7s cubic-bezier(.2,.7,.2,1); }
.region-row .amt { width: 116px; text-align: right; font-size: 13px; color: var(--ink); }

/* ============================== Forms =============================== */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.input, .textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-size: 14px; font-family: var(--font-ui); color: var(--text); background: var(--surface);
  outline: none; width: 100%; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus { border-color: var(--jade); box-shadow: 0 0 0 3px var(--jade-tint); }
.input.num { font-family: var(--font-num); }
.textarea { resize: vertical; min-height: 72px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 11.5px; color: var(--faint); }

/* ============================== Modal =============================== */

.overlay {
  position: fixed; inset: 0; background: rgba(15,23,41,.42);
  backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 100;
  padding: 24px; animation: fade .15s ease;
}
.modal {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  animation: pop .18s cubic-bezier(.2,.8,.2,1);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 22px; border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 18px 18px; position: sticky; bottom: 0; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

/* Line-item editor ----------------------------------------------------- */
.litem { display: grid; grid-template-columns: 1fr 70px 110px 110px 32px; gap: 8px; align-items: center;
  margin-bottom: 8px; }
.litem .head { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); font-weight: 700; }
.litem .total { text-align: right; font-family: var(--font-num); font-weight: 600; padding-right: 4px; }
.li-remove { color: var(--faint); border: 0; background: none; padding: 4px; border-radius: 7px; }
.li-remove:hover { color: var(--overdue); background: #FCEDED; }

.totals-box { margin-top: 14px; border-top: 1px dashed var(--line-strong); padding-top: 14px; }
.totals-row { display: flex; justify-content: space-between; padding: 5px 0; color: var(--muted); font-size: 13.5px; }
.totals-row.grand { color: var(--ink); font-weight: 700; font-size: 17px; padding-top: 10px;
  border-top: 1px solid var(--line); margin-top: 6px; }
.totals-row .num { font-weight: 600; }

/* ============================== Invoice view ========================= */

.invoice-doc {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 40px; max-width: 760px; margin: 0 auto; box-shadow: var(--shadow);
}
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 34px; }
.inv-from b { display: block; font-size: 17px; }
.inv-from span { color: var(--muted); font-size: 13px; }
.inv-meta { text-align: right; }
.inv-meta .num { font-size: 22px; font-weight: 700; color: var(--ink); }
.inv-meta .row { color: var(--muted); font-size: 13px; margin-top: 3px; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 28px; }
.inv-parties .lbl { font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); font-weight: 700; margin-bottom: 6px; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.inv-table th { text-align: left; font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
  color: var(--faint); padding: 10px 0; border-bottom: 2px solid var(--ink); }
.inv-table th.right, .inv-table td.right { text-align: right; }
.inv-table td { padding: 12px 0; border-bottom: 1px solid var(--line); }
.inv-foot-note { margin-top: 26px; color: var(--muted); font-size: 12.5px;
  border-top: 1px solid var(--line); padding-top: 16px; }

/* ============================== Empty / misc ======================== */

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--line-strong); margin-bottom: 12px; }
.empty h3 { color: var(--text); margin: 0 0 4px; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 7px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200;
  display: flex; align-items: center; gap: 9px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 16px; height: 16px; color: var(--jade); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ============================== Responsive ========================== */

.menu-toggle { display: none; }
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; width: 252px;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(15,23,41,.4); z-index: 50; }
  .app.nav-open .scrim { display: block; }
  .menu-toggle { display: grid; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 14px 18px; }
  .content { padding: 18px; }
  .search { width: 150px; }
}
@media (max-width: 620px) {
  .kpis { grid-template-columns: 1fr; }
  .field-row, .inv-parties { grid-template-columns: 1fr; }
  .topbar .sub { display: none; }
  .hide-sm { display: none; }
  .litem { grid-template-columns: 1fr 50px 90px; }
  .litem .li-head-price, .litem .total, .litem .li-remove { display: none; }
}

/* Accessibility ------------------------------------------------------- */
:focus-visible { outline: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================== Print =============================== */
@media print {
  .sidebar, .topbar, .no-print, .scrim { display: none !important; }
  .app { display: block; }
  .content { padding: 0; }
  .invoice-doc { border: 0; box-shadow: none; max-width: none; padding: 0; }
  body { background: #fff; }
}
