:root {
  --brand:       #0b0c13;
  --brand-mid:   #1c1e2a;
  --brand-lift:  #9293a0;
  --bg:          #f5f5f7;
  --surface:     #ffffff;
  --border:      #dddde4;
  --text:        #151314;
  --text-mid:    #333333;
  --text-muted:  #9293a0;
  --danger:      #b91c1c;
  --success:     #166534;
  --radius:      6px;
  --shadow:      0 1px 4px rgba(0,0,0,.09);
  --shadow-md:   0 4px 16px rgba(0,0,0,.13);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 28px;
  height: 54px;
  gap: 32px;
  box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
.topbar-brand { display: flex; align-items: baseline; gap: 12px; text-decoration: none; }
.topbar-logo { height: 28px; width: auto; filter: brightness(0) invert(1); display: block; }
.brand-sub { font-size: 11px; color: var(--brand-lift); letter-spacing: 1.2px; text-transform: uppercase; }
.topbar-nav { display: flex; gap: 4px; margin-left: auto; }
.topbar-nav a {
  color: var(--brand-lift);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: background .15s, color .15s;
}
.topbar-nav a:hover, .topbar-nav a.active { background: rgba(255,255,255,.10); color: #fff; }

/* ── main layout ── */
#app { padding: 28px 28px 60px; max-width: 1280px; margin: 0 auto; }

/* ── page headings ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--brand); }
.page-header p { color: var(--text-muted); font-size: 13px; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, box-shadow .15s, filter .15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-mid); }
.btn-accent { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-accent:hover { background: var(--brand-mid); }
.btn-ghost { background: transparent; color: var(--text-mid); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.12); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: var(--radius);
  line-height: 1;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── quote cards ── */
.quote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.quote-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top: 3px solid var(--brand);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
}
.quote-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card-docno { font-size: 11px; font-weight: 700; letter-spacing: .8px; color: var(--brand-lift); text-transform: uppercase; }
.card-title { font-size: 15px; font-weight: 700; line-height: 1.3; color: var(--text); }
.card-customer { font-size: 13px; color: var(--text-muted); }
.card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-total { font-size: 17px; font-weight: 700; color: var(--brand); margin-top: 4px; }
.card-actions { display: flex; gap: 8px; margin-top: 6px; }

/* ── editor layout ── */
.editor-layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 20px;
  align-items: start;
}
.editor-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 76px;
}
.editor-sidebar h3 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: block;
}
.sidebar-field { margin-bottom: 10px; }
.sidebar-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.sidebar-field input,
.sidebar-field textarea,
.sidebar-field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  font-family: inherit;
}
.sidebar-field input:focus,
.sidebar-field textarea:focus,
.sidebar-field select:focus {
  outline: 2px solid var(--brand);
  border-color: transparent;
}
.sidebar-field textarea { resize: vertical; min-height: 56px; }
.sidebar-section-divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.sidebar-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ── scope editor ── */
.scope-panel { display: flex; flex-direction: column; gap: 16px; }
.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.section-header {
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-header .btn-sm {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  font-weight: 600;
}
.section-header .btn-sm:hover { background: rgba(255,255,255,.22); }

.placement-table { width: 100%; border-collapse: collapse; }
.placement-table th {
  background: #f0f0f3;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.placement-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #ebebef;
  vertical-align: middle;
}
.placement-table tr:last-child td { border-bottom: none; }
.placement-table tr:hover td { background: #f8f8fb; }
.col-num { width: 52px; color: var(--text-muted); font-size: 12px; }
.col-name { font-weight: 500; }
.col-qty, .col-unit, .col-total { width: 110px; text-align: right; }
.col-actions { width: 64px; text-align: center; }
.input-price {
  width: 100%;
  text-align: right;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 13px;
  background: transparent;
  font-family: inherit;
}
.input-price:focus { background: var(--surface); border-color: var(--brand); outline: none; }
.input-qty {
  width: 52px;
  text-align: center;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 13px;
  background: transparent;
  font-family: inherit;
}
.input-qty:focus { background: var(--surface); border-color: var(--brand); outline: none; }
.total-bar {
  background: var(--brand);
  border-radius: var(--radius);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
}
.total-bar .label { font-size: 13px; color: var(--brand-lift); font-weight: 500; }
.total-bar .amount { font-size: 24px; font-weight: 700; color: #fff; }
.total-bar .excl { font-size: 11px; color: var(--brand-lift); margin-top: 2px; }
.empty-section {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ── modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0,0,0,.30);
  width: 100%;
  max-width: 700px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 460px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--brand);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.modal-header h2 { font-size: 15px; font-weight: 700; }
.modal-header .btn-icon { color: var(--brand-lift); }
.modal-header .btn-icon:hover { background: rgba(255,255,255,.12); color: #fff; }
.modal-toolbar {
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.input-search {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
}
.input-search:focus { outline: 2px solid var(--brand); border-color: transparent; }
.select-sm {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
}
.cat-list { overflow-y: auto; flex: 1; padding: 8px; }
.cat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.cat-item:hover { background: #f0f0f3; border-color: var(--border); }
.cat-item-code { font-size: 10px; font-weight: 700; letter-spacing: .7px; color: var(--brand-lift); text-transform: uppercase; margin-bottom: 2px; }
.cat-item-name { font-weight: 600; font-size: 13px; color: var(--text); }
.cat-item-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.cat-item-meta { display: flex; gap: 8px; margin-top: 4px; }
.cat-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  background: #e8e8ec;
  color: var(--text-mid);
  font-weight: 600;
}

/* ── new quote form ── */
.form-grid { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.form-grid input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
}
.form-grid input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ── misc ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-mid);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--brand); text-decoration: underline; }
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e8e8ec;
  color: var(--text-mid);
  letter-spacing: .4px;
}
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 300;
  animation: slide-in .2s ease;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes slide-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted  { color: var(--text-muted); }
