:root {
  --bg: #0a0a0a;
  --bg-2: #101010;
  --panel: rgba(18, 18, 18, 0.92);
  --panel-2: rgba(24, 24, 24, 0.96);
  --panel-3: rgba(255,255,255,0.03);
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(199,160,106,0.22);
  --text: #f4efe7;
  --muted: #b8ab95;
  --accent: #c7a06a;
  --accent-2: #e7c89d;
  --accent-soft: rgba(199,160,106,0.12);
  --bubble-in: #1c1c1c;
  --bubble-out: linear-gradient(180deg, rgba(199,160,106,0.26), rgba(199,160,106,0.14));
  --danger: #ff6b6b;
  --shadow: 0 24px 80px rgba(0,0,0,0.35);
  --radius: 22px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(199,160,106,0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(94,140,255,0.08), transparent 24%),
    linear-gradient(180deg, #080808 0%, #0d0d0d 100%);
  color: var(--text);
  overflow: hidden;
  line-height: 1.35;
}
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #fff; background: rgba(255, 107, 107, 0.16); border: 1px solid rgba(255, 107, 107, 0.45); padding: 10px 12px; border-radius: 12px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(199,160,106,0.18), transparent 28%),
    linear-gradient(180deg, #080808 0%, #101010 100%);
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-logo { width: 140px; margin-bottom: 18px; }
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-lockup-sidebar {
  padding-bottom: 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-logo-sidebar {
  width: auto;
  height: 34px;
  margin: 0;
}
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 14px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0f171d;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(199,160,106,0.45);
  box-shadow: 0 0 0 3px rgba(199,160,106,0.10);
}
textarea {
  resize: none;
  min-height: 52px;
  max-height: 180px;
  line-height: 1.45;
}
button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
button:hover { transform: translateY(-1px); }
button.primary { background: var(--accent); color: #081c15; font-weight: 700; }
button.primary { background: linear-gradient(180deg, #d7b37f, #c79f69); color: #18120c; }
button.secondary { background: var(--panel-3); color: var(--text); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 336px minmax(0, 1fr);
  overflow: hidden;
  gap: 0;
}
.sidebar,
.chat-panel,
.chat-view,
.message-list,
.conversation-list {
  min-height: 0;
}
.sidebar {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  overflow: hidden;
  backdrop-filter: blur(16px);
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.04);
}
.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 16px 14px;
}
.eyebrow {
  color: #ead1a9;
  letter-spacing: 0.18em;
  font-size: 11px;
  margin-bottom: 4px;
}
.sidebar h2 { margin: 0; font-size: 18px; line-height: 1.15; }
.sidebar-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  max-width: 220px;
}
.toolbar { padding: 0 16px 14px; display: grid; gap: 10px; }
.toolbar {
  padding: 0 14px 12px;
  display: grid;
  gap: 8px;
}
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 14px 12px;
}
.stat {
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 11px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat span { font-size: 11px; }
.stat strong { display: block; font-size: 16px; margin-top: 4px; }
.conversation-list {
  overflow: auto;
  padding: 0 8px 10px;
  overscroll-behavior: contain;
}
.conversation-item {
  display: grid;
  gap: 8px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}
.conversation-item:hover,
.conversation-item.active {
  background: rgba(255,255,255,0.045);
  border-color: var(--line-strong);
}
.conversation-item.active {
  box-shadow: inset 0 0 0 1px rgba(199,160,106,0.18), 0 6px 18px rgba(0,0,0,0.16);
}
.conversation-top,
.conversation-bottom {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.conversation-title { font-weight: 700; font-size: 14px; }
.conversation-phone { color: var(--muted); font-size: 12px; }
.conversation-preview {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
}
.badge.new { background: rgba(199,160,106,0.16); color: #f6e2be; }
.badge.open { background: rgba(255,255,255,0.08); color: var(--text); }
.badge.resolved { background: rgba(134,150,160,0.18); color: #c9d1d4; }
.unread-pill {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  background: var(--accent);
  color: #18120c;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.chat-panel {
  background:
    radial-gradient(circle at top left, rgba(199,160,106,0.06), transparent 24%),
    linear-gradient(180deg, #0b0b0b 0%, #111111 100%);
  display: grid;
  min-width: 0;
  padding: 0;
}
.empty-state {
  margin: auto 24px;
  text-align: center;
  max-width: 460px;
  color: var(--muted);
  padding: 36px 28px;
  background: linear-gradient(180deg, rgba(18,18,18,0.92) 0%, rgba(24,24,24,0.96) 100%);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.phone-emoji { font-size: 56px; margin-bottom: 12px; }
.chat-view {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
}
.chat-header {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  background: linear-gradient(180deg, rgba(25,25,25,0.96) 0%, rgba(20,20,20,0.94) 100%);
  min-width: 0;
}
.chat-header-main {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  flex: 1;
}
.profile-summary-btn {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  border-radius: 10px;
  cursor: pointer;
}
.profile-summary-btn:hover {
  background: rgba(255,255,255,0.04);
  transform: none;
}
.customer-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(199,160,106,0.26), rgba(199,160,106,0.1));
  border: 1px solid rgba(199,160,106,0.22);
  color: #ffe7c2;
  font-weight: 800;
  font-size: 12px;
}
.customer-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}
.customer-meta,
.chat-submeta {
  color: var(--muted);
  margin-top: 1px;
  line-height: 1.2;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-submeta { font-size: 10.5px; opacity: 0.86; }
.header-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-self: center;
  flex-shrink: 0;
}
.header-actions button {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 11px;
}
.compact-icon-btn {
  min-height: 34px;
  min-width: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.context-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  background: rgba(17,17,17,0.72);
}
.context-card {
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
.context-card .label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}
.context-card strong {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-list {
  overflow: auto;
  padding: 16px 18px 18px;
  display: grid;
  gap: 10px;
  background-color: transparent;
  background-image:
    radial-gradient(rgba(199,160,106,0.028) 1px, transparent 0),
    radial-gradient(rgba(255,255,255,0.012) 1px, transparent 0);
  background-size: 28px 28px, 56px 56px;
  background-position: 0 0, 14px 14px;
  overscroll-behavior: contain;
}
.message-row { display: flex; padding-inline: 4px; align-items: flex-start; }
.message-row.user { justify-content: flex-start; }
.message-row.assistant,
.message-row.advisor { justify-content: flex-end; }
.message-row.system { justify-content: center; }
.message-bubble {
  max-width: min(640px, 72%);
  width: auto;
  min-width: 44px;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 6px 9px 5px;
  border-radius: 10px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.14);
  white-space: pre-wrap;
  line-height: 1.32;
  word-break: break-word;
  font-size: 13px;
  position: relative;
}
.message-row.user .message-bubble,
.message-row.assistant .message-bubble,
.message-row.advisor .message-bubble {
  min-width: 0;
}
.message-row.user .message-bubble::before,
.message-row.assistant .message-bubble::before,
.message-row.advisor .message-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 10px;
  height: 12px;
}
.message-media {
  display: grid;
  gap: 8px;
}
.message-image {
  max-width: min(360px, 100%);
  max-height: 260px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.18);
}
.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.16);
  border: 1px solid rgba(255,255,255,0.08);
  color: inherit;
  text-decoration: none;
}
.message-file-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.08);
  font-weight: 700;
  font-size: 11px;
}
.message-file-meta {
  min-width: 0;
}
.message-file-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-file-size {
  color: rgba(255,255,255,0.68);
  font-size: 11px;
  margin-top: 2px;
}
.message-row.user .message-bubble {
  background: rgba(255,255,255,0.055);
  border-top-left-radius: 2px;
  border: 1px solid rgba(255,255,255,0.06);
}
.message-row.user .message-bubble::before {
  left: -6px;
  background: linear-gradient(135deg, rgba(255,255,255,0.055) 0 50%, transparent 50% 100%);
}
.message-row.assistant .message-bubble,
.message-row.advisor .message-bubble {
  background: linear-gradient(180deg, rgba(199,160,106,0.24), rgba(199,160,106,0.14));
  border-top-right-radius: 2px;
  border: 1px solid rgba(199,160,106,0.16);
}
.message-row.assistant .message-bubble::before,
.message-row.advisor .message-bubble::before {
  right: -6px;
  background: linear-gradient(225deg, rgba(199,160,106,0.22) 0 50%, transparent 50% 100%);
}
.message-row.system .message-bubble {
  background: rgba(255,255,255,0.08);
  color: var(--muted);
  box-shadow: none;
  max-width: min(680px, 90%);
  align-items: center;
}
.message-text {
  white-space: pre-wrap;
  display: block;
  margin: 0;
}
.message-footer {
  margin-top: 2px;
  display: flex;
  width: 100%;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  line-height: 1;
  padding-left: 18px;
  min-height: 12px;
}
.message-system-meta {
  margin-top: 4px;
  color: rgba(255,255,255,0.55);
  font-size: 11px;
  text-align: center;
}
.message-checks {
  color: #8ad7ff;
  font-size: 11px;
  letter-spacing: -1px;
}
.message-link-card {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-left: 3px solid rgba(255,255,255,0.24);
  border-radius: 8px;
  background: rgba(0,0,0,0.12);
  text-decoration: none;
  color: inherit;
  width: 100%;
}
.message-link-host {
  font-size: 12px;
  font-weight: 700;
}
.message-link-url {
  font-size: 12px;
  color: rgba(255,255,255,0.82);
  word-break: break-all;
}
.message-link-anchor {
  color: #53bdeb;
  text-decoration: none;
  word-break: break-word;
}
.message-link-anchor:hover {
  text-decoration: underline;
}
.composer {
  padding: 12px 16px 14px;
  border-top: 1px solid rgba(255,255,255,0.05);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  background: #202c33;
  align-items: end;
}
.composer-tools {
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: rgba(233,237,239,0.8);
  font-size: 18px;
}
.tool-btn:hover {
  background: rgba(255,255,255,0.06);
}
.composer-box {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.composer-box textarea {
  border-radius: 8px;
  border-color: rgba(255,255,255,0.04);
  background: #2a3942;
  padding: 10px 12px;
}
.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(199,160,106,0.2);
}
.attachment-preview-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.attachment-preview-thumb {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255,255,255,0.08);
  display: grid;
  place-items: center;
  font-weight: 700;
}
.attachment-preview-name {
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-preview-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.attachment-remove {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 12px;
}
.composer-meta {
  color: var(--muted);
  font-size: 11px;
  padding-left: 4px;
}
.composer-send {
  min-width: 94px;
  height: 40px;
  border-radius: 12px;
  font-size: 13px;
}

.profile-drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr min(360px, 92vw);
}
.profile-drawer-backdrop {
  background: rgba(0,0,0,0.34);
}
.profile-drawer-panel {
  background: #111b21;
  border-left: 1px solid rgba(255,255,255,0.06);
  box-shadow: -12px 0 36px rgba(0,0,0,0.28);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.profile-drawer-header {
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #111b21;
}
.profile-drawer-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.profile-drawer-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.profile-drawer-body {
  padding: 0;
  display: grid;
  align-content: start;
  gap: 0;
  overflow: auto;
}
.profile-hero {
  padding: 28px 24px 24px;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.profile-hero-avatar {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(199,160,106,0.22), rgba(199,160,106,0.08));
  border: 1px solid rgba(255,255,255,0.08);
  color: #c7fff1;
  font-size: 48px;
  font-weight: 800;
  margin-bottom: 10px;
}
.profile-hero-name {
  font-size: 18px;
  font-weight: 700;
}
.profile-hero-sub {
  font-size: 14px;
}
.profile-hero-type {
  color: #8fa7bd;
  font-size: 13px;
}
.profile-hero-status {
  color: #94a7b7;
  font-size: 13px;
}
.profile-hero-status span {
  color: #f0c86f;
  font-weight: 700;
}
.profile-share-btn {
  margin-top: 14px;
  background: transparent;
  color: #e7c89d;
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 8px 14px;
}
.profile-share-btn:hover { transform: none; }
.profile-share-icon {
  font-size: 28px;
  line-height: 1;
}
.profile-section-note {
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
}
.profile-info-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid #d7b37f;
  color: #d7b37f;
  font-size: 12px;
  font-weight: 700;
}
.profile-company-card {
  padding: 18px 24px;
  display: grid;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.profile-company-name {
  font-size: 13px;
  line-height: 1.45;
  color: #eef2f5;
}
.profile-company-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}
.profile-company-open {
  color: #f0c86f;
  font-weight: 700;
}
.profile-company-mail {
  color: #ead1a9;
  font-weight: 700;
  word-break: break-word;
}
.profile-block-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 14px 0;
}
.profile-block {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 11px 12px;
  display: grid;
  gap: 5px;
  margin: 10px 14px 0;
}
.profile-block-grid .profile-block {
  margin: 0;
}
.profile-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.profile-block strong {
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.conversation-list::-webkit-scrollbar,
.message-list::-webkit-scrollbar {
  width: 10px;
}
.conversation-list::-webkit-scrollbar-thumb,
.message-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
}
.conversation-list::-webkit-scrollbar-track,
.message-list::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 300px minmax(0, 1fr); }
  .context-strip { grid-template-columns: 1fr; }
  .header-actions { max-width: 320px; }
  .chat-panel { padding: 0; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .chat-panel { padding: 0; }
  .chat-view {
    grid-template-rows: auto auto minmax(320px, 1fr) auto;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
  .chat-header {
    position: static;
    display: grid;
  }
  .chat-header-main {
    grid-template-columns: 32px minmax(0, 1fr);
  }
  .header-actions {
    width: 100%;
    justify-content: stretch;
    max-width: none;
  }
  .header-actions button { flex: 1; }
  .composer {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .composer-send {
    grid-column: 1 / -1;
    width: 100%;
  }
  .message-bubble {
    max-width: 92%;
  }
  .profile-drawer {
    grid-template-columns: 1fr;
  }
  .profile-drawer-panel {
    margin-left: auto;
    width: min(360px, 92vw);
  }
}
