:root {
  --bg: #f4efe8;
  --paper: rgba(255, 251, 245, 0.94);
  --ink: #17212b;
  --muted: #5d6a78;
  --line: #d8cfbf;
  --accent: #1f5c74;
  --accent-strong: #153f50;
  --accent-soft: #dcecf3;
  --warm: #c26f45;
  --warn: #9f4738;
  --success: #336a4b;
  --shadow: 0 18px 40px rgba(23, 33, 43, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(31, 92, 116, 0.12), transparent 24%),
    radial-gradient(circle at top right, rgba(194, 111, 69, 0.14), transparent 22%),
    linear-gradient(180deg, #f9f6f1 0%, #efe7da 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  width: min(1580px, calc(100vw - 20px));
  height: 100vh;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
}

.app-shell.is-booting {
  visibility: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.95fr);
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(216, 207, 191, 0.88);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.topbar-copy {
  min-width: 0;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 5px;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
}

h1 {
  font-size: clamp(28px, 3vw, 38px);
  line-height: 0.98;
}

h2 {
  font-size: 22px;
  line-height: 1.04;
}

.lead {
  margin-top: 8px;
  max-width: 760px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
  justify-content: flex-end;
}

.sync-status-card,
.metric-card,
.panel,
.conversation-card,
.bubble {
  border: 1px solid rgba(216, 207, 191, 0.82);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.sync-status-card {
  padding: 11px 13px;
  border-radius: 16px;
  background: linear-gradient(150deg, #163342, #244c60);
  color: white;
  min-width: 250px;
  flex: 1 1 250px;
}

.sync-status-label {
  display: block;
  font-weight: 700;
  font-size: 13px;
}

.sync-status-meta {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.3;
  font-size: 12px;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease;
  font-size: 13px;
  text-decoration: none;
}

.ghost-button {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  font-weight: 700;
}

.ghost-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
}

.compact {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 13px;
}

.overview-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  padding: 9px 12px;
  border-radius: 16px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.2;
}

.service-launchpad {
  display: block;
}

.service-launchpad-card {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr) auto;
  gap: 14px;
  align-items: center;
  padding: 15px 18px;
  border-radius: 20px;
  border: 1px solid rgba(216, 207, 191, 0.88);
  background:
    radial-gradient(circle at top right, rgba(42, 159, 223, 0.14), transparent 28%),
    linear-gradient(145deg, rgba(255, 251, 245, 0.96), rgba(246, 252, 255, 0.94));
  box-shadow: var(--shadow);
}

.service-launchpad-copy {
  min-width: 0;
}

.service-launchpad-copy h2 {
  font-size: 24px;
  line-height: 1.04;
}

.service-launchpad-lead,
.service-launchpad-caption {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.service-launchpad-lead {
  margin-top: 8px;
}

.service-launchpad-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.service-launchpad-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(220, 236, 243, 0.88);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.service-launchpad-pill.warn {
  background: rgba(194, 111, 69, 0.14);
  color: var(--warn);
}

.service-launchpad-pill.success {
  background: rgba(51, 106, 75, 0.14);
  color: var(--success);
}

.service-launchpad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.panel {
  padding: 12px;
  border-radius: 18px;
}

.sidebar,
.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-head,
.chat-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-head {
  align-items: center;
}

.chat-head {
  align-items: flex-start;
}

.sidebar-head-copy {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
}

.sidebar-count {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 13px;
}

.sidebar h2 {
  font-size: 17px;
}

.chat-panel h2 {
  font-size: 30px;
  line-height: 0.96;
}

.channel-filters {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: 10px;
  margin-top: 18px;
  min-height: 92px;
}

.conversation-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.conversation-search-input {
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid rgba(216, 207, 191, 0.9);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.3;
}

.conversation-search-input:focus,
.chat-composer-input:focus,
.telegram-agent-account-select:focus {
  outline: none;
  border-color: rgba(31, 92, 116, 0.45);
  box-shadow: 0 0 0 3px rgba(31, 92, 116, 0.08);
}

.conversation-search-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(31, 92, 116, 0.18);
  background: rgba(220, 236, 243, 0.72);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.16s ease;
}

