/* Ruang Tagih: tampilan aplikasi + dokumen invoice A4 */
:root {
  --ink: #16211E;
  --muted: #5F6B67;
  --line: #E2E6E4;
  --bg: #F5F6F4;
  --card: #FFFFFF;
  --brand: #12312B;
  --brand-2: #1E5A4C;
  --brand-soft: #E7F0EC;
  --danger: #B42318;
  --warn-bg: #FFF6E0;
  --warn-ink: #7A4B00;
  --radius: 10px;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.5; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
a { color: var(--brand-2); }

/* ---------- Form dan tombol ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid #CED5D2; border-radius: 8px;
  padding: 9px 11px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9CC3B7; outline-offset: 0; border-color: var(--brand-2); }
input:disabled, select:disabled, textarea:disabled { background: #F1F3F2; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 10px; }
.check input { width: auto; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid #CED5D2; background: #fff; color: var(--ink);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #F1F4F2; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; justify-content: center; display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }
.small-link { font-size: 13px; display: inline-block; margin: -4px 0 12px; }
.error-text { color: var(--danger); font-size: 13px; margin: 0 0 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ---------- Login ---------- */
.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.logo { width: 34px; height: 34px; flex: none; }
.auth-sub { color: var(--muted); margin: 6px 0 20px; }
.auth-notice { background: var(--brand-soft); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.auth-notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.auth-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-note { color: var(--muted); font-size: 12.5px; margin: 16px 0 0; }

/* ---------- Kerangka ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar, .main, .editor > * { min-width: 0; }
.sidebar { background: var(--brand); color: #DCE8E3; padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.brand.side { color: #fff; font-size: 16px; padding: 0 6px; }
.ws-pick select { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
.ws-pick option { color: var(--ink); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #DCE8E3; text-decoration: none; padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 700; }
.side-foot { margin-top: auto; font-size: 12.5px; padding: 0 6px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.user-email { opacity: .8; word-break: break-all; }
.main { padding: 24px 28px 48px; min-width: 0; }
.banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; font-size: 13.5px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.stats .card + .card { margin-top: 0; }
.modal h3 { margin-top: 18px; }
.modal h2 + h3, .modal h2 + p + h3 { margin-top: 10px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .value { font-size: 21px; font-weight: 800; margin-top: 4px; letter-spacing: -.01em; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Tabel ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #F8FAF9; }
table.list .r { text-align: right; white-space: nowrap; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #EEF1F0; color: var(--muted); }
.badge.unpaid { background: #E8EEFB; color: #2747A0; }
.badge.overdue { background: #FDECEA; color: var(--danger); }
.badge.paid { background: #E3F4EA; color: #17643A; }
.badge.cancelled { background: #EEF0EF; color: #6B7470; text-decoration: line-through; }
.badge.off { background: #EEF0EF; color: #6B7470; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { max-width: 260px; }
.filters select { width: auto; }

/* ---------- Editor invoice ---------- */
.editor { display: grid; grid-template-columns: minmax(360px, 460px) 1fr; gap: 18px; align-items: start; }
.editor-form .card { padding: 14px; }
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #FBFCFB; }
.line-grid { display: grid; grid-template-columns: 70px 80px 1fr; gap: 8px; }
.line-total { font-size: 12.5px; color: var(--muted); }
.totals-mini { font-size: 13px; }
.totals-mini div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals-mini .big { font-weight: 800; font-size: 15px; }
.preview-wrap { position: sticky; top: 16px; }
.preview-scroll { background: #E9ECEA; border-radius: var(--radius); padding: 16px; overflow: auto; max-height: calc(100vh - 140px); }
.sheet { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,.12); transform-origin: top left; }
.tabs { display: none; gap: 6px; margin-bottom: 12px; }
.tabs .btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Modal dan toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,25,22,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; }
.modal.wide { max-width: 720px; }
.modal .row.end { margin-top: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 13.5px; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }
.img-prev { max-height: 64px; max-width: 200px; display: block; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* ---------- Dokumen invoice (layar dan cetak) ---------- */
.inv-doc { position: relative; padding: 16mm 16mm 14mm; color: #1A1F1D; font-size: 10pt; line-height: 1.45; font-family: "Plus Jakarta Sans", Arial, sans-serif; }
.inv-mark { position: absolute; top: 120mm; left: 0; right: 0; text-align: center; font-size: 64pt; font-weight: 800; color: rgba(180,35,24,.10); transform: rotate(-24deg); pointer-events: none; letter-spacing: .08em; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 10mm; border-bottom: 1px solid #D9DEDB; }
.inv-logo { max-height: 16mm; max-width: 50mm; display: block; margin-bottom: 4mm; }
.inv-biz { font-size: 14pt; font-weight: 800; }
.inv-title { font-size: 22pt; font-weight: 800; letter-spacing: .12em; color: #12312B; }
.inv-muted { color: #5F6B67; }
.inv-pre { white-space: pre-line; }
.inv-strong { font-weight: 700; }
.inv-label { font-size: 8pt; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #5F6B67; margin-bottom: 2mm; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; padding: 8mm 0; }
.inv-meta { border-collapse: collapse; }
.inv-meta td { padding: 0 4mm 1mm 0; vertical-align: top; }
.inv-meta td:first-child { color: #5F6B67; white-space: nowrap; }
.inv-items { width: 100%; border-collapse: collapse; }
.inv-items th { font-size: 8pt; text-transform: uppercase; letter-spacing: .06em; color: #5F6B67; text-align: left; padding: 2.5mm 2mm; border-bottom: 1.2px solid #1A1F1D; }
.inv-items td { padding: 2.5mm 2mm; border-bottom: 1px solid #E2E6E4; vertical-align: top; }
.inv-items .r { text-align: right; white-space: nowrap; }
.inv-items .n { width: 9mm; }
.inv-items tr { break-inside: avoid; }
.inv-sum { display: flex; justify-content: flex-end; margin-top: 4mm; break-inside: avoid; }
.inv-sum table { border-collapse: collapse; min-width: 75mm; }
.inv-sum td { padding: 1.2mm 0 1.2mm 8mm; text-align: right; }
.inv-sum td:first-child { color: #5F6B67; text-align: left; padding-left: 0; }
.inv-sum .inv-total td { font-weight: 800; font-size: 12pt; color: #1A1F1D; border-top: 1.2px solid #1A1F1D; padding-top: 2.5mm; }
.inv-words { margin: 4mm 0 0; font-style: italic; break-inside: avoid; }
.inv-words span { font-style: normal; color: #5F6B67; }
.inv-foot { display: grid; grid-template-columns: 1fr 60mm; gap: 10mm; margin-top: 10mm; break-inside: avoid; }
.inv-sign { text-align: center; }
.inv-sig { max-height: 22mm; max-width: 55mm; display: block; margin: 2mm auto; }
.inv-sig-space { height: 22mm; }
.inv-closing { text-align: center; color: #5F6B67; margin-top: 12mm; break-inside: avoid; }

#printArea { display: none; }
@page { size: A4; margin: 12mm 0 12mm; }
@media print {
  body { background: #fff; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  .inv-doc { padding: 2mm 16mm 0; }
  .inv-mark { position: fixed; top: 110mm; }
}

/* ---------- Layar kecil ---------- */
@media (max-width: 1100px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .tabs { display: flex; }
  .editor[data-tab="form"] .preview-wrap { display: none; }
  .editor[data-tab="preview"] .editor-form { display: none; }
  .preview-wrap { position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 12px; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .side-foot { flex-direction: row; justify-content: space-between; margin-top: 0; }
  .main { padding: 16px 14px 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .stat .value { font-size: 18px; }
}
