:root {
  color-scheme: light;
  --ink: #17263c;
  --muted: #68788c;
  --line: #dce3eb;
  --blue: #234b78;
  --blue-dark: #183958;
  --wash: #f4f6f9;
  --white: #fff;
  --green: #176843;
  --orange: #a35d12;
  --red: #a33434;
  --soft: #edf4f9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--wash); color: var(--ink); }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
a { color: var(--blue-dark); }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink); }
p { line-height: 1.45; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.45; }
.fine { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 8px 0 0; }
.muted { color: var(--muted); }
.error-text { color: var(--red); font-size: 13px; }
.warn-text { color: var(--orange); font-size: 13px; }
.ok-text { color: var(--green); }

/* header */
.top { display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; font-size: 17px; text-decoration: none; color: var(--blue-dark); letter-spacing: -.02em; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; color: var(--ink); font-size: 14px; font-weight: 600; padding: 7px 10px; border-radius: 7px; }
.nav a:hover { background: var(--soft); }
.nav a.active { background: var(--soft); color: var(--blue-dark); }
.top-right { display: flex; align-items: center; gap: 12px; }
.where { font-size: 13px; color: var(--muted); text-decoration: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.where.missing { color: var(--orange); font-weight: 600; }
.link { border: 0; background: none; color: var(--blue-dark); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.link.danger { color: var(--red); }

/* layout */
.app { width: min(100%, 1160px); margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: 0 8px 24px #17263c0a; }
.card + .card { margin-top: 16px; }
.card.tight { padding: 14px 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* forms */
form, .form { display: grid; gap: 14px; }
label, .label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
label small, .label small { font-weight: 500; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 42px; border: 1px solid #c8d2df; border-radius: 8px; padding: 9px 12px;
  color: var(--ink); background: #fff; font: inherit; font-size: 15px; outline: none;
}
textarea { min-height: 110px; line-height: 1.45; resize: vertical; }
textarea.tall { min-height: 220px; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { border-color: #3972aa; box-shadow: 0 0 0 3px #3972aa22; }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="checkbox"] { width: auto; min-height: 0; margin: 0 8px 0 0; accent-color: var(--blue); }
label.check { grid-auto-flow: column; justify-content: start; align-items: center; font-weight: 550; }
.counter { font-weight: 500; color: var(--muted); font-size: 12px; }
.counter.over { color: var(--red); font-weight: 700; }
button, .button {
  min-height: 42px; border: 0; border-radius: 8px; padding: 9px 16px; background: var(--blue); color: #fff;
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .button:hover { background: var(--blue-dark); }
button:disabled { opacity: .55; cursor: default; }
button.secondary, .button.secondary { background: #fff; color: var(--blue-dark); border: 1px solid var(--line); }
button.secondary:hover, .button.secondary:hover { background: var(--soft); }
button.small, .button.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
button.danger { background: #fff; color: var(--red); border: 1px solid #e3c3c3; }
button.danger:hover { background: #fbf0f0; }
button.ghost { background: none; color: var(--muted); border: 0; min-height: 0; padding: 2px 4px; font-weight: 600; }
button.ghost:hover { color: var(--ink); background: none; }
.status-line { min-height: 18px; font-size: 13px; color: var(--muted); }

/* lists */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--soft); color: var(--blue-dark); letter-spacing: .01em; white-space: nowrap; }
.badge.green { background: #e4f3ea; color: var(--green); }
.badge.orange { background: #fbeedc; color: var(--orange); }
.badge.red { background: #f8e4e4; color: var(--red); }
.badge.grey { background: #eef1f5; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 0; }
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip:hover { background: var(--soft); }
.chip.active:hover { background: var(--blue-dark); }
.empty { color: var(--muted); font-size: 14px; padding: 18px 2px; }

.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.product { display: grid; grid-template-rows: 160px auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; text-decoration: none; color: inherit; transition: box-shadow .15s; }
.product:hover { box-shadow: 0 8px 24px #17263c14; }
.product .thumb { background: var(--soft) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.product .body { padding: 10px 12px 12px; display: grid; gap: 5px; }
.product .title { font-weight: 650; font-size: 14px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 36px; }
.product .price { font-weight: 750; font-variant-numeric: tabular-nums; }
.product .meta { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--soft) center/cover no-repeat; border: 1px solid var(--line); cursor: grab; }
.photo.dragging { opacity: .4; }
.photo.over { outline: 3px solid #3972aa; }
.photo .n { position: absolute; left: 6px; top: 6px; background: #17263ccc; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.photo .x { position: absolute; right: 4px; top: 4px; background: #17263ccc; color: #fff; border: 0; border-radius: 6px; min-height: 0; padding: 2px 7px; font-size: 13px; line-height: 1.4; }
.photo .mv { position: absolute; bottom: 4px; display: flex; gap: 3px; left: 4px; right: 4px; justify-content: space-between; opacity: 0; transition: opacity .15s; }
.photo:hover .mv, .photo:focus-within .mv { opacity: 1; }
@media (hover: none) { .photo .mv { opacity: 1; } }
.photo .mv button { min-height: 0; padding: 2px 8px; font-size: 12px; background: #17263ccc; }
.photo.uploading::after { content: ""; position: absolute; inset: 0; background: #ffffffa0; }
.drop { border: 2px dashed #c8d2df; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); font-size: 14px; display: grid; gap: 8px; justify-items: center; transition: background .15s, border-color .15s; }
.drop.over { background: var(--soft); border-color: #3972aa; }

/* research */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 650; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.excluded td, tr.weak td { color: var(--muted); }
tr.excluded td.t, tr.weak td.t { text-decoration: line-through; }
td img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--soft); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.stat { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.stat.main { background: var(--blue); color: #fff; }
.stat.main span { color: #dbe6f3; }
.research-list { display: grid; gap: 8px; }
.research-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; cursor: pointer; }
.research-row:hover { background: var(--soft); }
.research-row .q { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.research-row .s { color: var(--muted); font-size: 12px; grid-column: 1; }
.research-row .p { font-weight: 750; font-variant-numeric: tabular-nums; grid-row: 1 / span 2; align-self: center; }

/* writer results */
.options { display: grid; gap: 8px; }
.option { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: #fff; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 14px; }
.option .len { color: var(--muted); font-size: 12px; }
.preview { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; font-size: 14px; line-height: 1.5; background: #fff; max-height: 360px; overflow: auto; }
.preview p { margin: 0 0 10px; }
.preview ul { margin: 0 0 10px; padding-left: 20px; }

/* misc */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.copy-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) auto; gap: 8px; align-items: start; font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.copy-row:last-child { border-bottom: 0; }
.copy-row .k { color: var(--muted); font-size: 13px; padding-top: 6px; }
.copy-row .v { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 160px; overflow: auto; padding-top: 6px; }
.banner { border-radius: 10px; padding: 12px 14px; font-size: 14px; background: var(--soft); }
.banner.warn { background: #fbeedc; color: #5c3a10; }
.banner.bad { background: #f8e4e4; color: #6b2323; }
.banner.good { background: #e4f3ea; color: #12492f; }
.problems { margin: 0; padding-left: 18px; font-size: 13px; color: var(--orange); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; max-width: min(92vw, 560px); z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--red); }
.login { width: min(100%, 380px); margin: 12vh auto 0; }
.login h1 { text-align: center; margin-bottom: 18px; }
.loc-table td:first-child { font-weight: 650; }
.now { background: var(--blue); color: #fff; border-radius: 12px; padding: 16px 18px; }
.now b { font-size: 20px; }
.now .muted { color: #cfdcec; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--soft); padding: 2px 5px; border-radius: 5px; overflow-wrap: anywhere; }
details { border: 1px solid var(--line); border-radius: 9px; padding: 10px 14px; }
details summary { cursor: pointer; font-weight: 650; font-size: 14px; }
details[open] summary { margin-bottom: 10px; }
.log { font-size: 13px; display: grid; gap: 6px; }
.log .row-l { display: grid; grid-template-columns: 150px 80px 1fr; gap: 10px; }
.log .row-l.error { color: var(--red); }
.bookmarklet { display: inline-block; padding: 8px 14px; border: 1px dashed var(--blue); border-radius: 8px; background: #fff; color: var(--blue-dark); font-weight: 700; text-decoration: none; cursor: grab; }
.aspect-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.aspect-grid label { font-size: 12px; }
.sticky-save { position: sticky; bottom: 0; background: #f4f6f9ee; backdrop-filter: blur(6px); padding: 10px 0; margin-top: 8px; display: flex; gap: 10px; align-items: center; justify-content: flex-end; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .top { gap: 10px; padding: 8px 12px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .where { max-width: 160px; }
  .app { padding: 16px 12px 90px; }
  .row3, .row4 { grid-template-columns: 1fr 1fr; }
  .copy-row { grid-template-columns: 1fr; }
  .copy-row .k { padding: 0; }
  .card { padding: 15px; border-radius: 12px; }
  h1 { font-size: 21px; }
}
@media (max-width: 480px) {
  .row { grid-template-columns: 1fr; }
  .products { grid-template-columns: repeat(2, 1fr); }
  .product { grid-template-rows: 120px auto; }
}
