:root {
  color-scheme: light;
  --ink: #25211f;
  --muted: #756b64;
  --cream: #f8f1e7;
  --paper: #fffdf9;
  --pink: #ed4e8b;
  --pink-dark: #a62d61;
  --green: #9aad5d;
  --line: rgba(37, 33, 31, .13);
  --shadow: 0 24px 70px rgba(76, 56, 41, .11);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 11%, rgba(237, 78, 139, .12), transparent 26rem),
    radial-gradient(circle at 92% 23%, rgba(154, 173, 93, .16), transparent 30rem),
    var(--cream);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.scanner-open { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 12px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid rgba(37, 33, 31, .08);
  background: rgba(248, 241, 231, .86);
  backdrop-filter: blur(16px);
}
.brand img { display: block; width: 132px; height: auto; }
.top-actions { display: flex; align-items: center; gap: 18px; }
.secure-pill { display: inline-flex; align-items: center; gap: 8px; color: #59623a; font-size: .82rem; font-weight: 750; }
.secure-pill i { width: 8px; height: 8px; border-radius: 99px; background: var(--green); box-shadow: 0 0 0 5px rgba(154, 173, 93, .17); }
.text-button { padding: 7px 0; border: 0; color: var(--muted); background: none; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }

.page-shell { width: min(1440px, calc(100% - 36px)); margin: 0 auto; padding: 62px 0 90px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(420px, .8fr); gap: 54px; align-items: end; margin-bottom: 50px; }
.eyebrow, .step { margin: 0 0 10px; color: var(--pink-dark); font-size: .73rem; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.hero h1 { margin: 0; font-size: clamp(3rem, 7vw, 6.4rem); line-height: .86; letter-spacing: -.07em; }
.hero h1 em { color: var(--pink); font-style: normal; }
.hero > div > p:last-child { max-width: 680px; margin: 25px 0 0; color: var(--muted); font-size: 1.06rem; line-height: 1.7; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 23px; background: rgba(255, 253, 249, .72); }
.stats div { min-width: 0; padding: 24px 20px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; }
.stats strong, .stats span { display: block; }
.stats strong { overflow: hidden; font-size: clamp(1.3rem, 2vw, 2rem); letter-spacing: -.04em; text-overflow: ellipsis; }
.stats span { margin-top: 5px; color: var(--muted); font-size: .76rem; }

.alert { margin: 0 0 22px; padding: 15px 18px; border-radius: 14px; font-weight: 650; }
.alert-success { color: #42502b; background: #e7efd1; }
.alert-error { color: #7b2045; background: #fde2ec; }

.editor-grid { display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(390px, .88fr); gap: 24px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: 28px; background: rgba(255, 253, 249, .92); box-shadow: var(--shadow); }
.editor-form, .preview-panel { padding: clamp(22px, 3vw, 36px); }
.preview-panel { position: sticky; top: 98px; }
.panel-heading, .library-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading { margin-bottom: 27px; }
h2 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.25rem); letter-spacing: -.045em; }
.small-link { color: var(--pink-dark); font-size: .83rem; font-weight: 700; text-underline-offset: 4px; }
.size-pill, .article-chip { display: inline-flex; align-items: center; white-space: nowrap; border-radius: 999px; }
.size-pill { padding: 8px 11px; color: #5d653d; background: #edf2dd; font-size: .72rem; font-weight: 800; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
label { display: grid; gap: 8px; color: #514943; font-size: .82rem; font-weight: 750; }
label.full { grid-column: 1 / -1; }
.qr-option { display: flex; grid-template-columns: none; align-items: flex-start; gap: 13px; padding: 15px 16px; border: 1px solid rgba(154, 173, 93, .35); border-radius: 15px; background: #f3f5e8; cursor: pointer; }
.qr-option input { flex: 0 0 auto; width: 20px; min-height: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--green); }
.qr-option span, .qr-option strong, .qr-option small { display: block; }
.qr-option strong { color: #47502e; }
.qr-option small { margin-top: 4px; color: #6e7652; font-weight: 550; line-height: 1.45; }
input, textarea, select {
  width: 100%;
  border: 1px solid rgba(37, 33, 31, .17);
  border-radius: 13px;
  outline: none;
  color: var(--ink);
  background: #fff;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input, select { min-height: 48px; padding: 0 14px; }
textarea { min-height: 95px; padding: 13px 14px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--pink); box-shadow: 0 0 0 4px rgba(237, 78, 139, .11); }
input[readonly] { color: #776f69; background: #f4f0ea; }

.ean-result { display: grid; grid-template-columns: 1fr auto; gap: 3px 15px; align-items: center; margin: 24px 0 18px; padding: 16px 18px; border-radius: 17px; color: white; background: var(--ink); }
.ean-result span { font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.ean-result strong { grid-row: span 2; font-family: "SFMono-Regular", Consolas, monospace; font-size: clamp(1.15rem, 2.3vw, 1.65rem); letter-spacing: .06em; }
.ean-result small { color: #c9c3bf; }

.reuse-warning { margin: 0 0 22px; padding: 20px; border: 2px solid #e5a622; border-radius: 18px; background: #fff8df; }
.reuse-warning .reuse-kicker { margin: 0 0 5px; color: #8b5a00; font-size: .69rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.reuse-warning h3 { margin: 0; color: #503500; font-size: 1.08rem; }
.reuse-warning > p:not(.reuse-kicker) { margin: 8px 0 14px; color: #73571d; font-size: .82rem; line-height: 1.5; }
.reuse-warning ul { display: grid; gap: 8px; max-height: 240px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.reuse-warning li { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; border: 1px solid rgba(139, 90, 0, .16); border-radius: 11px; background: rgba(255, 255, 255, .75); }
.reuse-warning li span, .reuse-warning li strong, .reuse-warning li small { display: block; }
.reuse-warning li small { margin-top: 3px; color: #77633b; line-height: 1.35; }
.reuse-warning li a { flex: 0 0 auto; color: #895500; font-size: .76rem; font-weight: 800; text-underline-offset: 3px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 46px; padding: 0 18px; border: 1px solid transparent; border-radius: 13px; cursor: pointer; font-weight: 800; text-decoration: none; transition: transform .16s ease, opacity .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button-primary { width: 100%; color: white; background: var(--pink); }
.button-secondary { color: var(--pink-dark); border-color: rgba(166, 45, 97, .2); background: #fff2f7; }
.button-ghost { color: var(--ink); border-color: var(--line); background: transparent; }
.button-dark { color: white; background: var(--ink); }
.button-scan { color: white; background: var(--pink-dark); }
.button-scan span { font-size: 1.1rem; line-height: 1; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }

.canvas-wrap { display: grid; place-items: center; min-height: 360px; padding: 26px; overflow: auto; border: 1px dashed rgba(37, 33, 31, .2); border-radius: 20px; background: #e9e5df; }
#barcode-preview { display: block; width: min(472px, 100%); height: auto; background: white; box-shadow: 0 10px 28px rgba(37, 33, 31, .18); }
.preview-help { margin: 13px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }

.library { margin-top: 28px; padding: clamp(22px, 3vw, 36px); border: 1px solid var(--line); border-radius: 28px; background: rgba(255, 253, 249, .9); box-shadow: var(--shadow); }
.library-heading { align-items: end; margin-bottom: 25px; }
.filters { display: grid; grid-template-columns: minmax(220px, 1fr) 150px auto auto; gap: 10px; margin-bottom: 18px; }
.search-field { position: relative; }

.scanner-modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 22px; }
.scanner-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(29, 24, 22, .76); cursor: pointer; backdrop-filter: blur(9px); }
.scanner-dialog { position: relative; width: min(720px, 100%); max-height: calc(100vh - 44px); padding: clamp(20px, 4vw, 34px); overflow: auto; border: 1px solid rgba(255, 255, 255, .2); border-radius: 28px; background: var(--paper); box-shadow: 0 30px 100px rgba(0, 0, 0, .35); }
.scanner-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 22px; margin-bottom: 20px; }
.scanner-close { display: grid; flex: 0 0 auto; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: #fff; cursor: pointer; font-size: 1.75rem; line-height: 1; }
.scanner-view { position: relative; min-height: 320px; overflow: hidden; border-radius: 20px; background: #191716; }
#scanner-video { display: block; width: 100%; height: min(52vh, 430px); min-height: 320px; object-fit: cover; }
.scanner-target { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; background: linear-gradient(rgba(0, 0, 0, .28), rgba(0, 0, 0, .28)); }
.scanner-target::before { content: ""; width: min(82%, 540px); height: clamp(105px, 20vw, 145px); border: 3px solid #fff; border-radius: 16px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .34), 0 0 0 5px rgba(237, 78, 139, .34); }
.scanner-target span { position: absolute; width: min(72%, 470px); height: 2px; border-radius: 99px; background: var(--pink); box-shadow: 0 0 14px rgba(237, 78, 139, .85); animation: scanner-line 1.8s ease-in-out infinite alternate; }
.scanner-settings { display: grid; grid-template-columns: minmax(180px, 1.25fr) minmax(170px, 1fr) auto; gap: 10px; align-items: end; margin-top: 15px; }
.scanner-settings label { position: relative; }
.scanner-settings output { position: absolute; top: 0; right: 0; color: var(--pink-dark); font-family: "SFMono-Regular", Consolas, monospace; font-size: .76rem; }
.scanner-settings input[type="range"] { min-height: 48px; padding: 0; border: 0; box-shadow: none; accent-color: var(--pink); }
.scanner-torch { white-space: nowrap; }
.scanner-torch.is-on { color: #4b552d; border-color: rgba(111, 128, 57, .28); background: #edf2dd; }
.scanner-help { margin: 16px 0 7px; color: var(--muted); font-size: .88rem; line-height: 1.55; }
.scanner-status { min-height: 23px; margin: 0; color: var(--pink-dark); font-size: .86rem; font-weight: 800; }
.scanner-status.is-success { color: #526331; }
.scanner-status.is-error { color: #9b234e; }
.scanner-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; margin-top: 18px; }
@keyframes scanner-line { from { transform: translateY(-43px); } to { transform: translateY(43px); } }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 16px 15px; border-bottom: 1px solid rgba(37, 33, 31, .09); text-align: left; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { color: #776e68; background: #f5f1ec; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; }
td { font-size: .85rem; }
td small { display: block; max-width: 320px; margin-top: 4px; overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; letter-spacing: .035em; }
.article-chip { padding: 6px 9px; color: #625f3a; background: #f0f1d9; font-family: "SFMono-Regular", Consolas, monospace; font-weight: 850; }
.qr-chip { display: inline-flex; margin-left: 5px; padding: 3px 6px; border-radius: 6px; color: #526331; background: #e9f0d7; font-size: .62rem; letter-spacing: .06em; vertical-align: 2px; }
.status { display: inline-flex; padding: 6px 9px; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.status-active { color: #4f5f32; background: #e9f0d7; }
.status-archived { color: #746b64; background: #eeeae6; }
.row-actions { min-width: 145px; text-align: right; white-space: nowrap; }
.row-actions a, .row-actions button { border: 0; color: var(--pink-dark); background: none; cursor: pointer; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.row-actions form { display: inline; margin-left: 8px; }
.row-actions button { color: #746b64; }
.empty-state { padding: 44px; color: var(--muted); text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 26px; }
.login-shell { width: min(980px, 100%); display: grid; grid-template-columns: .85fr 1.15fr; overflow: hidden; border: 1px solid var(--line); border-radius: 30px; background: var(--paper); box-shadow: var(--shadow); }
.login-brand { display: grid; place-items: center; min-height: 560px; padding: 55px; background: #f0dfc4; }
.login-brand img { width: min(280px, 100%); height: auto; }
.login-card { padding: clamp(38px, 6vw, 74px); }
.login-card h1 { margin: 0; font-size: clamp(2.7rem, 6vw, 4.8rem); line-height: .9; letter-spacing: -.065em; }
.login-card > p:not(.eyebrow):not(.alert) { margin: 22px 0 28px; color: var(--muted); line-height: 1.6; }
.login-card form { display: grid; gap: 16px; }
.login-card .button { margin-top: 5px; }

@media (max-width: 1050px) {
  .hero { grid-template-columns: 1fr; }
  .editor-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .filters { grid-template-columns: minmax(220px, 1fr) 145px auto; }
  .button-scan { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .page-shell { width: min(100% - 24px, 1440px); padding-top: 38px; }
  .topbar { min-height: 66px; padding-inline: 14px; }
  .brand img { width: 112px; }
  .secure-pill { display: none; }
  .stats { grid-template-columns: 1fr; }
  .stats div { border-top: 1px solid var(--line); border-left: 0; }
  .stats div:first-child { border-top: 0; }
  .form-grid { grid-template-columns: 1fr; }
  label.full { grid-column: auto; }
  .ean-result { grid-template-columns: 1fr; }
  .ean-result strong { grid-row: auto; word-break: break-all; }
  .canvas-wrap { min-height: 250px; padding: 14px; }
  .button-row, .filters { grid-template-columns: 1fr; }
  .button-scan { grid-column: auto; }
  .scanner-modal { padding: 10px; }
  .scanner-dialog { max-height: calc(100vh - 20px); padding: 18px; border-radius: 22px; }
  .scanner-view, #scanner-video { min-height: 260px; }
  .scanner-settings { grid-template-columns: 1fr; }
  .scanner-actions { display: grid; grid-template-columns: 1fr; }
  .library-heading { align-items: flex-start; flex-direction: column; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 180px; padding: 35px; }
  .login-brand img { width: 180px; }
}

@page { size: 40mm 20mm; margin: 0; }
@media print {
  html, body { width: 40mm; height: 20mm; margin: 0; padding: 0; background: white; }
  body * { visibility: hidden !important; }
  .canvas-wrap, .canvas-wrap * { visibility: visible !important; }
  .canvas-wrap { position: fixed; inset: 0; display: block; width: 40mm; min-height: 0; height: 20mm; padding: 0; border: 0; background: white; }
  #barcode-preview { width: 40mm; height: auto; box-shadow: none; }
}
