:root {
  --bg: #0d0c0a;
  --surface: #141210;
  --surface-2: #1b1916;
  --border: #2b2825;
  --border-light: #201e1b;
  --text: #eee8dc;
  --text-muted: #7b7268;
  --text-faint: #3d3930;
  --accent: #c8912b;
  --accent-light: #17140e;
  --gold: #c8912b;
  --gold-light: #17140b;
  --danger: #ba3c2e;
  --danger-light: #1a0d0b;
  --success: #5b8c65;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,0.5), 0 2px 12px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.6);
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-ui: 'Outfit', 'Helvetica Neue', sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Topbar ── */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 40%, var(--gold) 60%, transparent 100%);
  opacity: 0.6;
}

.topbar-brand { display: flex; align-items: center; gap: 13px; }

.brand-mark {
  width: 32px;
  height: 32px;
  border: 1.5px solid rgba(200, 145, 43, 0.45);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
}

.brand-mark svg { width: 16px; height: 16px; }

.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--text);
  line-height: 1;
}

.brand-sub {
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 3px;
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

/* ── Layout ── */

.page { max-width: 1140px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }

/* ── Cards ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card-header {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-family: var(--font-ui);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
}

.row-count-badge {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-faint);
}

.card-body { padding: 20px; }

/* ── Order Header Form ── */

.header-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-family: var(--font-ui);
  font-size: 9.5px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.field input {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 11px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: rgba(200,145,43,0.5); }

.defaults-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-top: 1px solid var(--border-light);
  background: var(--accent-light);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.defaults-row span {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

.defaults-msg {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--success);
  min-width: 60px;
}

.gold-price-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.gold-price-row label {
  font-family: var(--font-ui);
  font-size: 9.5px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.gold-price-row input {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--gold);
  background: var(--gold-light);
  border: 1px solid rgba(200,145,43,0.2);
  border-radius: var(--radius);
  padding: 6px 10px;
  outline: none;
  width: 120px;
  transition: border-color 0.15s;
}

.gold-price-row input:focus { border-color: rgba(200,145,43,0.55); }

.gold-price-row .hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
}

/* ── Karat Selector ── */

.karat-selector { display: flex; gap: 4px; }

.karat-btn {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  transition: all 0.15s;
  letter-spacing: 0.06em;
}

.karat-btn:hover { border-color: var(--text-muted); color: var(--text); }

.karat-btn.active {
  background: var(--gold);
  color: #0d0c0a;
  border-color: var(--gold);
  font-weight: 600;
}

/* ── Order Lines Table ── */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 12px;
}

thead th {
  padding: 10px 8px;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

thead th.center { text-align: center; }

tbody tr { border-bottom: 1px solid var(--border-light); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

tbody td { padding: 3px 4px; vertical-align: middle; }

.cell-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text);
  padding: 5px 4px;
  outline: none;
  border-radius: 4px;
}

.cell-input:focus {
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border);
}

.cell-input.center { text-align: center; }
.cell-input.right { text-align: right; }

.img-cell {
  width: 52px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.img-cell img {
  max-width: 46px;
  max-height: 42px;
  object-fit: contain;
  border-radius: 3px;
  display: block;
}

.img-placeholder {
  width: 46px;
  height: 40px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 9px;
  color: var(--text-faint);
  text-align: center;
  cursor: pointer;
  background: transparent;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1.3;
  padding: 2px;
}

.img-placeholder:hover { border-color: var(--gold); color: var(--text-muted); }

.del-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.del-btn:hover { color: var(--danger); background: var(--danger-light); }

.add-row-wrap {
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.add-row-count {
  width: 52px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 7px;
  outline: none;
}

/* ── Column Widths ── */

.col-w   { width: 62px; }
.col-img { width: 58px; }
.col-vs  { width: 90px; }
.col-sn  { width: 78px; }
.col-mt  { width: 52px; }
.col-qty { width: 44px; }
.col-obs { min-width: 100px; }
.col-uw  { width: 72px; }
.col-del { width: 34px; }

/* ── Totals ── */

.totals-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  display: flex;
  align-items: flex-end;
  gap: 52px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.total-stat { display: flex; flex-direction: column; gap: 4px; }

.total-stat .label {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.total-stat .value {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 300;
  color: var(--text);
  line-height: 1;
  letter-spacing: 0.02em;
}

.total-stat.gold .value {
  color: var(--gold);
  font-size: 40px;
}

.total-stat .formula-note {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 3px;
}

/* ── Buttons ── */

.btn {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
  letter-spacing: 0.04em;
}

.btn:hover { border-color: var(--text-muted); color: var(--text); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gold);
  color: #0d0c0a;
  border-color: var(--gold);
  font-weight: 600;
}

.btn-primary:hover { background: #d9a034; border-color: #d9a034; color: #0d0c0a; }

.btn-sm { font-size: 10.5px; padding: 5px 11px; }

/* ── Export Row ── */

.export-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  align-items: center;
}

.hide-totals-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  margin-right: auto;
}

.export-separator {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 0 4px;
}

/* ── Print (ctrl+P on main page) ── */

@media print {
  body { background: white !important; color: #111 !important; font-size: 11px; }
  .topbar, .defaults-row, .add-row-wrap, .export-row, .topbar-actions, .del-btn, .gold-price-row { display: none !important; }
  .card, .totals-card { box-shadow: none !important; border: 1px solid #ddd !important; background: white !important; page-break-inside: avoid; }
  .card-header { background: white !important; border-bottom-color: #ddd !important; }
  .card-title { color: #666 !important; }
  thead th { background: white !important; color: #666 !important; border-bottom-color: #ddd !important; }
  tbody tr { border-bottom-color: #eee !important; }
  tbody td, .cell-input { color: #111 !important; background: transparent !important; }
  .total-stat .value { color: #111 !important; font-size: 20px !important; }
  .total-stat.gold .value { color: #b8901a !important; font-size: 24px !important; }
  .total-stat .label, .total-stat .formula-note { color: #777 !important; }
  .page { padding: 0; max-width: 100%; }
  .img-placeholder { display: none; }
}
