:root {
  --ink: #161412;
  --muted: #68615a;
  --paper: #f4efe8;
  --panel: #fffdf9;
  --line: #ddd3c8;
  --crimson: #b21f32;
  --green: #687563;
  --gold: #b9985b;
  --charcoal: #23201d;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  color: #f8f3eb;
  background: var(--charcoal);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.brand img {
  width: 34px;
  height: 34px;
  filter: invert(1);
}

.account {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--gold);
}

.account strong,
.account p {
  display: block;
  margin: 0;
}

.account p {
  color: #cfc4b6;
  font-size: 12px;
}

.workspace-nav {
  display: grid;
  gap: 8px;
}

.workspace-nav button,
.ghost-button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  color: #f8f3eb;
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.workspace-nav button.active {
  color: #fff;
  background: var(--crimson);
  border-color: var(--crimson);
}

.ghost-button {
  margin-top: auto;
  text-align: center;
}

.logout-link {
  width: 100%;
}
.auth-panel,
.main-panel {
  padding: clamp(22px, 4vw, 56px);
  min-width: 0;
}

.auth-panel {
  display: grid;
  align-content: center;
  gap: 32px;
}

.auth-copy {
  max-width: 760px;
}

.kicker {
  margin: 0 0 10px;
  color: var(--crimson);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 1.02;
}

h2 {
  margin-bottom: 18px;
  font-size: 24px;
}

.auth-copy p:last-child,
.panel p {
  color: var(--muted);
}

.auth-grid,
.calc-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.admin-wide {
  grid-column: 1 / -1;
}

.panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #4d4741;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfc4b7;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
}

input,
select {
  height: 46px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

.language-switcher {
  display: block;
  margin: -8px 0 0;
  color: inherit;
  font-size: 13px;
  font-weight: 800;
  text-transform: none;
}

.language-switcher select {
  height: 40px;
  border-color: rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.language-switcher option {
  color: var(--ink);
  background: #fff;
}

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

.panel button,
.tool-row button,
.upload-form button {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 5px;
  color: #fff;
  background: var(--crimson);
  font-weight: 900;
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.panel button.secondary-button {
  width: auto;
  min-width: 104px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.topbar h1 {
  margin: 0;
}

.site-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
}

.section {
  display: none;
  min-width: 0;
}

.section.active {
  display: block;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 220px 120px;
  gap: 12px;
  margin-bottom: 18px;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.product-card {
  min-height: 236px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.product-media-preview,
.product-media-placeholder {
  width: 100%;
  min-height: 132px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(135deg, #f7f1e9, #e9dfd2);
}

.product-media-preview {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--ink);
  text-align: center;
}

.product-media-preview span {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0;
  border: 2px solid #1d1a17;
  border-radius: 50%;
  color: #1d1a17;
  font-size: 13px;
}

.product-media-preview b {
  font-size: 13px;
}

.product-media-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.product-card span {
  display: inline-block;
  margin-bottom: 28px;
  color: var(--crimson);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.product-card p {
  color: var(--muted);
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.meta-line b {
  padding: 5px 8px;
  border-radius: 4px;
  background: #eee5dc;
  font-size: 12px;
}

.product-edit-button {
  width: 100%;
  min-height: 38px;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  background: #fff;
  font-weight: 900;
}

.product-viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.product-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 16, 14, 0.72);
}

.product-viewer-dialog {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(820px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(320px, 62vh) auto;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0,0,0,0.32);
}

.product-viewer-dialog header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.product-viewer-dialog h2 {
  margin: 0;
}

.product-viewer-close {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 26px;
  line-height: 1;
}

.product-viewer-canvas {
  min-height: 320px;
  touch-action: none;
}

.product-viewer-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.product-viewer-hint {
  margin: 0;
  padding: 14px 22px 18px;
  color: var(--muted);
}

body.modal-open {
  overflow: hidden;
}

output {
  display: block;
  min-height: 48px;
  margin-top: 14px;
  padding: 14px;
  border-radius: 6px;
  background: #eee5dc;
  color: var(--ink);
  font-weight: 900;
}

.upload-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  margin-bottom: 22px;
  min-width: 0;
}

.viewer-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
}

.viewer-canvas {
  width: 100%;
  height: 460px;
}

.viewer-canvas canvas {
  display: block;
}

.viewer-meta {
  padding: 16px 18px;
  color: #fff;
  background: #1d1b19;
}

.viewer-meta p {
  margin: 4px 0 0;
  color: #c7beb4;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.viewer-actions button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 5px;
  color: #fff;
  background: transparent;
  font-weight: 900;
}

.viewer-actions button[aria-pressed="true"] {
  border-color: var(--crimson);
  background: var(--crimson);
}

.dimension-text {
  color: #fff !important;
  font-weight: 900;
}

.view-gallery {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.view-gallery:empty {
  display: none;
}

.view-gallery figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171412;
}

.view-gallery img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.view-gallery figcaption {
  padding: 10px 12px;
  color: #f4efe8;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #625a52;
  font-size: 12px;
  text-transform: uppercase;
}

td button {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  color: #2d2925;
  background: #eee5dc;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.preview_ready {
  color: #fff;
  background: var(--green);
}

.status-pill.cad_source {
  color: #fff;
  background: var(--crimson);
}

.user-list {
  display: grid;
  gap: 10px;
}

.user-item,
.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border-radius: 6px;
  background: #f3ece3;
}

.user-item.user-editor {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(190px, 1.2fr) minmax(150px, 0.85fr) minmax(170px, 1fr) auto;
  align-items: end;
}

.user-editor label {
  margin: 0;
}

.user-editor button {
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 5px;
  color: #fff;
  background: var(--crimson);
  font-weight: 900;
}

.user-item select {
  width: 100%;
}

.queue-list {
  display: grid;
  gap: 10px;
}

.queue-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.inquiry-item {
  align-items: flex-start;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 16px;
  border-radius: 6px;
  color: #fff;
  background: var(--charcoal);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .workspace-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .upload-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .auth-grid,
  .calc-grid,
  .admin-grid,
  .tool-row,
  .data-grid {
    grid-template-columns: 1fr;
  }

  .workspace-nav {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .user-item.user-editor {
    grid-template-columns: 1fr;
  }

  .viewer-canvas {
    height: 340px;
  }

  .table-wrap {
    overflow-x: visible;
    border: 0;
    background: transparent;
  }

  table {
    min-width: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }

  td {
    display: grid;
    grid-template-columns: minmax(84px, 34%) minmax(0, 1fr);
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: #625a52;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
  }

  td button {
    width: 100%;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .panel button.secondary-button {
    width: 100%;
  }

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