:root {
  --bg: #f5f4f2;
  --card: #ffffff;
  --ink: #1c1917;
  --muted: #6b6560;
  --line: #e5e1dc;
  --accent: #d4560f;      /* Hammer orange */
  --accent-dark: #b34509;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok-bg: #e6f6ec;
  --ok-ink: #1e7a3c;
  --err-bg: #fdebea;
  --err-ink: #a52a1d;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

main.narrow { max-width: 760px; margin: 0 auto; padding: 16px 12px 90px; }
main.full   { max-width: 1100px; margin: 0 auto; padding: 16px 12px 90px; }
@media (min-width: 700px) {
  main.narrow, main.full { padding: 24px 16px 80px; }
}

h1 { font-size: 1.4rem; margin: 0.2em 0 0.6em; }
h2 { font-size: 1.05rem; margin: 1.2em 0 0.5em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code { background: #ece9e4; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; word-break: break-all; }

/* ── Nav (mobile-first: brand row + scrollable links) ── */
.topnav {
  display: flex; align-items: center; justify-content: space-between;
  background: #14110e; color: #fff; padding: 10px 14px; flex-wrap: wrap; gap: 6px;
  position: sticky; top: 0; z-index: 20;
}
.topnav .brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 1.1rem; letter-spacing: 0.02em; }
.topnav .brand span { color: #ff8a3d; font-weight: 500; }
.topnav .links {
  display: flex; align-items: center; gap: 16px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  max-width: 100%; padding-bottom: 2px;
}
.topnav .links::-webkit-scrollbar { display: none; }
.topnav .links a { color: #d6cec7; text-decoration: none; white-space: nowrap; padding: 6px 0; }
.topnav .links a:hover { color: #fff; }
.linklike { background: none; border: 0; color: #94897f; cursor: pointer; font: inherit; padding: 6px 0; white-space: nowrap; }
.linklike:hover { color: #fff; }

/* ── Cards / layout ── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 14px 0;
}
@media (min-width: 700px) { .card { padding: 18px 20px; } }
.auth-card { max-width: 400px; margin: 6vh auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .two-col { grid-template-columns: 1fr 1fr; } }
.three-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (min-width: 700px) { .three-col { grid-template-columns: 1fr 1fr 1fr; } }

/* ── Forms (44px+ touch targets) ── */
label { display: block; margin: 10px 0; font-weight: 600; font-size: 0.9rem; }
label.check { font-weight: 400; }
input:not([type=checkbox]):not([type=file]), textarea, select {
  display: block; width: 100%; margin-top: 4px;
  padding: 11px 12px; font: inherit; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  display: inline-block; padding: 11px 16px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  cursor: pointer; text-decoration: none; text-align: center; min-height: 44px;
}
.btn:hover { border-color: #c4bcb3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #e5b6b0; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; min-height: 34px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.55; cursor: default; }
form.inline { display: inline; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.flash { padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.flash.error { background: var(--err-bg); color: var(--err-ink); }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em; vertical-align: middle;
}
.badge.muted { background: #9a938c; }
.badge.ok { background: var(--ok-ink); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.disabled-row td { opacity: 0.5; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.user-actions { white-space: nowrap; }
.user-actions select { display: inline-block; width: auto; min-height: 34px; padding: 5px 28px 5px 8px; font-size: 0.85rem; }

.qr-wrap { text-align: center; margin: 14px 0; }
.qr-wrap img { border: 1px solid var(--line); border-radius: 8px; }

/* ── Build grid ── */
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
@media (min-width: 700px) { .vgrid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; } }
.vcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.vthumb { display: block; position: relative; aspect-ratio: 4/3; background: #e3ded8; }
.vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.status-badge {
  position: absolute; top: 8px; left: 8px; color: #fff;
  font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 4px; text-transform: uppercase;
}
.status-draft { background: #6b6560; }
.status-ready { background: #1f6feb; }
.status-published { background: var(--ok-ink); }
.vbody { padding: 10px 12px 12px; }
.vtitle { font-weight: 700; color: var(--ink); text-decoration: none; display: block; }
.vmeta { color: var(--muted); font-size: 0.85rem; margin: 2px 0 8px; }
.vactions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Photos ── */
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.dropzone.over { border-color: var(--accent); background: #fff4ec; }
.filebtn {
  display: inline-block; padding: 10px 16px; border: 1px dashed var(--line);
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.9rem; margin: 0;
}
.filebtn:hover { border-color: var(--accent); color: var(--accent); }

.photo-list { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; padding: 0; margin: 12px 0; }
@media (min-width: 700px) { .photo-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.photo-item {
  position: relative; aspect-ratio: 4/3; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: #ece9e4;
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-item.dragging { opacity: 0.4; }
.photo-item:first-child::before {
  content: "COVER"; position: absolute; top: 4px; left: 4px; z-index: 1;
  background: #14110e; color: #fff; font-size: 0.6rem; font-weight: 700;
  padding: 2px 5px; border-radius: 3px;
}
.photo-tools {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between;
  background: linear-gradient(transparent, rgba(0,0,0,0.65)); padding: 14px 4px 4px;
}
.photo-tools button {
  border: 0; border-radius: 6px; background: rgba(0,0,0,0.55); color: #fff;
  min-width: 32px; min-height: 32px; font-size: 15px; cursor: pointer;
}
.photo-tools button:hover { background: var(--accent); }
.remove-photo { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,0.6); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }
.remove-photo:hover { background: var(--danger); }

/* ── Parts ── */
.part-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 2px; border-bottom: 1px dashed var(--line); }
.part-name { font-weight: 600; }
.part-meta { color: var(--muted); font-size: 0.83rem; }
.typeahead-wrap { position: relative; }
.typeahead-menu {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-top: 2px;
  max-height: 240px; overflow-y: auto; box-shadow: 0 6px 18px rgba(0,0,0,0.1);
}
.typeahead-menu button {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border: 0; background: none; font: inherit; cursor: pointer;
}
.typeahead-menu button:hover, .typeahead-menu button.hl { background: #fff4ec; }

/* ── Articles ── */
.channel-tabs { display: flex; gap: 8px; margin: 14px 0 4px; }
.channel-tabs a {
  padding: 9px 16px; border-radius: 8px 8px 0 0; text-decoration: none; font-weight: 600;
  color: var(--muted); border: 1px solid transparent;
}
.channel-tabs a.on { background: var(--card); border-color: var(--line); border-bottom-color: var(--card); color: var(--ink); }
.section-block { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 10px 0; background: #fbfaf9; }
.section-block textarea { font-size: 0.95rem; }
.photo-pick { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0; }
.photo-pick label { flex: 0 0 auto; margin: 0; cursor: pointer; }
.photo-pick img { width: 84px; height: 63px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; display: block; }
.photo-pick input { display: none; }
.photo-pick input:checked + img { border-color: var(--accent); }
.kw-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.kw-chip { background: #ece9e4; border-radius: 999px; padding: 4px 10px; font-size: 0.82rem; }
.kw-chip b { font-weight: 700; }

.publish-row { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.danger-zone { border-color: #e5b6b0; }

/* ── Settings groups ── */
.setting-group h2 { display: flex; align-items: center; gap: 10px; }
.conf-dot { width: 10px; height: 10px; border-radius: 50%; background: #c4bcb3; display: inline-block; }
.conf-dot.on { background: var(--ok-ink); }
.test-result { margin-top: 8px; }

/* ── Progress / async ── */
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid #d6cec7; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Feedback widget + log ── */
#fb-widget { position: fixed; right: 14px; bottom: 14px; z-index: 50; }
#fb-open {
  width: 52px; height: 52px; border-radius: 50%; border: 2px solid #fff; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 26px; font-weight: 800; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
#fb-open:hover { background: var(--accent-dark); }
#fb-panel {
  position: absolute; right: 0; bottom: 62px; width: min(340px, calc(100vw - 28px));
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
#fb-panel h3 { margin: 0 0 4px; font-size: 1rem; }
#fb-previews { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.fb-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; }
.fb-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.filebtn.small { padding: 6px 10px; font-size: 0.85rem; }

.msg-link { position: relative; font-size: 1.05rem; }
.msg-badge {
  position: absolute; top: -2px; right: -10px; background: var(--accent); color: #fff;
  border-radius: 999px; font-size: 0.65rem; font-weight: 700; padding: 1px 5px; line-height: 1.3;
}
.fb-unread { background: #fff4ec; border-radius: 8px; padding-left: 8px; padding-right: 8px; }

.fb-item .fb-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fb-check input { width: auto; min-height: 0; display: inline; margin-right: 4px; }
.fb-raw { margin: 10px 0; padding: 8px 12px; border-left: 3px solid var(--line); color: var(--ink); background: #fbfaf9; }
.fb-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.fb-thumbs .fb-thumb { width: 110px; height: 82px; }
.fb-pre { white-space: pre-wrap; font-size: 0.85rem; background: #fbfaf9; padding: 10px; border-radius: 8px; }
.fb-triage { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 4px; }
label.check.small { font-size: 0.85rem; }
