:root {
  --bg: #0f172a;
  --panel: #111c34;
  --panel-2: #16233f;
  --line: rgba(148, 163, 184, 0.18);
  --text: #e5eefb;
  --muted: #94a3b8;
  --accent: #7dd3fc;
  --accent-2: #38bdf8;
  --success: #34d399;
  --error: #f87171;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: "Segoe UI", Helvetica, Arial, sans-serif; background: radial-gradient(circle at top, #172554 0%, #0f172a 48%, #0b1120 100%); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.auth-page, .app-page { min-height: 100vh; }
.muted { color: var(--muted); }
.eyebrow { display: inline-block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(125, 211, 252, 0.18);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-shell-split { grid-template-columns: repeat(auto-fit, minmax(320px, 460px)); gap: 24px; align-content: center; justify-content: center; }
.auth-card {
  width: min(460px, 100%);
  padding: 32px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(17, 28, 52, 0.96), rgba(15, 23, 42, 0.92));
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.48);
}
.auth-card h1 { margin: 10px 0 12px; font-size: 34px; line-height: 1.04; }
.auth-form { display: grid; gap: 16px; margin: 24px 0 16px; }
.auth-form label { display: grid; gap: 8px; }
.auth-form span, .label { font-size: 13px; color: var(--muted); }
.auth-form input, .inline-form input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
}
.auth-form button, .ghost-link, .inline-form button, .workspace-item button {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.32);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(14, 165, 233, 0.12));
  color: var(--text);
  cursor: pointer;
}
.auth-form button:disabled, .workspace-item button:disabled { opacity: 0.5; cursor: default; }
.message { margin: 0; font-size: 13px; color: var(--muted); min-height: 18px; }
.message[data-state="success"] { color: var(--success); }
.message[data-state="error"] { color: var(--error); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  background: rgba(9, 14, 27, 0.78);
}
.brand { font-size: 30px; font-weight: 700; }
.nav-list { display: grid; gap: 10px; margin: 32px 0 auto; }
.nav-list a {
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  border: 1px solid transparent;
  background: rgba(15, 23, 42, 0.3);
}
.nav-list a:hover, .nav-list a.is-active { color: var(--text); border-color: var(--line); background: rgba(22, 35, 63, 0.7); }
.workspace-box {
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(17, 28, 52, 0.74);
  display: grid;
  gap: 8px;
}
.content { padding: 36px; }
.content-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 28px;
}
.content-header h1 { margin: 8px 0 12px; font-size: 40px; line-height: 1.05; }
.page-body { min-height: 420px; }
.page-loading { min-height: 320px; display: grid; place-items: center; gap: 12px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }
.split-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; margin-top: 18px; }
.card {
  padding: 24px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 28, 52, 0.88), rgba(13, 18, 32, 0.86));
}
.card-wide { grid-column: span 2; }
.card h2 { margin: 0 0 12px; font-size: 20px; }
.card p { margin: 0; color: var(--muted); line-height: 1.65; }
.info-stack { display: grid; gap: 14px; }
.info-stack div { display: grid; gap: 6px; }
.workspace-list, .mini-table { display: grid; gap: 12px; margin-bottom: 16px; }
.workspace-item, .mini-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.4);
}
.workspace-item.is-current { border-color: rgba(125, 211, 252, 0.36); background: rgba(22, 35, 63, 0.7); }
.workspace-item div, .mini-row div { display: grid; gap: 4px; }
.workspace-item span, .mini-row span { color: var(--muted); font-size: 13px; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.metric-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.tag-block { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.48);
  color: var(--muted);
  font-size: 13px;
}
.empty-card {
  padding: 18px;
  border-radius: 14px;
  border: 1px dashed rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.28);
  color: var(--muted);
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); gap: 24px; }
  .content { padding: 24px; }
  .content-header { flex-direction: column; }
  .card-wide { grid-column: span 1; }
  .inline-form, .split-grid { grid-template-columns: 1fr; }
}

.support-shell {
  display: grid;
  gap: 18px;
}

