/* Invoicing app styles — no dependencies */
:root {
  --brand: #2563eb;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --red: #b91c1c;
  --green: #15803d;
  --amber: #b45309;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.25; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-top: 18px; }
code, pre.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre.code { background: #111827; color: #e5e7eb; padding: 12px 14px; border-radius: 8px; overflow-x: auto; user-select: all; }
em { font-style: normal; }

/* ---- layout ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #111827; color: #d1d5db; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; flex: none; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; padding: 4px 10px 18px; font-size: 15px; }
.sidebar .brand img { max-height: 30px; max-width: 40px; border-radius: 4px; background: #fff; padding: 2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a { color: #cbd5e1; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.sidebar .count { background: #f59e0b; color: #111827; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 8px; }
.side-foot { padding: 10px; border-top: 1px solid #1f2937; }
.side-foot .link { background: none; border: 0; color: #9ca3af; padding: 0; cursor: pointer; font: inherit; }
.side-foot .link:hover { color: #fff; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px 0; }
.topbar h1 { font-size: 22px; margin: 0; }
.menu-btn { display: none; background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 18px; padding: 4px 10px; cursor: pointer; }
.content { padding: 16px 28px 48px; max-width: 1280px; }

/* ---- components ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.card.flush { padding: 0; overflow: hidden; }
.pad { padding: 16px 20px; margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head.pad { margin: 0; padding-bottom: 6px; }
.danger-zone { border-color: #fecaca; }
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.detail { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); align-items: start; }
.grid.detail > div > .card { margin-bottom: 18px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.kpi-value { font-size: 22px; font-weight: 700; margin: 4px 0 2px; white-space: nowrap; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.kpi-lines { margin-top: 8px; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn, .text-amber { color: var(--amber); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.big { font-size: 22px; font-weight: 700; }
.spacer { flex: 1; }
.dim { opacity: .55; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.count-pill { background: #fef3c7; color: #92400e; border-radius: 999px; font-size: 12px; padding: 1px 9px; margin-left: 6px; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 9px 12px; background: #f9fafb; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table th.right, .table td.right { text-align: right; }
.table.sum td { padding: 4px 12px; border: 0; }
.table-scroll { overflow-x: auto; }
.card:not(.flush) > .table th:first-child, .card:not(.flush) > .table td:first-child { padding-left: 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: #fff; color: var(--text); border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand); filter: brightness(.92); }
.btn-danger { color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-active { background: #e5e7eb; }
.btn.block, .btn-block { display: flex; width: 100%; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #e5e7eb; color: #374151; white-space: nowrap; }
.b-paid, .b-active { background: #dcfce7; color: #166534; }
.b-sent { background: #dbeafe; color: #1e40af; }
.b-partially_paid, .b-paused { background: #fef3c7; color: #92400e; }
.b-overdue { background: #fee2e2; color: #991b1b; }
.b-void, .b-draft, .b-ended { background: #e5e7eb; color: #4b5563; }

/* forms */
.form h2 { margin-top: 22px; padding-top: 4px; }
.form h2:first-child, .form > h2:first-of-type { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { font-size: 12px; }
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid #d1d5db; border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 3px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 18px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid .span2 { grid-column: span 2; }
.check { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0 10px; cursor: pointer; }
.check input { margin-top: 3px; }
.actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.narrow { max-width: 640px; }
.form.compact { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 4px; }
.inline-fields { display: flex; gap: 8px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 9px 16px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; text-decoration: none; }

/* invoice editor */
.line-tools { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.line-tools select { max-width: 340px; }
.table.lines td { padding: 6px 8px; }
.table.lines th { padding: 7px 8px; }
.table.lines textarea { min-height: 38px; }
.table.lines .line-total { padding-top: 14px; }
.totals-box { margin: 14px 0 18px auto; width: 300px; max-width: 100%; }
.totals-box > div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals-box .grand { border-top: 2px solid var(--brand); margin-top: 4px; padding-top: 8px; font-size: 16px; }

/* misc blocks */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 8px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.dl.cols { grid-template-columns: 130px 1fr 130px 1fr; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border: 0; }
.sla { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.sla-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.sla-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.sla-meta { display: flex; gap: 6px 20px; flex-wrap: wrap; margin-top: 8px; }
.pager { display: flex; gap: 6px; margin: 14px 0; }
.pager a, .pager span { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
.pager a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.bars { display: flex; align-items: flex-end; gap: 14px; height: 170px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.bar { width: 100%; max-width: 46px; background: var(--brand); border-radius: 5px 5px 0 0; opacity: .85; }
.bar-val, .bar-lbl { color: var(--muted); margin: 3px 0; }

/* login & installer */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px 30px; width: 100%; max-width: 400px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.auth-card h1 { font-size: 22px; }
.auth-logo { max-height: 56px; margin-bottom: 12px; }
body.install { padding: 30px 16px; }
.install-wrap { max-width: 820px; margin: 0 auto; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { padding: 4px 0; }
.checks .ok { color: var(--green); }
.checks .bad { color: var(--red); }
.checks .warn { color: var(--amber); }

/* responsive */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: -240px; z-index: 50; transition: left .2s; width: 230px; }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: inline-block; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .grid.detail { grid-template-columns: 1fr; }
  .grid.two { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .dl.cols { grid-template-columns: 110px 1fr; }
}
@media print { .sidebar, .topbar, .toolbar, .actions { display: none; } .content { padding: 0; } }

.btn-success { background: #15803d; border-color: #15803d; color: #fff; }
.btn-success:hover { background: #166534; border-color: #166534; color: #fff; }
.sig-pad { border: 1px dashed #9ca3af; border-radius: 8px; background: #fff; width: 100%; max-width: 420px; height: 150px; touch-action: none; cursor: crosshair; display: block; }
.sig-current { margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: inline-block; }
.sig-current img { max-height: 70px; display: block; }
