/* JewelCAD Studio — design tokens (dark default, light via [data-theme="light"]) */
:root {
  --bg: #0d0c0b;
  --panel: #151412;
  --panel-2: #1c1a17;
  --input: #11100e;
  --line: #2b2823;
  --line-2: #3a352e;
  --text: #ece7df;
  --text-2: #cfc7ba;
  --muted: #918879;
  --gold: #d4ae68;
  --gold-2: #ecd39a;
  --gold-ink: #1b1508;
  --accent-soft: rgba(212, 174, 104, .12);
  --danger: #e2735f;
  --danger-soft: rgba(226, 115, 95, .12);
  --ok: #67c08a;
  --topbar: #0a0908;
  --viewer-a: #2a2622;
  --viewer-b: #0d0c0b;
  --checker-a: #2a2622;
  --checker-b: #221f1b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --panel-2: #f8f6f2;
  --input: #ffffff;
  --line: #e6e1d8;
  --line-2: #d6cfc3;
  --text: #1f1b16;
  --text-2: #3d362e;
  --muted: #7b7266;
  --gold: #a9833c;
  --gold-2: #8a6a2c;
  --gold-ink: #ffffff;
  --accent-soft: rgba(169, 131, 60, .1);
  --danger: #c2462f;
  --danger-soft: rgba(194, 70, 47, .08);
  --ok: #2f8f57;
  --topbar: #ffffff;
  --viewer-a: #ffffff;
  --viewer-b: #e9e5de;
  --checker-a: #efebe4;
  --checker-b: #e4dfd6;
  --shadow: 0 10px 30px rgba(60, 45, 20, .10);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; color: inherit; }
a { color: var(--gold-2); }

/* ---------------------------------------------------------------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  border-bottom: 1px solid var(--line); background: var(--topbar); height: 58px; }
.brand { font-family: "Cormorant Garamond", serif; font-size: 23px; font-weight: 600; letter-spacing: .4px;
  text-decoration: none; color: var(--text); white-space: nowrap; }
.brand { font-family: Inter, system-ui, sans-serif; font-weight: 600; letter-spacing: 2.5px; font-size: 19px; }
.brand em { color: var(--gold); font-style: normal; }
.tag { color: var(--muted); font-size: 12px; letter-spacing: .3px; white-space: nowrap; }
.auth .tagline { color: #d4ae68; letter-spacing: 2px; text-transform: uppercase; font-size: 12px; font-weight: 600; margin: 0 0 14px; }
.logo { color: var(--gold); }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 500; }
.nav a.on, .nav a:hover { color: var(--text); background: var(--panel-2); }
.spacer { flex: 1; }
.credits { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px;
  background: var(--accent-soft); color: var(--gold-2); font-weight: 600; font-size: 13px; border: 1px solid transparent;
  cursor: pointer; font-variant-numeric: tabular-nums; }
.credits:hover { border-color: var(--gold); }
.iconbtn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; color: var(--text-2); }
.iconbtn:hover { border-color: var(--gold); color: var(--gold-2); }
.iconbtn svg { width: 18px; height: 18px; }
.usermenu { position: relative; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--panel-2);
  color: var(--gold-2); font-weight: 600; cursor: pointer; display: grid; place-items: center; }
.menu { position: absolute; right: 0; top: 44px; min-width: 240px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 30; }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who b { display: block; }
.menu .who span { color: var(--muted); font-size: 12px; }
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 13px; }
.menu button:hover, .menu a:hover { background: var(--panel-2); }

/* ---------------------------------------------------------------- studio layout */
.layout { display: grid; grid-template-columns: 330px 1fr 350px; height: calc(100vh - 58px); }
.panel { background: var(--panel); padding: 18px 18px 26px; overflow-y: auto; }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
h2 { font-size: 11.5px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted);
  margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
h2:first-child { margin-top: 0; }
h2 .step { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px;
  background: var(--accent-soft); color: var(--gold-2); letter-spacing: 0; }

.drop { display: grid; place-items: center; min-height: 170px; border: 1.5px dashed var(--line-2);
  border-radius: var(--radius); background: var(--panel-2); cursor: pointer; text-align: center;
  padding: 12px; transition: border-color .2s, background .2s; overflow: hidden; }
.drop:hover, .drop.over { border-color: var(--gold); background: var(--accent-soft); }
.drop img { max-width: 100%; max-height: 220px; border-radius: 8px; background:
  repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 16px 16px; }
.drop span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.dropIcon { font-size: 24px; color: var(--gold); }

.seg { display: grid; grid-template-columns: repeat(2, 1fr); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 4px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--gold); color: var(--gold-ink); font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 4px; }
.center { text-align: center; }
.muted { color: var(--muted); font-style: normal; font-size: 11.5px; }

