/* =====================================================================
   Design tokens
   Palette: warm neutral background, deep slate for structure/nav, a
   burnt-bronze accent (nods to anodized aluminium finishes) for
   primary actions. Monospace for anything numeric - codes, dimensions,
   cut lengths - so measurements read like they would on a spec sheet.
   ===================================================================== */

:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-sunken: #f0eee9;
  --border: #ddd9d0;
  --border-strong: #c7c2b6;

  --text: #262421;
  --text-muted: #6b675f;
  --text-faint: #9b968b;

  --primary: #2f4858;
  --primary-hover: #24384a;
  --primary-tint: #e7edf0;

  --accent: #a15c33;
  --accent-hover: #8a4c29;
  --accent-tint: #f3e6dc;

  --danger: #a33b3b;
  --danger-tint: #f6e5e5;
  --success: #3f7a5c;
  --success-tint: #e5f0ea;

  --sans:
    -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono:
    ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(38, 36, 33, 0.06);
  --shadow-md: 0 6px 20px rgba(38, 36, 33, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

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

h1,
h2,
h3 {
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 4px;
}

h1 {
  font-size: 20px;
}
h2 {
  font-size: 16px;
}
h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

a {
  color: var(--primary);
}

.mono {
  font-family: var(--mono);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header p {
  color: var(--text-muted);
  margin: 4px 0 0;
  font-size: 13px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin: 2px 0 20px;
}

/* ---- App shell -------------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 12px;
}

.sidebar-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.sidebar-brand-text span {
  display: block;
  font-weight: 400;
  font-size: 11px;
  opacity: 0.65;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}

.sidebar nav a {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 13.5px;
  padding: 9px 12px;
  border-radius: var(--radius);
  transition: background 0.12s ease, color 0.12s ease;
}

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

.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 600;
}

.sidebar nav .nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.4);
  padding: 16px 12px 4px;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: 220px;
  padding: 28px 36px 60px;
}

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
  line-height: 1.2;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface-sunken);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}
.btn-danger:hover {
  background: var(--danger-tint);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Cards / surfaces ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad {
  padding: 20px;
}

/* ---- Tables --------------------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-sunken);
}

tr.row-clickable {
  cursor: pointer;
}

tr.row-clickable td.actions {
  cursor: default;
}

td.num,
th.num {
  font-family: var(--mono);
  text-align: right;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

.empty-row td {
  text-align: center;
  color: var(--text-faint);
  padding: 32px 14px;
  font-style: italic;
}

/* ---- Forms ------------------------------------------------------------------ */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.field input[type="number"] {
  font-family: var(--mono);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.field textarea {
  resize: vertical;
  min-height: 60px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.form-error {
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ---- Modal ------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(38, 36, 33, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 22px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

/* ---- Badges / pills ------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--surface-sunken);
  color: var(--text-muted);
}

.badge-accent {
  background: var(--accent-tint);
  color: var(--accent-hover);
}

.badge-primary {
  background: var(--primary-tint);
  color: var(--primary);
}

/* ---- Toolbar (search + add button row) ------------------------------------------ */

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.toolbar input[type="search"] {
  flex: 1;
  max-width: 320px;
  font-family: var(--sans);
  font-size: 13.5px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---- Cutting list spec cards (the signature element) ---------------------------- */

.cut-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.cut-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 16px;
  background: var(--surface-sunken);
  border-bottom: 1px dashed var(--border-strong);
}

.cut-card-header .ref {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
}

.cut-card-header .dims {
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 12.5px;
}

.cut-card-body {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.cut-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cut-metric .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.cut-metric .value {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
}

.cut-metric .value .unit {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 400;
  margin-left: 2px;
}

.cut-proportion {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin: 10px 16px 14px;
  background: var(--surface-sunken);
}

.cut-proportion .seg-frame {
  background: var(--primary);
}
.cut-proportion .seg-sash {
  background: var(--accent);
}
.cut-proportion .seg-glass {
  background: #cfd8de;
}

.cut-legend {
  display: flex;
  gap: 14px;
  padding: 0 16px 14px;
  font-size: 11px;
  color: var(--text-muted);
}

.cut-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.cut-legend i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}
.cut-legend .i-frame {
  background: var(--primary);
}
.cut-legend .i-sash {
  background: var(--accent);
}
.cut-legend .i-glass {
  background: #cfd8de;
}

.cut-summary-bar {
  display: flex;
  gap: 24px;
  padding: 14px 20px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.cut-summary-bar .stat .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
}
.cut-summary-bar .stat .value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
}

/* ---- Misc ------------------------------------------------------------------------- */

.helper-text {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
}

.image-preview-box {
  width: 160px;
  height: 160px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--surface-sunken);
  overflow: hidden;
  outline: none;
}

.image-preview-box:hover,
.image-preview-box:focus {
  border-color: var(--primary);
}

.image-preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-preview-hint {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 0 10px;
  line-height: 1.5;
}

.product-thumb {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
  vertical-align: middle;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.tab-row {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-row a {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-row a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.htmx-request .htmx-indicator {
  opacity: 1;
}
.htmx-request.htmx-indicator {
  opacity: 1;
}
