:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #172033;
  background: #f2f5f9;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --navy: #101827;
  --muted: #7b879b;
  --line: #e5eaf1;
  --soft: #f6f8fb;
  --green: #16a56a;
  --orange: #e89027;
  --red: #d84e5b;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; min-width: 320px; overflow: hidden; }
body { min-height: 100vh; background: #f2f5f9; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, 1fr) minmax(420px, .8fr); background: #fff; }
.login-brand { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; gap: 18px; color: #fff; background: radial-gradient(circle at 15% 20%, rgba(75,132,255,.5), transparent 32%), linear-gradient(145deg, #0e1b35, #173a79); }
.login-brand::after { content: ""; position: absolute; width: 430px; height: 430px; right: -180px; bottom: -180px; border: 1px solid rgba(255,255,255,.14); border-radius: 50%; box-shadow: 0 0 0 75px rgba(255,255,255,.025), 0 0 0 150px rgba(255,255,255,.02); }
.login-brand > span { width: 68px; height: 68px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.4); border-radius: 22px; background: rgba(255,255,255,.12); font-size: 30px; font-weight: 800; }
.login-brand div { display: grid; gap: 7px; }
.login-brand strong { font-size: 28px; letter-spacing: .08em; }
.login-brand small { color: rgba(255,255,255,.65); font-size: 13px; }
.login-card { align-self: center; width: min(390px, calc(100% - 48px)); margin: 0 auto; }
.eyebrow { margin: 0 0 9px; color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.login-card h1 { margin: 0 0 9px; color: #14203a; font-size: 32px; }
.login-card > p:not(.eyebrow) { margin: 0 0 32px; color: var(--muted); font-size: 14px; }
.login-card label, .compact-form label { display: grid; gap: 8px; margin: 16px 0; color: #556176; font-size: 13px; font-weight: 600; }
.login-card input, .compact-form input, .compact-form textarea, .compact-form select { width: 100%; border: 1px solid var(--line); border-radius: 12px; outline: 0; padding: 11px 12px; color: #172033; background: #fff; }
.login-card input { height: 48px; }
.login-card input:focus, .compact-form input:focus, .compact-form textarea:focus, .compact-form select:focus { border-color: #8eaff9; box-shadow: 0 0 0 4px rgba(37,99,235,.08); }
.login-card > button, .compact-form > button { width: 100%; height: 48px; margin-top: 8px; border: 0; border-radius: 13px; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-dark)); font-weight: 750; box-shadow: 0 11px 24px rgba(37,99,235,.22); }
.form-error { margin-top: 13px; padding: 10px 12px; border-radius: 10px; color: #a72f3d; background: #fff0f2; font-size: 12px; }

.app-view { height: 100vh; min-height: 0; display: grid; grid-template-rows: 66px minmax(0, 1fr); overflow: hidden; }
.topbar { z-index: 4; display: flex; align-items: center; gap: 30px; padding: 0 20px; color: #fff; background: var(--navy); box-shadow: 0 5px 22px rgba(11,20,37,.13); }
.topbar-brand { width: 260px; display: flex; align-items: center; gap: 11px; }
.topbar-brand span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: linear-gradient(145deg, #3c7bf0, #2057c6); font-weight: 800; }
.topbar-brand strong { font-size: 16px; letter-spacing: .04em; }
.topbar-stats { display: flex; gap: 24px; color: #aab5c7; font-size: 12px; }
.topbar-stats span { display: flex; align-items: center; gap: 7px; }
.topbar-stats i, .connection-state i { width: 8px; height: 8px; border-radius: 50%; }
.waiting-dot { background: var(--orange); }
.open-dot { background: #38c989; }
.topbar-stats b { color: #fff; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.connection-state { display: flex; align-items: center; gap: 6px; color: #9faabe; font-size: 11px; }
.connection-state i { background: var(--orange); }
.connection-state.connected i { background: #37d389; box-shadow: 0 0 0 4px rgba(55,211,137,.1); }
.ghost-button { height: 34px; border: 1px solid #344155; border-radius: 10px; padding: 0 13px; color: #c7d0df; background: transparent; font-size: 12px; }
.ghost-button:hover { color: #fff; border-color: #536179; }
.avatar-button { width: 36px; height: 36px; border: 0; border-radius: 12px; color: #fff; background: #2c64d2; font-weight: 800; }

.workspace { min-height: 0; display: grid; grid-template-columns: 310px minmax(480px, 1fr) minmax(420px, 460px); overflow: hidden; }
.conversation-sidebar, .detail-panel { min-height: 0; background: #fff; }
.conversation-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 14px; }
.sidebar-heading h1 { margin: 0 0 4px; font-size: 18px; }
.sidebar-heading span { color: var(--muted); font-size: 11px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; color: #657189; background: #fff; font-size: 18px; }
.search-box { display: flex; align-items: center; gap: 8px; margin: 0 16px 12px; padding: 0 11px; border: 1px solid var(--line); border-radius: 11px; color: #8792a5; background: var(--soft); }
.search-box input { width: 100%; height: 39px; border: 0; outline: 0; background: transparent; font-size: 12px; }
.status-tabs { display: grid; grid-template-columns: repeat(4, 1fr); padding: 0 12px 12px; border-bottom: 1px solid var(--line); }
.status-tabs button { height: 32px; border: 0; border-radius: 9px; color: #7f899b; background: transparent; font-size: 11px; }
.status-tabs button.active { color: var(--brand); background: #edf3ff; font-weight: 700; }
.conversation-list { min-height: 0; flex: 1; overflow-y: auto; padding: 8px; }
.conversation-item { width: 100%; display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: start; margin: 2px 0; border: 0; border-radius: 13px; padding: 12px 10px; text-align: left; background: transparent; }
.conversation-item:hover { background: #f7f9fc; }
.conversation-item.active { background: #edf3ff; }
.conversation-avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; color: #2f63c7; background: #e7efff; font-size: 12px; font-weight: 800; }
.conversation-copy { min-width: 0; }
.conversation-copy strong { display: block; overflow: hidden; color: #263249; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy p { margin: 6px 0 0; overflow: hidden; color: #8a95a7; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-side { display: grid; justify-items: end; gap: 8px; color: #9da6b6; font-size: 9px; }
.mini-status { padding: 3px 6px; border-radius: 6px; font-size: 9px; }
.mini-status.waiting { color: #a96512; background: #fff3df; }
.mini-status.open { color: #148358; background: #def7ed; }
.mini-status.closed { color: #788395; background: #eef1f5; }
.list-empty { padding: 45px 18px; color: #98a2b3; text-align: center; font-size: 12px; line-height: 1.7; }

.chat-panel { min-width: 0; min-height: 0; background: #f4f6fa; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; color: #929dae; text-align: center; }
.empty-state div { width: 72px; height: 72px; display: grid; place-items: center; border-radius: 24px; background: #fff; box-shadow: 0 15px 40px rgba(37,55,89,.08); font-size: 30px; }
.empty-state h2 { margin: 18px 0 6px; color: #536078; font-size: 18px; }
.empty-state p { margin: 0; font-size: 12px; }
.active-chat { height: 100%; display: grid; grid-template-rows: 72px minmax(0, 1fr) auto auto; }
.chat-heading { display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.visitor-avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: linear-gradient(145deg, #4e7fe0, #315fbd); font-weight: 800; }
.chat-heading h2 { margin: 0 0 4px; font-size: 14px; }
.chat-heading span { color: var(--muted); font-size: 10px; }
.chat-heading-actions { margin-left: auto; display: flex; gap: 8px; }
.secondary-button { height: 33px; border: 1px solid #b9cdf7; border-radius: 9px; padding: 0 12px; color: #2d62c8; background: #f4f8ff; font-size: 11px; }
.secondary-button.danger { border-color: #efc5ca; color: #be4350; background: #fff7f8; }
.admin-messages { min-height: 0; overflow-y: auto; padding: 22px 22px 10px; }
.admin-message { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 16px; }
.admin-message.agent { flex-direction: row-reverse; }
.admin-message-avatar { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 10px; color: #fff; background: #5679bd; font-size: 10px; font-weight: 800; }
.admin-message-card { max-width: 68%; }
.admin-message-meta { margin: 0 3px 5px; color: #929cad; font-size: 9px; }
.admin-message.agent .admin-message-meta { text-align: right; }
.admin-message-bubble { padding: 10px 13px; border: 1px solid #e2e8f0; border-radius: 7px 15px 15px 15px; color: #273247; background: #fff; box-shadow: 0 3px 12px rgba(28,44,76,.04); white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.55; }
.admin-message.agent .admin-message-bubble { border: 0; border-radius: 15px 7px 15px 15px; color: #fff; background: var(--brand); }
.conversation-closed { padding: 8px 15px; color: #8b5d17; background: #fff3d6; text-align: center; font-size: 11px; }
.reply-composer { position: relative; margin: 0 18px 18px; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: 0 8px 28px rgba(28,43,70,.06); }
.reply-toolbar { height: 38px; display: flex; align-items: center; justify-content: space-between; padding: 0 11px; border-bottom: 1px solid #edf0f4; }
.reply-toolbar select { max-width: 180px; border: 0; outline: 0; color: #60708a; background: transparent; font-size: 10px; }
.reply-toolbar span { color: #a2aaba; font-size: 9px; }
.reply-composer textarea { width: 100%; min-height: 72px; max-height: 160px; resize: vertical; border: 0; outline: 0; padding: 12px 92px 12px 13px; color: #273247; line-height: 1.5; }
.reply-composer > button { position: absolute; right: 10px; bottom: 10px; height: 34px; border: 0; border-radius: 10px; padding: 0 16px; color: #fff; background: var(--brand); font-size: 11px; font-weight: 700; }
.reply-composer.disabled { opacity: .6; pointer-events: none; }

.detail-panel { overflow-y: auto; border-left: 1px solid var(--line); padding: 18px; }
.detail-heading { display: flex; align-items: center; justify-content: space-between; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.detail-heading-actions { display: flex; align-items: center; gap: 8px; }
.mobile-detail-button, .detail-close-button { display: none; }
.detail-heading h2 { margin: 0; font-size: 14px; }
.status-badge { padding: 4px 8px; border-radius: 8px; color: #778196; background: #f0f2f5; font-size: 9px; }
.status-badge.waiting { color: #a96512; background: #fff3df; }
.status-badge.open { color: #148358; background: #def7ed; }
.status-badge.closed { color: #788395; background: #eef1f5; }
.detail-panel dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; margin: 8px 0 20px; }
.detail-panel dl div { padding: 10px 0; border-bottom: 1px dashed #edf0f4; }
.detail-panel dt { margin-bottom: 5px; color: #9aa3b2; font-size: 9px; }
.detail-panel dd { margin: 0; overflow-wrap: anywhere; color: #4e5a70; font-size: 11px; line-height: 1.5; }
.notes-field { display: grid; gap: 8px; color: #657188; font-size: 11px; }
.notes-field textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 11px; outline: 0; padding: 10px; color: #39455a; }
.wide-button { width: 100%; height: 36px; margin-top: 10px; border: 0; border-radius: 10px; color: #fff; background: #34435c; font-size: 11px; }
.recharge-section { margin: 0 0 18px; }
.recharge-section h3 { margin: 0 0 9px; color: #4e5a70; font-size: 12px; }
.recharge-list { display: grid; gap: 8px; }
.detail-empty { margin: 0; padding: 11px; border-radius: 10px; color: #98a2b3; background: #f7f9fc; font-size: 10px; text-align: center; }
.recharge-record { padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #f9fbff; }
.recharge-record div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.recharge-record strong { color: #2d62c8; font-size: 11px; }
.recharge-record span { color: #7c879a; font-size: 9px; }
.recharge-record p { margin: 7px 0 4px; overflow-wrap: anywhere; color: #526078; font-size: 9px; }
.recharge-record small { color: #98a2b3; font-size: 9px; }

.settings-dialog { width: min(1180px, calc(100vw - 40px)); max-height: calc(100vh - 40px); overflow: auto; border: 0; border-radius: 20px; padding: 0; color: #172033; box-shadow: 0 30px 100px rgba(12,25,49,.28); }
.settings-dialog::backdrop { background: rgba(14,24,42,.55); backdrop-filter: blur(3px); }
.dialog-heading { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 15px; border-bottom: 1px solid var(--line); background: #fff; }
.dialog-heading h2 { margin: 0; font-size: 20px; }
.dialog-heading .eyebrow { margin-bottom: 5px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 25px; padding: 22px 24px 28px; }
.settings-grid h3 { margin: 0 0 13px; font-size: 15px; }
.setting-list { display: grid; gap: 8px; max-height: 220px; overflow-y: auto; }
.setting-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; }
.setting-item-copy { min-width: 0; flex: 1; }
.setting-item-copy strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.setting-item-copy span { color: var(--muted); font-size: 10px; }
.setting-item button { border: 0; color: #bd4955; background: transparent; font-size: 10px; }
.compact-form { margin-top: 18px; padding: 15px; border-radius: 14px; background: var(--soft); }
.compact-form h4 { margin: 0 0 6px; font-size: 13px; }
.compact-form label { margin: 10px 0; font-size: 10px; }
.compact-form input, .compact-form select { height: 38px; }
.compact-form > button { height: 39px; margin-top: 3px; font-size: 11px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.settings-grid > section { min-width: 0; }
.line-help { margin: -4px 0 13px; color: var(--muted); font-size: 10px; line-height: 1.6; }
.setting-item.line-item { align-items: stretch; flex-wrap: wrap; }
.line-item .setting-item-copy { flex-basis: 100%; }
.line-link { display: block; overflow: hidden; margin-top: 3px; color: #5273ac !important; text-overflow: ellipsis; white-space: nowrap; }
.line-agent-select { min-width: 0; flex: 1; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 7px; color: #4e5a70; background: #fff; font-size: 10px; }
.line-actions { display: flex; align-items: center; gap: 4px; }
.line-actions button { padding: 6px 7px; border-radius: 7px; background: #f4f6fa; }

.app-toast { position: fixed; left: 50%; bottom: 28px; z-index: 10; transform: translateX(-50%); max-width: 420px; padding: 10px 15px; border-radius: 10px; color: #fff; background: rgba(20,29,45,.92); font-size: 12px; box-shadow: 0 10px 30px rgba(17,28,46,.2); }

@media (max-width: 1280px) {
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .workspace { grid-template-columns: 280px minmax(380px, 1fr); }
  .mobile-detail-button { display: inline-flex; align-items: center; }
  .detail-close-button { display: grid; width: 30px; height: 30px; }
  .detail-panel { display: none; }
  .detail-panel.mobile-open {
    position: fixed;
    top: 66px;
    right: 0;
    bottom: 0;
    z-index: 8;
    display: block;
    width: min(370px, 100vw);
    border-left: 1px solid var(--line);
    background: #fff;
    box-shadow: -18px 0 50px rgba(20,32,55,.18);
  }
}
@media (max-width: 760px) {
  .login-view { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .topbar-brand { width: auto; }
  .topbar-stats, .connection-state { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .conversation-sidebar { width: 100%; }
  .chat-panel { position: fixed; inset: 66px 0 0; z-index: 3; transform: translateX(100%); transition: transform .2s; }
  .chat-panel.mobile-open { transform: translateX(0); }
  .chat-heading { gap: 7px; padding: 0 9px; }
  .visitor-avatar { width: 34px; height: 34px; border-radius: 10px; }
  .chat-heading-actions { gap: 4px; }
  .secondary-button { padding: 0 7px; font-size: 10px; }
  .admin-message-card { max-width: 82%; }
  .reply-composer { margin: 0 8px 8px; }
  .settings-grid { grid-template-columns: 1fr; }
}
.detail-select { width: 100%; border: 1px solid var(--line); border-radius: 8px; outline: 0; padding: 7px 8px; color: #4e5a70; background: #fff; font-size: 11px; }
.detail-select:focus { border-color: #8eaff9; box-shadow: 0 0 0 3px rgba(37,99,235,.08); }