.field { margin: 12px 0; }
.field label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field output { color: var(--gold-2); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--gold); }
details { margin: 8px 0 4px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); margin: 8px 0; }
.check.small { margin: 0; font-size: 12px; }

.primary { width: 100%; margin-top: 14px; padding: 11px 14px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--gold); color: var(--gold-ink); font-weight: 600; letter-spacing: .2px; transition: filter .15s; }
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.primary .cost { opacity: .75; font-weight: 500; margin-left: 6px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--panel); cursor: pointer; font-size: 13px; color: var(--text); text-decoration: none; }
.btn:hover { border-color: var(--gold); }
.btn.gold { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.ghost:hover { border-color: var(--gold); }
.ghost.small { padding: 4px 10px; font-size: 12px; }
.ghost.active { border-color: var(--gold); color: var(--gold-2); }

.status { margin-top: 10px; font-size: 12px; color: var(--muted); }
.status .bar { height: 4px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .3s; }
.status.error { color: var(--danger); }
.bar.indet i { width: 35% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

.viewer { position: relative; background: radial-gradient(ellipse at 50% 40%, var(--viewer-a), var(--viewer-b) 75%); min-width: 0; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); pointer-events: none; }
.empty .gem { font-size: 56px; color: var(--line-2); }
.viewerBar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 8px;
  background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(8px); border: 1px solid var(--line);
  padding: 8px 10px; border-radius: 12px; flex-wrap: wrap; justify-content: center; box-shadow: var(--shadow); }
select { background: var(--input); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }

.downloads { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dl { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none;
  color: var(--text); background: var(--panel-2); transition: border-color .2s; }
.dl b { display: block; color: var(--gold-2); letter-spacing: .5px; }
.dl span { font-size: 11px; color: var(--muted); }
.dl:hover { border-color: var(--gold); }
.dl.disabled { opacity: .35; pointer-events: none; }
.dlmode { margin-bottom: 6px; }

.stats { margin-top: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.stats table { width: 100%; border-collapse: collapse; }
.stats td { padding: 3px 0; }
.stats td:last-child { text-align: right; color: var(--gold-2); font-variant-numeric: tabular-nums; }
.stats .sep td { border-top: 1px solid var(--line); padding-top: 6px; }
.notes { color: var(--danger); font-size: 12px; margin-top: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.renders { display: grid; gap: 10px; margin-top: 14px; }
.renders figure { margin: 0; background: var(--panel-2); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.renders img { width: 100%; display: block; background:
  repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 16px 16px; cursor: zoom-in; }
.renders figcaption { display: flex; justify-content: space-between; padding: 6px 10px; font-size: 12px; color: var(--muted); }

.warn { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); border-radius: 10px; padding: 10px; font-size: 12.5px; }

.ident { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }
.identHead { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.identHead b { font-size: 14px; color: var(--text); }
.identHead p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--gold-2); white-space: nowrap; }
.pill.ok { background: rgba(103, 192, 138, .14); color: var(--ok); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.ident .field { margin: 0; }
.num { width: 90px; background: var(--input); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.stonesHead { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text-2); }
.stoneList { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.stoneList li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; background: var(--input); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; }
.stoneList li.off { opacity: .4; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(128,128,128,.4); display: inline-block; }
.stoneList .meta { color: var(--muted); margin-left: auto; white-space: nowrap; }
.stoneList button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 2px; }
.stoneList .none { color: var(--muted); justify-content: center; }

.views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.vslot { position: relative; aspect-ratio: 1; border: 1.5px dashed var(--line-2); border-radius: 8px; background: var(--input);
  display: grid; place-items: center; cursor: pointer; font-size: 11px; color: var(--muted); overflow: hidden; text-align: center; }
.vslot:hover, .vslot.over { border-color: var(--gold); }
.vslot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.vslot .lbl { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.6); color: #eee; padding: 2px; }
.vslot .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.7); border: 0; color: #fff; border-radius: 50%;
  width: 18px; height: 18px; cursor: pointer; font-size: 11px; line-height: 18px; padding: 0; }

/* ---------------------------------------------------------------- dialogs, forms, toasts */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; min-width: 380px;
  max-width: min(560px, 94vw); box-shadow: var(--shadow); padding: 20px 22px; }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin: 0 0 12px; font-size: 16px; }
.list { list-style: none; padding: 0; margin: 0; max-height: 55vh; overflow: auto; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.list li.click { cursor: pointer; }
.list li.click:hover { background: var(--panel-2); }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.form input, .form select, .form textarea, .input { width: 100%; background: var(--input); border: 1px solid var(--line-2);
  border-radius: 9px; padding: 9px 11px; outline: none; }
.form input:focus, .form select:focus, .input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--accent-soft); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.err { color: var(--danger); font-size: 12.5px; min-height: 1em; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--gold); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 13px;
  max-width: 360px; animation: pop .2s ease-out; }
