:root {
  color-scheme: light;
  --line: #06c755;
  --ink: #182536;
  --muted: #6f7f91;
  --soft: #f6f8fa;
  --panel: #ffffff;
  --border: #dce3ea;
  --blue: #2f80ed;
  --warning: #ffb020;
  --danger: #e5483f;
  --shadow: 0 10px 30px rgba(24, 37, 54, 0.08);
  font-family: "Segoe UI", "Microsoft JhengHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f3f6f9;
}

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

button {
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  min-height: 720px;
  display: grid;
  grid-template-columns: 270px 1fr;
  grid-template-rows: 58px 1fr;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 360px;
}

.line-wordmark {
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
  color: #050505;
}

.brand-lockup strong,
.brand-lockup span {
  display: block;
}

.brand-lockup span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.environment-switch {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.env-pill {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}

.env-pill.demo {
  color: #056d30;
  background: #ecfff4;
  border-color: #b8efcb;
}

.account-area {
  display: flex;
  align-items: center;
  gap: 9px;
}

.top-action,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 14px;
  font-weight: 700;
}

.top-action,
.primary-button {
  color: #fff;
  background: var(--blue);
}

.secondary-button {
  color: var(--ink);
  border: 1px solid var(--border);
  background: #fff;
}

.full {
  width: 100%;
}

.sidebar {
  background: #f7f9fb;
  border-right: 1px solid var(--border);
  padding: 18px 0;
  overflow-y: auto;
}

.sidebar nav {
  display: grid;
  gap: 4px;
  padding: 0 14px 16px;
}

.nav-item {
  min-height: 44px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: #2b3b4d;
  border-radius: 6px;
  padding: 0 10px;
  text-align: left;
}

.nav-item.active {
  color: var(--line);
  background: #effbf3;
  font-weight: 800;
}

.nav-item b {
  min-width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: var(--line);
  border-radius: 9px;
  font-size: 11px;
}

.nav-icon {
  width: 22px;
  height: 22px;
  position: relative;
}

.nav-icon::before,
.nav-icon::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid currentColor;
  border-radius: 5px;
}

.nav-icon.chat::after {
  width: 8px;
  height: 8px;
  inset: auto auto 0 4px;
  border-top: 0;
  border-right: 0;
  transform: rotate(-20deg);
}

.nav-icon.service::after {
  inset: 8px 5px 5px;
  border-top: 0;
}

.nav-icon.pin::before {
  border-radius: 50%;
}

.nav-icon.pin::after {
  inset: 7px;
  border-radius: 50%;
}

.nav-icon.gear::before {
  border-radius: 50%;
}

.nav-icon.users::before {
  border-radius: 50%;
  inset: 2px 7px 9px;
}

.nav-icon.users::after {
  inset: 12px 4px 4px;
  border-radius: 8px 8px 4px 4px;
}

.nav-icon.line::before {
  border-radius: 50%;
}

.nav-icon.line::after {
  inset: 7px 4px 5px;
  border-top: 0;
  border-left: 0;
  transform: rotate(35deg);
}

.side-section {
  padding: 18px 18px 0;
}

.side-section h2 {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
}

.tag-filter-list {
  display: grid;
  gap: 6px;
}

.tag-filter-list button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 8px 10px;
  color: #304154;
}

.tag-filter-list button.selected,
.tag-filter-list button:hover {
  background: #fff;
  border-color: var(--border);
}

.branch-note {
  margin-top: 20px;
  border-top: 1px solid var(--border);
}

.branch-note p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: 360px minmax(480px, 1fr) 340px;
  overflow: hidden;
}

.conversation-column,
.chat-column,
.inspector {
  min-width: 0;
  min-height: 0;
}

