:root {
  --ink: #172033;
  --muted: #7d8797;
  --line: #e5eaf1;
  --paper: #fff;
  --canvas: #eef6fb;
  --nav: #dcecff;
  --green: #3478f6;
  --green-dark: #1f65e6;
  --green-soft: #eaf2ff;
  --blue: #3478f6;
  --blue-soft: #e8f0ff;
  --shadow: 0 12px 36px rgba(44, 72, 112, .09);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

body { background: linear-gradient(135deg, #e8f3fb, #e9f7f4); }

.app-shell { min-height: 100vh; grid-template-columns: 58px minmax(0, 1fr); }

.sidebar {
  width: 58px;
  padding: 8px 6px 10px;
  color: #64748b;
  background: linear-gradient(180deg, #dbeafe 0%, #d9e9ff 56%, #d8f2ee 100%);
  border-right: 1px solid rgba(126, 158, 196, .18);
  align-items: center;
}

.brand { padding: 0 0 11px; justify-content: center; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; color: #fff; background: #3979f6; box-shadow: 0 7px 18px rgba(52, 120, 246, .22); }
.brand-copy, .nav-label { display: none; }
.main-nav { width: 100%; gap: 5px; }
.main-nav button {
  justify-content: center;
  width: 46px;
  height: 42px;
  margin: auto;
  padding: 0;
  border-radius: 10px;
  color: #73839a;
}
.main-nav button .nav-icon { width: auto; font-size: 21px; line-height: 1; }
.main-nav button:hover, .main-nav button.active { color: #276bf0; background: rgba(255, 255, 255, .72); box-shadow: none; }
.main-nav button.active { box-shadow: inset 3px 0 #3979f6, 0 4px 12px rgba(72, 112, 160, .06); }
.sidebar-foot { width: 100%; display: grid; place-items: center; gap: 8px; }
.rail-status { display: grid; place-items: center; width: 36px; height: 32px; }
.rail-status i { width: 8px; height: 8px; border-radius: 50%; background: #25bf77; box-shadow: 0 0 0 4px rgba(37, 191, 119, .14); }
.rail-status.offline i { background: #ef5b5b; box-shadow: 0 0 0 4px rgba(239, 91, 91, .13); }
.text-button { width: 38px; height: 36px; padding: 0; border-radius: 9px; color: #76859a; font-size: 20px; }
.text-button:hover { background: rgba(255,255,255,.65); color: #276bf0; }

.workspace { grid-column: 2; min-width: 0; }
.topbar { height: 68px; padding: 0 24px; border-bottom-color: #e7ebf1; }
.topbar h2 { font-size: 18px; margin-bottom: 2px; }
.topbar p { font-size: 11px; }
.connection { padding: 7px 11px; }
main { max-width: none; padding: 22px 24px 70px; }

.workspace[data-page="messages"] .topbar,
.workspace[data-page="contacts"] .topbar { display: none; }
.workspace[data-page="messages"] main,
.workspace[data-page="contacts"] main { padding: 6px; }

.button { border-radius: 7px; padding: 9px 14px; font-size: 12px; }
.button.primary { background: #3478f6; box-shadow: 0 5px 14px rgba(52, 120, 246, .18); }
.button.primary:hover { background: #2268ea; }
.button.secondary { color: #596579; background: #f7f9fc; border-color: #e5e9ef; }
.icon-button { border: 1px solid #e6eaf0; background: #f7f9fc; color: #657085; border-radius: 7px; height: 34px; min-width: 34px; }

/* Shared second-level navigation */
.module-rail { min-width: 0; background: #f6f9fd; border-right: 1px solid var(--line); overflow: hidden; }
.module-title { height: 54px; padding: 0 13px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #edf0f5; }
.module-title strong { font-size: 15px; }
.module-title button { border: 0; background: transparent; color: #7b8595; font-size: 16px; }
.module-rail nav { padding: 8px; display: grid; gap: 3px; }
.module-rail nav button { width: 100%; height: 36px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: #5f697a; font-size: 12px; text-align: left; }
.module-rail nav button > span:first-child { width: 17px; color: #718095; text-align: center; }
.module-rail nav button small { margin-left: auto; }
.module-rail nav button:hover, .module-rail nav button.active { color: #3478f6; background: #e5edff; }
.module-rail nav button.active > span:first-child { color: #3478f6; }
.module-rail .ai-icon { color: #7269f7 !important; font-size: 9px; font-weight: 800; }
.nav-group-title { display: flex; align-items: center; justify-content: space-between; padding: 13px 13px 3px; }
.nav-group-title strong { font-size: 11px; }
.nav-group-title button { border: 0; background: #3478f6; color: #fff; border-radius: 50%; width: 18px; height: 18px; line-height: 16px; }
.module-empty { min-height: 175px; display: grid; place-items: center; align-content: center; color: #a0aaba; font-size: 11px; }
.module-empty span { font-size: 34px; color: #d5deea; }
.module-empty p { margin: 8px 0; }
.module-bottom-nav { border-top: 1px solid var(--line); }

/* Conversation workspace */
.messages-page.active {
  display: grid;
  grid-template-columns: 216px 318px minmax(400px, 1fr) 300px;
  height: calc(100vh - 12px);
  min-height: 650px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #dfe5ed;
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(50, 76, 108, .06);
}
.conversation-list { min-width: 0; border-right: 1px solid var(--line); background: #fff; overflow: hidden; }
.conversation-head { height: 54px; padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between; }
.conversation-head h3 { margin: 0; font-size: 14px; }
.conversation-head p { margin: 3px 0 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #9aa3b1; font-size: 9px; }
.conversation-search { height: 34px; margin: 0 10px 7px; display: flex; align-items: center; gap: 6px; padding: 0 9px; border: 1px solid #e4e8ee; border-radius: 7px; background: #f7f8fa; color: #9ba5b4; }
.conversation-search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-size: 11px; color: var(--ink); }
.conversation-search span { padding: 2px 5px; border: 1px solid #e3e7ec; border-radius: 4px; color: #a0a9b7; background: #fff; font-size: 8px; white-space: nowrap; }
.conversation-filters { display: flex; gap: 5px; padding: 0 10px 9px; border-bottom: 1px solid #edf0f4; }
.conversation-filters button, .contact-filter-tabs button { border: 0; border-radius: 5px; background: #f1f3f6; color: #6f7988; padding: 5px 10px; font-size: 10px; }
.conversation-filters button.active, .contact-filter-tabs button.active { color: #286ef1; background: #e8f0ff; font-weight: 700; }
.peer-list { height: calc(100% - 135px); padding: 5px 7px 12px; overflow-y: auto; }
.peer { min-height: 65px; padding: 9px 8px; border-radius: 7px; gap: 10px; }
.peer:hover, .peer.active { background: #e9f0ff; }
.peer-avatar, .peer-avatar .contact-avatar { width: 38px; height: 38px; flex-basis: 38px; }
.peer .contact-avatar { border-radius: 50%; background: linear-gradient(145deg, #6ea6ff, #7c7af1); color: #fff; }
.peer-body strong { color: #30394a; font-size: 12px; font-weight: 650; }
.peer-body small { color: #8993a2; font-size: 10px; }
.peer-meta time { color: #98a2b1; font-size: 9px; }

.chat-panel { display: grid; grid-template-rows: 54px minmax(0, 1fr) 136px; min-width: 0; background: #f9fafc; }
.chat-head { height: 54px; padding: 0 14px; background: rgba(255,255,255,.94); }
.chat-person { min-width: 0; display: flex; align-items: center; gap: 9px; }
.mini-avatar { width: 28px; height: 28px; display: grid; place-items: center; flex: 0 0 28px; border-radius: 50%; background: linear-gradient(145deg, #f8bc43, #f47c48); color: #fff; font-size: 11px; font-weight: 800; }
.mini-avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.chat-head strong { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.chat-head small { font-size: 9px; }
.chat-head-actions { display: flex; align-items: center; gap: 3px; }
.chat-head-actions button { width: 29px; height: 29px; border: 0; background: transparent; color: #778293; border-radius: 6px; }
.chat-head-actions button:hover { background: #f0f3f7; color: #3478f6; }
.status-pill { padding: 5px 8px; font-size: 9px; }
.message-list { height: auto; min-height: 0; padding: 24px 18px; overflow-y: auto; background: #f9fafc; }
.bubble-row { gap: 7px; margin: 13px 0; }
.bubble { max-width: min(560px, 74%); padding: 9px 12px; border-radius: 5px 13px 13px 13px; color: #3f4858; font-size: 11px; line-height: 1.55; }
.outgoing .bubble { border-color: #dfe9fb; background: #e8f0ff; color: #2f3f5d; border-radius: 13px 5px 13px 13px; }
.bubble-row > .contact-avatar { width: 29px; height: 29px; flex-basis: 29px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #6ea6ff, #7b75ec); font-size: 10px; }
.bubble small { color: #94a0b1; font-size: 8px; }
.composer { display: grid; grid-template-columns: 1fr; grid-template-rows: 27px 1fr 31px; gap: 0; align-items: stretch; padding: 7px 11px 8px; border-top: 1px solid var(--line); background: #fff; }
.composer-mode { display: flex; align-items: center; justify-content: space-between; color: #9ba4b2; font-size: 9px; }
.composer-mode button { border: 0; background: transparent; padding: 0; color: #596579; font-size: 10px; }
.composer textarea { min-height: 46px; max-height: 70px; padding: 4px 1px; border: 0; border-radius: 0; box-shadow: none !important; font-size: 11px; }
.composer-tools, .composer-tools > div { display: flex; align-items: center; justify-content: space-between; }
.composer-tools > div { gap: 3px; }
.tool-button, .attach-button { width: 29px; height: 29px; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: #657184; font-size: 15px; }
.tool-button:hover, .attach-button:hover { background: #f0f3f7; color: #3478f6; }
.tool-button span { position: absolute; margin: 16px 0 0 19px; color: #3478f6; font-size: 6px; font-weight: 800; }
.send-button { width: 31px; height: 28px; border: 0; border-radius: 6px; color: #fff; background: #3478f6; }
.send-button:disabled { color: #aab2bf; background: #eef1f4; }

.customer-detail { min-width: 0; border-left: 1px solid var(--line); background: #f7f9fc; overflow-y: auto; }
.customer-detail-head { position: sticky; top: 0; z-index: 2; height: 54px; padding: 0 13px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); }
.customer-detail-head strong { font-size: 12px; }
.customer-detail-head button { border: 0; background: transparent; color: #7b8594; }
.customer-detail-content { padding: 10px; }
.empty-detail { min-height: 300px; display: grid; place-items: center; align-content: center; color: #9ca6b5; font-size: 11px; }
.empty-detail span { font-size: 34px; color: #d8e0ea; }
.empty-detail p { margin: 8px; }
.customer-card { padding: 12px; border-radius: 7px; background: #fff; border: 1px solid #edf0f4; }
.customer-identity { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid #eef1f4; }
.customer-identity .contact-avatar { width: 38px; height: 38px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #f7bc48, #f3814a); }
.customer-identity strong, .customer-identity small { display: block; }
.customer-identity strong { font-size: 12px; }
.customer-identity small { margin-top: 3px; color: #98a2b1; font-size: 9px; }
.customer-facts { display: grid; gap: 10px; padding-top: 12px; }
.customer-fact { display: grid; grid-template-columns: 68px minmax(0,1fr); gap: 8px; font-size: 10px; }
.customer-fact span { color: #929dac; }
.customer-fact strong { overflow: hidden; color: #596475; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.detail-section { margin-top: 9px; border: 1px solid #edf0f4; border-radius: 7px; background: #fff; }
.detail-section > strong { display: block; padding: 10px 11px; border-bottom: 1px solid #eff2f5; font-size: 10px; }
.detail-section-content { padding: 10px; }
.detail-section textarea { width: 100%; min-height: 62px; resize: vertical; padding: 8px; border: 1px solid #e8ebef; border-radius: 6px; outline: none; background: #f7f8fa; font-size: 10px; }
.tag { display: inline-flex; padding: 4px 7px; margin: 0 5px 5px 0; border-radius: 4px; color: #2769e6; background: #eaf1ff; font-size: 9px; }

/* Customer table */
.contacts-page.active { display: grid; grid-template-columns: 162px minmax(0, 1fr); height: calc(100vh - 12px); min-height: 650px; overflow: hidden; border: 1px solid #dfe5ed; border-radius: 10px; background: #fff; box-shadow: 0 10px 32px rgba(50, 76, 108, .06); }
.contact-workspace { min-width: 0; display: grid; grid-template-rows: 48px minmax(0, 1fr); }
.contact-page-head { min-width: 0; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.contact-tabs { min-width: 0; display: flex; align-items: center; gap: 6px; }
.contact-tabs strong { margin-right: 8px; font-size: 13px; }
.contact-tabs button { height: 29px; padding: 0 9px; border: 0; border-radius: 5px; background: transparent; color: #788394; font-size: 10px; }
.contact-tabs button.active { color: #3478f6; background: #eef3ff; }
.contact-tabs em { padding: 2px 4px; border-radius: 3px; color: #3478f6; background: #e3edff; font-style: normal; font-size: 8px; }
.contact-head-actions { display: flex; gap: 6px; white-space: nowrap; }
.contact-view-layout { min-height: 0; display: grid; grid-template-columns: 170px minmax(0, 1fr); }
.view-sidebar { padding: 10px 8px; border-right: 1px solid var(--line); background: #fbfcfe; }
.view-title { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 10px; }
.view-title strong { font-size: 11px; }
.view-title button { width: 20px; height: 20px; border: 0; border-radius: 50%; color: #fff; background: #3478f6; }
.view-sidebar > button { width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: #647084; text-align: left; font-size: 10px; }
.view-sidebar > button.active { color: #3478f6; background: #e9f0ff; }
.customer-table-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 43px 43px minmax(0,1fr); padding: 0 10px 9px; }
.customer-table-title { display: flex; align-items: center; justify-content: space-between; }
.customer-table-title h3 { display: inline; margin: 0; font-size: 13px; }
.customer-table-title p { display: inline; margin-left: 8px; color: #9aa3b0; font-size: 9px; }
.customer-filterbar { min-width: 0; display: flex; align-items: center; gap: 6px; padding-bottom: 8px; overflow-x: auto; }
.table-search { flex: 0 0 245px; height: 31px; display: flex; align-items: center; gap: 6px; padding: 0 9px; border: 1px solid #e5e9ef; border-radius: 5px; color: #99a3b2; background: #f8f9fb; }
.table-search input { min-width: 0; width: 100%; padding: 0; border: 0; outline: none; background: transparent; font-size: 10px; }
.contact-filter-tabs { display: flex; gap: 3px; }
.filter-chip { height: 30px; padding: 0 9px; border: 0; background: transparent; color: #657084; font-size: 10px; white-space: nowrap; }
.filter-chip:hover { border-radius: 5px; background: #f2f5f8; }
.contact-grid { min-width: 0; min-height: 0; display: block; overflow: auto; border: 1px solid #e4e8ee; border-radius: 6px; }
.contact-grid.empty-state { display: grid; min-height: 260px; }
.customer-table { min-width: 1180px; color: #596475; font-size: 10px; }
.customer-row { display: grid; grid-template-columns: 34px 220px 190px 190px 95px 150px 145px 120px 80px; min-height: 48px; align-items: center; border-bottom: 1px solid #edf0f4; background: #fff; }
.customer-row:hover:not(.customer-table-header) { background: #f8faff; }
.customer-table-header { position: sticky; top: 0; z-index: 2; min-height: 40px; color: #4c5666; background: #f4f5f7; font-weight: 700; }
.customer-cell { min-width: 0; padding: 7px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-check { display: grid; place-items: center; padding: 0; }
.customer-check input { width: 12px; height: 12px; accent-color: #3478f6; }
.customer-name { display: flex; align-items: center; gap: 8px; color: #2f70ec; font-weight: 600; }
.customer-name .contact-avatar { width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; color: #fff; background: linear-gradient(145deg, #64a2ff, #726ff0); font-size: 10px; }
.customer-cell.location { color: #7d8795; }
.customer-cell.status { color: #1b9b61; }
.customer-cell.action { display: flex; gap: 8px; color: #2e73f0; }
.customer-cell.action button { padding: 0; border: 0; background: transparent; color: inherit; font-size: 10px; }
.customer-table-footer { position: sticky; bottom: 0; min-width: 1180px; height: 38px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; color: #8a94a3; background: #fff; border-top: 1px solid #e8ecf1; font-size: 9px; }

@media (min-width: 1800px) {
  .messages-page.active { grid-template-columns: 250px 370px minmax(500px, 1fr) 340px; }
  .conversation-head h3, .module-title strong { font-size: 16px; }
  .peer { min-height: 70px; }
}

@media (max-width: 1380px) {
  .messages-page.active { grid-template-columns: 184px 286px minmax(370px, 1fr) 264px; }
  .module-rail nav button { padding: 0 7px; }
  .customer-fact { grid-template-columns: 58px minmax(0,1fr); }
}

@media (max-width: 1160px) {
  .messages-page.active { grid-template-columns: 178px 276px minmax(360px, 1fr); }
  .customer-detail { display: none; }
  .contacts-page.active { grid-template-columns: 148px minmax(0,1fr); }
  .contact-view-layout { grid-template-columns: 142px minmax(0,1fr); }
  .contact-head-actions .button.secondary { display: none; }
}

@media (max-width: 900px) and (min-width: 821px) {
  .messages-page.active { grid-template-columns: 64px 260px minmax(340px,1fr); }
  .chat-navigation .module-title strong, .chat-navigation nav button:not(.active) { display: none; }
  .chat-navigation nav button.active { justify-content: center; }
  .chat-navigation .nav-group-title, .chat-navigation .module-empty, .chat-navigation .module-bottom-nav { display: none; }
  .contacts-page.active { grid-template-columns: 60px minmax(0,1fr); }
  .customer-navigation nav button { justify-content: center; padding: 0; font-size: 0; }
  .customer-navigation nav button span { font-size: 15px; }
  .customer-navigation .module-title strong { display: none; }
  .contact-view-layout { grid-template-columns: 112px minmax(0,1fr); }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .workspace[data-page="messages"] .topbar,
  .workspace[data-page="contacts"] .topbar { display: flex; }
  .workspace[data-page="messages"] main,
  .workspace[data-page="contacts"] main { padding: 10px 10px 88px; }
  .topbar { height: 62px; }
  .messages-page.active, .contacts-page.active { display: block; height: auto; min-height: 0; border-radius: 9px; overflow: visible; }
  .module-rail, .customer-detail, .view-sidebar { display: none; }
  .conversation-list { min-height: 390px; border: 0; }
  .peer-list { height: 290px; }
  .chat-panel { min-height: 600px; grid-template-rows: 54px minmax(360px, 1fr) 136px; border-top: 1px solid var(--line); }
  .contact-page-head { min-height: 58px; flex-wrap: wrap; padding: 8px 10px; }
  .contact-tabs strong { display: none; }
  .contact-head-actions .icon-button { display: none; }
  .contact-view-layout { display: block; }
  .customer-table-panel { min-height: 620px; grid-template-rows: 44px auto minmax(0,1fr); padding: 0 8px 9px; }
  .customer-filterbar { flex-wrap: wrap; overflow: visible; }
  .table-search { flex-basis: 100%; }
  .filter-chip { display: none; }
  .contact-grid { min-height: 500px; }
}
