:root {
  --accent: #1e3a5f;
  --accent-dark: #14283f;
  --accent-tint: #eaf0f6;
  --border: #d5dbe2;
  --border-strong: #b8c1cc;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2530;
  --text-muted: #5b6774;
  --text-faint: #8b95a1;
  --danger: #a3372f;
  --danger-tint: #fbeceb;
  --success: #2c6e49;
  --success-tint: #eaf5ee;
  --warn: #8a6116;
  --warn-tint: #fbf1de;
  --radius: 3px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- Top nav ---------- */
.topnav {
  display: flex;
  align-items: center;
  height: 52px;
  min-height: 52px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  gap: 24px;
}

.topnav .brand {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 28px;
  max-width: 120px;
  object-fit: contain;
}

.topnav nav {
  display: flex;
  gap: 4px;
}

.topnav .spacer { flex: 1; }

.topnav .user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.85);
}
.topnav .user-badge button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  padding: 5px 11px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
}
.topnav .user-badge button:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- Login page ---------- */
.login-body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 {
  font-size: 16px;
  margin: 0;
  color: var(--accent);
}
.login-card .text-muted { margin: -8px 0 4px; font-size: 12.5px; }
.login-error {
  background: var(--danger-tint);
  color: var(--danger);
  border: 1px solid #e0b7b3;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12.5px;
}

.topnav nav button {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.topnav nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.topnav nav button.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 600;
}

/* ---------- Layout ---------- */
.view {
  flex: 1;
  overflow: auto;
  padding: 24px 28px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.view-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.view-header .sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  padding: 7px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}

.btn:hover { background: #f0f2f4; }
.btn:active { background: #e6e9ec; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger {
  color: var(--danger);
  border-color: #e0b7b3;
  background: var(--danger-tint);
}
.btn-danger:hover { background: #f7dcda; }

.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-text {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 4px 6px;
  cursor: pointer;
  font-size: 12.5px;
}
.btn-text:hover { text-decoration: underline; }
.btn-text.danger { color: var(--danger); }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

input[type="text"], input[type="number"], input[type="date"], input[type="email"],
select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 9px;
  background: #fff;
  width: 100%;
}

input[type="checkbox"] { width: auto; }

textarea { resize: vertical; min-height: 60px; font-family: inherit; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(30, 58, 95, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-grid .span-2 { grid-column: span 2; }

/* ---------- Letterhead ---------- */
.letterhead {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-strong);
}
.letterhead-logo {
  height: 64px;
  max-width: 200px;
  object-fit: contain;
}
.letterhead-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.letterhead-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  font-weight: 600;
  background: #fafbfc;
  border-bottom: 1px solid var(--border-strong);
}

tbody tr:hover { background: #fafbfc; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.mono-num { font-variant-numeric: tabular-nums; }

.scope-cell {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-draft { background: #eceff2; color: var(--text-muted); }
.badge-sent { background: #e5eef8; color: #275685; }
.badge-accepted { background: var(--success-tint); color: var(--success); }
.badge-declined { background: var(--danger-tint); color: var(--danger); }

.status-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 3px 20px 3px 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%235b6774' d='M3 4.5l3 3 3-3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 9px;
}
.status-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Toolbar / filters ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar input[type="text"] { width: 260px; }

.chip {
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Stat strip (Quotations list summary) ---------- */
.stat-strip {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stat-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px 16px;
  min-width: 160px;
}
.stat-tile-margin {
  background: #fdf8ef;
  border-color: #ecdcb4;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-value {
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}
.stat-tile-margin .stat-value { color: var(--warn); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state p { margin: 0 0 14px; font-size: 14px; }

/* ---------- Editor layout ---------- */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;
}

.editor-main { display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin: 0 0 12px;
  font-weight: 700;
}

.totals-panel {
  position: sticky;
  top: 0;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.totals-row.grand {
  border-top: 1px solid var(--border-strong);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 17px;
  font-weight: 700;
}
.totals-row .val { font-variant-numeric: tabular-nums; }

.profitability-card {
  background: #fdf8ef;
  border-color: #ecdcb4;
}
.profitability-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.internal-badge {
  text-transform: none;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.2px;
  color: var(--warn);
  background: #f3e6c4;
  border-radius: 8px;
  padding: 1px 7px;
}

/* ---------- Signature block ---------- */
.signature-block {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 220px;
}
.signature-img {
  max-height: 56px;
  max-width: 200px;
  object-fit: contain;
}
.signature-blank {
  height: 56px;
}
.signature-line {
  border-top: 1px solid var(--text);
  width: 200px;
  margin-top: 4px;
}
.signature-name {
  font-weight: 700;
  font-size: 13px;
  margin-top: 4px;
}
.signature-title {
  font-size: 12px;
  color: var(--text-muted);
}
.pr-sig-preview { margin-bottom: 4px; }
.pr-sig-preview .signature-img { max-height: 32px; max-width: 90px; }
.pr-sig-preview .signature-blank { height: 32px; width: 60px; background: #fafbfc; border: 1px dashed var(--border-strong); }

.discount-toggle {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  width: fit-content;
}
.discount-toggle button {
  border: none;
  background: #fff;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 12.5px;
  border-right: 1px solid var(--border-strong);
}
.discount-toggle button:last-child { border-right: none; }
.discount-toggle button.active { background: var(--accent); color: #fff; }

.table-scroll { overflow-x: auto; }
.line-items-table td { vertical-align: top; }
.line-items-table input[type="text"], .line-items-table input[type="number"] {
  padding: 5px 7px;
}
.line-items-table { min-width: 920px; }
.line-items-table .qty-input { width: 60px; }
.line-items-table .cost-input { width: 80px; }
.line-items-table .margin-input { width: 70px; }
.line-items-table .drag-handle {
  cursor: grab;
  color: var(--text-faint);
  width: 18px;
  text-align: center;
}
.line-items-table tr.dragging { opacity: 0.4; }
.line-items-table tr.drop-target { border-top: 2px solid var(--accent); }

.add-row-control {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}
.add-row-control select { flex: 1; max-width: 360px; }

.hint {
  font-size: 11.5px;
  color: var(--warn);
  background: var(--warn-tint);
  border: 1px solid #ecdcb4;
  padding: 4px 8px;
  border-radius: var(--radius);
  display: inline-block;
  margin-top: 4px;
}

.footer-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 6px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 33, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  width: 460px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  overflow: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
}
.modal h2 { margin: 0 0 14px; font-size: 15px; }
.modal .footer-actions { margin-top: 16px; }

.pdf-modal {
  width: 820px;
  max-width: calc(100vw - 60px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
}
.pdf-frame {
  flex: 1;
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #525659;
}

/* ---------- Settings ---------- */
.settings-section { margin-bottom: 26px; }
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.logo-preview {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border: 1px solid var(--border);
  background: #fafbfc;
}
.catalog-table input[type="text"] { min-width: 140px; }
.catalog-table input[type="number"] { width: 100px; }
.catalog-table td:last-child { text-align: right; }
.catalog-img-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.catalog-img-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #fafbfc;
}
.catalog-img-blank { }
.catalog-img-cell input[type="file"] {
  font-size: 11px;
  width: 120px;
}
.data-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #fafbfc;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius);
  word-break: break-all;
  color: var(--text-muted);
}
.import-warning {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.toast.warn { background: var(--warn); }
