/* Shire QR Studio — design system + app shell */

:root {
  color-scheme: light;
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --surface-2: #f0f2f8;
  --line:      #e3e7f0;
  --line-soft: #eef1f7;
  --ink:       #151821;
  --ink-2:     #454c5c;
  --muted:     #6b7387;
  --primary:   #4f46e5;
  --primary-2: #6366f1;
  --primary-ink: #ffffff;
  --primary-soft: #eef2ff;
  --accent:    #0d9f6e;
  --accent-soft: #e7f7f1;
  --warn:      #b45309;
  --warn-soft: #fef4e7;
  --danger:    #dc2626;
  --danger-soft: #fdeceb;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(21, 24, 33, .05);
  --shadow:    0 4px 16px rgba(21, 24, 33, .07);
  --shadow-lg: 0 18px 48px rgba(21, 24, 33, .18);

  --rail: 216px;
  --topbar: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #0e1016;
    --surface:   #171a22;
    --surface-2: #1e222c;
    --line:      #2a2f3b;
    --line-soft: #232833;
    --ink:       #e9ebf1;
    --ink-2:     #b9c0cf;
    --muted:     #8b93a7;
    --primary:   #6366f1;
    --primary-2: #818cf8;
    --primary-soft: #1e213a;
    --accent:    #34d399;
    --accent-soft: #11291f;
    --warn:      #fbbf24;
    --warn-soft: #2a2113;
    --danger:    #f87171;
    --danger-soft: #2c1719;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #0e1016;
  --surface:   #171a22;
  --surface-2: #1e222c;
  --line:      #2a2f3b;
  --line-soft: #232833;
  --ink:       #e9ebf1;
  --ink-2:     #b9c0cf;
  --muted:     #8b93a7;
  --primary:   #6366f1;
  --primary-2: #818cf8;
  --primary-soft: #1e213a;
  --accent:    #34d399;
  --accent-soft: #11291f;
  --warn:      #fbbf24;
  --warn-soft: #2a2113;
  --danger:    #f87171;
  --danger-soft: #2c1719;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 16px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

/* Any explicit `display` beats the UA stylesheet's [hidden] rule, and most
   elements here get one. Keep the attribute authoritative. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--primary); }

/* ---------------------------------------------------------------- shell */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 15px; font-weight: 700; letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand .mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: 9px; font-size: 15px;
}
.brand .sub { color: var(--muted); font-weight: 500; }

.topbar .spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; color: var(--ink-2); max-width: 260px;
}
.avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.user-chip .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shell { display: grid; grid-template-columns: var(--rail) 1fr; align-items: start; }

.rail {
  position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar));
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface);
}
.rail-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 650; padding: 12px 10px 6px;
}
.rail button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-2);
  font: inherit; font-weight: 550; text-align: left; cursor: pointer;
}
.rail button .ico { width: 18px; text-align: center; font-size: 15px; }
.rail button:hover { background: var(--surface-2); color: var(--ink); }
.rail button.active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.rail .rail-foot { margin-top: auto; }

