:root {
  --paper: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #fbf8f2;
  --line: #e5ded2;
  --line-strong: #d3c8b7;
  --ink: #191712;
  --muted: #6e6559;
  --faint: #7b7264;
  --accent: #a8461f;
  --accent-ink: #8c3817;
  --accent-soft: #f3e2d8;
  --ok: #2f6b4a;
  --ok-soft: #e3efe7;
  --warn: #8a6414;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(25, 23, 18, .04), 0 8px 24px -18px rgba(25, 23, 18, .45);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

/* hidden всегда побеждает: иначе display у компонентов его перебивает */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--accent-ink); }

input, textarea, select, button { font: inherit; color: inherit; }
textarea { caret-color: var(--accent); }
input { caret-color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 2px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- вход ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 0;
  font: 400 34px/1 var(--serif);
  letter-spacing: -.02em;
}

.login-hint { margin: 8px 0 22px; color: var(--muted); font-size: 13.5px; }

.login-error {
  margin: 0 0 14px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13.5px;
}

/* ---------- каркас ---------- */

.app {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 2px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(var(--paper) 76%, rgba(245, 242, 236, 0));
}

.brand { display: flex; align-items: center; gap: 9px; }

.brand-mark { color: var(--accent); display: inline-flex; }

.brand-name {
  font: 400 23px/1 var(--serif);
  letter-spacing: -.015em;
}

.top-actions { display: flex; gap: 4px; }

/* ---------- кнопки ---------- */

.btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  min-height: 36px;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn-ghost { color: var(--muted); border-color: var(--line); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }

.btn-primary {
  background: var(--accent);
  color: #fff8f2;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-quiet {
  color: var(--muted);
  padding: 8px 10px;
}
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn[data-busy="1"] { opacity: .6; pointer-events: none; }

/* ---------- табы ---------- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 0;
  background: none;
  padding: 10px 11px 11px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

.count {
  font-variant-numeric: tabular-nums;
  color: var(--faint);
  margin-left: 3px;
  font-weight: 400;
}
.tab.is-active .count { color: var(--accent); }

/* ---------- панель поиска ---------- */

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 11px;
  color: var(--faint);
}
.search:focus-within { border-color: var(--line-strong); }

.search input {
  flex: 1;
  border: 0;
  background: none;
  padding: 10px 0;
  font-size: 14px;
  color: var(--ink);
  min-width: 0;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; }

select {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 9px;
  padding: 0 10px;
  font-size: 13.5px;
  color: var(--ink);
  max-width: 44%;
}

/* ---------- лента ---------- */

.feed {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.event {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 0 12px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
  animation: arrive .32s cubic-bezier(.2, .7, .2, 1) both;
}
.event:last-child { border-bottom: 0; }

@keyframes arrive {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .event { animation: none; }
}

.src {
  grid-row: 1 / span 3;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  user-select: none;
}
.src[data-src="telegram"] { color: #1f6f8b; background: #e4f0f4; border-color: #cfe4ea; }
.src[data-src="petrovich"] { color: #8a4a12; background: #f6e9da; border-color: #ecd9c2; }
.src[data-src="youdo"] { color: #2f6b4a; background: var(--ok-soft); border-color: #cfdfd2; }
.src[data-src="vk"] { color: #3c4d78; background: #e8ebf4; border-color: #d4daeb; }
.src[data-src="avito"] { color: #7a3b57; background: #f4e6ec; border-color: #e8d3dc; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.3;
}

.meta .place { color: var(--ink); font-weight: 500; }
.meta .dot { color: var(--line-strong); }

.time { font-variant-numeric: tabular-nums; }

.hot {
  color: var(--accent-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hot::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 5px;
  vertical-align: 1px;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.budget {
  color: var(--ok);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ask {
  grid-column: 2;
  margin: 8px 0 10px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.ask.is-open { display: block; }

.reply {
  grid-column: 2;
  margin: 0 0 10px;
}

.variants {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.vpick {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 6px;
  min-width: 26px;
  height: 24px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.vpick.is-active { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.vpick:hover:not(.is-active) { border-color: var(--line-strong); }

.vlabel { margin-left: auto; font-size: 11.5px; color: var(--faint); }

textarea.draft {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 11px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 62px;
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease;
}
textarea.draft:focus { outline: none; border-color: var(--line-strong); background: var(--surface); }

.actions {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.actions .btn-primary { min-height: 40px; padding: 0 18px; }
.actions .spacer { flex: 1; }

.open-link {
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--line-strong);
}
.open-link:hover { color: var(--ink); }

.status-note {
  grid-column: 2;
  font-size: 12.5px;
  color: var(--muted);
}
.status-note.sent { color: var(--ok); }
.status-note.skipped { color: var(--faint); }

.replied-badge {
  grid-column: 2;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--ok);
  background: var(--ok-soft);
  border-radius: 6px;
  padding: 3px 8px;
  justify-self: start;
}

/* ---------- пусто, подвал ---------- */

.empty {
  padding: 56px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-title { font: 400 22px/1.2 var(--serif); color: var(--ink); margin: 0 0 8px; }
.empty-text { margin: 0; font-size: 13.5px; }
.empty code { background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 12.5px; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px 0;
  font-size: 12px;
  color: var(--faint);
}

.conn::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  margin-right: 6px;
  vertical-align: 1px;
}
.conn.is-live::before { background: var(--ok); }

/* ---------- диалог профиля ---------- */

.dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100% - 24px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px -28px rgba(25, 23, 18, .5);
}
.dialog::backdrop { background: rgba(25, 23, 18, .38); backdrop-filter: blur(2px); }
.dialog form { padding: 22px 22px 18px; }
.dialog h2 { margin: 0 0 6px; font: 400 22px/1.15 var(--serif); }
.dialog-hint { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field-wide { grid-column: 1 / -1; }
.field span { font-size: 12.5px; color: var(--muted); }
.field input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 9px 10px;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--line-strong); background: var(--surface); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ---------- тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--surface);
  border-radius: 9px;
  padding: 10px 15px;
  font-size: 13.5px;
  max-width: calc(100% - 32px);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  pointer-events: none;
}
.toast.is-shown { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.is-error { background: var(--accent-ink); }

/* ---------- мобильный ---------- */

@media (max-width: 620px) {
  .app { padding: 0 10px calc(20px + env(safe-area-inset-bottom)); }
  .top { padding: 12px 2px 10px; }
  .feed { border-radius: 10px; }
  .event { grid-template-columns: 26px 1fr; gap: 0 10px; padding: 14px 12px 12px; }
  .src { width: 25px; height: 25px; font-size: 9.5px; }
  .ask { font-size: 14.5px; }
  .actions { gap: 4px; }
  .actions .btn { padding: 9px 12px; }
  .actions .btn-primary { flex: 1; }
  .toolbar { flex-wrap: wrap; }
  select { max-width: 100%; width: 100%; height: 40px; }
  .grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .brand-name { font-size: 20px; }
  .top-actions .btn { padding: 7px 9px; font-size: 12.5px; }
}
