:root {
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b91c1c;
  --bg: #f3f4f6;
  --card: #ffffff;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 1.25rem 1rem;
}
.header-inner { max-width: 1200px; margin: 0 auto; }
.app-header h1 { margin: 0; font-size: 1.5rem; }
.tagline { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Editor ---------- */
.editor {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.editor h2 { margin: 0 0 1rem; font-size: 1.15rem; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem;
  margin: 0 0 1rem;
}
legend { font-weight: 600; padding: 0 0.4rem; }
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.6rem;
}
input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { resize: vertical; }
.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; margin-bottom: 0.75rem; }
#itemsTable { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
#itemsTable th, #itemsTable td { padding: 0.35rem 0.3rem; text-align: left; }
#itemsTable th { font-size: 0.8rem; color: var(--muted); border-bottom: 1px solid var(--line); }
#itemsTable input { margin-top: 0; padding: 0.4rem; }
#itemsTable .qty, #itemsTable .price { width: 5.5rem; }
#itemsTable .amount { font-weight: 600; white-space: nowrap; text-align: right; }
.row-remove {
  background: none; border: none; color: var(--danger);
  font-size: 1.1rem; cursor: pointer; padding: 0.25rem 0.4rem;
}
.row-remove:hover { background: #fef2f2; border-radius: 4px; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 0.6rem 1rem; border-radius: 8px; border: 1px solid transparent;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.secondary { background: #fff; border-color: #d1d5db; color: var(--ink); }
.btn.secondary:hover { background: #f9fafb; }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.hint { font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Invoice preview ---------- */
.preview-wrap { position: sticky; top: 1rem; }
@media (max-width: 900px) { .preview-wrap { position: static; } }

.invoice {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  font-size: 0.92rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.inv-head {
  display: flex; justify-content: space-between; gap: 1rem;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 1rem; margin-bottom: 1.25rem;
}
.inv-brand { display: flex; gap: 0.8rem; align-items: flex-start; }
.logo-badge {
  width: 52px; height: 52px; flex: none;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; font-weight: 700;
}
.inv-biz-name { font-weight: 700; font-size: 1.05rem; }
.inv-biz-meta { color: var(--muted); font-size: 0.85rem; white-space: pre-line; }
.inv-title-block { text-align: right; }
.inv-title { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.08em; }
.inv-meta { font-size: 0.85rem; color: var(--muted); }
.inv-meta span { display: inline-block; min-width: 5.5rem; }
.inv-meta strong { color: var(--ink); }

.inv-billto { margin-bottom: 1.25rem; }
.inv-billto > span, .inv-notes > span, .inv-payment > span {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700;
}
.inv-client-name { font-weight: 700; margin-top: 0.15rem; }
.inv-billto div { white-space: pre-line; }

.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.inv-table th, .inv-table td { padding: 0.55rem 0.4rem; text-align: left; }
.inv-table th {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); border-bottom: 1px solid var(--ink);
}
.inv-table td { border-bottom: 1px solid var(--line); }
.inv-table .num { text-align: right; white-space: nowrap; }

.inv-totals { margin-left: auto; width: min(100%, 280px); }
.totals-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.3rem 0; font-size: 0.92rem;
}
.totals-row.grand {
  border-top: 2px solid var(--ink);
  margin-top: 0.35rem; padding-top: 0.6rem;
  font-size: 1.05rem;
}

.inv-foot {
  display: flex; justify-content: space-between; gap: 1.5rem;
  margin-top: 1.5rem; padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.inv-notes { flex: 1; }
.inv-notes div, .inv-payment div { white-space: pre-line; margin-top: 0.15rem; }
.inv-payment { text-align: right; max-width: 45%; }
.qr { margin-top: 0.5rem; display: inline-block; }
.qr img, .qr table { display: block; margin-left: auto; }

.app-footer {
  max-width: 1200px; margin: 0 auto; padding: 1rem;
  color: var(--muted); font-size: 0.85rem; text-align: center;
}
.app-footer a { color: var(--accent); }

/* ---------- Print: invoice only ---------- */
@media print {
  body { background: #fff; }
  .app-header, .editor, .app-footer { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; margin: 0; }
  .preview-wrap { position: static; }
  .invoice {
    border: none; border-radius: 0; box-shadow: none;
    padding: 0; font-size: 12pt;
  }
}
