:root {
  --purple: #8112ff;
  --cyan: #1dace4;
  --blue: #0f8bff;
  --blue-dark: #0a6fd6;
  --green: #12b76a;
  --green-dark: #0e9f5b;
  --grad: linear-gradient(100deg, #8112ff 0%, #4f5cf0 50%, #1dace4 100%);
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e2e6ee;
  --panel: #eef1f6;
  --row: #ffffff;
  --row-open: #f4f6fb;
  --warn: #b54708;
  --warn-bg: #fff6e5;
  --ok: #067647;
  --ok-bg: #e7f8ef;
  font-family: "Source Sans 3", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: #e9ecf3; font-size: 15px; line-height: 1.45; min-height: 100vh; }
[hidden] { display: none !important; }
a { color: var(--blue-dark); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: #f1f3f8; padding: 1px 5px; border-radius: 4px; }
h4 { margin: 18px 0 8px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ================= HEADER ================= */
.hero { background: var(--grad); color: #fff; padding: 0 24px; }
.hero-bar { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 0 14px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand img { background: #fff; border-radius: 10px; padding: 5px; width: 44px; height: 44px; object-fit: contain; }
.brand-text { font-size: 24px; letter-spacing: -.01em; line-height: 1.1; }
.brand-text small { display: block; font-size: 12.5px; opacity: .9; letter-spacing: .02em; text-transform: uppercase; margin-top: 3px; }
.top-nav { display: flex; gap: 6px; }
.top-nav a { color: #fff; text-decoration: none; font-weight: 700; text-transform: uppercase; font-size: 14px; letter-spacing: .04em; padding: 8px 14px; border-radius: 8px; opacity: .88; }
.top-nav a:hover { opacity: 1; background: rgba(255,255,255,.12); }
.top-nav a.active { opacity: 1; background: rgba(255,255,255,.2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #f79009; color: #fff; font-size: 11px; text-align: center; }

.type-bar { max-width: 1240px; margin: 0 auto; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding-top: 4px; }
.type-bar::-webkit-scrollbar { display: none; }
.type-bar button, .more > button { background: none; border: 0; color: rgba(255,255,255,.85); font: inherit; font-size: 15px; text-transform: uppercase; letter-spacing: .02em; padding: 12px 13px 14px; cursor: pointer; white-space: nowrap; border-bottom: 3px solid transparent; }
.type-bar button:hover { color: #fff; }
.type-bar button.active { color: #fff; font-weight: 700; border-bottom-color: #fff; }
.more { position: static; }
.more > button { display: inline-flex; align-items: center; gap: 6px; }
.more-menu { position: absolute; z-index: 30; background: #fff; border-radius: 10px; box-shadow: 0 12px 32px rgba(17,24,39,.2); padding: 6px; min-width: 200px; }
.more-menu button { display: block; width: 100%; text-align: left; color: var(--ink); text-transform: none; font-size: 15px; padding: 9px 12px; border-radius: 6px; border: 0; }
.more-menu button:hover, .more-menu button.active { background: var(--row-open); color: var(--ink); }

/* ================= STUDIO CARD ================= */
.view { padding: 0 24px 60px; }
#view-create { background: linear-gradient(#e9ecf3, #e9ecf3) bottom / 100% calc(100% - 70px) no-repeat, var(--grad); padding-top: 0; }
.studio { max-width: 1240px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 400px; background: #fff; border-radius: 6px; box-shadow: 0 10px 40px rgba(17,24,39,.18); overflow: clip; }
.controls { background: var(--panel); padding: 32px 36px 24px; min-width: 0; }
.output { padding: 32px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; align-self: start; }

/* accordion */
.acc { margin-bottom: 8px; }
.acc-head { width: 100%; display: flex; align-items: stretch; background: var(--row); border: 0; padding: 0; cursor: pointer; text-align: left; font: inherit; min-height: 64px; box-shadow: 0 1px 2px rgba(17,24,39,.06); }
.acc-icon { width: 64px; flex: 0 0 64px; display: grid; place-items: center; background: #f6f7fa; color: #5b6170; }
.acc-icon svg { width: 22px; height: 22px; }
.acc-title { flex: 1; align-self: center; padding: 0 22px; font-size: 19px; text-transform: uppercase; letter-spacing: .02em; color: #3b4250; }
.acc-toggle { width: 56px; position: relative; }
.acc-toggle::before, .acc-toggle::after { content: ""; position: absolute; left: 50%; top: 50%; width: 16px; height: 2.5px; background: #9aa1ad; transform: translate(-50%, -50%); border-radius: 2px; }
.acc-toggle::after { transform: translate(-50%, -50%) rotate(90deg); }
.acc.open .acc-toggle::after { transform: translate(-50%, -50%) rotate(0deg); }
.acc.open .acc-head { background: var(--row-open); }
.acc.open .acc-icon { background: var(--grad); color: #fff; }
.acc-body { display: none; padding: 18px 2px 14px; }
.acc.open .acc-body { display: block; }

/* form controls */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 14px; color: #4b5260; margin-bottom: 14px; min-width: 0; }
label output { font-weight: 400; color: var(--muted); }
input:not([type]), input[type=text], input[type=url], input[type=email], input[type=tel], input[type=number], input[type=search], input[type=datetime-local], input[type=date], select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid transparent; border-radius: 3px; padding: 12px 14px; width: 100%; box-shadow: 0 1px 2px rgba(17,24,39,.05); }
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -2px; }
input[type=range] { width: 100%; accent-color: var(--blue); }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; accent-color: var(--blue); margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 18px; }
.grid2.narrow { max-width: 560px; }
.radios { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 12px; }
label.radio { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--ink-2); margin: 0 0 8px; cursor: pointer; }
.sub { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.note { font-size: 13.5px; margin: 6px 0 12px; }
.note.warn { color: var(--warn); background: var(--warn-bg); padding: 10px 12px; border-radius: 6px; }

/* color pickers (swatch + hex) */
.color-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.color { display: flex; width: 220px; height: 48px; background: #fff; box-shadow: 0 1px 2px rgba(17,24,39,.08); border-radius: 3px; overflow: hidden; }
.color input[type=color] { width: 52px; height: 48px; border: 0; padding: 0; background: none; cursor: pointer; flex: 0 0 52px; }
.color input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color input[type=color]::-webkit-color-swatch { border: 0; }
.color input[type=text] { border: 0; box-shadow: none; font-size: 17px; text-transform: uppercase; border-radius: 0; }
.swap { background: #fff; border: 1px solid var(--line); border-radius: 50%; width: 34px; height: 34px; cursor: pointer; font-size: 16px; color: var(--ink-2); }

/* statistics switch */
.track-row { display: flex; align-items: center; gap: 14px; margin: 6px 0 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px 0 6px; border-radius: 22px; background: #fff; border: 0; box-shadow: 0 1px 3px rgba(17,24,39,.12); cursor: pointer; font: inherit; color: #6b7280; font-size: 17px; }
.switch .knob { width: 30px; height: 30px; border-radius: 50%; background: #6b7280; transition: background .15s; }
.switch[aria-checked=true] { background: var(--green); color: #fff; flex-direction: row-reverse; padding: 0 6px 0 16px; }
.switch[aria-checked=true] .knob { background: #fff; }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.track-title { font-size: 17px; color: #4b5260; }
.info { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #c9ceda; color: #fff; font-size: 13px; font-weight: 700; cursor: help; position: relative; }
.info:hover::after, .info:focus::after { content: attr(data-tip); position: absolute; left: 50%; top: 28px; transform: translateX(-50%); width: 280px; background: var(--ink); color: #fff; font-weight: 400; font-size: 13px; padding: 10px 12px; border-radius: 6px; z-index: 20; line-height: 1.4; }
.track-fields { background: #fff; border-radius: 6px; padding: 16px 16px 4px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(17,24,39,.05); }
.track-fields input, .track-fields select { background: #f6f7fa; box-shadow: none; }
.encodes { display: flex; gap: 10px; align-items: center; margin: -4px 0 12px; font-size: 13px; color: var(--muted); overflow: hidden; }
.encodes code { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }

/* logo */
.logo-top { display: grid; grid-template-columns: 130px auto 1fr; gap: 18px; align-items: start; margin-bottom: 14px; }
.logo-slot { width: 130px; height: 130px; background: #fff; display: grid; place-items: center; padding: 12px; box-shadow: 0 1px 2px rgba(17,24,39,.06); }
.logo-slot span { border: 2px dashed #c9ceda; width: 100%; height: 100%; display: grid; place-items: center; color: #6b7280; text-transform: uppercase; font-size: 14px; }
.logo-slot img { max-width: 100%; max-height: 100%; }
.logo-buttons { display: flex; flex-direction: column; gap: 10px; }
.logo-tip { border: 2px solid var(--blue); background: #e6f1fd; border-radius: 4px; padding: 14px 16px; font-size: 14px; color: #4b5260; display: flex; flex-direction: column; gap: 4px; }
.logo-tip strong { color: var(--ink-2); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.gallery button { aspect-ratio: 1; background: #fff; border: 2px solid transparent; border-radius: 2px; padding: 12px; cursor: pointer; box-shadow: 0 1px 2px rgba(17,24,39,.06); display: grid; place-items: center; }
.gallery button img { max-width: 100%; max-height: 100%; }
.gallery button:hover { border-color: #b9d6fb; }
.gallery button.active { border-color: var(--blue); }

/* shapes */
.shape-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.shape-grid button { aspect-ratio: 1; background: #fff; border: 2px solid transparent; padding: 10px; cursor: pointer; box-shadow: 0 1px 2px rgba(17,24,39,.06); border-radius: 2px; }
.shape-grid button svg { width: 100%; height: 100%; display: block; }
.shape-grid button:hover { border-color: #b9d6fb; }
.shape-grid button.active { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.file-hint { margin: 26px 0 0 4px; font-size: 16px; color: var(--ink-2); }
.file-hint a { font-weight: 700; text-decoration: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-size: 16px; border: 0; border-radius: 3px; padding: 12px 18px; cursor: pointer; text-decoration: none; font-weight: 600; flex-direction: row; margin: 0; white-space: nowrap; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover { background: var(--blue-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-dark); }
.btn-ghost { background: #fff; color: var(--ink-2); box-shadow: 0 1px 2px rgba(17,24,39,.08); }
.btn-ghost:hover { background: #f6f7fa; }
.btn-outline { background: #fff; color: var(--blue); border: 1.5px solid #b9d6fb; font-size: 18px; font-weight: 400; padding: 12px 6px; }
.btn-outline:hover { border-color: var(--blue); background: #f3f8ff; }
.btn.big { font-size: 20px; padding: 16px 20px; }

/* preview column */
.preview-wrap { position: relative; }
.preview { aspect-ratio: 1; width: 100%; display: grid; place-items: center; }
.preview svg { width: 100%; height: 100%; display: block; }
.preview.transparent { background: repeating-conic-gradient(#eef0f4 0 25%, #fff 0 50%) 0 0 / 18px 18px; }
.scan-badge { position: absolute; right: 0; bottom: -6px; font-size: 12.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.scan-badge.ok { background: var(--ok-bg); color: var(--ok); }
.scan-badge.bad { background: var(--warn-bg); color: var(--warn); }
.quality { margin-top: 18px; }
.quality input[type=range] { -webkit-appearance: none; appearance: none; height: 5px; background: #dfe7f5; border-radius: 3px; outline: none; }
.quality input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 34px; height: 34px; border-radius: 50%; background: var(--blue); border: 10px solid var(--blue); box-shadow: inset 0 0 0 4px #fff; cursor: pointer; }
.quality input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 8px solid var(--blue); cursor: pointer; }
.quality-labels { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 14.5px; margin-top: 10px; }
.quality-labels strong { color: var(--ink-2); font-size: 16px; }
.dl-main { display: flex; gap: 12px; }
.dl-main .btn { flex: 1; }
.dl-formats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.toast { font-size: 14px; border-radius: 6px; }
.toast.show { padding: 10px 12px; background: var(--ok-bg); color: var(--ok); }
.toast.error { background: var(--warn-bg); color: var(--warn); }

.templates-tab { max-width: 1240px; margin: 0 auto; display: flex; justify-content: center; }
.templates-tab button { display: inline-flex; align-items: center; gap: 10px; background: #6d55e0; background: var(--grad); color: #fff; border: 0; font: inherit; font-weight: 700; font-size: 18px; padding: 14px 28px; border-radius: 0 0 6px 6px; cursor: pointer; box-shadow: 0 8px 20px rgba(17,24,39,.15); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.55); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 10px; width: min(980px, 100%); max-height: 90vh; overflow: auto; padding: 24px 28px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 22px; }
.close { background: none; border: 0; font-size: 30px; cursor: pointer; color: var(--muted); line-height: 1; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tpl { background: #f6f7fa; border: 2px solid transparent; border-radius: 8px; padding: 10px; cursor: pointer; text-align: center; font: inherit; font-size: 13.5px; color: var(--ink-2); position: relative; }
.tpl:hover { border-color: var(--blue); }
.tpl .thumb { background: #fff; border-radius: 4px; aspect-ratio: 1; display: block; margin-bottom: 8px; }
.tpl .thumb svg { width: 100%; height: 100%; display: block; }
.tpl .del { position: absolute; top: 4px; right: 6px; background: #fff; border-radius: 50%; width: 22px; height: 22px; border: 1px solid var(--line); font-size: 14px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-foot { display: flex; gap: 10px; margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.modal-foot input { background: #f6f7fa; box-shadow: none; }
.empty-tpl { color: var(--muted); font-size: 14px; grid-column: 1 / -1; }

/* pages */
.view.page { max-width: 1240px; margin: 24px auto 0; }
.page-card { background: #fff; border-radius: 6px; box-shadow: 0 4px 20px rgba(17,24,39,.08); padding: 24px 28px; margin-bottom: 20px; }
.page-card.flush { padding: 0; overflow: hidden; }
.page-card h1 { margin: 0 0 6px; font-size: 24px; }
.codes-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.codes-head p { max-width: 640px; margin: 0; }
.codes-actions { display: flex; gap: 10px; }
.codes-actions input { width: 220px; background: #f6f7fa; box-shadow: none; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table.codes { width: 100%; border-collapse: collapse; font-size: 14px; }
.codes th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; text-transform: uppercase; letter-spacing: .03em; }
.codes td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.codes tr:last-child td { border-bottom: 0; }
.codes td.dest { max-width: 300px; word-break: break-all; }
.codes .sub { margin: 2px 0 0; }
.status { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.status.live { background: var(--ok-bg); color: var(--ok); }
.status.pending { background: var(--warn-bg); color: var(--warn); }
.status.changed { background: #e6f1fd; color: var(--blue-dark); }
.status.off { background: #f1f3f8; color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button { font: inherit; font-size: 13px; padding: 5px 10px; border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; }
.row-actions button:hover { background: #f6f7fa; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
#lookerFrame { width: 100%; height: 82vh; border: 0; display: block; }
.checklist li { margin-bottom: 10px; }
.checklist li.done { color: var(--muted); }
.checklist li.done strong::before { content: "✓ "; color: var(--ok); }

/* ================= RESPONSIVE ================= */
@media (max-width: 1080px) {
  .studio { grid-template-columns: minmax(0, 1fr) 340px; }
  .logo-top { grid-template-columns: 110px 1fr; }
  .logo-slot { width: 110px; height: 110px; }
  .logo-tip { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .hero { padding: 0 16px; }
  .hero-bar { flex-wrap: wrap; }
  .brand-text { font-size: 20px; }
  .view { padding: 0 12px 40px; }
  .studio { grid-template-columns: 1fr; }
  .output { order: -1; padding: 20px; border-bottom: 1px solid var(--line); position: static; }
  .preview-wrap { max-width: 320px; margin: 0 auto; width: 100%; }
  .controls { padding: 20px 14px; }
  .acc-title { font-size: 16px; padding: 0 14px; }
  .acc-icon { width: 52px; flex-basis: 52px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .color { width: 100%; max-width: 260px; }
  .codes-actions { width: 100%; }
  .codes-actions input { flex: 1; width: auto; }
  .modal-foot { flex-direction: column; }
}