.text-right  { text-align: right; }
.mt-2        { margin-top: 8px; }

/* ── status badges ── */
.status-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: .4px;
  text-transform: uppercase;
  vertical-align: middle;
}
.status-draft    { background: #e8e8ec; color: #555; }
.status-sent     { background: #dbeafe; color: #1d4ed8; }
.status-po-issued { background: #dcfce7; color: #15803d; }
.status-invoiced { background: #d1fae5; color: #065f46; }

/* ── catalogue admin list ── */
.admin-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.admin-table th {
  background: #f0f0f3;
  padding: 9px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: default;
}
.admin-table th[onclick] { cursor: pointer; user-select: none; }
.admin-table th[onclick]:hover { color: var(--text-mid); background: #e8e8ec; }
.admin-table th.sort-active { color: var(--brand); }
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #ebebef;
  font-size: 13px;
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f8f8fb; }
.admin-code {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--brand-lift);
  text-transform: uppercase;
  white-space: nowrap;
}
.admin-table .col-sec { width: 52px; color: var(--text-muted); text-align: center; }
.admin-table .col-actions-th, .admin-table .col-actions-td { width: 140px; text-align: right; white-space: nowrap; }
.admin-table .col-actions-td { display: flex; gap: 6px; justify-content: flex-end; }

/* ── catalogue item editor ── */
.card-body { padding: 14px 16px; }
.card-hint { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.card-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  line-height: 1.6;
  padding: 8px 10px;
}
.card-textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }

/* ── attribute key-value editor ── */
.attr-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  margin-bottom: 5px;
  align-items: center;
}
.attr-label-input, .attr-value-input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.attr-label-input:focus, .attr-value-input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.attr-remove { font-size: 13px; padding: 2px 6px; }

/* ── modal size variant ── */
.modal-lg { max-width: 860px; }

/* ── catalogue history modal ── */
.cathistory-body {
  overflow-y: auto;
  max-height: 70vh;
  padding: 8px;
}
.history-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.history-meta {
  background: #f0f0f3;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.history-who { font-weight: 600; color: var(--brand); }
.history-when { color: var(--text-muted); }
.history-changes {
  list-style: none;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-changes li { font-size: 13px; color: var(--text-mid); }
.history-changes strong { color: var(--brand); margin-right: 4px; }
.history-init { font-size: 12px; color: var(--text-muted); font-style: italic; padding: 10px 14px; }

/* ── topbar auth area ── */
#topbar-auth {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#topbar-auth[hidden] { display: none; }
.topbar-email {
  font-size: 12px;
  color: var(--brand-lift);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-signout {
  background: rgba(255,255,255,.10);
  color: var(--brand-lift);
  border: 1px solid rgba(255,255,255,.16);
  padding: 4px 11px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: inherit;
}
.btn-signout:hover { background: rgba(255,255,255,.20); color: #fff; }

/* ── login screen ── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 110px);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 44px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.login-card h2 { font-size: 22px; font-weight: 700; color: var(--brand); }
.login-card .login-sub { font-size: 13px; color: var(--text-muted); margin-top: -8px; }
.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.login-field input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.login-field input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.login-error {
  background: #fee2e2;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid #fca5a5;
}
