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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #1a1a1a;
  line-height: 1.5;
}

/* Accessibility utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
header {
  background: #1a1a1a;
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.header-logo {
  height: 36px;
  width: auto;
  display: block;
  flex-shrink: 0;
  mix-blend-mode: lighten;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
}

header a {
  color: #b0b0b0;
  text-decoration: none;
  font-size: 13px;
  transition: color .15s;
}

header a:hover {
  color: #e0e0e0;
}

.header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.header-nav .nav-username {
  color: #888;
  font-size: 13px;
}

.header-nav a {
  color: #c0c0c0;
  text-decoration: none;
  font-size: 13px;
  transition: color .15s;
}

.header-nav a:hover {
  color: #fff;
}

.header-nav button {
  background: none;
  border: 1px solid #e86a25;
  color: #e86a25;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.header-nav button:hover {
  background: #e86a25;
  color: #fff;
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* Cards */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
  padding: 22px 24px;
  margin-bottom: 18px;
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  color: #3d3d3d;
}

/* Buttons */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s, background .15s, color .15s, box-shadow .15s;
  line-height: 1.4;
}

button:focus-visible, .btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(232, 106, 37, 0.25);
}

.btn-primary {
  background: #e86a25;
  color: #fff;
  box-shadow: 0 1px 4px rgba(232,106,37,0.25);
}

.btn-primary:hover {
  opacity: .88;
}

.btn-danger {
  background: #c53030;
  color: #fff;
}

.btn-danger:hover {
  opacity: .88;
}

.btn-ghost {
  background: transparent;
  color: #e86a25;
  border: 1px solid #e86a25;
}

.btn-ghost:hover {
  background: #fff3ec;
}

.btn-success {
  background: #2d7a4f;
  color: #fff;
}

.btn-success:hover {
  opacity: .88;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Forms */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

label {
  font-size: 12px;
  font-weight: 500;
  color: #3d3d3d;
}

input, select, textarea {
  padding: 7px 10px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
  background: #fff;
  color: #1a1a1a;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #e86a25;
  box-shadow: 0 0 0 3px rgba(232, 106, 37, 0.15);
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.checkbox-row input[type=checkbox] {
  width: auto;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 9px 12px;
  background: #f5f5f5;
  font-weight: 600;
  color: #3d3d3d;
  border-bottom: 1px solid #eee;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  color: #1a1a1a;
}

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

tr:hover td {
  background: #fdf4ef;
}

/* Quote list */
.quote-list .quote-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid #eee;
}

.quote-item:last-child {
  border-bottom: none;
}

.quote-item .meta {
  font-size: 12px;
  color: #888;
  margin-top: 3px;
}

.quote-item .actions {
  display: flex;
  gap: 8px;
}

/* Variants / Tab buttons */
.variant-tabs {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
  margin-bottom: 0;
  margin-top: 8px;
  align-items: flex-end;
  border-bottom: 2px solid #e86a25;
}

.tab-btn {
  padding: 8px 18px;
  border: 1px solid #d0d5dd;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: #f5f6f8;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  margin-right: 3px;
  transition: background .12s, color .12s;
  position: relative;
  top: 2px;
}

.tab-btn:hover {
  background: #ffe8d6;
  color: #e86a25;
}

.tab-btn.active {
  background: #fff;
  color: #e86a25;
  border-color: #e86a25;
  border-bottom: 2px solid #fff;
  font-weight: 600;
  z-index: 1;
}

/* Pieces table actions */
.pieces-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* Result page */
.result-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-box {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  border-left: 4px solid #e86a25;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
}

.stat-box .value {
  font-size: 26px;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1.1;
}

.stat-box .label {
  font-size: 12px;
  color: #888;
  margin-top: 5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.strategy-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: #fff3ec;
  color: #e86a25;
}

/* Cutting diagrams */
.diagrams {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 14px;
}

.diagram-wrap {
  border: 1px solid #eee;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.diagram-wrap svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1a1a1a;
  color: #fff;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
}

#toast.show {
  opacity: 1;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Stale result warning */
.stale-warning {
  background: #fffbeb;
  border: 1px solid #f6ad55;
  color: #7b341e;
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 14px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #aaa;
  font-size: 14px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: 560px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

.modal-close:hover {
  color: #1a1a1a;
  background: #f5f5f5;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 13px 20px;
  border-top: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-search {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}

.modal-search:focus {
  outline: none;
  border-color: #e86a25;
  box-shadow: 0 0 0 3px rgba(232, 106, 37, 0.15);
}

/* Material brand groups */
.mat-brand-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  margin-top: 6px;
  border-radius: 6px;
  background: #f5f5f5;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
  transition: background .15s;
}

.mat-brand-header:hover {
  background: #eee;
}

.mat-brand-arrow {
  font-size: 10px;
  color: #999;
  transition: transform .15s;
  margin-left: auto;
}

.mat-brand-header.open .mat-brand-arrow {
  transform: rotate(90deg);
}

.mat-brand-count {
  font-size: 11px;
  font-weight: 400;
  color: #999;
  margin-left: 4px;
}

.mat-brand-items {
  display: none;
  padding: 2px 0 4px 4px;
}

.mat-brand-items.open {
  display: block;
}

.mat-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s;
}

.mat-check-row:hover {
  background: #fdf4ef;
}

.mat-check-row input[type="checkbox"] {
  cursor: pointer;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  accent-color: #e86a25;
}

.mat-check-row label {
  cursor: pointer;
  font-size: 13px;
  flex: 1;
  color: #1a1a1a;
}

/* Backsplash toggle row */
.backsplash-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff8f4;
  border-radius: 6px;
  margin-top: 4px;
  font-size: 13px;
  border: 1px solid #f5dbc9;
}

/* Modal selection count — left side */
.modal-sel-count {
  font-size: 12px;
  color: #888;
  margin-right: auto;
}
