:root {
  --sidebar-bg: #233648;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(21, 143, 210, 0.18);
  --sidebar-text: #a8b4c0;
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-w: 232px;

  --bg: #eef1f5;
  --bg-card: #ffffff;
  --bg-soft: #f7f9fb;
  --bg-input: #ffffff;
  --line: #dce1e8;
  --line-strong: #c8ced6;

  --text: #2b3137;
  --muted: #7a828a;
  --accent: #158fd2;
  --accent-hover: #1278b3;
  --accent-soft: rgba(21, 143, 210, 0.1);
  --success: #27ae60;
  --warn: #f5a623;
  --danger: #e74c3c;
  --draft: #5b9bd5;

  --radius: 3px;
  --radius-sm: 3px;
  --font: "PT Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --transition: 0.15s ease;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-gate[hidden],
#appShell[hidden] {
  display: none !important;
}

.auth-card {
  width: min(400px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  display: grid;
  gap: 12px;
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 4px;
}

.auth-brand strong {
  display: block;
  font-size: 18px;
}

.auth-brand small {
  color: var(--muted);
  font-size: 12px;
}

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--sidebar-border);
}

.proxy-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
}

.proxy-type {
  width: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}

::selection {
  background: var(--accent-soft);
}

/* Icons */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.main {
  min-height: 100vh;
  overflow: auto;
  background: var(--bg);
}

.view { display: none; }
.view.active { display: block; }

/* Brand */
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
}

.brand strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
}

.brand small {
  color: var(--sidebar-text);
  font-size: 12px;
}

/* Nav — amoCRM style */
.sidebar-create {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 12px 10px;
  padding: 9px 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-create:hover {
  background: var(--accent-hover);
}

.sidebar-create.active {
  outline: 2px solid rgba(255, 255, 255, 0.35);
  outline-offset: 1px;
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 10px 0 8px;
  flex: 1;
  border-top: 1px solid var(--sidebar-border);
}

.nav-divider {
  height: 1px;
  margin: 8px 16px;
  background: var(--sidebar-border);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 11px 20px 11px 17px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.nav-btn.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  opacity: 0.85;
}

.nav-btn.active .nav-icon {
  opacity: 1;
}

.nav-count {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

.nav-btn.active .nav-count {
  background: var(--accent);
}

/* Bot card in sidebar */
.bot-card {
  margin: auto 12px 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.15);
  display: grid;
  gap: 6px;
}

.bot-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bot-card-top strong {
  font-size: 13px;
  color: #fff;
}

.bot-card-name {
  font-size: 12px;
  color: var(--sidebar-text);
  word-break: break-all;
  line-height: 1.35;
}

.bot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sidebar-text);
  flex-shrink: 0;
}

.bot-card.ok { border-color: rgba(39, 174, 96, 0.45); }
.bot-card.ok .bot-dot,
.conn-banner.ok .bot-dot { background: var(--success); }
.bot-card.ok .bot-card-name { color: #7dcea0; }

.bot-card.bad { border-color: rgba(231, 76, 60, 0.45); }
.bot-card.bad .bot-dot,
.conn-banner.bad .bot-dot { background: var(--danger); }

.bot-card.warn { border-color: rgba(245, 166, 35, 0.45); }
.bot-card.warn .bot-dot,
.conn-banner.warn .bot-dot { background: var(--warn); }

.sidebar .btn.ghost {
  color: var(--sidebar-text);
  border-color: var(--sidebar-border);
  background: transparent;
}

.sidebar .btn.ghost:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.bulk-summary > span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Page shell — amoCRM content area */
.page-shell {
  padding: 0;
}

.page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.page-topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.page-topbar-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.page-body {
  padding: 20px 24px 32px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-eyebrow {
  display: none;
}

.toolbar-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 8px;
}

/* Stats strip */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.stat-warn { color: var(--warn); }

/* Panels */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
}

.panel.narrow { max-width: 720px; }

/* Day navigator */
.day-nav { margin-bottom: 12px; }

.day-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.day-nav-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
}

.day-nav-title strong {
  font-size: 15px;
  font-weight: 700;
  text-transform: capitalize;
}