.support-banner {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border-radius: 20px;
  border: 1px solid rgba(125, 211, 252, 0.18);
  background: linear-gradient(135deg, rgba(17, 28, 52, 0.92), rgba(12, 18, 34, 0.92));
}

.support-banner strong {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}

.support-banner p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(52, 211, 153, 0.22);
  background: rgba(52, 211, 153, 0.1);
  color: #bbf7d0;
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.12);
}

.chat-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 280px;
  gap: 18px;
  min-height: 680px;
}

.conv-list-panel,
.chat-detail-panel,
.support-tool-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(17, 28, 52, 0.88), rgba(13, 18, 32, 0.86));
}

.conv-list-panel,
.chat-detail-panel {
  display: flex;
  flex-direction: column;
}

.support-tool-panel {
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.support-tool-panel h2 {
  margin: 0;
  font-size: 18px;
}

.support-tool-card {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.4);
  display: grid;
  gap: 8px;
}

.support-tool-card strong {
  font-size: 14px;
}

.support-tool-card p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.support-kv {
  display: grid;
  gap: 10px;
}

.support-kv div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.support-kv strong {
  color: var(--text);
  font-size: 13px;
}

.chat-mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 18px 18px 12px;
}

.chat-mode-tab {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.5);
  color: var(--muted);
}

.chat-mode-tab.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--text);
}

.conv-search {
  padding: 0 18px 14px;
}

.search-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.38);
}

.search-box input,
.filter-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
}

.conv-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn,
.filter-select {
  min-height: 40px;
}

.filter-btn {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.5);
  color: var(--muted);
}

.filter-btn.active {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.3);
  background: rgba(56, 189, 248, 0.14);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
  display: grid;
  gap: 10px;
}

.conv-item,
.contact-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  border-radius: 16px;
  border: 1px solid transparent;
  background: rgba(15, 23, 42, 0.32);
}

.conv-item.is-active,
.contact-list-item.is-active {
  border-color: rgba(125, 211, 252, 0.26);
  background: rgba(22, 35, 63, 0.7);
}

.conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}

.conv-name-col,
.contact-info {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 6px;
}

.conv-name,
.contact-name {
  font-weight: 600;
  color: var(--text);
}

.conv-meta,
.conv-preview,
.contact-detail {
  color: var(--muted);
  font-size: 13px;
}

.conv-time,
.contact-level {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.chat-empty,
.contacts-empty,
.contacts-loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  color: var(--muted);
  padding: 24px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.chat-header-phone {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.chat-header-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(125, 211, 252, 0.22);
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.chat-bubble {
  max-width: min(78%, 520px);
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  gap: 8px;
}

.chat-bubble.agent {
  justify-self: end;
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.22);
}

.chat-bubble.customer {
  justify-self: start;
}

.bubble-content {
  line-height: 1.65;
}

.bubble-time {
  font-size: 12px;
  color: var(--muted);
}

.cs-quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 14px;
}

.cs-quick-btn {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.45);
  color: var(--muted);
  font-size: 12px;
}

.chat-compose {
  display: grid;
  gap: 12px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

.support-inline-note {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(125, 211, 252, 0.18);
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent);
  font-size: 12px;
}

.chat-compose textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  font: inherit;
}

.chat-compose-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.chat-compose-note {
  color: var(--muted);
  font-size: 12px;
}

.chat-compose-note.is-success {
  color: #bbf7d0;
}

.chat-compose-note.is-error {
  color: #fecaca;
}

.chat-compose-actions {
  display: flex;
  gap: 10px;
}

.ghost-button,
.primary-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost-button {
  background: rgba(15, 23, 42, 0.5);
}

.primary-button {
  border-color: rgba(56, 189, 248, 0.3);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(14, 165, 233, 0.12));
}

@media (max-width: 1240px) {
  .chat-layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .support-tool-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 960px) {
  .support-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .conv-list-panel,
  .chat-detail-panel,
  .support-tool-panel {
    min-height: 0;
  }

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