* {
  box-sizing: border-box;
}

:root {
  --tc-bg: #eef2ff;
  --tc-card: #ffffff;
  --tc-text: #0f172a;
  --tc-muted: #64748b;
  --tc-accent: #0d9488;
  --tc-accent-hover: #0f766e;
  --tc-border: #e2e8f0;
  --tc-bubble-self: #ccfbf1;
  --tc-bubble-other: #f1f5f9;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--tc-bg);
  color: var(--tc-text);
  height: 100vh;
}

h1,
h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.subtitle {
  margin: 0;
  color: var(--tc-muted);
  font-size: 0.85rem;
}

.card {
  background: var(--tc-card);
  border: 1px solid var(--tc-border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

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

.login-card {
  width: min(520px, 100%);
  padding: 28px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--tc-accent);
  color: #fff;
}

.btn:hover {
  background: var(--tc-accent-hover);
}

.btn.secondary {
  background: #fff;
  color: var(--tc-text);
  border: 1px solid var(--tc-border);
}

.btn.secondary:hover {
  background: #f8fafc;
}

.hidden {
  display: none !important;
}

.app-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
  height: 100vh;
  padding: 12px;
  max-width: 1200px;
  margin: 0 auto;
}

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

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--tc-border);
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  color: #fff;
  border-radius: 14px 14px 0 0;
}

.sidebar-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-header-row h1 {
  flex: 1;
  min-width: 0;
}

.btn-header-logout {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
}

.btn-header-logout:hover {
  background: rgba(255, 255, 255, 0.32);
}

.sidebar-header .subtitle {
  color: rgba(255, 255, 255, 0.9);
  margin-top: 8px;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--tc-border);
}

.sidebar-section-grow {
  flex: 1;
  border-bottom: none;
}

.sidebar-label {
  margin: 8px 4px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tc-muted);
}

.sidebar-empty {
  margin: 0;
  padding: 8px 4px 12px;
  font-size: 0.82rem;
  color: var(--tc-muted);
}

.sidebar-empty.error {
  color: #b91c1c;
}

.contact-retry {
  margin: 0 4px 12px;
  width: calc(100% - 8px);
}

.contact-search {
  width: 100%;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--tc-border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
}

.contacts-list {
  max-height: 38vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.contact-item:hover {
  background: #f8fafc;
}

.contact-item.active {
  background: #ecfeff;
  border-color: #99f6e4;
}

.contact-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f766e;
  background: #ccfbf1;
}

.contact-text {
  min-width: 0;
  flex: 1;
}

.contact-text strong {
  display: block;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-text span {
  display: block;
  font-size: 0.78rem;
  color: var(--tc-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 12px;
}

.conversation-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  margin-bottom: 4px;
}

.conversation-item:hover {
  background: #f8fafc;
}

.conversation-item.active {
  background: #ecfeff;
  border-color: #99f6e4;
}

.conversation-item strong {
  display: block;
  font-size: 0.95rem;
}

.conversation-item span {
  display: block;
  font-size: 0.8rem;
  color: var(--tc-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--tc-border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.chat-header h2 {
  flex: 1;
  min-width: 140px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-bubble {
  max-width: min(85%, 520px);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.message-bubble.self {
  align-self: flex-end;
  background: var(--tc-bubble-self);
}

.message-bubble.other {
  align-self: flex-start;
  background: var(--tc-bubble-other);
}

.message-meta {
  font-size: 0.75rem;
  color: var(--tc-muted);
  margin-bottom: 4px;
}

.message-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--tc-border);
  align-items: flex-end;
}

.message-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  max-height: 120px;
  border-radius: 10px;
  border: 1px solid var(--tc-border);
  padding: 10px;
  font: inherit;
}

.chat-empty-hint {
  margin: auto;
  color: var(--tc-muted);
  text-align: center;
  padding: 24px;
}

.mobile-top {
  display: none;
  padding: 10px 14px;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  gap: 8px;
}

dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: min(440px, 92vw);
}

dialog form {
  padding: 20px;
  display: grid;
  gap: 12px;
}

dialog label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
}

dialog input,
dialog select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--tc-border);
  font: inherit;
}

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

@media (max-width: 800px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    max-height: 40vh;
  }

  .mobile-top {
    display: flex;
    grid-row: 1;
  }
}