.day-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.day-pill {
  flex: 0 0 auto;
  min-width: 64px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 3px;
  justify-items: center;
  font: inherit;
  transition: var(--transition);
}

.day-pill:hover { border-color: var(--line-strong); background: #fff; }

.day-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.day-pill.today:not(.active) { border-color: rgba(21, 143, 210, 0.45); }

.day-pill-wd {
  font-size: 11px;
  color: var(--muted);
  text-transform: capitalize;
}

.day-pill-num {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.day-pill-bar {
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.day-pill-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--muted);
  transition: width 0.3s ease;
}

.day-pill.complete .day-pill-fill { background: var(--success); }
.day-pill.partial .day-pill-fill { background: var(--warn); }
.day-pill.empty .day-pill-fill { background: #b0b8c0; }

.day-pill-pct {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Alerts */
.alert {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(245, 166, 35, 0.45);
  background: #fff8eb;
  color: #9a6700;
  font-size: 13px;
  font-weight: 600;
}

.alert.ok {
  border-color: rgba(39, 174, 96, 0.45);
  background: #edfbf3;
  color: #1e7e45;
}

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field-compact { margin-bottom: 0; }

.field > span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.field-note {
  font-style: normal;
  font-weight: 400;
  opacity: 0.8;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
select,
.editor {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: inherit;
  transition: var(--transition);
}

input:focus,
select:focus,
.editor:focus {
  outline: none;
  border-color: var(--accent);
}

.input-lg, .select-lg { min-width: 160px; }

.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  line-height: 1.45;
}

/* Buttons — amoCRM flat */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-soft);
  border-color: var(--line-strong);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.ghost:hover { color: var(--text); background: var(--bg-soft); }

.btn.danger {
  color: var(--danger);
  border-color: rgba(231, 76, 60, 0.35);
}

.btn.danger:hover { background: #fdf0ee; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 9px 16px; font-size: 14px; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius);
}

.btn-icon .icon { width: 16px; height: 16px; }

/* Search & filters */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

input.search-input,
.search-input {
  width: auto;
  min-width: 220px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
}

input.search-input:focus,
.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="search"].search-input::-webkit-search-decoration,
input[type="search"].search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.chip {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.chip.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.overview-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

.overview-chip {
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
}

.overview-chip:hover { border-color: var(--line-strong); color: var(--text); }
.overview-chip.bad { border-color: rgba(245, 166, 35, 0.5); color: #9a6700; }
.overview-chip.ok { border-color: rgba(39, 174, 96, 0.5); color: var(--success); }
.overview-chip.active {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  color: var(--text);
}

/* Bulk panel */
.bulk-panel { margin-bottom: 12px; }

.bulk-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 2px 0 12px;
  list-style: none;
  user-select: none;
}

.bulk-summary::-webkit-details-marker { display: none; }

.bulk-summary::after {
  content: "▾";
  font-size: 12px;
  color: var(--muted);
}

.bulk-panel[open] .bulk-summary::after { transform: rotate(180deg); display: inline-block; }

.bulk-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.bulk-card {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-soft);
}

.bulk-card h3 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
}

