/* Nutri Farmart Invoice Maker — light, clear (matches admin panel) */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

:root {
  --im-bg: #f1f5f9;
  --im-surface: #ffffff;
  --im-border: #e2e8f0;
  --im-text: #1e293b;
  --im-muted: #64748b;
  --im-light: #94a3b8;
  --im-accent: #0d9488;
  --im-accent-dark: #0f766e;
  --im-accent-soft: #f0fdfa;
  --im-accent-muted: #ccfbf1;
  --im-danger: #dc2626;
  --im-ok: #15803d;
  --im-radius: 12px;
  --im-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  --im-shadow-md: 0 4px 20px rgba(15, 23, 42, 0.08);
  --im-font: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  min-height: 100%;
  font-family: var(--im-font);
  background: var(--im-bg);
  color: var(--im-text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: 14px; }

.im-site-strip {
  background: var(--im-surface);
  border-bottom: 1px solid var(--im-border);
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 60;
  box-shadow: var(--im-shadow);
}
.im-site-strip a.im-brand {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--im-text);
  letter-spacing: -0.02em;
}
.im-site-strip a.im-brand span { color: var(--im-accent); }
.im-site-strip .im-home {
  margin-left: auto;
  font-size: 13px;
  color: var(--im-muted);
  text-decoration: none;
  font-weight: 500;
}
.im-site-strip .im-home:hover { color: var(--im-accent); }