.main { padding: 24px; min-width: 0; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 18px; display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.view-head h1 { font-size: 20px; }
.view-head p { margin: 3px 0 0; color: var(--muted); }
.view-head .spacer { flex: 1; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}
.card-head h3 { font-size: 14px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

/* collapsible section */
.section { border-bottom: 1px solid var(--line-soft); }
.section:last-child { border-bottom: 0; }
.section > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; cursor: pointer; list-style: none;
  font-weight: 650; font-size: 13px; user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after {
  content: '⌄'; margin-left: auto; color: var(--muted);
  transition: transform .18s ease; font-size: 15px; line-height: 1;
}
.section[open] > summary::after { transform: rotate(180deg); }
.section > summary:hover { background: var(--surface-2); }
.section .section-body { padding: 4px 18px 18px; }
.section .badge-chip {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
}

/* ---------------------------------------------------------------- forms */

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
label .opt { font-weight: 500; color: var(--muted); font-size: 11px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.hint code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
  font-size: 11.5px; border: 1px solid var(--line);
}

input[type="text"], input[type="url"], input[type="email"], input[type="tel"],
input[type="password"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="search"], textarea, select {
  display: block; width: 100%; margin-top: 5px;
  padding: 8px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink); font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input[type="color"] {
  margin-top: 5px; width: 100%; height: 34px; padding: 2px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); cursor: pointer;
}
input[type="file"] { font-size: 12px; color: var(--ink-2); max-width: 100%; }

label.check {
  display: flex; align-items: flex-start; gap: 9px;
  font-weight: 550; cursor: pointer; margin-bottom: 12px;
}
label.check input { width: auto; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
label.check span { color: var(--ink-2); }
label.check em { font-style: normal; color: var(--muted); font-size: 11px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.span2 { grid-column: span 2; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  text-decoration: none; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: all .12s;
}
.chips button:hover { color: var(--ink); border-color: var(--muted); }
.chips button.active {
  background: var(--primary); border-color: var(--primary); color: var(--primary-ink);
}

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.dynamic { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.static  { background: var(--surface-2); color: var(--muted); }
.badge.paused  { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.locked  { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* ---------------------------------------------------------------- designer */

.designer { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .designer { grid-template-columns: 1fr; } }

.preview-col { position: sticky; top: calc(var(--topbar) + 24px); }
.preview-stage {
  display: grid; place-items: center; padding: 24px; max-width: 100%; min-width: 0;
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) -8px 0/16px 16px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 0 0/16px 16px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) 0 0/16px 16px;
  border-radius: var(--r);
}
.frame-wrap {
  border: 4px solid transparent; border-radius: 16px; overflow: hidden;
  background: transparent; max-width: 100%; min-width: 0;
}
#qr-preview { max-width: 100%; }
.frame-wrap.framed { padding: 10px; }
.frame-wrap.framed:has(.frame-label:not([hidden])) { padding: 0 10px; }
.frame-label {
  text-align: center; font-weight: 700; letter-spacing: .08em; color: #fff;
  padding: 9px 16px; font-size: 14px; margin: 0 -10px;
}
#frame-label-top { margin-bottom: 10px; }
#frame-label-bottom { margin-top: 10px; }
#qr-preview canvas, #qr-preview svg { max-width: 100%; height: auto; display: block; border-radius: 4px; }

.note {
  font-size: 12px; padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--primary-soft); color: var(--primary);
  word-break: break-all; line-height: 1.45;
}
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note strong { font-weight: 700; }

.dl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dl-row select { margin-top: 0; }

.presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.presets button {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--line); padding: 0; transition: transform .12s;
}
.presets button:hover { transform: scale(1.12); }
.presets button.active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.p-classic  { background: #1a1a2e; }
.p-ocean    { background: linear-gradient(135deg, #0b3866, #00b4d8); }
.p-sunset   { background: linear-gradient(135deg, #c2185b, #ff8f00); }
.p-forest   { background: linear-gradient(135deg, #1b4332, #52b788); }
.p-plum     { background: linear-gradient(135deg, #3c096c, #c77dff); }
.p-midnight { background: linear-gradient(135deg, #14213d 55%, #e9c46a 55%); }
.p-cherry   { background: linear-gradient(135deg, #9d0208, #ff5d8f); }
.p-shire    { background: linear-gradient(135deg, #4f46e5, #22d3ee); }

/* ---------------------------------------------------------------- code grid */

.code-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.code-card {
  position: relative;
  display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 12px;
  padding: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s;
}
.code-pick { position: absolute; top: 10px; right: 10px; z-index: 2; }
.code-pick input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; cursor: pointer; }
#codes-bulkbar { display: flex; gap: 8px; align-items: center; }
.code-card:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); box-shadow: var(--shadow); }
.code-card .thumb {
  width: 84px; height: 84px; border-radius: var(--r-sm); overflow: hidden;
  background: #fff; display: grid; place-items: center;
}
.code-card .thumb canvas { width: 100%; height: 100%; }
.code-card .meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.code-card .meta .name {
  font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.code-card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.code-card .link {
  font-size: 12px; color: var(--primary); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.code-card .row-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 4px; }

.empty {
  text-align: center; padding: 48px 24px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--r-lg); background: var(--surface);
}
.empty .big { font-size: 30px; margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 6px; font-size: 15px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type="search"] { margin-top: 0; max-width: 260px; }
.toolbar select { margin-top: 0; width: auto; }

/* ---------------------------------------------------------------- tables */

/* Wide tables scroll inside their own container so the page never does. */
.table-wrap { overflow-x: auto; max-width: 100%; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 650; padding: 8px 12px; border-bottom: 1px solid var(--line);
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
table.data tr:last-child td { border-bottom: 0; }
table.data td.right, table.data th.right { text-align: right; }
table.data .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------------------------------------------------------------- stats */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  padding: 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line-soft);
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.stat .v { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }

.chart { width: 100%; height: 150px; display: block; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover { fill: var(--primary-2); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 9px; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bars .b-row { display: grid; grid-template-columns: 92px 1fr 44px; gap: 10px; align-items: center; font-size: 12.5px; }
.bars .track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--primary); border-radius: 999px; }
.bars .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-weight: 550; }

/* ---------------------------------------------------------------- dialogs */

dialog {
  border: 0; padding: 0; border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-lg); max-width: min(720px, calc(100vw - 32px));
  width: 100%;
}
dialog::backdrop { background: rgba(10, 12, 18, .55); backdrop-filter: blur(3px); }
dialog .dlg-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-soft);
}
dialog .dlg-head h3 { font-size: 15px; }
dialog .dlg-head .spacer { flex: 1; }
dialog .dlg-body { padding: 20px; max-height: min(72vh, 720px); overflow-y: auto; }
dialog .dlg-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line-soft); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
dialog.narrow { max-width: 400px; }

.error-msg {
  color: var(--danger); background: var(--danger-soft);
  padding: 9px 12px; border-radius: var(--r-sm); font-size: 12.5px; margin: 0 0 12px;
}

.key-reveal {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px; word-break: break-all; margin: 10px 0;
}

/* ---------------------------------------------------------------- toast */

.toasts {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  padding: 11px 15px; border-radius: var(--r-sm);
  background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 550;
  animation: toast-in .2s ease; max-width: 380px;
}
.toast.ok  { background: var(--accent); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- misc */

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 28px 20px 8px; }

.landing-hero {
  display: grid; place-items: center; min-height: calc(100vh - var(--topbar));
  padding: 40px 20px; text-align: center;
}
.landing-hero .inner { max-width: 460px; }
.landing-hero h1 { font-size: 26px; margin-bottom: 10px; }
.landing-hero p { color: var(--muted); margin: 0 0 22px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: static; height: auto; flex-direction: row; overflow-x: auto;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 8px;
  }
  .rail .rail-label, .rail .rail-foot { display: none; }
  .rail button { width: auto; white-space: nowrap; }
  .main { padding: 16px; }
  .preview-col { position: static; }
  .preview-stage { padding: 10px; }
  .card-body { padding: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .user-chip .who { display: none; }
}

/* Below this the topbar can no longer hold the wordmark and the auth buttons. */
@media (max-width: 560px) {
  .brand-text { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 6px 9px; font-size: 12px; }
  .view-head h1 { font-size: 18px; }
}

/* ---------------------------------------------------------------- barcode */

.mode-chips { margin-bottom: 12px; }
.mode-chips button { font-size: 13px; padding: 7px 15px; }
.code-card .thumb-barcode { background: #fff; padding: 4px; }
.code-card .thumb-barcode canvas { width: 100%; height: auto; object-fit: contain; }
#qr-preview canvas { max-width: 100%; height: auto; }
input[type="range"] {
  width: 100%; margin-top: 8px; accent-color: var(--primary); background: transparent;
}
.code-card .thumb-pending {
  background: repeating-linear-gradient(45deg, var(--surface-2) 0 6px, transparent 6px 12px);
}
