/* ─── Pointers Calculator — Production Styles ─── */

:root {
  color-scheme: light;
  --ink: #1a1a1a;
  --ink-secondary: #555248;
  --muted: #7a7468;
  --line: #e4ddd0;
  --line-light: #f0ebe0;
  --paper: #faf8f4;
  --field: #ffffff;
  --card: #ffffff;
  --accent: #b8922e;
  --accent-hover: #9a7a20;
  --accent-light: rgba(184, 146, 46, 0.08);
  --accent-ring: rgba(184, 146, 46, 0.25);
  --deep: #1b2825;
  --deep-lighter: #263532;
  --soft: #f5f0e4;
  --danger: #c0392b;
  --danger-light: #fdf0ef;
  --success: #27ae60;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(30, 28, 22, 0.06);
  --shadow-md: 0 4px 16px rgba(30, 28, 22, 0.07);
  --shadow-lg: 0 8px 32px rgba(30, 28, 22, 0.09);
  --transition: 0.18s ease;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: inherit;
}

/* ─── Header ─── */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 20px 28px;
  background: var(--deep);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  position: relative;
  z-index: 10;
}

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

.brand-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.3px;
}

h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.price-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#priceStatus {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
}

.price-status .btn-refresh {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 13px;
  padding: 6px 14px;
  min-height: 34px;
  border-radius: 8px;
  font-weight: 600;
  transition: background var(--transition), border-color var(--transition);
}

.price-status .btn-refresh:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
}

.price-status .btn-refresh.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* ─── Buttons ─── */

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
}

button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:active {
  transform: scale(0.97);
}

button:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-secondary);
  font-weight: 600;
}

.btn-ghost:hover {
  background: var(--soft);
  border-color: var(--line);
  color: var(--ink);
}

/* ─── Tabs ─── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 16px 28px 0;
  background: var(--paper);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 700;
  position: relative;
  transition: color var(--transition), background var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover {
  color: var(--ink);
  background: var(--soft);
}

.tab.active {
  background: var(--card);
  color: var(--accent-hover);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--card);
}

/* ─── Views ─── */

.view[hidden] {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.75fr);
  gap: 20px;
  padding: 20px 28px 40px;
  align-items: start;
}

.repair-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.75fr);
  gap: 20px;
  padding: 20px 28px 40px;
  align-items: start;
}

.conversion-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.75fr);
  gap: 20px;
  padding: 20px 28px 40px;
  align-items: start;
}

.conv-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
}

.conv-table {
  background: var(--soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}

.conv-table h2 {
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.conv-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.conv-table th {
  text-align: left;
  font-weight: 600;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink-secondary);
}

.conv-table td {
  padding: 6px 0;
  border-bottom: 1px solid var(--line-light);
}

.conv-table td:last-child,
.conv-table th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ─── Panels & Cards ─── */

.panel,
.summary {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-md);
}

.quote-panel {
  grid-column: 1;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-light);
}

.panel-heading h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-heading .btn-ghost {
  min-height: 34px;
  font-size: 13px;
  padding: 0 12px;
}

/* ─── Form Controls ─── */

.grid {
  display: grid;
  gap: 16px;
}

.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7468' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

textarea {
  resize: vertical;
  line-height: 1.5;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 12px;
  background: var(--soft);
  border-color: var(--line-light);
}

input[type="number"] {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ─── Conversion Inline ─── */

.conversion-inline {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-light);
}

.conversion-inline .grid {
  margin-top: 12px;
}

#conversionInlineFields[hidden] {
  display: none;
}

/* ─── Extras Row ─── */

.er-addons {
  display: grid;
  gap: 2px;
  padding: 8px 0;
}

.er-addons .checkline {
  min-height: 36px;
  font-size: 13px;
}

.extras {
  display: grid;
  grid-template-columns: minmax(170px, 0.65fr) repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line-light);
}

.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.checkline input[type="checkbox"],
.checkline input[type="radio"] {
  width: 18px;
  min-height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.choice-group {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--field);
}

.choice-group legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0 4px;
}

.choice-group .checkline {
  min-height: 28px;
  font-size: 13px;
}

.polish-fields,
.resize-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.polish-fields[hidden],
.resize-fields[hidden] {
  display: none;
}

.polish-fields .choice-group {
  grid-column: 1 / -1;
}

/* ─── Stone Rows ─── */