.conversation-column {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.list-toolbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  background: #fff;
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.icon-button span,
.icon-button span::before,
.icon-button span::after {
  width: 16px;
  height: 2px;
  display: block;
  background: #6b7785;
  border-radius: 1px;
  content: "";
}

.icon-button span {
  position: relative;
}

.icon-button span::before,
.icon-button span::after {
  position: absolute;
  left: 0;
}

.icon-button span::before {
  top: -6px;
}

.icon-button span::after {
  top: 6px;
}

.list-toolbar input {
  min-width: 0;
  width: 100%;
  height: 36px;
  border: 1px solid #ccd6e0;
  border-radius: 2px;
  padding: 0 12px;
  color: var(--ink);
}

.conversation-list {
  height: calc(100vh - 114px);
  overflow-y: auto;
}

.conversation-item {
  width: 100%;
  min-height: 86px;
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid #f0f2f4;
  background: #fff;
  text-align: left;
  padding: 12px 18px;
}

.conversation-item.active,
.conversation-item:hover {
  background: #f6f8fa;
}

.avatar {
  --avatar-color: #7a8ca0;
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: var(--avatar-color);
  border-radius: 50%;
  font-weight: 800;
  flex: 0 0 auto;
}

.avatar.tiny {
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.avatar.large {
  width: 58px;
  height: 58px;
  font-size: 20px;
}

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

.conversation-copy strong,
.conversation-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-copy small,
.conversation-meta time {
  color: #91a0af;
  font-size: 13px;
}

.conversation-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.conversation-meta i {
  width: 12px;
  height: 12px;
  display: block;
  overflow: hidden;
  color: transparent;
  background: var(--line);
  border-radius: 50%;
}

.no-results {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.chat-column {
  position: relative;
  background: #f8fafc;
  display: grid;
}

.empty-state {
  align-self: center;
  justify-self: center;
  text-align: center;
  color: #a6b2bf;
}

.line-bubble {
  width: 152px;
  height: 112px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #d2d8df;
  border-radius: 54px;
  font-size: 34px;
  font-weight: 900;
  position: relative;
}

.line-bubble::after {
  content: "";
  position: absolute;
  right: 28px;
  bottom: -14px;
  width: 34px;
  height: 34px;
  background: #d2d8df;
  clip-path: polygon(0 0, 100% 20%, 20% 100%);
}

.chat-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.chat-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.chat-header h1 {
  margin: 0;
  font-size: 20px;
}

.chat-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.quick-routing {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.quick-routing button {
  border: 1px solid #c9d7e4;
  color: #24537a;
  background: #f4f9fd;
  min-height: 32px;
  border-radius: 6px;
  padding: 0 12px;
  font-weight: 700;
}

.message-timeline {
  min-height: 0;
  padding: 22px;
  overflow-y: auto;
}

.message-row {
  display: flex;
  margin: 10px 0;
}

.message-row.user {
  justify-content: flex-start;
}

.message-row.agent {
  justify-content: flex-end;
}

.message-row.system {
  justify-content: center;
}

.message-bubble {
  max-width: min(520px, 82%);
  border-radius: 8px;
  padding: 10px 12px 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(24, 37, 54, 0.08);
}

.message-row.agent .message-bubble {
  color: #fff;
  background: var(--line);
}

.message-row.system .message-bubble {
  color: #5d6b7a;
  background: #e9eef3;
}

.message-bubble p {
  margin: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.message-bubble time {
  display: block;
  margin-top: 4px;
  text-align: right;
  color: rgba(91, 106, 122, 0.72);
  font-size: 11px;
}

.message-row.agent time {
  color: rgba(255, 255, 255, 0.82);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--border);
}

.composer input {
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
}

.inspector {
  background: #fff;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 48px;
  border-bottom: 1px solid var(--border);
}

.inspector-tabs button {
  border: 0;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.inspector-tabs button.active {
  color: var(--line);
  box-shadow: inset 0 -3px 0 var(--line);
}

.inspector-panel {
  padding: 18px;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 13px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.profile-head h2 {
  margin: 0;
  font-size: 20px;
}

.profile-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.profile-facts {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.profile-facts div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.profile-facts dt {
  color: var(--muted);
}

.profile-facts dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.panel-block {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}

.panel-block h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-cloud button {
  min-height: 30px;
  border: 1px solid #bae8ca;
  background: #effbf3;
  color: #056d30;
  border-radius: 6px;
  padding: 0 10px;
  font-weight: 700;
}

.panel-block select,
.panel-block textarea,
.rule-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  resize: vertical;
}

.rule-list,
.notification-list {
  display: grid;
  gap: 10px;
}

.rule-item {
  display: grid;
  grid-template-columns: 1fr auto 26px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.rule-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.rule-item strong {
  color: #056d30;
  white-space: nowrap;
}

.rule-item button {
  width: 26px;
  height: 26px;
  border: 0;
  background: #f3f6f9;
  border-radius: 5px;
  color: var(--muted);
}

.rule-form {
  display: grid;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rule-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.notification-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

.notification-item strong,
.notification-item span {
  display: block;
}

.notification-item p {
  margin: 8px 0;
  color: #405063;
  line-height: 1.5;
}

.notification-item span {
  color: var(--muted);
  font-size: 12px;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f3f6f9;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.auth-panel p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.auth-panel form,
.auth-panel label {
  display: grid;
  gap: 8px;
}

.auth-panel form {
  gap: 14px;
}

.auth-panel input,
.rule-form select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.user-list {
  display: grid;
  gap: 10px;
}

.user-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

.user-item strong,
.user-item span {
  display: block;
}

.user-item span {
  color: var(--muted);
  font-size: 12px;
}

.user-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.user-actions button,
.user-actions select {
  min-height: 30px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 0 8px;
}

.module-panel {
  min-height: 0;
  overflow-y: auto;
  background: #fff;
}

.module-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}

.module-header h1 {
  margin: 0;
  font-size: 22px;
}

.module-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.module-view {
  padding: 22px;
}

.module-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 360px);
  gap: 20px;
  align-items: start;
}

.settings-form,
.settings-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
}

.settings-form h2,
.settings-card h2,
.module-grid h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.settings-form input,
.settings-form select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}

.settings-card p {
  margin: 0;
  color: #405063;
  line-height: 1.6;
}

.line-groups-card {
  margin-top: 20px;
}

.line-group-list {
  display: grid;
  gap: 10px;
}

.line-group-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.line-group-item strong,
.line-group-item span,
.line-group-item small {
  display: block;
}

.line-group-item span,
.line-group-item small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.settings-facts {
  display: grid;
  gap: 10px;
  margin: 0;
}

.settings-facts div {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px;
  align-items: start;
}

.settings-facts dt {
  color: var(--muted);
}

.settings-facts dd {
  margin: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
  }

  .workspace {
    grid-template-columns: 320px minmax(420px, 1fr);
  }

  .inspector {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    overflow: visible;
  }

  .topbar {
    min-height: 58px;
    flex-wrap: wrap;
    padding: 12px;
  }

  .brand-lockup {
    min-width: 0;
  }

  .environment-switch,
  .account-area {
    width: 100%;
    margin-left: 0;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .side-section {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .conversation-list {
    height: auto;
    max-height: 360px;
  }

  .chat-panel {
    min-height: 620px;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .quick-routing,
  .composer {
    width: 100%;
  }

  .quick-routing {
    overflow-x: auto;
  }

  .composer {
    grid-template-columns: 1fr;
  }
}