#app {
  min-height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.app-bar {
  background: var(--im-surface);
  color: var(--im-text);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 52px;
  z-index: 50;
  border-bottom: 1px solid var(--im-border);
  box-shadow: var(--im-shadow);
}
.app-bar h1.app-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  color: var(--im-text);
  line-height: 1.3;
}
.app-bar .icon-btn {
  background: var(--im-bg);
  border: 1px solid var(--im-border);
  color: var(--im-muted);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.app-bar .icon-btn:hover {
  background: var(--im-accent-soft);
  color: var(--im-accent);
  border-color: var(--im-accent-muted);
}
.app-bar-actions { display: flex; gap: 6px; margin-left: auto; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.app-content {
  flex: 1;
  padding: 14px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.summary-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.summary-card {
  background: var(--im-surface);
  border-radius: var(--im-radius);
  padding: 14px;
  border: 1px solid var(--im-border);
  box-shadow: var(--im-shadow);
}
.summary-card .lbl {
  font-size: 11px;
  color: var(--im-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.summary-card .val {
  font-size: 22px;
  font-weight: 800;
  margin-top: 4px;
  color: var(--im-text);
}
.summary-card .val.danger { color: var(--im-danger); }
.summary-hint {
  font-size: 12px;
  color: var(--im-muted);
  text-align: center;
  margin: -4px 0 12px;
  line-height: 1.5;
}

.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.filter-chips button {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1px solid var(--im-border);
  background: var(--im-surface);
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
  color: var(--im-muted);
  cursor: pointer;
}
.filter-chips button.active {
  background: var(--im-accent);
  color: #fff;
  border-color: var(--im-accent);
}

.inv-card {
  background: var(--im-surface);
  border-radius: var(--im-radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--im-border);
  box-shadow: var(--im-shadow);
  cursor: pointer;
}
.inv-card .num { font-weight: 700; font-size: 15px; color: var(--im-text); }
.inv-card .client { font-size: 13px; color: var(--im-muted); margin-top: 2px; }
.inv-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.inv-card .bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.inv-card .amt { font-weight: 700; font-size: 16px; color: var(--im-accent-dark); }
.inv-card .meta { font-size: 12px; color: var(--im-muted); text-align: right; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 11px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}
.status-unpaid, .status-sent { background: #ffedd5; color: #c2410c; }
.status-paid { background: #dcfce7; color: #15803d; }
.status-partial { background: #dbeafe; color: #1d4ed8; }
.status-overdue { background: #fee2e2; color: #b91c1c; }
.status-draft { background: #f1f5f9; color: #64748b; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--im-accent);
  color: #fff;
  border: none;
  font-size: 22px;
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.35);
  cursor: pointer;
  z-index: 40;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--im-surface);
  border-top: 1px solid var(--im-border);
  display: flex;
  padding: 6px 0 env(safe-area-inset-bottom);
  z-index: 50;
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.05);
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 6px 4px;
  color: var(--im-light);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.bottom-nav button i { font-size: 20px; }
.bottom-nav button.active { color: var(--im-accent); }

.card-section {
  background: var(--im-surface);
  border-radius: var(--im-radius);
  margin-bottom: 12px;
  border: 1px solid var(--im-border);
  overflow: hidden;
  box-shadow: var(--im-shadow);
}
.card-section .sec-hdr {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--im-muted);
  text-transform: uppercase;
  background: #f8fafc;
}
.row-link {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border-top: 1px solid var(--im-border);
  gap: 12px;
}
.row-link:first-of-type { border-top: none; }
.row-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.row-icon.blue { background: var(--im-accent-soft); color: var(--im-accent); }
.row-icon.orange { background: #ffedd5; color: #c2410c; }
.row-body { flex: 1; min-width: 0; }
.row-body strong { display: block; font-size: 15px; }
.row-body small { color: var(--im-muted); font-size: 12px; }

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--im-border);
  cursor: pointer;
}
.item-row:first-child { border-top: none; }
.item-row .price { font-weight: 700; color: var(--im-accent-dark); }

.panel-form { padding: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--im-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--im-border);
  border-radius: 8px;
  background: #fff;
}
.form-group textarea { min-height: 80px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary { background: var(--im-accent); color: #fff; }
.btn-primary:hover { background: var(--im-accent-dark); }
.btn-outline { background: #fff; border: 1px solid var(--im-border); color: var(--im-text); }
.btn-danger { background: var(--im-danger); color: #fff; }
.btn-block { width: 100%; }

.danger-zone { border-color: #fecaca; background: #fef2f2; }
.danger-title { font-size: 15px; font-weight: 700; color: var(--im-danger); margin-bottom: 8px; }
.danger-desc { font-size: 13px; color: var(--im-muted); line-height: 1.5; margin-bottom: 14px; }

.toolbar-row { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.search-field { flex: 1; }
.search-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--im-border);
  border-radius: 10px;
  background: #fff;
}
.btn-clear-search {
  width: 40px;
  height: 40px;
  border: 1px solid var(--im-border);
  border-radius: 10px;
  background: #fff;
  color: var(--im-muted);
  cursor: pointer;
  flex-shrink: 0;
}

.empty { padding: 40px 20px; text-align: center; color: var(--im-muted); }
.empty i { font-size: 40px; opacity: 0.35; margin-bottom: 12px; display: block; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.overlay.open { display: flex; }
#importOverlay.open { display: flex; }
.overlay.center { align-items: center; padding: 16px; }

.sheet {
  background: var(--im-surface);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.overlay.center .sheet { border-radius: var(--im-radius); max-height: 85vh; }
.sheet-hdr {
  padding: 16px;
  border-bottom: 1px solid var(--im-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sheet-hdr h2 { flex: 1; font-size: 17px; font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }

.editor-full, .preview-full {
  position: fixed;
  inset: 0;
  background: var(--im-bg);
  z-index: 180;
  display: none;
  flex-direction: column;
}
.editor-full.open, .preview-full.open { display: flex; }
.preview-full { z-index: 220; }
.editor-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}
.editor-ftr {
  padding: 12px 16px;
  background: var(--im-surface);
  border-top: 1px solid var(--im-border);
  display: flex;
  gap: 10px;
}
.editor-ftr .btn { flex: 1; }

.hero-inv {
  background: var(--im-surface);
  border-radius: var(--im-radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--im-border);
}
.hero-inv .big-num { font-size: 28px; font-weight: 800; color: var(--im-accent-dark); }
.hero-inv .dates { font-size: 13px; color: var(--im-muted); margin-top: 6px; line-height: 1.6; }

.line-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.line-table th {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--im-muted);
  text-align: left;
  padding: 8px 4px;
  border-bottom: 2px solid var(--im-border);
}
.line-table td { padding: 6px 4px; border-bottom: 1px solid var(--im-border); }
.line-table input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--im-border);
  border-radius: 6px;
}

.add-line-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--im-border);
  border-radius: 10px;
  color: var(--im-accent);
  font-weight: 600;
  cursor: pointer;
  margin: 8px 0;
}
.add-line-btn--primary {
  background: var(--im-accent-soft);
  border: 2px solid var(--im-accent);
  font-size: 15px;
}
.im-build-hint {
  font-size: 11px;
  color: var(--im-muted);
  text-align: center;
  margin: 0 0 4px;
}
.items-subtotal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px 4px;
  border-top: 1px solid var(--im-border);
  margin-top: 4px;
}
.items-subtotal-row .lbl { font-weight: 700; color: var(--im-text); }
.items-subtotal-row .val { font-weight: 800; color: var(--im-text); font-size: 16px; }

.add-item-full {
  position: fixed;
  inset: 0;
  background: var(--im-bg);
  z-index: 190;
  display: none;
  flex-direction: column;
}
.add-item-full.open { display: flex; }
.add-item-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}
.pick-search-wrap { margin-bottom: 10px; }
.pick-search-wrap input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--im-border);
  border-radius: 10px;
  background: #fff;
}
.new-item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: var(--im-surface);
  border: 1px solid var(--im-border);
  border-radius: var(--im-radius);
  box-shadow: var(--im-shadow);
  cursor: pointer;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--im-text);
}
.new-item-card:hover { border-color: var(--im-accent-muted); background: var(--im-accent-soft); }
.new-item-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--im-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.item-list-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--im-muted);
  margin: 4px 2px 8px;
}
.item-picker-list {
  background: var(--im-surface);
  border: 1px solid var(--im-border);
  border-radius: var(--im-radius);
  overflow: hidden;
  box-shadow: var(--im-shadow);
}
.item-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--im-border);
  background: #fff;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
}
.item-pick-row:last-child { border-bottom: none; }
.item-pick-row:hover { background: var(--im-accent-soft); }
.item-pick-row .name { font-weight: 600; color: var(--im-text); flex: 1; padding-right: 8px; }
.item-pick-row .price { font-weight: 600; color: var(--im-text); white-space: nowrap; }

