:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #1c1b19;
  --muted: #6b6861;
  --line: #e2dfd8;
  --accent: #2f5d3a;
  --accent-text: #ffffff;
  --tag: #eeece6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --card: #1f1f1c;
    --text: #ecebe6;
    --muted: #a09d94;
    --line: #33322e;
    --accent: #7fb88d;
    --accent-text: #10210f;
    --tag: #2b2a26;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 18px; margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { display: block; }

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; }

main { max-width: 680px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}

.feed { display: flex; flex-direction: column; gap: 12px; }

input, select, textarea, button, .file-button {
  font: inherit; color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

textarea { width: 100%; resize: vertical; display: block; }
button, .file-button { cursor: pointer; white-space: nowrap; }
button:disabled { opacity: .6; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.add { margin-bottom: 8px; }
.add.dragging { border-color: var(--accent); border-style: dashed; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.add-row input { flex: 1 1 160px; min-width: 0; }

.previews { display: flex; flex-wrap: wrap; gap: 8px; }
.previews:not(:empty) { margin-top: 8px; }
.preview { position: relative; }
.preview img { height: 72px; border-radius: 6px; display: block; }
.remove { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; line-height: 1; border-radius: 50%; }

.status { color: var(--muted); font-size: 13px; margin: 8px 0; min-height: 1em; }
.error { color: #c0392b; margin: 0; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.meta time { margin-left: auto; color: var(--muted); font-size: 13px; }
.tag { background: var(--tag); color: var(--muted); border-radius: 999px; padding: 1px 8px; font-size: 12px; }

.text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 10px 0 0; }
a { color: var(--accent); }

.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.media:has(> :only-child) { grid-template-columns: minmax(0, 360px); }
.thumb { position: relative; padding: 0; border-radius: 8px; overflow: hidden; background: var(--tag); }
.thumb img { display: block; width: 100%; height: auto; }
.badge { position: absolute; left: 6px; bottom: 6px; background: rgb(0 0 0 / .7); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.file { display: inline-block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.origin { display: inline-block; margin-top: 10px; font-size: 13px; }

.more { display: block; margin: 16px auto; }

dialog { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 96vh; }
dialog::backdrop { background: rgb(0 0 0 / .8); }
dialog img { display: block; max-width: 96vw; max-height: 96vh; cursor: zoom-out; }

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); }

.nav { display: flex; gap: 4px; margin-right: auto; }
.nav a { padding: 4px 10px; border-radius: 999px; text-decoration: none; color: var(--muted); }
.nav a[aria-current] { background: var(--tag); color: var(--text); font-weight: 600; }

.in-stock { display: block; width: 100%; margin-top: 10px; padding: 6px 10px; border: 0; border-radius: 8px; background: var(--tag); color: var(--accent); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.in-stock + .origin { margin-left: 2px; }

main.wide { max-width: 1100px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 8px; }
.controls input[type=search] { flex: 1 1 220px; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--card); }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }
.check input { padding: 0; }

.group { margin-top: 12px; padding: 0; overflow: hidden; }
.group h2 { font-size: 15px; margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.group h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 5px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--card); }
td.qty, th.qty { text-align: right; font-variant-numeric: tabular-nums; }
td.none { color: var(--muted); }
td.has { font-weight: 600; }
.pivot th:first-child, .pivot td:first-child { position: sticky; left: 0; background: var(--card); border-right: 1px solid var(--line); }

.sent { width: min(760px, calc(100vw - 32px)); max-height: 80vh; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); }
.sent[open] { display: flex; flex-direction: column; }
.sent::backdrop { background: rgb(0 0 0 / 0.45); }
.sent header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sent h2 { flex: 1; margin: 0; font-size: 15px; }
.sent header a { font-size: 13px; white-space: nowrap; }
.sent header button { border: 0; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.sent .scroll { overflow: auto; padding: 0 16px 12px; }
td.src { white-space: nowrap; font-size: 13px; }
th a { color: inherit; }

.company { display: flex; flex-direction: column; gap: 10px; }
.company h2 { margin: 0; font-size: 18px; }
.company label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.company label input, .company label textarea { color: var(--text); font-size: 15px; }
.company .add-row { align-items: center; }
.quick { font-size: 14px; }
.company-row { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); }
.company-row .status { margin: 0; }
.meta strong a, .group h2 a, td a { text-decoration: none; }
.meta strong a { color: inherit; }
.meta strong a:hover, .group h2 a:hover, td a:hover { text-decoration: underline; }
.login-card .brand { flex-direction: column; gap: 12px; font-size: 28px; font-weight: 800; margin-bottom: 6px; }
.login-card .brand img { width: 100%; height: auto; }
