/* =========================================================================
   REDLINE24 BILLING — APPLICATION CHROME
   Sidebar, topbar, cards, tables, forms, editor split.
   Document styles live in document.css and are the only thing that prints.
   ========================================================================= */

:root{
  --red:#E5251B; --red-ink:#C70001; --red-deep:#810016; --red-soft:#FDF0EF;
  --paper:#FBFAF8; --white:#fff; --ink:#17161A; --ink-2:#3B383F;
  --n-50:#FAF9F7; --n-100:#F4F2EF; --n-150:#EDEAE5; --n-200:#E4E0DA;
  --n-300:#D3CEC6; --n-400:#AEA9A0; --n-500:#847F76; --n-600:#605C56;
  --rule:rgba(23,22,26,.09); --rule-2:rgba(23,22,26,.14);
  --ok:#177245; --ok-bg:#E9F5EE; --warn:#8A5A00; --warn-bg:#FBF2E1;
  --info:#1F4E79; --info-bg:#EAF1F8;
  --font:"Space Grotesk","Helvetica Neue",Arial,sans-serif;
  --rail-w:246px; --top-h:66px;
  --r-sm:8px; --r:11px; --r-lg:16px; --r-pill:999px;
  --sh-sm:0 1px 2px rgba(23,22,26,.05);
  --sh:0 1px 2px rgba(23,22,26,.05),0 8px 24px -12px rgba(23,22,26,.16);
  --sh-lg:0 24px 60px -24px rgba(23,22,26,.28),0 2px 6px rgba(23,22,26,.06);
  --ease:cubic-bezier(.2,.7,.3,1);
}

