:root {
  --navy: #0f172a;
  --navy-2: #1e3a8a;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 72px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.875rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline-price-input { width: 92px !important; text-align: right; padding: 0.3rem 0.45rem !important; font-size: 0.85rem !important; }
.price-cell-btn {
  background: none; border: 1px dashed transparent; border-radius: 6px;
  padding: 0.2rem 0.45rem; font: inherit; color: inherit; cursor: pointer;
}
.price-cell-btn:hover {
  background: #f1f5f9; border-color: #94a3b8;
}

.offline-banner {
  background: #991b1b;
  color: #fff;
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-logo-img {
  height: 38px;
  width: auto;
  background: #ffffff;
  padding: 4px 8px;
  border-radius: 8px;
  object-fit: contain;
  display: block;
}
.topbar h1 { margin: 0; font-size: 1.05rem; }
.version-pill {
  font-size: 0.7rem; font-weight: 600; background: rgba(255,255,255,0.14);
  color: #cbd5e1; padding: 0.16rem 0.5rem; border-radius: 999px; white-space: nowrap;
}
.mobile-break { display: none; }
.brand-sub { margin: 0; font-size: 0.78rem; color: #94a3b8; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.role-badge {
  background: #1e293b; border: 1px solid #334155; color: #e2e8f0;
  padding: 0.3rem 0.65rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
}
.demo-select {
  background: #1e293b; color: #fff; border: 1px solid #475569;
  border-radius: 8px; padding: 0.35rem 0.5rem; font-size: 0.8rem;
}

.btn {
  border: none; border-radius: 8px; padding: 0.5rem 0.9rem;
  font-weight: 600; font-size: 0.875rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.78rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: rgba(255,255,255,0.12); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.8rem; padding: 0; font-weight: 600; }
.doc-link-btn {
  background: none; border: none; color: var(--primary); cursor: pointer;
  padding: 0; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 2px;
  text-align: left;
}
.doc-link-btn:hover { color: var(--navy-2); }
.doc-sheet {
  border: 1px solid var(--border); border-radius: 10px; padding: 1rem; background: #fff;
}
.doc-sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  border-bottom: 2px solid var(--navy); padding-bottom: 0.75rem; margin-bottom: 0.9rem; flex-wrap: wrap;
}
.doc-sheet-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem 1rem;
  font-size: 0.86rem; margin-bottom: 1rem;
}
.doc-sheet-grid div strong { display: block; font-size: 0.74rem; color: var(--muted); text-transform: uppercase; }
.doc-sheet-total {
  margin-top: 0.85rem; display: flex; justify-content: flex-end; gap: 1.5rem; align-items: baseline;
  font-size: 1rem; padding-top: 0.6rem; border-top: 1px solid var(--border);
}
.sign-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem;
  margin-top: 2rem; padding-top: 0.5rem;
}
.sign-box {
  border-top: 1px solid #334155; padding-top: 0.35rem; font-size: 0.8rem; color: var(--muted); text-align: center;
}
@page { margin: 0; }
@media print {
  body { background: #fff; padding: 0; margin: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body > *:not(#docDetailModal) { display: none !important; }
  #docDetailModal { position: static !important; display: block !important; background: none !important; padding: 0 !important; }
  #docDetailModal .modal-card { max-height: none; box-shadow: none; max-width: 100%; border-radius: 0; }
  #docDetailModal .modal-body { overflow: visible; padding: 0; }
  #docDetailModal .doc-sheet { border: none; padding: 12mm; break-inside: avoid; }
  #docDetailModal .modal-header, #docDetailModal .modal-footer { display: none !important; }
}

.app-shell { max-width: 1320px; margin: 1.25rem auto; padding: 0 1rem; }

.splash-screen {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(circle at top, #1e3a8a 0%, #0f172a 65%);
  color: #fff; display: grid; place-items: center; padding: 1.5rem;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.splash-screen.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-card { text-align: center; max-width: 340px; width: 100%; }
.splash-logo-wrap, .auth-logo-wrap {
  display: inline-flex; background: #fff; padding: 0.65rem 1.1rem;
  border-radius: 14px; box-shadow: 0 12px 28px rgba(0,0,0,0.22); margin-bottom: 1rem;
}
.splash-logo { height: 48px; width: auto; display: block; }
.auth-logo { height: 42px; width: auto; display: block; }
.splash-card h2 { margin: 0 0 0.35rem; font-size: 1.25rem; }
.splash-status { margin: 0 0 1rem; color: #cbd5e1; font-size: 0.88rem; }
.splash-bar { height: 5px; border-radius: 999px; background: rgba(255,255,255,0.16); overflow: hidden; }
.splash-bar-fill {
  height: 100%; width: 42%; border-radius: 999px; background: #38bdf8;
  animation: splashSlide 1.1s ease-in-out infinite alternate;
}
@keyframes splashSlide {
  from { transform: translateX(-15%); }
  to { transform: translateX(155%); }
}

.auth-gate { display: grid; place-items: center; min-height: 60vh; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem; max-width: 440px; width: 100%; text-align: center;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}
.auth-roles-pills { display: flex; justify-content: center; gap: 0.45rem; flex-wrap: wrap; margin: 0.75rem 0 0.25rem; }
.auth-buttons { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1.25rem; }
.auth-buttons .btn-ghost { color: var(--text); background: #f1f5f9; }
.error-text { color: var(--danger); font-size: 0.875rem; margin-top: 0.75rem; }

.tabs-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  padding: 0.55rem 1rem; border-radius: 10px; font-weight: 600; cursor: pointer;
}
.tab-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.kpi-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem; margin-bottom: 1rem;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.95rem 1.1rem;
}
.kpi-label { font-size: 0.8rem; color: var(--muted); }
.kpi-value { font-size: 1.45rem; font-weight: 700; margin-top: 0.25rem; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.search-box { flex: 1; min-width: 220px; }
input[type="search"], input[type="text"], input[type="email"], input[type="number"], input[type="date"], select {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid #cbd5e1;
  border-radius: 8px; font-size: 0.9rem; background: #fff;
}

.chips-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip {
  border: 1px solid #cbd5e1; background: #f8fafc; color: var(--text);
  padding: 0.35rem 0.75rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td {
  padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left;
}
.data-table th { color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
.data-table td.num, .data-table th.num { white-space: nowrap; }
.data-table tr.doc-main-row td { border-bottom: none; padding-bottom: 0.35rem; }
.data-table tr.doc-actions-row td { padding: 0.15rem 0.6rem 0.65rem; border-bottom: 2px solid #cbd5e1; }
.data-table tr.doc-band-even { background: #ffffff; }
.data-table tr.doc-band-odd { background: #f1f5f9; }
.data-table tr.doc-band-even:not(.doc-main-row) td,
.data-table tr.doc-band-odd:not(.doc-main-row) td { border-bottom: 2px solid #cbd5e1; }
.doc-actions-bar { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
.doc-actions-bar .btn,
.mobile-card-actions .btn {
  background: #e2e8f0;
  color: #1e293b;
  border: 1px solid #94a3b8;
  font-weight: 600;
}
.doc-actions-bar .btn:hover,
.mobile-card-actions .btn:hover {
  background: #cbd5e1;
  border-color: #64748b;
}

.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
}
.badge-neutral { background: #e2e8f0; color: #334155; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }

.switch-btn {
  border: 1px solid #cbd5e1; border-radius: 999px; padding: 0.25rem 0.65rem;
  font-size: 0.76rem; font-weight: 700; cursor: pointer; background: #fff;
}
.switch-btn.paid { background: #dcfce7; border-color: #86efac; color: #166534; }
.switch-btn.unpaid { background: #fef3c7; border-color: #fcd34d; color: #92400e; }

.cards-list { display: grid; gap: 0.75rem; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.75rem; }
.mobile-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.85rem; background: #fff;
}
.mobile-card-top { display: flex; justify-content: space-between; align-items: start; gap: 0.5rem; }
.mobile-card-meta { margin: 0.4rem 0; font-size: 0.83rem; color: var(--muted); }
.mobile-card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.65rem; }

.report-filters {
  display: grid; grid-template-columns: 160px 160px 1fr auto; gap: 0.85rem; align-items: end; margin-bottom: 1rem;
}
.field-group { display: flex; flex-direction: column; gap: 0.3rem; }
.field-group label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.field-clients { position: relative; }
.client-dd-trigger {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid #cbd5e1;
  border-radius: 8px; font-size: 0.9rem; background: #fff; color: var(--text);
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  cursor: pointer; text-align: left;
}
.client-dd-trigger:hover { border-color: #94a3b8; }
.client-dd-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14); background: #fff;
}
.client-multiselect {
  border: 1px solid #cbd5e1; border-radius: 8px; padding: 0.5rem; background: #fff;
}
.client-ms-actions { display: flex; gap: 0.75rem; margin: 0.35rem 0; }
.client-checklist {
  max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem;
}
.client-check-item { display: flex; align-items: center; gap: 0.45rem; font-size: 0.84rem; cursor: pointer; }
.report-summary {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 0.65rem 0.9rem; margin-bottom: 0.9rem; display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.88rem;
}

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.modal-card {
  background: #fff; border-radius: 14px; width: 100%; max-width: 500px;
  max-height: 92vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-lg { max-width: 780px; }
.modal-header, .modal-footer {
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; flex-wrap: wrap; }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem 1.1rem; overflow-y: auto; }
.icon-btn { background: none; border: none; font-size: 1.15rem; cursor: pointer; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.form-grid .full { grid-column: 1 / -1; }
.lines-section { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.9rem; }
.lines-header { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.lines-header h4 { margin: 0; }
.add-line-bar { display: flex; gap: 0.5rem; flex: 1; max-width: 440px; }
.quote-lines { display: grid; gap: 0.6rem; }
.quote-line-row {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.65rem;
  display: grid; grid-template-columns: 2fr 95px 95px 105px auto; gap: 0.5rem; align-items: center;
}
.quote-totals {
  margin-top: 0.85rem; display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
  border-top: 1px solid var(--border); display: none; justify-content: space-around; padding: 0.4rem 0; z-index: 30;
}
.bottom-nav button {
  background: none; border: none; color: var(--muted); font-size: 0.74rem; font-weight: 600;
  padding: 0.35rem 0.5rem; cursor: pointer;
}
.bottom-nav button.active { color: var(--primary); }

.toast {
  position: fixed; bottom: 80px; right: 1rem; background: var(--navy); color: #fff;
  padding: 0.65rem 1rem; border-radius: 10px; font-size: 0.86rem; z-index: 60;
}

.mobile-only { display: none; }
.desktop-only { display: block; }

@media (max-width: 820px) {
  .topbar {
    position: static;
    padding: 0.55rem 0.75rem;
    gap: 0.45rem;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }
  .topbar-brand { order: 0; flex: 1 1 auto; min-width: 0; }
  .brand-logo-img { height: 28px; padding: 2px 5px; }
  .topbar h1 { font-size: 0.88rem; }
  .brand-sub { display: none; }
  .topbar-actions { display: contents; }
  #btnAuth { order: 1; padding: 0.3rem 0.55rem; font-size: 0.74rem; white-space: nowrap; flex-shrink: 0; }
  .mobile-break { display: block; order: 2; flex-basis: 100%; height: 0; }
  .demo-select { order: 3; flex: 1 1 130px; width: auto; padding: 0.32rem 0.45rem; font-size: 0.76rem; }
  #btnNewQuote { order: 4; padding: 0.32rem 0.55rem; font-size: 0.75rem; white-space: nowrap; }
  #btnRefresh { order: 5; padding: 0.32rem 0.5rem; font-size: 0.76rem; }
  .version-pill { order: 6; }
  .role-badge { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-filters { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .quote-line-row { grid-template-columns: 1fr 1fr; }
  .desktop-only { display: none; }
  .mobile-only { display: grid; }
  .tabs-bar { display: none; }
  .bottom-nav { display: flex; }
}

.report-mode-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.shortage-actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0.65rem 0;
}
.section-subtitle {
  margin: 0.9rem 0 0.45rem;
  font-size: 0.94rem;
  color: var(--navy);
}
.shortage-box {
  margin-top: 0.9rem;
  padding: 0.85rem;
  border-radius: 10px;
  border: 1px solid #f59e0b;
  background: #fffbeb;
}
.shortage-options {
  display: grid;
  gap: 0.45rem;
}
.shortage-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.86rem;
  cursor: pointer;
}
.inv-qty-input {
  width: 84px;
  padding: 0.3rem 0.45rem;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 6px;
}
