:root {
  color-scheme: light;
  --bg: #efe8db;
  --bg-deep: #12100c;
  --panel: #fffdf8;
  --panel-2: #f7f1e6;
  --line: #e2d8c6;
  --line-strong: #d3c6ae;
  --brass: #9a7348;
  --brass-bright: #c4a574;
  --ink: #1c1914;
  --muted: #6f675c;
  --ok: #2f6b45;
  --ok-bg: #e7f3ea;
  --bad: #a33b2c;
  --bad-bg: #f8e8e6;
  --shadow: 0 18px 44px rgba(28, 25, 20, 0.1);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  line-height: 1.45;
  background:
    radial-gradient(900px 420px at 8% -8%, #f7ecd6 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, #e7d7bc 0%, transparent 50%),
    var(--bg);
}

button, input, textarea, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.shell {
  width: 100%;
  max-width: 78rem;
  margin: 0 auto;
  padding: 1.25rem 1.15rem 3rem;
  overflow-x: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(16rem, 1.1fr) minmax(18rem, 0.9fr);
  gap: 1.25rem 1.75rem;
  align-items: end;
  padding: 1.35rem 1.5rem 1.4rem;
  background: var(--bg-deep);
  color: #f3eee4;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.15rem;
}

.mark {
  margin: 0 0 0.35rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--brass-bright);
}

.topbar h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0.45rem 0 0;
  color: #b7aea0;
  font-size: 0.92rem;
  max-width: 38rem;
}

.auth {
  display: grid;
  gap: 0.55rem;
}

.auth label, .toolbar label, .editor label, .gate label {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.topbar label { color: #b7aea0; }

.topbar .status {
  min-height: 0;
  margin: 0;
}

.topbar .status.ok { color: #9dcc9a; }
.topbar .status.muted { color: #b7aea0; }
.topbar .status.bad { color: #e8a39a; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

input, textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.58rem 0.72rem;
}

.topbar input {
  background: #1b1914;
  border-color: #3a3429;
  color: #f3eee4;
}

.gate {
  max-width: 28rem;
  margin: 2rem auto 0;
}

.gate .card { padding: 1.35rem 1.4rem 1.5rem; }

.gate form { display: grid; gap: 0.7rem; }

.gate h2 { margin: 0 0 0.35rem; }

.tabs {
  display: flex;
  gap: 0.4rem;
  margin: 0.9rem 0 1rem;
}

.tabs button {
  flex: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 550;
}

.tabs button.active {
  background: color-mix(in srgb, var(--brass) 18%, transparent);
  color: var(--ink);
  border-color: var(--brass);
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.35rem;
  margin: 0.9rem 0 1rem;
  padding: 0 0.1rem;
  align-items: center;
}

#navLogout { margin-left: auto; }

.app-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
}

.app-nav a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.app-nav a.active {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

#app[hidden], #gate[hidden] { display: none !important; }

input:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brass) 55%, transparent);
  border-color: var(--brass);
}

button {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  background: var(--brass-bright);
  color: #1a150e;
  font-weight: 650;
  cursor: pointer;
}

button:hover { filter: brightness(1.05); }

button.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-weight: 550;
}

.topbar button.ghost {
  border-color: #4a4338;
  color: #f3eee4;
}

button.danger {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line));
  color: var(--bad);
  font-weight: 550;
}

button.danger:hover { background: var(--bad-bg); }

button.danger-outline {
  background: transparent;
  border: 1px solid var(--bad);
  color: var(--bad);
  font-weight: 550;
}

button.danger-outline:hover { background: var(--bad-bg); }

button.danger-solid {
  background: #ee3b32;
  border: 1px solid #c62822;
  color: #fff;
  font-weight: 700;
}

button.danger-solid:hover {
  background: #f04a42;
  filter: none;
}

button.success-solid {
  background: #2f8a4e;
  border: 1px solid #246c3d;
  color: #fff;
  font-weight: 650;
}

button.success-solid:hover {
  background: #349456;
  filter: none;
}

.status {
  min-height: 1.2rem;
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
}