.conversation-search-button:hover {
  transform: translateY(-1px);
  border-color: rgba(31, 92, 116, 0.32);
  background: rgba(220, 236, 243, 0.9);
}

.conversation-search-status {
  margin-top: -2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 14px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(216, 207, 191, 0.76);
  border-radius: 18px;
}

.conversation-card {
  width: 100%;
  padding: 11px 13px;
  border: none;
  border-bottom: 1px solid rgba(216, 207, 191, 0.72);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.9);
  text-align: left;
  cursor: pointer;
  display: block;
  box-shadow: none;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.conversation-card:first-child {
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
}

.conversation-card:last-of-type {
  border-bottom: none;
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 18px;
}

.conversation-card.active {
  background: linear-gradient(180deg, rgba(235, 240, 245, 0.98), rgba(249, 251, 253, 0.98));
}

.conversation-card:hover {
  background: rgba(245, 249, 252, 0.98);
}

.conversation-card-top,
.bubble-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.conversation-card-main {
  min-width: 0;
}

.conversation-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.conversation-card-top strong {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time {
  flex: 0 0 auto;
  font-size: 13px;
  white-space: nowrap;
  color: var(--muted);
}

.conversation-card-bottom {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3px;
  min-height: 42px;
  font-size: 12px;
  color: var(--muted);
}

.conversation-card-bottom p {
  margin-top: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.conversation-card-status {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  min-width: 64px;
}

.conversation-delivered {
  color: #9aa7b1;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge,
.badge-soft,
.badge-warn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  white-space: nowrap;
}

.badge,
.badge-soft {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.warn,
.badge-warn {
  background: rgba(159, 71, 56, 0.14);
  color: var(--warn);
}

.chat-head-copy {
  max-width: 760px;
}

.chat-head-topline {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-head-topline .panel-kicker {
  margin: 0;
  font-size: 10px;
}

.chat-head-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.chat-subtitle,
.chat-toolbar-meta {
  color: var(--muted);
}

.chat-subtitle {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.35;
}

.chat-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
  min-height: 22px;
  align-items: flex-start;
  align-content: flex-start;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.chat-toolbar-meta {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
}

.chat-scroll {
  flex: 1 1 auto;
  margin-top: 8px;
  padding: 10px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(249, 243, 233, 0.9)),
    rgba(255, 251, 245, 0.9);
  border: 1px solid rgba(216, 207, 191, 0.7);
  min-height: 0;
  overflow: auto;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(216, 207, 191, 0.7);
  min-height: 72px;
  align-items: stretch;
}

.chat-composer-input {
  width: 100%;
  min-height: 48px;
  resize: none;
  overflow: hidden;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid rgba(216, 207, 191, 0.9);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble-row {
  display: flex;
}

.bubble-row.inbound {
  justify-content: flex-start;
}

.bubble-row.outbound {
  justify-content: flex-end;
}

.bubble {
  max-width: min(72ch, 78%);
  padding: 10px 12px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
}

.bubble-row.outbound .bubble {
  background: linear-gradient(180deg, rgba(220, 236, 243, 0.96), rgba(245, 251, 255, 0.95));
}

.bubble-meta {
  align-items: baseline;
  margin-bottom: 5px;
  font-size: 12px;
}

.bubble-body {
  font-size: 15px;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.bubble-body p {
  margin-top: 8px;
}

.bubble-foot {
  margin-top: 6px;
  font-size: 11px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.empty-chat,
.empty-list {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  line-height: 1.35;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .topbar,
  .service-launchpad-card,
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    width: min(100vw, calc(100vw - 12px));
    height: auto;
    min-height: 100vh;
    padding: 6px 0;
  }

  .overview-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-head,
  .chat-toolbar,
  .chat-composer,
  .service-launchpad-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-head-actions,
  .chat-badges {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .bubble {
    max-width: 100%;
  }
}