.stone-head,
.stone-row {
  display: grid;
  grid-template-columns: 0.9fr 1.2fr 1.1fr 80px 110px 38px;
  gap: 8px;
  align-items: center;
}

.stone-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 0 2px;
}

.stone-rows {
  display: grid;
  gap: 8px;
}

.stone-rows:empty::after {
  content: "No stones added yet";
  display: block;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  background: var(--soft);
  border-radius: 8px;
  border: 1px dashed var(--line);
}

.stone-kind {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line-light);
  border-radius: 8px;
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.remove-stone {
  width: 38px;
  min-height: 38px;
  padding: 0;
  background: var(--danger-light);
  color: var(--danger);
  border-color: transparent;
  font-size: 18px;
  line-height: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-stone:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ─── Summary Sidebar ─── */

.summary {
  grid-column: 2;
  grid-row: 1 / span 2;
  position: sticky;
  top: 16px;
  display: grid;
  gap: 18px;
  padding: 0;
  overflow: hidden;
}

.summary-total {
  padding: 24px 22px;
  background: var(--deep);
  color: #fff;
}

.summary-total span {
  display: block;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

#convResult {
  display: inline;
  font-size: inherit;
  color: inherit;
  font-weight: inherit;
  text-transform: none;
  letter-spacing: inherit;
}

.summary-total strong {
  display: block;
  margin-top: 6px;
  font-size: 36px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.summary-body {
  padding: 0 22px 22px;
  display: grid;
  gap: 18px;
}

.breakdown {
  margin: 0;
  display: grid;
  gap: 0;
}

.breakdown div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-light);
}

.breakdown div[hidden] {
  display: none !important;
}

.breakdown div:last-child {
  border-bottom: none;
}

.breakdown dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.breakdown dd {
  margin: 0;
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#erAddonRows {
  display: contents;
}

.discount-row dt,
.discount-row dd {
  color: var(--danger);
}

.market {
  background: var(--soft);
  border-radius: var(--radius);
  padding: 16px;
}

.market h2 {
  margin-bottom: 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.market-list {
  display: grid;
  gap: 0;
}

.market-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(125, 93, 24, 0.12);
  font-size: 13px;
}

.market-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.market-row span {
  color: var(--ink-secondary);
  font-weight: 600;
}

.market-row strong {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.wide {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
  border-radius: var(--radius);
}

.wide.copied {
  background: var(--success);
  border-color: var(--success);
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--deep);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Loading Pulse ─── */

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.loading-text {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ─── Responsive ─── */

@media (max-width: 1024px) {
  .layout,
  .repair-layout,
  .conversion-layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .quote-panel,
  .summary {
    grid-column: auto;
    grid-row: auto;
  }

  .summary {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px 18px;
    gap: 12px;
  }

  .price-status {
    align-items: flex-start;
    justify-content: flex-start;
    width: 100%;
  }

  h1 {
    font-size: 20px;
  }

  .tabs {
    padding: 12px 16px 0;
  }

  .tab {
    padding: 8px 16px;
    font-size: 13px;
  }

  .layout,
  .repair-layout {
    padding: 12px;
    gap: 14px;
  }

  .panel,
  .summary {
    border-radius: var(--radius);
  }

  .two,
  .extras,
  .polish-fields {
    grid-template-columns: 1fr;
  }

  .stone-head {
    display: none;
  }

  .stone-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 12px;
    background: var(--soft);
    border-radius: 8px;
    border: 1px solid var(--line-light);
  }

  .stone-row select,
  .stone-row .stone-kind {
    grid-column: 1 / -1;
  }

  .remove-stone {
    width: 100%;
    grid-column: 1 / -1;
  }

  .summary-total strong {
    font-size: 28px;
  }

  .dist-mode-toggle {
    flex-direction: column;
  }
}

/* ─── Distribution Tab ─── */

.dist-mode-toggle {
  display: flex;
  gap: 0;
  margin: 16px 28px 0;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

.dist-mode {
  flex: 1;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  background: var(--card);
  border: none;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 42px;
}

.dist-mode:hover {
  background: var(--soft);
  color: var(--ink);
}

.dist-mode.active {
  background: var(--deep);
  color: #fff;
}

.dist-sub[hidden] {
  display: none;
}

.dist-gold-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-hover);
}

.dist-gold-info strong {
  font-size: 15px;
  color: var(--deep);
}