.bulk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.mini {
  display: grid;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.mini input {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 8px;
  font: inherit;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

/* Schedule slots */
.slot-panel { padding: 14px 16px; }

.slot-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.schedule-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.dot.free { background: #b0b8c0; }
.dot.filled { background: var(--warn); }
.dot.conflict { background: var(--danger); }
.dot.done { background: var(--success); }

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
}

.slot {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  min-height: 64px;
  font: inherit;
  transition: var(--transition);
}

.slot:hover {
  border-color: var(--accent);
  background: #fff;
}

.slot .t {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.slot .p {
  font-size: 11px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.slot.free { opacity: 0.75; }
.slot.free .p { font-style: italic; }
.slot.filled { border-color: rgba(245, 166, 35, 0.55); background: #fffaf0; }
.slot.conflict { border-color: rgba(231, 76, 60, 0.55); background: #fdf0ee; }
.slot.published { border-color: rgba(39, 174, 96, 0.55); background: #edfbf3; }

.schedule-controls select,
.schedule-controls input {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 10px;
  font: inherit;
}

/* Editor */
.editor-grid {
  display: grid;
  grid-template-columns: 1.55fr 0.85fr;
  gap: 16px;
  align-items: start;
}

.editor-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}

.toolbar button {
  min-width: 30px;
  height: 30px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.toolbar button:hover {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 5px 4px;
  align-self: center;
}

.editor {
  min-height: 280px;
  outline: none;
  line-height: 1.55;
  white-space: pre-wrap;
  border: none;
  border-radius: 0;
  padding: 14px;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif,
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Segoe UI Symbol",
    "Noto Color Emoji";
}

.editor .tg-spoiler {
  background: #495159;
  color: #495159;
  border-radius: 3px;
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 72px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  background: var(--bg-soft);
}

.file-drop:hover,
.file-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-drop-text {
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.media-row { display: flex; gap: 8px; margin-top: 8px; }

.media-preview {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  background: var(--bg-soft);
}

.side-panel { position: sticky; top: 16px; }

.side-section { margin-bottom: 16px; }

.side-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.side-hint { margin-bottom: 8px; }

.checks {
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
}

.check:hover { border-color: var(--accent); }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.dt-row {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 6px;
}

.dt-quick { margin-top: 8px; }
.dt-quick .chip { padding: 5px 9px; font-size: 11px; }

.preview-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #0e1621;
  margin-bottom: 14px;
}

.preview-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #8b9bab;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.tg-logo {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2aabee;
  display: inline-grid;
  place-items: center;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
}

/* Telegram channel post preview */
.tg-preview-shell {
  background: #0e1621;
  border-radius: 6px;
  overflow: hidden;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif,
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Segoe UI Symbol",
    "Noto Color Emoji";
}

.tg-preview-header {
  padding: 10px 12px 0;
}

.tg-preview-channel {
  font-size: 14px;
  font-weight: 700;
  color: #6ab3f3;
  letter-spacing: 0.01em;
}

.tg-preview-body {
  padding: 0 0 4px;
}

.tg-preview-media img,
.tg-preview-media video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  background: #17212b;
}

.tg-preview-media .preview-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: #6ab3f3;
  text-decoration: none;
  background: #17212b;
  font-size: 14px;
}

.tg-message-text {
  color: #f5f5f5;
  font-size: 15px;
  line-height: 1.3125;
  padding: 8px 12px 12px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  letter-spacing: 0.01em;
}

.tg-message-text.empty {
  color: #6b7c8a;
  font-style: italic;
}

.tg-message-text b,
.tg-message-text strong {
  font-weight: 700;
}

.tg-message-text i,
.tg-message-text em {
  font-style: italic;
}

.tg-message-text u,
.tg-message-text ins {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tg-message-text s,
.tg-message-text strike,
.tg-message-text del {
  text-decoration: line-through;
}

.tg-message-text a {
  color: #6ab3f3;
  text-decoration: none;
  word-break: break-all;
}

.tg-message-text a:hover {
  text-decoration: underline;
}

.tg-message-text code {
  font-family: "Courier New", Courier, ui-monospace, monospace;
  font-size: 0.92em;
  background: rgba(0, 0, 0, 0.28);
  padding: 1px 5px;
  border-radius: 3px;
  color: #e8edf2;
}

.tg-message-text pre {
  font-family: "Courier New", Courier, ui-monospace, monospace;
  font-size: 0.92em;
  background: rgba(0, 0, 0, 0.28);
  padding: 8px 10px;
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre-wrap;
  margin: 4px 0;
  color: #e8edf2;
}

.tg-message-text blockquote {
  margin: 4px 0;
  padding: 2px 0 2px 10px;
  border-left: 3px solid #6ab3f3;
  color: #d8dee4;
}

.tg-spoiler {
  background: #495159;
  color: transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  user-select: none;
}

.tg-spoiler:hover {
  background: #5a636b;
}

.tg-spoiler.revealed {
  background: rgba(0, 0, 0, 0.22);
  color: inherit;
  user-select: text;
}

.tg-bubble {
  background: #182533;
  border-radius: 4px 12px 12px 12px;
  padding: 10px 12px;
  line-height: 1.5;
  word-break: break-word;
  font-size: 13px;
  color: #e8edf2;
}

.tg-bubble.empty { color: #6b7c8a; font-style: italic; }
.tg-bubble a { color: #64b5f6; }
.tg-bubble code, .tg-bubble pre {
  font-family: var(--mono);
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.25);
  padding: 1px 4px;
  border-radius: 3px;
}
.tg-bubble .tg-spoiler {
  background: #374151;
  color: transparent;
  border-radius: 3px;
}

.actions-col { display: grid; gap: 8px; }

/* Data table — amoCRM list style */
.data-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  cursor: pointer;
  transition: var(--transition);
}

.data-table tbody tr:hover { background: #f5f8fb; }

.data-table .col-title {
  font-weight: 600;
  color: var(--text);
  max-width: 280px;
}

.data-table .col-preview {
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table .col-actions {
  text-align: right;
  white-space: nowrap;
}

.data-table .col-actions .btn {
  padding: 4px 8px;
  margin-left: 4px;
}

.row-actions {
  display: inline-flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.data-table tbody tr:hover .row-actions { opacity: 1; }

/* Cards fallback */
.post-list, .channel-list { display: grid; gap: 8px; }

.card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-card);
}

.card:hover { border-color: var(--line-strong); }

.card h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge.draft { background: #e8f2fb; color: var(--draft); }
.badge.scheduled { background: #fff8eb; color: #9a6700; }
.badge.published { background: #edfbf3; color: var(--success); }
.badge.failed { background: #fdf0ee; color: var(--danger); }

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 100px;
}

.inline-form, .stack-form { display: grid; gap: 10px; }
.inline-form, .channel-form { grid-template-columns: 1.2fr 1fr auto; }

.conn-banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-soft);
  margin-bottom: 16px;
}

.conn-banner strong { display: block; margin-bottom: 2px; font-size: 14px; }
.conn-banner.ok { border-color: rgba(39, 174, 96, 0.45); background: #edfbf3; }
.conn-banner.bad { border-color: rgba(231, 76, 60, 0.45); background: #fdf0ee; }
.conn-banner.warn { border-color: rgba(245, 166, 35, 0.45); background: #fff8eb; }

.steps-card {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-soft);
}

.steps-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}

.steps {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-state p {
  margin: 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(35, 54, 72, 0.45);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

#confirmModal {
  z-index: 120;
}

.modal[hidden] { display: none !important; }

.modal-card {
  width: min(440px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-wide {
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.confirm-card {
  width: min(400px, 100%);
}

.confirm-message {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.confirm-actions .btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.confirm-actions .btn.danger:hover {
  background: #c0392b;
  border-color: #c0392b;
}

.preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

.preview-error { color: var(--danger); }

.preview-media {
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}

.preview-img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #17212b;
}

.preview-doc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: var(--accent);
  text-decoration: none;
  background: var(--bg-soft);
}

.preview-doc:hover { text-decoration: underline; }

.preview-modal-box { margin-bottom: 14px; }

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card-clickable .card-body { cursor: pointer; }

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--bg-card);
  border: 1px solid rgba(39, 174, 96, 0.45);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 360px;
  z-index: 200;
  font-weight: 600;
  font-size: 13px;
}

.toast.error {
  border-color: rgba(231, 76, 60, 0.45);
  background: #fdf0ee;
}

/* Scrollbar */
.main::-webkit-scrollbar { width: 8px; }
.main::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

/* Responsive */
@media (max-width: 1100px) {
  .bulk-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px;
    gap: 8px;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: unset;
    order: 3;
    width: 100%;
    padding: 0;
  }
  .nav-btn {
    padding: 8px 12px;
    border-left: none;
    border-bottom: 2px solid transparent;
  }
  .nav-btn.active { border-bottom-color: var(--accent); border-left-color: transparent; }
  .sidebar-create { margin: 0 0 8px; width: 100%; }
  .bot-card { margin: 0; width: 100%; order: 4; }
  .page-body { padding: 16px; }
  .page-topbar { padding: 12px 16px; }
  .editor-grid { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .inline-form, .channel-form { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr; }
  .row-actions { opacity: 1; }
}