.toast.bad { border-left-color: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- auth pages */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth .art { position: relative; overflow: hidden; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(circle at 30% 20%, #3a3023, #120f0c 70%); color: #f2ead9; }
.auth .art .brand { color: #f2ead9; font-size: 26px; }
.auth .art h1 { font-family: "Cormorant Garamond", serif; font-weight: 600; font-size: 46px; line-height: 1.08; margin: 0 0 16px; max-width: 520px; }
.auth .art p { color: #c9bea9; max-width: 460px; font-size: 15px; }
.auth .art ul { list-style: none; padding: 0; margin: 22px 0 0; display: grid; gap: 10px; color: #e3d6bd; font-size: 14px; }
.auth .art li::before { content: "◆"; color: #d4ae68; margin-right: 10px; font-size: 10px; }
.auth .art .ringart { position: absolute; right: -120px; bottom: -120px; width: 460px; height: 460px; border-radius: 50%;
  border: 38px solid rgba(212,174,104,.16); box-shadow: inset 0 0 60px rgba(212,174,104,.12); }
.auth .side { display: grid; place-items: center; padding: 32px; background: var(--bg); position: relative; }
.auth .card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow); }
.auth .card h2 { text-transform: none; letter-spacing: 0; font-size: 22px; color: var(--text); margin: 0 0 4px; font-weight: 600; }
.auth .card .sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 18px; }
.tabs button { border: 0; background: none; padding: 8px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.auth .themefab { position: absolute; top: 20px; right: 20px; }

/* ---------------------------------------------------------------- admin */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 58px); }
.admin aside { border-right: 1px solid var(--line); background: var(--panel); padding: 16px 12px; }
.admin aside button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 9px 12px; border: 0; background: none;
  border-radius: 9px; cursor: pointer; color: var(--text-2); text-align: left; font-weight: 500; }
.admin aside button.on, .admin aside button:hover { background: var(--panel-2); color: var(--text); }
.admin aside button.on { box-shadow: inset 3px 0 0 var(--gold); }
.admin main { padding: 24px 28px; overflow: auto; }
.admin h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
.admin .lead { color: var(--muted); margin: 0 0 20px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi b { display: block; font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card2 { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card2 h3 { margin: 0 0 12px; font-size: 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .input { max-width: 280px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: var(--panel-2); }
.tbl .num { width: auto; border: 0; background: none; padding: 0; text-align: right; font-variant-numeric: tabular-nums; }
.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.chart div { flex: 1; background: var(--gold); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; opacity: .85; }
.chart div span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart div b { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-2); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewer { height: max(65vh, 420px); order: -1; }
  .viewerBar { bottom: 8px; padding: 5px 6px; gap: 5px; flex-wrap: nowrap; max-width: calc(100% - 16px); overflow-x: auto; }
  .viewerBar select, .viewerBar .ghost.small { font-size: 11px; padding: 3px 6px; }
  .panel { border: 0; border-top: 1px solid var(--line); }
  .auth { grid-template-columns: 1fr; }
  .auth .art { display: none; }
  .admin { grid-template-columns: 1fr; }
  .admin aside { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .admin aside button { width: auto; white-space: nowrap; }
  .admin main { padding: 18px 16px; }
  .nav, .tag { display: none; }
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand { font-size: 19px; }
}

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.match figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.match img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; cursor: zoom-in; }
.match figcaption { font-size: 11px; color: var(--muted); padding: 4px 8px; background: var(--panel-2); }

/* ---------------------------------------------------------------- fit-to-panel fixes */
.panel { overflow-x: hidden; }
.panel > *, .ident, .ident > * { min-width: 0; max-width: 100%; }
.grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid2 label { min-width: 0; }
select, .grid2 select, .ident select { width: 100%; max-width: 100%; min-width: 0; text-overflow: ellipsis; }
.viewerBar select { width: auto; }
.identHead > div { min-width: 0; }
.identHead b, .identHead p { overflow-wrap: anywhere; }
.stonesHead { flex-wrap: wrap; gap: 4px 10px; }
.stoneList li { flex-wrap: wrap; row-gap: 2px; }
.stoneList li > span:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.stoneList .meta { margin-left: 0; white-space: normal; flex-basis: 100%; padding-left: 20px; font-size: 11.5px; }
.stoneList button { position: relative; margin-left: auto; }
.check { flex-wrap: wrap; }
.field label { gap: 8px; }
.drop span { overflow-wrap: anywhere; }

.vslot select.lbl { width: 100%; border: 0; border-radius: 0; font-size: 10.5px; padding: 2px; background: rgba(0,0,0,.65);
  color: #eee; text-align: center; cursor: pointer; }
