/* ==========================================================================
   InvoiceFlow — Interactive Micro-SaaS Workspace + Clean Print PDF Styles
   ========================================================================== */

:root {
  --bg: #070b14;
  --panel: #0e1424;
  --panel-2: #141c30;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #10b981;
  --doc-accent: #10b981;
  --font: "Plus Jakarta Sans", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* Top App Bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(7, 11, 20, 0.9); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.top-left, .top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 800; color: var(--text); text-decoration: none; font-size: 1rem; margin-right: 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #34d399, #059669); color: #022c22; display: grid; place-items: center; font-weight: 900; font-size: 0.82rem; }

.mode-switch { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.mode-btn { border: none; background: transparent; color: var(--muted); font-family: inherit; font-weight: 700; font-size: 0.82rem; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.mode-btn.active { background: #1e293b; color: #fff; }

.kpi-strip { display: inline-flex; gap: 8px; align-items: center; }
.kpi-pill { font-size: 0.78rem; padding: 5px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.kpi-pill strong { color: #fff; }
.kpi-pill.paid strong { color: #34d399; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; font-family: inherit; font-weight: 700; font-size: 0.84rem; cursor: pointer; border: 1px solid transparent; transition: background 0.15s ease, transform 0.15s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, #34d399, #10b981); color: #022c22; }
.btn-ghost { background: var(--panel); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-pro { background: linear-gradient(135deg, #f59e0b, #d97706); color: #1c1917; }
.btn-danger { background: rgba(239, 68, 68, 0.14); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }

/* Main Split Layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 470px) 1fr;
  min-height: calc(100vh - 60px);
}

.editor {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}

.section-card {
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 14px;
}
.section-title { font-size: 0.76rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: #34d399; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 0.76rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 0.86rem;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: #34d399; }

.swatches { display: flex; gap: 8px; align-items: center; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: #fff; transform: scale(1.1); }

/* Line Items Editor */
.item-row { display: grid; grid-template-columns: 1fr 56px 82px 28px; gap: 6px; margin-bottom: 8px; align-items: center; }
.item-row input { padding: 8px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 0.84rem; width: 100%; }
.del-btn { width: 28px; height: 32px; border-radius: 7px; border: 1px solid rgba(239,68,68,0.3); background: rgba(239,68,68,0.12); color: #fca5a5; cursor: pointer; font-weight: 700; }

/* Right Preview Pane */
.preview-pane {
  padding: 28px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(circle at 50% 0%, rgba(16,185,129,0.08), transparent 60%), #0a0f1c;
}

.paper {
  width: 100%;
  max-width: 780px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 12px;
  padding: 44px 48px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  border-top: 6px solid var(--doc-accent);
  position: relative;
}

.paper-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 32px; }
.paper-logo { max-height: 52px; max-width: 160px; object-fit: contain; margin-bottom: 10px; display: none; }
.paper-brand { font-size: 1.35rem; font-weight: 800; color: #0f172a; }
.paper-muted { color: #64748b; font-size: 0.86rem; white-space: pre-line; }

.doc-type-label { font-size: 1.8rem; font-weight: 900; letter-spacing: -0.03em; color: var(--doc-accent); text-align: right; line-height: 1.1; }
.doc-meta { text-align: right; margin-top: 8px; font-size: 0.85rem; color: #475569; }
.status-badge { display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.status-badge.draft { background: #f1f5f9; color: #475569; }
.status-badge.sent { background: #e0f2fe; color: #0369a1; }
.status-badge.paid { background: #d1fae5; color: #047857; }

.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 18px 0; border-top: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; margin-bottom: 24px; }
.party-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; color: #64748b; margin-bottom: 4px; }
.party-name { font-weight: 700; font-size: 1rem; margin-bottom: 3px; }

.proposal-scope { background: #f8fafc; border-left: 3px solid var(--doc-accent); padding: 14px 16px; border-radius: 6px; margin-bottom: 24px; display: none; }
.proposal-scope h4 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--doc-accent); margin-bottom: 6px; }
.proposal-scope p { font-size: 0.88rem; color: #334155; white-space: pre-line; }

.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.doc-table th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: #64748b; border-bottom: 2px solid #e2e8f0; padding: 10px 6px; }
.doc-table td { padding: 12px 6px; border-bottom: 1px solid #f1f5f9; font-size: 0.9rem; }
.doc-table th.num, .doc-table td.num { text-align: right; }

.totals-wrap { display: flex; justify-content: flex-end; margin-bottom: 28px; }
.totals-box { width: 270px; display: flex; flex-direction: column; gap: 8px; font-size: 0.9rem; }
.tot-row { display: flex; justify-content: space-between; color: #475569; }
.tot-row.grand { border-top: 2px solid #0f172a; padding-top: 10px; margin-top: 4px; font-weight: 900; font-size: 1.15rem; color: var(--doc-accent); }

.notes-block { background: #f8fafc; border-radius: 8px; padding: 14px 16px; font-size: 0.84rem; color: #475569; white-space: pre-line; margin-bottom: 24px; }
.notes-block strong { display: block; color: #0f172a; margin-bottom: 4px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; }

.signature-block { display: none; grid-template-columns: 1fr 1fr; gap: 36px; margin-top: 32px; padding-top: 20px; }
.sig-line { border-top: 1px solid #94a3b8; padding-top: 8px; font-size: 0.8rem; color: #64748b; }

.watermark { text-align: center; margin-top: 28px; padding-top: 14px; border-top: 1px dashed #e2e8f0; font-size: 0.76rem; color: #94a3b8; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(6px); display: none; place-items: center; z-index: 100; padding: 20px; }
.modal-backdrop.open { display: grid; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 560px; padding: 24px; max-height: 85vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; }

.saved-list { display: flex; flex-direction: column; gap: 10px; }
.saved-item { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.saved-item strong { font-size: 0.92rem; display: block; }
.saved-item small { color: var(--muted); font-size: 0.78rem; }

.toast { position: fixed; bottom: 20px; right: 20px; background: #10b981; color: #022c22; font-weight: 800; padding: 10px 18px; border-radius: 10px; opacity: 0; transform: translateY(10px); transition: 0.25s ease; pointer-events: none; z-index: 120; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .editor, .preview-pane { max-height: none; }
  .paper { padding: 28px 22px; }
}

/* Clean Print / PDF Export */
@media print {
  body { background: #fff !important; }
  .topbar, .editor, .modal-backdrop, .toast { display: none !important; }
  .workspace { display: block !important; }
  .preview-pane { padding: 0 !important; background: #fff !important; max-height: none !important; overflow: visible !important; }
  .paper { box-shadow: none !important; max-width: 100% !important; border-radius: 0 !important; padding: 20px 24px !important; }
}