.sheet-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--im-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 8px 0 4px;
}
.req { color: var(--im-danger); }
.line-amount-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin: 8px 0;
  border-top: 1px dashed var(--im-border);
  font-size: 15px;
}
.line-amount-preview strong { color: var(--im-danger); font-size: 18px; }
.save-catalog-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--im-muted);
  margin-bottom: 14px;
  cursor: pointer;
}

.totals-bar {
  background: var(--im-accent);
  color: #fff;
  border-radius: var(--im-radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0;
}
.totals-bar .val { font-size: 20px; font-weight: 800; }

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  justify-content: center;
}
.invoice-paper {
  background: #fff;
  width: 100%;
  max-width: 400px;
  min-height: 520px;
  padding: 24px 20px;
  box-shadow: var(--im-shadow-md);
  font-size: 11px;
  line-height: 1.5;
  border-radius: 8px;
}
.invoice-paper .inv-title { font-size: 26px; font-weight: 800; }
.invoice-paper .total-row {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 800;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 2px solid var(--im-text);
}

.report-card {
  background: var(--im-surface);
  border-radius: var(--im-radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--im-border);
}
.client-bar .bar {
  height: 6px;
  background: var(--im-border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.client-bar .fill { height: 100%; background: var(--im-accent); }

.mark-opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: none;
  background: none;
  border-bottom: 1px solid var(--im-border);
  font-size: 15px;
  cursor: pointer;
}
.mark-opt.active { background: var(--im-accent-soft); color: var(--im-accent-dark); font-weight: 600; }

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--im-text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: 0.25s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.im-load-err {
  padding: 24px;
  text-align: center;
  color: var(--im-danger);
  max-width: 400px;
  margin: 2rem auto;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}

@media (min-width: 768px) {
  .fab { right: calc(50% - 320px + 20px); }
}
