:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e3e5ee;
  --text: #1b1d29;
  --muted: #6b6f85;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --danger: #dc2626;
  --success-bg: #ecfdf3; --success-fg: #067647;
  --error-bg: #fef2f2;   --error-fg: #b42318;
  --warn-bg: #fffaeb;    --warn-fg: #93370d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3d;
    --text: #e7e9f1;
    --muted: #9095aa;
    --primary: #7c74ff;
    --primary-hover: #8f88ff;
    --primary-soft: #23264a;
    --success-bg: #0f2a1d; --success-fg: #6ce9a6;
    --error-bg: #2d1416;   --error-fg: #fda29b;
    --warn-bg: #2b2010;    --warn-fg: #fec84b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .9rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1.05rem; padding: 0 8px; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 1.3rem; padding: 0; margin-bottom: .25rem; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--primary); color: #fff; font-weight: 700;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.sidebar nav a svg { width: 18px; height: 18px; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.who { font-weight: 600; font-size: .9rem; }
.who small { display: block; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 32px clamp(16px, 4vw, 48px); max-width: 1280px; width: 100%; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.page-head p { margin: 0; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 12px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .who small { display: none; }
  .content { padding: 20px 16px; }
}

/* ---------- Cards & Forms ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); min-width: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .9rem; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type="range"] { padding: 0; accent-color: var(--primary); border: 0; height: 38px; }
input[type="checkbox"] { width: auto; accent-color: var(--primary); }
select.sm { width: auto; padding: 6px 10px; font-size: .85rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid h2 { margin: 8px 0 -4px; }
.span-2 { grid-column: span 2; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-top: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row-between h2 { margin: 0; }
.actions { display: flex; gap: 10px; }
@media (max-width: 700px) {
  .form-grid, .grid-2, .grid-3, .two-col { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; padding: 12px; }
.btn.danger { color: var(--danger); }
.inline { display: inline; }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 11px 14px; border-radius: 8px; font-size: .9rem; }
.alert.success { background: var(--success-bg); color: var(--success-fg); }
.alert.error { background: var(--error-bg); color: var(--error-fg); }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); }
.alert.warn a { color: inherit; font-weight: 600; }
.badge { font-size: .72rem; background: var(--primary-soft); color: var(--primary); padding: 2px 7px; border-radius: 99px; font-weight: 600; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 32px; }
.auth-card p { margin: 0 0 6px; }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 22px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile h2 { margin: 8px 0 0; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.tile-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.tile-icon svg { width: 22px; height: 22px; }
.tile-meta { margin-top: auto; padding-top: 12px; font-size: .82rem; color: var(--muted); }
.tile.placeholder { border-style: dashed; box-shadow: none; background: transparent; }
.tile.placeholder .tile-icon { background: var(--surface-2); color: var(--muted); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 0 10px 10px; }
.table td { padding: 11px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tr.current td { background: var(--primary-soft); }
.history a { color: var(--text); }
@media (max-width: 700px) {
  .history th:nth-child(2), .history td:nth-child(2), .history th:nth-child(4), .history td:nth-child(4) { display: none; }
  .ellipsis { max-width: 26ch; }
}

/* ---------- Studio ---------- */
.studio { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .studio { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -6px; }
.chip { font: inherit; font-size: .8rem; padding: 4px 11px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.improve { display: flex; gap: 8px; margin-top: -6px; }
.improve input { padding: 6px 10px; font-size: .85rem; }
.improve .btn { white-space: nowrap; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-weight: 400; }
.segmented span small { color: var(--muted); font-size: .78rem; }
.segmented input:checked + span { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.segmented input:checked + span b { color: var(--primary); }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.segmented input:disabled + span { opacity: .45; cursor: not-allowed; }
.hint { margin: -6px 0 0; font-size: .8rem; color: var(--muted); }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.advanced summary { cursor: pointer; font-weight: 500; font-size: .9rem; color: var(--muted); }
.result { position: sticky; top: 20px; }
.result audio { width: 100%; margin: 10px 0 4px; }
.result p { margin: 4px 0 0; }
.spoken { margin: 14px 0 0; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; font-size: .9rem; max-height: 180px; overflow: auto; }
.downloads { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.dl { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.dl:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }
.dl small { color: var(--muted); font-size: .78rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty svg { width: 48px; height: 48px; opacity: .5; }

/* ---------- QR Studio ---------- */
.qr-studio { grid-template-columns: minmax(0, 1fr) minmax(0, 400px); }
@media (max-width: 1000px) { .qr-studio { grid-template-columns: 1fr; } .qr-result { order: -1; } }
.qr-result { display: flex; flex-direction: column; gap: 20px; position: sticky; top: 20px; }
@media (max-width: 1000px) { .qr-result { position: static; } }
.segmented.six { grid-template-columns: repeat(6, 1fr); }
.segmented.six span { align-items: center; padding: 8px 4px; font-size: .85rem; }
@media (max-width: 560px) { .segmented.six { grid-template-columns: repeat(3, 1fr); } }
.color { display: flex; gap: 6px; }
.color input[type="color"] { width: 44px; height: 40px; padding: 3px; flex: none; cursor: pointer; }
.color input:not([type]) { font-family: ui-monospace, monospace; text-transform: lowercase; }
.qr-preview {
  display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--surface-2);
}
.qr-preview canvas, .qr-preview svg { width: 100% !important; height: auto !important; max-width: 320px; display: block; }
.qr-preview[data-transparent="1"] {
  background: repeating-conic-gradient(#d9dce5 0% 25%, #ffffff 0% 50%) 50% / 20px 20px;
}
.scan { margin: 12px 0 14px; font-size: .88rem; font-weight: 600; min-height: 1.4em; }
.scan small { display: block; font-weight: 400; color: var(--muted); margin-top: 2px; }
.scan.ok { color: var(--success-fg); }
.scan.warn { color: var(--warn-fg); }
.scan.bad { color: var(--error-fg); }
.export { margin-bottom: 12px; }
.actions { flex-wrap: wrap; }
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.logo-tile { position: relative; cursor: pointer; }
.logo-tile input { position: absolute; opacity: 0; pointer-events: none; }
.logo-tile span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 96px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; font-weight: 400; text-align: center;
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 14px 14px;
}
.logo-tile img { max-width: 100%; max-height: 52px; object-fit: contain; }
.logo-tile small { font-size: .72rem; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-tile .none { background: var(--surface); color: var(--muted); font-size: .85rem; }
.logo-tile input:checked + span { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.logo-tile input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
details.card summary { cursor: pointer; }
details.card .table { margin-top: 10px; }
.form-stack > label.check { align-self: flex-start; padding-bottom: 0; }