.status:empty { display: none; }

.status.ok { color: var(--ok); }
.status.muted { color: var(--muted); }

.lang-row {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  color: #b7aea0;
  font-size: 0.82rem;
  justify-self: end;
}

.lang-select {
  width: auto;
  min-width: 0;
  background: #1b1914;
  border: 1px solid #4a4338;
  border-radius: 10px;
  padding: 0.4rem 0.65rem;
  color: #f3eee4;
  cursor: pointer;
}

.meta-grid {
  display: none;
  margin-bottom: 1rem;
}

.meta-grid:has(#qrimg[src]) {
  display: block;
}

#qrimg {
  display: none;
  width: 11.5rem;
  height: auto;
  background: #fff;
  padding: 0.55rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}

#qrimg[src] { display: block; }

.workspace {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.25rem;
  min-width: 0;
  max-width: 100%;
}

.catalog { min-width: 0; }

.card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem);
  gap: 0.85rem 1.2rem;
  align-items: end;
  margin-bottom: 0.9rem;
}

.editor-head {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.editor-head button { justify-self: end; }

.card-head h2,
.editor h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--brass);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 650;
}

.hint, .muted { color: var(--muted); font-size: 0.9rem; }

.name-variation { font-size: 0.75rem; }

.hint { margin: 0.2rem 0 0; max-width: 36rem; }

.pair-steps {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 42rem;
}

.pair-steps li { margin: 0.22rem 0; }

.pair-steps strong {
  color: var(--ink);
  font-weight: 650;
}

.toolbar {
  min-width: 0;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}

.toolbar label { flex: 1; min-width: 10rem; }

.toolbar button { white-space: nowrap; }

.banner {
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  margin: 0 0 0.85rem;
  border: 1px solid transparent;
}

.banner.err {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 28%, var(--line));
}

.table-wrap {
  overflow: auto;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 42rem;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--panel-2);
  position: sticky;
  top: 0;
}

tbody tr:last-child td { border-bottom: 0; }

tbody tr:hover td { background: #faf6ee; }

tr.selected td {
  background: #f4ead8;
}

tr.selected td:first-child {
  box-shadow: inset 3px 0 0 var(--brass);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.6rem 0.8rem !important;
}

.lbl { display: none; }

code, .sku {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
}

.price {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.stock {
  display: inline-flex;
  min-width: 2.1rem;
  justify-content: center;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 650;
  background: var(--ok-bg);
  color: var(--ok);
}

.stock.out {
  background: var(--bad-bg);
  color: var(--bad);
}

.actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  white-space: nowrap;
}

.actions button { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem 0.8rem;
}

.grid > * { min-width: 0; }

.wide { grid-column: 1 / -1; }

.editor .row { margin-top: 0.15rem; }

.foot {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.foot code {
  border-radius: 6px;
  padding: 0.05rem 0.35rem;
}

@media (max-width: 860px) {
  .topbar, .workspace, .meta-grid, .grid, .card-head:not(.editor-head) {
    grid-template-columns: 1fr;
  }

  .wide { grid-column: auto; }

  .shell { padding: 0.85rem 0.75rem 2.5rem; }

  .topbar { padding: 1.1rem 1rem 1.15rem; }

  #qrimg, #qrimg[src] { width: 10rem; }

  table { min-width: 36rem; }

  /* Catalog rows become cards on small screens */
  #pageInventory .table-wrap {
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  #pageInventory table { min-width: 0; }

  #pageInventory thead { display: none; }

  #pageInventory tbody {
    display: block;
  }

  #pageInventory tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.65rem;
  }

  #pageInventory tbody tr:last-child { margin-bottom: 0; }

  #pageInventory td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0.5rem;
    min-width: 0;
    border: 0;
    padding: 0;
  }

  #pageInventory td.empty {
    grid-column: 1 / -1;
    text-align: left;
  }

  #pageInventory tr > td:last-child {
    grid-column: 1 / -1;
    display: block;
  }

  #pageInventory .lbl {
    display: inline;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .toolbar { max-width: none; }
}
