/* ============================================================
   Invoice Generator — Arkana Media
   ============================================================ */
:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 26px; }
.brand strong { display: block; font-size: 15px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.seg button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

.btn {
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  transition: transform .04s ease, background .15s ease, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-ghost:hover { background: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-dashed {
  width: 100%; border: 1.5px dashed var(--line-strong); background: transparent;
  color: var(--muted); padding: 10px; border-radius: 10px; font-weight: 600; margin-top: 8px;
}
.btn-dashed:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  align-items: start;
  gap: 0;
  height: calc(100vh - 61px);
}
.panel { height: 100%; overflow-y: auto; }
.form-panel { padding: 20px; border-right: 1px solid var(--line); }
.preview-panel { display: flex; flex-direction: column; background: #e7ecf3; }

/* ---------------- Cards / form ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 14px; }
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="email"], input[type="date"], input[type="number"],
textarea, select {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 11px; font-size: 14px; font-family: inherit; color: var(--ink);
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); margin-top: 10px; cursor: pointer; }
.check input { width: auto; }
.inline-input { display: flex; gap: 6px; }
.inline-input input { flex: 1; }
.suffix-select { width: auto; flex: 0 0 90px; }
.hint { font-size: 12px; color: var(--muted); text-align: center; padding: 4px 0 24px; }

/* template picker */
.template-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tmpl-chip {
  border: 1.5px solid var(--line-strong); background: #fff; border-radius: 10px;
  padding: 10px 6px; font-size: 12px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; justify-content: center; min-height: 46px;
  position: relative; overflow: hidden;
}
.tmpl-chip::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--line-strong);
}
.tmpl-chip[data-template="classic"]::before { background: #334155; }
.tmpl-chip[data-template="modern"]::before { background: var(--accent); }
.tmpl-chip[data-template="minimal"]::before { background: #94a3b8; }
.tmpl-chip[data-template="bold"]::before { background: linear-gradient(var(--accent), #0f172a); }
.tmpl-chip[data-template="receipt"]::before { background: repeating-linear-gradient(45deg,#475569,#475569 3px,#fff 3px,#fff 6px); }
.tmpl-chip.active { border-color: var(--accent); color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }

/* color */
.color-row { display: flex; align-items: center; gap: 10px; }
input[type="color"] { width: 44px; height: 38px; padding: 2px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 2px var(--accent); }

/* logo */
.logo-uploader { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.logo-drop {
  width: 96px; height: 96px; flex: 0 0 auto; border: 1.5px dashed var(--line-strong);
  border-radius: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--bg);
}
.logo-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-placeholder { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); }
.logo-placeholder span { font-size: 24px; line-height: 1; }
.logo-placeholder small { font-size: 11px; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; }

/* items rows */
.items-head, .item-row {
  display: grid;
  grid-template-columns: 1fr 56px 92px 92px 28px;
  gap: 8px; align-items: center;
}
.items-head { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 0 2px 8px; }
.item-row { margin-bottom: 8px; }
.item-row .amount-cell { font-size: 13px; font-weight: 600; text-align: right; color: var(--ink); padding-right: 2px; overflow: hidden; text-overflow: ellipsis; }
.item-row input { padding: 7px 8px; font-size: 13px; }
.item-del {
  border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1;
  width: 28px; height: 30px; border-radius: 7px;
}
.item-del:hover { background: #fee2e2; color: #dc2626; }

/* ---------------- Preview ---------------- */
.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.6);
}
.zoom-controls { display: flex; align-items: center; gap: 8px; }
.zoom-controls span { min-width: 40px; text-align: center; }
.preview-scroll { flex: 1; overflow: auto; padding: 28px; display: flex; justify-content: center; align-items: flex-start; }
.preview-stage { transform-origin: top center; transition: transform .12s ease; }

/* ============================================================
   INVOICE PAGE (A4 @96dpi = 794 x 1123)
   ============================================================ */
.invoice-page {
  width: 794px; min-height: 1120px; background: #fff; color: #0f172a;
  box-shadow: 0 10px 40px rgba(15, 23, 42, .18);
  --pad: 56px; --pacc: var(--accent);
  font-size: 14px; line-height: 1.5;
  display: flex; flex-direction: column;
}
.invoice-page * { box-sizing: border-box; }
.inv { padding: var(--pad); flex: 1; display: flex; flex-direction: column; }
.inv-logo { max-height: 72px; max-width: 240px; object-fit: contain; }
.inv-logo-text { font-size: 22px; font-weight: 800; }

.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.inv-title { font-size: 34px; font-weight: 800; letter-spacing: .02em; margin: 0; color: var(--pacc); }
.inv-meta { text-align: right; font-size: 13px; color: #475569; }
.inv-meta .num { font-size: 16px; font-weight: 700; color: #0f172a; }
.inv-meta-row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 3px; }
.inv-meta-row b { color: #0f172a; font-weight: 600; }

.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 32px 0 8px; }
.inv-party .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #94a3b8; font-weight: 700; margin-bottom: 6px; }
.inv-party .nm { font-weight: 700; font-size: 15px; }
.inv-party .ln { color: #475569; font-size: 13px; white-space: pre-line; }

table.inv-items { width: 100%; border-collapse: collapse; margin-top: 22px; }
table.inv-items thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: #fff; background: var(--pacc); padding: 11px 14px; font-weight: 700;
}
table.inv-items thead th.r { text-align: right; }
table.inv-items thead th.c { text-align: center; }
table.inv-items tbody td { padding: 12px 14px; border-bottom: 1px solid #eef2f7; font-size: 13.5px; vertical-align: top; }
table.inv-items tbody td.r { text-align: right; white-space: nowrap; }
table.inv-items tbody td.c { text-align: center; }
table.inv-items tbody td .desc-main { font-weight: 600; }
table.inv-items tbody tr:last-child td { border-bottom: 1px solid #cbd5e1; }

.inv-bottom { display: flex; justify-content: space-between; gap: 32px; margin-top: 22px; }
.inv-notes { flex: 1; font-size: 12.5px; color: #475569; }
.inv-notes h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #94a3b8; margin: 0 0 4px; }
.inv-notes .block { margin-bottom: 14px; white-space: pre-line; }

.inv-totals { width: 290px; flex: 0 0 auto; }
.inv-totals .trow { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; color: #475569; }
.inv-totals .trow b { color: #0f172a; font-weight: 600; }
.inv-totals .trow.grand {
  margin-top: 6px; padding: 12px 14px; background: var(--pacc); color: #fff; border-radius: 8px; font-size: 16px;
}
.inv-totals .trow.grand span, .inv-totals .trow.grand b { color: #fff; font-weight: 700; }
.inv-totals .trow.due { font-weight: 700; color: #0f172a; border-top: 1px solid #e2e8f0; margin-top: 4px; padding-top: 10px; }

.inv-foot { margin-top: auto; padding-top: 28px; text-align: center; color: #94a3b8; font-size: 12px; }
.inv-foot .thanks { color: var(--pacc); font-weight: 700; font-size: 15px; margin-bottom: 4px; }

/* ============ TEMPLATE: CLASSIC ============ */
.tmpl-classic .inv-title { font-family: "Playfair Display", serif; color: #0f172a; }
.tmpl-classic table.inv-items thead th { background: #0f172a; }
.tmpl-classic .inv-totals .trow.grand { background: #0f172a; border: 0; }
.tmpl-classic .inv { border-top: 6px solid var(--pacc); }
.tmpl-classic .inv-foot .thanks { color: #0f172a; }

/* ============ TEMPLATE: MODERN ============ */
.tmpl-modern .inv { padding: 0; }
.tmpl-modern .inv-banner {
  background: var(--pacc); color: #fff; padding: 40px var(--pad) 34px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
}
.tmpl-modern .inv-banner .inv-title { color: #fff; }
.tmpl-modern .inv-banner .inv-meta, .tmpl-modern .inv-banner .inv-meta .num,
.tmpl-modern .inv-banner .inv-meta-row b { color: #fff; }
.tmpl-modern .inv-banner .inv-meta { opacity: .95; }
.tmpl-modern .inv-banner .inv-logo-text { color: #fff; }
.tmpl-modern .inv-body { padding: 8px var(--pad) var(--pad); display: flex; flex-direction: column; flex: 1; }
.tmpl-modern table.inv-items thead th { background: #f1f5f9; color: #475569; }
.tmpl-modern .inv-totals .trow.grand { background: var(--pacc); }

/* ============ TEMPLATE: MINIMAL ============ */
.tmpl-minimal .inv-title { font-weight: 600; color: #0f172a; letter-spacing: .14em; font-size: 26px; }
.tmpl-minimal table.inv-items thead th { background: transparent; color: #94a3b8; border-bottom: 2px solid #0f172a; }
.tmpl-minimal table.inv-items thead th.r, .tmpl-minimal table.inv-items thead th.c { color: #94a3b8; }
.tmpl-minimal .inv-totals .trow.grand { background: transparent; color: #0f172a; border-top: 2px solid #0f172a; border-radius: 0; padding: 12px 0; }
.tmpl-minimal .inv-totals .trow.grand span, .tmpl-minimal .inv-totals .trow.grand b { color: #0f172a; }
.tmpl-minimal .inv-party .lbl, .tmpl-minimal .inv-foot .thanks { color: var(--pacc); }

/* ============ TEMPLATE: BOLD ============ */
.tmpl-bold { display: flex; }
.tmpl-bold .inv { flex-direction: row; padding: 0; }
.tmpl-bold .inv-side {
  width: 240px; flex: 0 0 240px; background: var(--pacc); color: #fff; padding: 40px 28px;
  display: flex; flex-direction: column; gap: 26px;
}
.tmpl-bold .inv-side .inv-title { color: #fff; font-size: 30px; }
.tmpl-bold .inv-side .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .8; margin-bottom: 5px; }
.tmpl-bold .inv-side .nm { font-weight: 700; }
.tmpl-bold .inv-side .ln, .tmpl-bold .inv-side .val { font-size: 12.5px; opacity: .92; white-space: pre-line; }
.tmpl-bold .inv-side .inv-logo-text { color: #fff; }
.tmpl-bold .inv-main { flex: 1; padding: 40px 40px; display: flex; flex-direction: column; }
.tmpl-bold table.inv-items thead th { background: #0f172a; }
.tmpl-bold .inv-totals { width: 100%; }
.tmpl-bold .inv-totals .trow.grand { background: var(--pacc); }

/* ============ TEMPLATE: RECEIPT ============ */
.tmpl-receipt .invoice-page,
.invoice-page.tmpl-receipt { width: 420px; min-height: 700px; }
.tmpl-receipt .inv { padding: 36px 34px; font-family: "Space Grotesk", monospace; }
.tmpl-receipt .inv-head { flex-direction: column; align-items: center; text-align: center; gap: 8px; border-bottom: 2px dashed #cbd5e1; padding-bottom: 18px; }
.tmpl-receipt .inv-title { font-size: 24px; letter-spacing: .2em; }
.tmpl-receipt .inv-meta { text-align: center; }
.tmpl-receipt .inv-meta-row { justify-content: center; }
.tmpl-receipt .inv-parties { grid-template-columns: 1fr; gap: 14px; text-align: center; margin: 18px 0 0; }
.tmpl-receipt table.inv-items thead th { background: transparent; color: #94a3b8; border-bottom: 1px dashed #cbd5e1; padding: 8px 4px; }
.tmpl-receipt table.inv-items tbody td { padding: 8px 4px; border-bottom: 1px dashed #eef2f7; }
.tmpl-receipt .inv-bottom { flex-direction: column-reverse; gap: 18px; }
.tmpl-receipt .inv-totals { width: 100%; }
.tmpl-receipt .inv-totals .trow.grand { background: transparent; color: #0f172a; border-top: 2px dashed #0f172a; border-bottom: 2px dashed #0f172a; border-radius: 0; }
.tmpl-receipt .inv-totals .trow.grand span, .tmpl-receipt .inv-totals .trow.grand b { color: #0f172a; }
.tmpl-receipt .inv-foot { border-top: 2px dashed #cbd5e1; padding-top: 18px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { height: auto; overflow: visible; }
  .form-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-panel { min-height: 80vh; }
  .topbar-actions .btn-ghost { display: none; }
}

/* ---------------- Print ---------------- */
@media print {
  .topbar, .form-panel, .preview-toolbar { display: none !important; }
  body, .preview-panel, .layout { background: #fff; height: auto; display: block; }
  .preview-scroll { padding: 0; overflow: visible; display: block; }
  .preview-stage { transform: none !important; }
  .invoice-page { box-shadow: none; }
  @page { margin: 0; }
}
