:root {
  --ink: #12201c;
  --muted: #5b6b66;
  --line: #d7e0dc;
  --paper: #f7faf8;
  --card: #ffffff;
  --teal: #0f766e;
  --teal-deep: #115e59;
  --amber: #c97816;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(18, 32, 28, 0.08);
  --radius: 18px;
  --font: 'DM Sans', system-ui, sans-serif;
  --display: 'Instrument Serif', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}
.bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(15, 118, 110, 0.16), transparent 60%),
    radial-gradient(700px 420px at 100% 0%, rgba(201, 120, 22, 0.12), transparent 55%),
    linear-gradient(180deg, #eef5f2 0%, #f7faf8 40%, #f3f1ea 100%);
}
.app { max-width: 960px; margin: 0 auto; padding: 28px 18px 64px; }

.brand-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 28px;
}
.brand-mark { display: flex; flex-direction: column; gap: 2px; }
.brand-mark strong {
  font-family: var(--display);
  font-size: 1.65rem; font-weight: 400; letter-spacing: -0.02em;
}
.brand-mark span { color: var(--muted); font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid rgba(215, 224, 220, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.7rem;
  margin: 0 0 6px;
}
.card .lede { color: var(--muted); margin: 0 0 20px; }

label { display: grid; gap: 6px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--teal);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stack { display: grid; gap: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

button, .btn {
  appearance: none; border: 0; cursor: pointer;
  border-radius: 999px;
  padding: 11px 18px;
  font: 600 0.92rem var(--font);
  background: #e8efec;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button.primary, .btn.primary {
  background: linear-gradient(180deg, #0f766e, #0d5f59);
  color: #fff;
}
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: #fef3f2; color: var(--danger); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.err {
  background: #fef3f2; color: var(--danger);
  border: 1px solid #fecdca; border-radius: 12px;
  padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px;
}
.ok {
  background: #ecfdf5; color: #067647;
  border: 1px solid #a6f4c5; border-radius: 12px;
  padding: 10px 12px; font-size: 0.9rem; margin-bottom: 12px;
}
.hint { font-size: 0.8rem; color: var(--muted); font-weight: 400; }

.templates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.tmpl {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  background: #fff;
  text-align: left;
  transition: border-color .15s, transform .15s;
}
.tmpl:hover { transform: translateY(-1px); }
.tmpl.selected { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.tmpl strong { display: block; font-size: 1rem; color: var(--ink); margin-bottom: 4px; font-weight: 700; }
.tmpl span { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 400; }
.tmpl-preview {
  width: 100%;
  height: 72px;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid #e5ebe8;
  flex-shrink: 0;
}
.tmpl-preview.classic {
  background: linear-gradient(#fff, #fff), repeating-linear-gradient(0deg, #e2e8f0, #e2e8f0 1px, transparent 1px, transparent 12px);
  background-blend-mode: normal;
  box-shadow: inset 0 0 0 2px #0f172a;
}
.tmpl-preview.modern {
  background: linear-gradient(135deg, #0f766e 0 38%, #f8fafc 38% 100%);
}
.tmpl-preview.bold {
  background: linear-gradient(#111827 0 42%, #f59e0b 42% 48%, #fff 48% 100%);
}
.tmpl-preview.compact {
  background:
    linear-gradient(#fff, #fff);
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 9px, #cbd5e1 9px, #cbd5e1 10px),
    linear-gradient(90deg, #0f172a 0 2px, transparent 2px);
}

.home-hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.home-hero h1 {
  font-family: var(--display); font-weight: 400; font-size: 2.2rem; margin: 0;
}
.export-card { margin-bottom: 16px; }
.export-row {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  justify-content: space-between;
}
.export-row label { min-width: 160px; }
.catalog-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: #fbfdfc;
}
.catalog-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-family: var(--display);
  font-weight: 400;
}
.catalog-list { display: grid; gap: 8px; margin-bottom: 12px; }
.catalog-chip {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; background: #fff; border: 1px solid var(--line);
  font-size: 0.9rem;
}
.catalog-chip button { padding: 6px 10px; font-size: 0.78rem; }
.catalog-add {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center;
}
@media (max-width: 640px) {
  .catalog-add { grid-template-columns: 1fr; }
}
.issued-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(18, 32, 28, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.issued-card {
  width: min(400px, 100%);
  box-shadow: 0 24px 60px rgba(18, 32, 28, 0.2);
}
.list { display: grid; gap: 10px; }
.inv-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: #fff;
}
.inv-row:hover { border-color: #b7cdc6; }
.inv-row-main {
  flex: 1; display: flex; justify-content: space-between; gap: 12px; align-items: center;
  text-decoration: none; color: inherit; min-width: 0;
}
.inv-row-main:hover { opacity: 0.92; }
.inv-dup { flex-shrink: 0; padding: 8px 12px; font-size: 0.82rem; }
.product-pick { margin-bottom: 6px; }
.inv-row .meta { color: var(--muted); font-size: 0.82rem; }

.empty-state {
  text-align: center; padding: 28px 16px;
  border: 1px dashed var(--line); border-radius: 14px; background: #fbfdfc;
}
.empty-state .lede { margin: 8px 0 18px; }

.details-block {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; background: #fbfdfc;
}
.details-block summary {
  cursor: pointer; font-weight: 600; color: var(--ink); list-style: none;
}
.details-block summary::-webkit-details-marker { display: none; }
.details-block summary::before { content: '▸ '; color: var(--teal); }
.details-block[open] summary::before { content: '▾ '; }

.inline-add {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 8px; padding: 10px; border-radius: 12px;
  background: #ecfdf5; border: 1px solid #a6f4c5;
}
.inline-add .inline-add-val { flex: 1; min-width: 120px; margin: 0; }

button.linkish, .linkish {
  width: auto; align-self: flex-start;
  padding: 6px 0; border: 0; background: transparent;
  color: var(--teal-deep); font-weight: 600; font-size: 0.88rem;
  text-decoration: underline; text-underline-offset: 3px;
}
button.linkish:hover { opacity: 0.85; }

.extras-panel { padding: 12px; border-radius: 14px; background: #fbfdfc; border: 1px solid var(--line); }

@media (max-width: 640px) {
  .inv-row { flex-direction: column; align-items: stretch; }
  .inv-row-main { flex-direction: column; align-items: flex-start; gap: 6px; }
  .inv-dup { width: 100%; }
  .brand-bar { flex-wrap: wrap; }
  .home-hero { flex-direction: column; align-items: stretch; }
  .home-hero .primary#new-inv { display: none; }
  .fab { display: inline-flex; align-items: center; justify-content: center; }
}

.line-items { display: grid; gap: 12px; }
.line {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: #fbfdfc;
  display: grid; gap: 10px;
}
.line-top { display: flex; justify-content: space-between; align-items: center; }
.add-line-btn {
  margin-top: 10px;
  width: 100%;
  border-radius: 12px !important;
  border: 1px dashed var(--line);
  background: transparent;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}
.seg button {
  border-radius: 0;
  background: transparent;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
}
.seg button.on {
  background: var(--teal);
  color: #fff;
}
.suggestions {
  position: absolute; z-index: 4; left: 0; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 200px; overflow: auto;
}
.suggestions button {
  width: 100%; border-radius: 0; background: transparent; justify-content: flex-start;
  border-bottom: 1px solid #f1f5f4; font-weight: 500;
}
.suggestions button:hover { background: #f0fdfa; }
.rel { position: relative; }

.totals-live {
  margin-top: 8px; padding: 14px 16px; border-radius: 14px;
  background: #12201c; color: #ecfdf5;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.totals-live strong { font-size: 1.25rem; color: #5eead4; }

.login-wrap { max-width: 420px; margin: 48px auto; }
.logo-setup { margin-bottom: 4px; }
.logo-row {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  margin-top: 6px;
}
.logo-preview {
  max-height: 56px; max-width: 120px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff;
}

.otp-resend-row {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; margin-top: 4px;
}
.otp-resend-row .linkish { width: auto; }

.list-loading {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 28px 16px; color: var(--muted); font-size: 0.92rem;
}
.spin {
  width: 18px; height: 18px; border: 2px solid var(--line);
  border-top-color: var(--teal); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 100; max-width: min(360px, calc(100% - 32px));
  padding: 12px 18px; border-radius: 999px; font-size: 0.9rem; font-weight: 600;
  box-shadow: 0 12px 40px rgba(18, 32, 28, 0.18);
  animation: toast-in 0.25s ease;
}
.toast-ok { background: #ecfdf5; color: #067647; border: 1px solid #a6f4c5; }
.toast-err { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; }
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.fab {
  position: fixed; bottom: 24px; right: 20px; z-index: 40;
  width: 56px; height: 56px; border-radius: 50%;
  font-size: 1.75rem; line-height: 1; padding: 0;
  box-shadow: 0 8px 28px rgba(15, 118, 110, 0.35);
  display: none;
}

@media (max-width: 720px) {
  .grid-2, .grid-3, .templates { grid-template-columns: 1fr; }
  .home-hero h1 { font-size: 1.8rem; }
  .fab { display: inline-flex; align-items: center; justify-content: center; }
  .home-hero .primary#new-inv { display: none; }
  .brand-bar .row-actions { gap: 6px; }
  .brand-bar .row-actions button { padding: 8px 12px; font-size: 0.82rem; }
}
