:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6f6c66;
  --line: #e4e1da;
  --accent: #1d1d1b;
  --accent-text: #ffffff;
  --hover: #efede8;
  --selected: #ebe8e1;
  --danger: #b3261e;
  --ok: #2e7d32;
  --warn: #9a6700;
  --ember: #d9481f;
  --ember-soft: color-mix(in srgb, var(--ember) 12%, transparent);
  --bar: #141413;
  --bar-text: #f4f2ee;
  --bar-muted: #9c978e;
  --bar-hover: #24231f;
  --bar-line: #2a2925;
  --radius: 12px;
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--ember);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #201f1d;
    --text: #edebe6;
    --muted: #a19d95;
    --line: #34322e;
    --accent: #edebe6;
    --accent-text: #161615;
    --hover: #2a2926;
    --selected: #33312d;
    --danger: #ef6b62;
    --ok: #7cc47f;
    --warn: #e0b04f;
    --ember: #f0714f;
    --bar: #0d0d0c;
    --bar-line: #262522;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.05rem; }
.dot { color: var(--muted); }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--ember); box-shadow: 0 0 0 3px var(--ember-soft); }
button:focus-visible, a:focus-visible, .file-btn:focus-within { outline: none; box-shadow: var(--focus); }
input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
input[type="range"] { padding: 0; border: 0; accent-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.88; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn { white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: end; }

.switch { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 0.9rem; min-height: 36px; }
.switch input { width: auto; accent-color: var(--accent); }

.badge { font-size: 0.8rem; padding: 2px 10px; border-radius: 99px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.msg { margin: 0; font-size: 0.85rem; }
.msg.ok { color: var(--ok); }
.msg.err, .error { color: var(--danger); margin: 0; font-size: 0.85rem; }
.warn { color: var(--warn); font-size: 0.85rem; margin: 6px 0 0; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; border-radius: 6px; }
.mark { width: 22px; height: 22px; flex: none; }
.mark-core { fill: var(--ember); }
.wordmark { font-weight: 700; font-size: 0.95rem; letter-spacing: 0.24em; margin-right: -0.24em; }
.by { font-size: 0.78rem; color: var(--bar-muted); padding-left: 10px; border-left: 1px solid var(--bar-line); line-height: 1.1; }
.brand-lg .mark { width: 30px; height: 30px; }
.brand-lg .wordmark { font-size: 1.35rem; }
.by-inline { color: var(--text); font-weight: 500; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; gap: 18px; }
.login-card p { margin: 0; }
.btn-block { justify-content: center; width: 100%; padding: 10px 14px; text-decoration: none; gap: 10px; }
.gh { width: 18px; height: 18px; }
.small-note { font-size: 0.8rem; text-align: center; }

/* Topbar */
.topbar { background: var(--bar); color: var(--bar-text); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--bar-line); }
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px; height: 56px;
  display: flex; align-items: stretch; gap: 32px;
}
.topbar .brand { align-self: center; }
.tabs { display: flex; gap: 4px; flex: 1; align-items: stretch; }
.tab {
  font: inherit; font-size: 0.9rem; border: 0; background: none; color: var(--bar-muted); cursor: pointer;
  padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; position: relative; border-radius: 0;
  transition: color .15s;
}
.tab svg, .icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tab:hover { color: var(--bar-text); }
.tab.active { color: var(--bar-text); font-weight: 500; }
.tab.active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: var(--ember); border-radius: 2px 2px 0 0; }
.tab:focus-visible { box-shadow: inset 0 0 0 2px var(--ember); border-radius: 6px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.user { display: inline-flex; align-items: center; gap: 8px; color: var(--bar-text); font-size: 0.85rem; padding: 0 6px; }
.user img { border-radius: 50%; display: block; }
.divider { width: 1px; height: 20px; background: var(--bar-line); margin: 0 4px; }
.icon-btn {
  font: inherit; font-size: 0.85rem; color: var(--bar-muted); background: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; height: 34px; border-radius: 8px; white-space: nowrap;
}
.icon-btn:hover { color: var(--bar-text); background: var(--bar-hover); }
.topbar :focus-visible { box-shadow: 0 0 0 2px var(--ember); }

/* Layout */
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; padding: 24px 20px; max-width: 1280px; margin: 0 auto; }
.layout.no-sidebar { grid-template-columns: 1fr; }
.sidebar { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sidebar-head { display: flex; gap: 8px; }
.link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 150px); overflow: auto; }
.link-list li button {
  width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
}
.link-list li button:hover { background: var(--hover); }
.link-list li button { position: relative; }
.link-list li button.selected { background: var(--selected); }
.link-list li button.selected::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--ember); }
.link-list .l-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list .l-code { font-size: 0.8rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list .l-scans { font-size: 0.75rem; color: var(--muted); grid-row: span 2; align-self: center; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.link-list .l-scans svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; }
.link-list .inactive .l-title { text-decoration: line-through; color: var(--muted); }

.editor { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.prefix-input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.prefix-input span { padding: 8px 0 8px 10px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; display: flex; align-items: center; }
.prefix-input input { border: 0; border-radius: 0; padding-left: 2px; font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; }

/* Designer */
.designer { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 24px; align-items: start; }
.preview-col { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 76px; }
.qr-preview { aspect-ratio: 1; width: 100%; border-radius: 10px; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.qr-preview svg, .qr-preview canvas { width: 100%; height: 100%; display: block; }
.checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.qr-data { margin: 0; font-size: 0.8rem; color: var(--muted); text-align: center; word-break: break-all; }
.controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; padding: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font: inherit; font-size: 0.75rem; color: var(--muted); width: 74px;
}
.chip svg { width: 40px; height: 40px; }
.chip:hover { background: var(--hover); }
.chip.active { border-color: var(--text); color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets .btn { font-size: 0.85rem; }
.file-btn { cursor: pointer; flex-direction: row; color: var(--text); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .link-list { max-height: 260px; }
  .designer { grid-template-columns: 1fr; }
  .preview-col { position: static; max-width: 360px; margin: 0 auto; width: 100%; }
}
@media (max-width: 900px) {
  .topbar-inner { gap: 16px; padding: 0 16px; }
  .icon-btn span, .user span { display: none; }
  .icon-btn { width: 36px; justify-content: center; padding: 0; }
}
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 10px; row-gap: 6px; }
  .topbar .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -4px; }
  .tab { flex: 1; justify-content: center; height: 44px; padding: 0 8px; }
  .tab.active::after { left: 8px; right: 8px; }
}
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
}