*,*::before,*::after{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font-family:var(--font); background:var(--n-100); color:var(--ink);
  font-size:14px; line-height:1.55; letter-spacing:-.004em;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,p,dl,dd{margin:0}
button,input,select,textarea{font:inherit;color:inherit}
svg{width:1em;height:1em;fill:none;stroke:currentColor;stroke-width:1.6;
    stroke-linecap:round;stroke-linejoin:round}
a{color:inherit;text-decoration:none}

/* ---------------------------------------------------------------- SIDEBAR */
.rail{
  position:fixed; inset:0 auto 0 0; width:var(--rail-w); z-index:40;
  display:flex; flex-direction:column; background:var(--white);
  border-right:1px solid var(--rule); padding:22px 14px 16px;
}
.rail-brand{display:block; padding:0 8px 22px}
.rail-brand img{display:block;height:auto}
.rail-brand-sub{
  display:block; margin-top:7px; font-size:11px; font-weight:500;
  letter-spacing:.13em; text-transform:uppercase; color:var(--n-500);
}
.rail-nav{display:flex;flex-direction:column;gap:2px}
.rail-link{
  display:flex; align-items:center; gap:11px; min-height:44px; padding:0 12px;
  border-radius:var(--r); font-size:14px; font-weight:500; color:var(--ink-2);
  transition:background .16s var(--ease),color .16s var(--ease);
}
.rail-link svg{width:18px;height:18px;flex:none;color:var(--n-500);transition:color .16s}
.rail-link:hover{background:var(--n-100)}
.rail-link.is-on{background:var(--red-soft);color:var(--red-ink);font-weight:600}
.rail-link.is-on svg{color:var(--red)}
.rail-foot{margin-top:auto;padding-top:18px}
.rail-note{
  margin-top:12px;text-align:center;font-size:11.5px;color:var(--n-500);
}
.rail-note b{font-weight:600;color:var(--n-600)}

/* ------------------------------------------------------------------- MAIN */
.main{margin-left:var(--rail-w);min-height:100%;display:flex;flex-direction:column}
.topbar{
  position:sticky; top:0; z-index:30; height:var(--top-h); flex:none;
  display:flex; align-items:center; gap:14px; padding:0 28px;
  background:rgba(251,250,248,.88); backdrop-filter:blur(12px);
  border-bottom:1px solid var(--rule);
}
.topbar-head{min-width:0}
.topbar-title{font-size:19px;font-weight:600;letter-spacing:-.02em;line-height:1.2;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.topbar-sub{font-size:12.5px;color:var(--n-500);line-height:1.3}
.topbar-actions{margin-left:auto;display:flex;align-items:center;gap:8px}
.pad{padding:26px 28px 60px}
.pad-narrow{max-width:940px}

/* ---------------------------------------------------------------- BUTTONS */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  min-height:38px; padding:0 15px; border:1px solid transparent;
  border-radius:var(--r); background:var(--n-100); color:var(--ink);
  font-size:13.5px; font-weight:500; cursor:pointer; white-space:nowrap;
  transition:background .16s var(--ease),border-color .16s,box-shadow .16s,transform .1s;
}
.btn svg{width:16px;height:16px}
.btn:hover{background:var(--n-150)}
.btn:active{transform:translateY(.5px)}
.btn-primary{background:var(--red);color:#fff;box-shadow:0 1px 2px rgba(129,0,22,.28)}
.btn-primary:hover{background:var(--red-deep)}
.btn-ghost{background:var(--white);border-color:var(--n-200);box-shadow:var(--sh-sm)}
.btn-ghost:hover{background:var(--white);border-color:var(--n-300)}
.btn-danger-ghost{background:var(--white);border-color:var(--n-200);color:var(--red-ink)}
.btn-danger-ghost:hover{background:var(--red-soft);border-color:#F3C9C6}
.btn-block{width:100%}
.btn-sm{min-height:34px;padding:0 12px;font-size:13px}
.btn-row{display:flex;flex-wrap:wrap;gap:8px}
.icon-btn{
  display:inline-flex;align-items:center;justify-content:center;
  width:38px;height:38px;border:1px solid transparent;border-radius:var(--r);
  background:transparent;color:var(--n-600);cursor:pointer;transition:background .16s;
}
.icon-btn svg{width:17px;height:17px}
.icon-btn:hover{background:var(--n-150);color:var(--ink)}
.link{color:var(--red-ink);font-weight:500;font-size:13.5px}
.link:hover{text-decoration:underline}
.only-mobile{display:none}

/* ------------------------------------------------------------------ CARDS */
.card{
  background:var(--white); border:1px solid var(--rule); border-radius:var(--r-lg);
  box-shadow:var(--sh-sm); margin-bottom:20px; overflow:hidden;
}
.card-head{
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
  padding:16px 20px; border-bottom:1px solid var(--rule);
}
.card-title{font-size:15px;font-weight:600;letter-spacing:-.015em}
.card-head .link,.card-head .btn{margin-left:auto}
.card-head .search{margin-left:auto}
.card-hint{padding:14px 20px;font-size:12.5px;color:var(--n-500);border-top:1px solid var(--rule)}
.card>.grid-2,.card>.grid-4,.card>.f,.card>.btn-row{padding:20px}
.card>.btn-row{padding-top:4px}
.card-danger{border-color:#EFDBD9}

/* ------------------------------------------------------------------ STATS */
.stat-row{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-bottom:20px}
.stat{
  background:var(--white);border:1px solid var(--rule);border-radius:var(--r-lg);
  padding:16px 18px;box-shadow:var(--sh-sm);
}
.stat-k{font-size:12px;font-weight:500;color:var(--n-500);letter-spacing:.02em}
.stat-v{margin-top:6px;font-size:25px;font-weight:600;letter-spacing:-.03em;line-height:1.1}
.stat-v small{font-size:13px;font-weight:500;color:var(--n-500);margin-left:3px;letter-spacing:0}
.stat-sub{margin-top:3px;font-size:12px;color:var(--n-500)}

/* ------------------------------------------------------------------ TABLE */
.tbl{width:100%;border-collapse:collapse}
.tbl th{
  padding:10px 20px; text-align:left; font-size:11px; font-weight:600;
  letter-spacing:.07em; text-transform:uppercase; color:var(--n-500);
  background:var(--n-50); border-bottom:1px solid var(--rule);
}
.tbl td{padding:13px 20px;border-bottom:1px solid var(--rule);vertical-align:middle}
.tbl tr:last-child td{border-bottom:0}
.tbl tbody tr{cursor:pointer;transition:background .13s}
.tbl tbody tr:hover{background:var(--n-50)}
.tbl .r{text-align:right;font-variant-numeric:tabular-nums}
.t-strong{font-weight:600}
.t-mut{color:var(--n-500);font-size:12.5px}
.t-num{font-variant-numeric:tabular-nums}
.row-actions{display:flex;gap:2px;justify-content:flex-end;opacity:0;transition:opacity .15s}
.tbl tr:hover .row-actions{opacity:1}
.row-actions .icon-btn{width:32px;height:32px}
.row-actions .icon-btn svg{width:15px;height:15px}

.chip{
  display:inline-flex;align-items:center;gap:5px;height:23px;padding:0 9px;
  border-radius:var(--r-pill);font-size:11.5px;font-weight:600;letter-spacing:.01em;
}
.chip::before{content:"";width:5px;height:5px;border-radius:50%;background:currentColor}
.chip-draft{background:var(--n-150);color:var(--n-600)}
.chip-sent{background:var(--info-bg);color:var(--info)}
.chip-accepted{background:var(--ok-bg);color:var(--ok)}
.chip-paid{background:var(--ok-bg);color:var(--ok)}
.chip-quotation{background:var(--n-150);color:var(--n-600)}
.chip-invoice{background:var(--red-soft);color:var(--red-ink)}
.chip-proforma{background:var(--warn-bg);color:var(--warn)}

/* ------------------------------------------------------------ SEG + SEARCH */
.seg{display:inline-flex;gap:2px;padding:3px;background:var(--n-100);border-radius:var(--r)}
.seg-btn{
  min-height:30px;padding:0 12px;border:0;border-radius:8px;background:transparent;
  font-size:13px;font-weight:500;color:var(--n-600);cursor:pointer;transition:.15s;
}
.seg-btn:hover{color:var(--ink)}
.seg-btn.is-on{background:var(--white);color:var(--ink);box-shadow:var(--sh-sm);font-weight:600}
.search{position:relative;display:flex;align-items:center}
.search svg{position:absolute;left:11px;width:15px;height:15px;color:var(--n-400)}
.search input{
  width:240px;height:38px;padding:0 12px 0 33px;border:1px solid var(--n-200);
  border-radius:var(--r);background:var(--white);font-size:13.5px;
}
.search input:focus{outline:0;border-color:var(--n-400);box-shadow:0 0 0 3px var(--n-150)}

/* ------------------------------------------------------------------ EMPTY */
.empty{padding:56px 20px 62px;text-align:center}
.empty svg{width:40px;height:40px;color:var(--n-300);stroke-width:1.3}
.empty-title{margin-top:14px;font-size:15px;font-weight:600}
.empty-sub{margin-top:4px;font-size:13px;color:var(--n-500)}

/* ------------------------------------------------------------------ FORMS */
.f{display:block;margin-bottom:16px}
.f-lbl{display:block;margin-bottom:6px;font-size:12.5px;font-weight:500;color:var(--n-600)}
.f input,.f select,.f textarea{
  width:100%;min-height:40px;padding:9px 12px;border:1px solid var(--n-200);
  border-radius:var(--r);background:var(--white);font-size:13.5px;
  transition:border-color .15s,box-shadow .15s;
}
.f textarea{min-height:auto;resize:vertical;line-height:1.6}
.f select{
  appearance:none;padding-right:32px;cursor:pointer;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M6 8l4 4 4-4' fill='none' stroke='%23847F76' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat:no-repeat;background-position:right 9px center;background-size:18px;
}
.f input:focus,.f select:focus,.f textarea:focus{
  outline:0;border-color:var(--red);box-shadow:0 0 0 3px var(--red-soft);
}
.f input::placeholder,.f textarea::placeholder{color:var(--n-400)}
.f-check{display:flex;align-items:center;gap:9px;min-height:36px;margin-bottom:8px;cursor:pointer}
.f-check input{width:17px;height:17px;min-height:0;margin:0;accent-color:var(--red);cursor:pointer}
.f-check span{font-size:13.5px}
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:0 16px}
.grid-4{display:grid;grid-template-columns:repeat(4,1fr);gap:0 14px}
.f-wide{grid-column:1/-1}
.input-pair{display:flex;gap:8px}
.input-pair input{flex:1}
.input-pair select{width:104px;flex:none}

/* ----------------------------------------------------------------- EDITOR */
.view-editor{flex:1;min-height:0}
.split{display:grid;grid-template-columns:minmax(430px,1fr) minmax(520px,1.12fr);
  height:calc(100vh - var(--top-h))}
.form-pane{overflow-y:auto;padding:24px 26px;background:var(--white);
  border-right:1px solid var(--rule);scrollbar-width:thin}
.fset{padding-bottom:22px;margin-bottom:22px;border-bottom:1px solid var(--rule)}
.fset:last-of-type{border-bottom:0}
.fset-head{display:flex;align-items:center;gap:10px;margin-bottom:14px}
.fset-title{font-size:12px;font-weight:600;letter-spacing:.09em;text-transform:uppercase;
  color:var(--n-500);margin-bottom:14px}
.fset-head .fset-title{margin-bottom:0}
.fset-note{margin-left:auto;font-size:12px;color:var(--n-500);font-variant-numeric:tabular-nums}
.fset-spacer{height:40px}

/* ---- line item cards ---- */
.lines{display:flex;flex-direction:column;gap:10px;margin-bottom:12px}
.line{
  position:relative;border:1px solid var(--n-200);border-radius:var(--r-lg);
  background:var(--n-50);padding:12px 12px 12px 34px;transition:border-color .15s,background .15s;
}
.line:focus-within{border-color:var(--n-300);background:var(--white);box-shadow:var(--sh-sm)}
.line-n{
  position:absolute;left:11px;top:14px;width:18px;height:18px;border-radius:6px;
  background:var(--n-150);color:var(--n-600);font-size:11px;font-weight:600;
  display:flex;align-items:center;justify-content:center;font-variant-numeric:tabular-nums;
}
.line-x{position:absolute;right:8px;top:8px;width:28px;height:28px}
.line-x svg{width:14px;height:14px}
.line .f{margin-bottom:9px}
.line .f:last-child{margin-bottom:0}
.line-grid{display:grid;grid-template-columns:76px 84px 1fr 74px;gap:0 9px}
.line-amt{
  display:flex;align-items:baseline;justify-content:flex-end;gap:6px;
  padding-top:9px;margin-top:2px;border-top:1px dashed var(--n-200);
  font-size:13px;font-variant-numeric:tabular-nums;
}
.line-amt b{font-weight:600}
.line-amt span{color:var(--n-500);font-size:12px}

/* ---- mini totals ---- */
.totals-mini{border:1px solid var(--n-200);border-radius:var(--r-lg);
  background:var(--n-50);padding:12px 14px}
.totals-mini div{display:flex;justify-content:space-between;gap:16px;
  padding:4px 0;font-size:13px;font-variant-numeric:tabular-nums}
.totals-mini div span:first-child{color:var(--n-600)}
.totals-mini .tm-sum{
  margin-top:6px;padding-top:9px;border-top:1px solid var(--n-200);
  font-size:15px;font-weight:600;letter-spacing:-.02em;
}

/* ------------------------------------------------------------ PREVIEW PANE */
.preview-pane{display:flex;flex-direction:column;min-width:0;background:var(--n-150)}
.preview-bar{
  flex:none;display:flex;align-items:center;gap:14px;height:46px;padding:0 18px;
  border-bottom:1px solid var(--rule);background:rgba(244,242,239,.8);backdrop-filter:blur(8px);
}
.zoom{display:flex;align-items:center;gap:2px}
.zoom span{min-width:46px;text-align:center;font-size:12.5px;font-weight:500;
  color:var(--n-600);font-variant-numeric:tabular-nums}
.zoom .icon-btn{width:30px;height:30px}
.zoom .icon-btn svg{width:14px;height:14px}
.fit-flag{margin-left:auto;font-size:12px;font-weight:500;display:flex;align-items:center;gap:6px}
.fit-flag::before{content:"";width:6px;height:6px;border-radius:50%;background:currentColor}
.fit-ok{color:var(--ok)}
.fit-over{color:var(--red-ink)}
.stage{flex:1;overflow:auto;padding:26px;display:flex;justify-content:center;align-items:flex-start}
.paper-wrap{transform-origin:top center;transition:transform .18s var(--ease)}

/* ------------------------------------------------------------------ TOAST */
.toast{
  position:fixed;left:50%;bottom:26px;transform:translateX(-50%) translateY(8px);
  z-index:80;padding:11px 18px;border-radius:var(--r-pill);
  background:var(--ink);color:#fff;font-size:13.5px;font-weight:500;
  box-shadow:var(--sh-lg);opacity:0;transition:opacity .2s,transform .2s var(--ease);
}
.toast.is-on{opacity:1;transform:translateX(-50%) translateY(0)}

.scrim{position:fixed;inset:0;z-index:35;background:rgba(23,22,26,.34)}

/* ------------------------------------------------------------ RESPONSIVE */
@media (max-width:1180px){
  .split{grid-template-columns:1fr}
  .preview-pane{display:none}
  body.show-preview .form-pane{display:none}
  body.show-preview .preview-pane{display:flex}
  .stat-row{grid-template-columns:repeat(2,1fr)}
}
@media (max-width:860px){
  .rail{transform:translateX(-100%);transition:transform .22s var(--ease)}
  body.rail-open .rail{transform:none;box-shadow:var(--sh-lg)}
  .main{margin-left:0}
  .only-mobile{display:inline-flex}
  .pad{padding:18px 16px 48px}
  .topbar{padding:0 14px}
  .grid-2,.grid-4{grid-template-columns:1fr}
  .search input{width:150px}
  .form-pane{padding:18px 16px}
  .stat-row{grid-template-columns:1fr}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.001ms!important;transition-duration:.001ms!important}
}

/* ------------------------------------------------------- SETTINGS LISTS */
.rec{
  display:flex; align-items:flex-start; gap:14px;
  padding:14px 20px; border-bottom:1px solid var(--rule);
}
.rec:last-child{border-bottom:0}
.rec-main{flex:1; min-width:0}
.rec-title{display:flex; align-items:center; gap:8px; font-size:14px; font-weight:600}
.rec-body{
  margin-top:4px; font-size:12.5px; color:var(--n-500); line-height:1.55;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden;
}
.rec-body.is-mono{font-variant-numeric:tabular-nums}
.rec-acts{display:flex; gap:4px; flex:none}
.tag{
  display:inline-flex; align-items:center; height:20px; padding:0 8px;
  border-radius:var(--r-pill); background:var(--red-soft); color:var(--red-ink);
  font-size:11px; font-weight:600; letter-spacing:.01em;
}

.mini-select{
  margin-left:auto; height:32px; padding:0 28px 0 10px; border:1px solid var(--n-200);
  border-radius:var(--r-sm); background:var(--white); font-size:12.5px; cursor:pointer;
  appearance:none;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M6 8l4 4 4-4' fill='none' stroke='%23847F76' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat:no-repeat; background-position:right 7px center; background-size:16px;
}
.mini-select:focus{outline:0; border-color:var(--red); box-shadow:0 0 0 3px var(--red-soft)}
.f-hint{margin:-8px 0 14px; font-size:12.5px; color:var(--n-500)}

/* --------------------------------------------------------------- MODAL */
.modal{
  width:min(560px, calc(100vw - 32px)); padding:0; border:0; border-radius:var(--r-lg);
  background:var(--white); box-shadow:var(--sh-lg); color:var(--ink);
}
.modal::backdrop{background:rgba(23,22,26,.42)}
.modal[open]{animation:modalIn .18s var(--ease)}
@keyframes modalIn{from{opacity:0; transform:translateY(6px) scale(.99)} to{opacity:1}}
.modal-card{display:flex; flex-direction:column; max-height:min(84vh, 780px)}
.modal-title{
  flex:none; padding:18px 22px; font-size:16px; font-weight:600; letter-spacing:-.02em;
  border-bottom:1px solid var(--rule);
}
.modal-body{flex:1; overflow-y:auto; padding:20px 22px 4px}
.modal-body .f:last-of-type{margin-bottom:16px}
.modal-foot{
  flex:none; display:flex; justify-content:flex-end; gap:8px;
  padding:14px 22px; border-top:1px solid var(--rule); background:var(--n-50);
}
