:root {
  --navy: #06183a;
  --navy-2: #0a2a61;
  --blue: #1264ff;
  --cyan: #09d7e8;
  --ink: #0b1732;
  --muted: #6f7c96;
  --line: #e6ebf3;
  --panel: #ffffff;
  --canvas: #f4f7fb;
  --success: #17b77a;
  --warning: #f0a22a;
  --danger: #ec4c69;
  --shadow: 0 24px 70px rgba(16, 43, 91, .12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-height: 100vh; overflow: hidden; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }
.eyebrow { color: var(--blue); font-size: 11px; line-height: 1; font-weight: 800; letter-spacing: .14em; }

.splash { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; background: radial-gradient(circle at 50% 35%, #fff 0, #fff 28%, #eef7ff 66%, #e6f3ff 100%); transition: opacity .35s ease; }
.splash::before { content: ""; position: absolute; width: 340px; height: 340px; border-radius: 50%; border: 1px solid rgba(18,100,255,.11); box-shadow: 0 0 0 45px rgba(18,100,255,.035), 0 0 0 95px rgba(8,216,232,.025); }
.splash img { width: 230px; position: relative; filter: drop-shadow(0 18px 24px rgba(22,85,181,.12)); }
.splash p { color: var(--muted); font-size: 13px; margin: 18px 0 0; position: relative; }
.loader { display: flex; gap: 6px; margin-top: -16px; position: relative; }
.loader span { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: bounce 1s infinite ease-in-out; }
.loader span:nth-child(2) { animation-delay: .14s; background: #0b9cff; }
.loader span:nth-child(3) { animation-delay: .28s; background: var(--cyan); }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-7px); opacity: 1; } }

.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); background: #fff; color: var(--navy); border-radius: 13px; font-weight: 800; display: grid; place-items: center; }
.icon-button:hover { background: #f7f9fd; }

/* User */
.user-shell { height: 100dvh; max-width: 760px; margin: 0 auto; display: grid; grid-template-rows: auto auto 1fr; padding: max(14px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); gap: 14px; background: radial-gradient(circle at 90% 5%, rgba(9,215,232,.12), transparent 26%), var(--canvas); }
.user-header { display: flex; align-items: center; justify-content: space-between; }
.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-lockup img { width: 76px; height: 48px; object-fit: contain; object-position: center; border-radius: 12px; background: white; }
.brand-lockup div { display: grid; gap: 4px; }
.brand-lockup b { color: var(--navy); font-size: 17px; letter-spacing: -.02em; }
.brand-lockup span, .operator-card span { font-size: 11px; color: var(--muted); }
.brand-lockup i, .operator-card i { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(23,183,122,.12); }
.user-intro { background: linear-gradient(135deg, var(--navy) 0%, #0a3277 58%, #0a7fd1 100%); color: white; border-radius: 26px; padding: 24px; position: relative; overflow: hidden; box-shadow: 0 18px 42px rgba(6,24,58,.18); }
.user-intro::after { content: ""; position: absolute; width: 190px; height: 190px; border: 34px solid rgba(9,215,232,.12); transform: rotate(22deg); right: -80px; top: -95px; border-radius: 42px; }
.user-intro .eyebrow { color: #62eef4; }
.user-intro h1 { font-size: clamp(25px, 6vw, 34px); letter-spacing: -.035em; margin: 9px 0 8px; position: relative; z-index: 1; }
.user-intro p { max-width: 520px; margin: 0; color: rgba(255,255,255,.72); font-size: 13px; line-height: 1.5; position: relative; z-index: 1; }
.topic-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; position: relative; z-index: 1; }
.topic-row button { border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.1); color: white; border-radius: 999px; padding: 9px 13px; font-size: 12px; backdrop-filter: blur(8px); }
.topic-row button:hover { background: rgba(255,255,255,.2); }
.chat-card { min-height: 0; background: white; border: 1px solid rgba(222,229,240,.8); border-radius: 26px; box-shadow: var(--shadow); overflow: hidden; }
.user-chat-card { display: grid; grid-template-rows: 1fr auto; }
.message-stream { min-height: 0; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 11px; scroll-behavior: smooth; }
.day-label { align-self: center; padding: 5px 9px; color: #8994a8; font-size: 10px; background: #f4f6fa; border-radius: 99px; }
.message { max-width: min(78%, 520px); display: grid; gap: 5px; align-self: flex-start; }
.message.user { align-self: flex-end; }
.bubble { padding: 11px 14px; background: #f0f4fa; color: var(--ink); border-radius: 7px 18px 18px 18px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.message.user .bubble { color: white; background: linear-gradient(135deg, #0c58ee, #1593ef); border-radius: 18px 7px 18px 18px; box-shadow: 0 8px 18px rgba(18,100,255,.2); }
.message.admin .bubble { background: #e9f9fb; border: 1px solid #d1f0f3; }
.message.auto .bubble { background: #f0f5ff; border: 1px solid #dce6fb; }
.message-meta { color: #9ba5b7; font-size: 9px; padding: 0 4px; }
.message.user .message-meta { text-align: right; }
.message img { width: 100%; max-height: 320px; display: block; object-fit: cover; border-radius: 16px; background: #edf2f8; }
.composer { border-top: 1px solid var(--line); padding: 12px 14px 10px; background: rgba(255,255,255,.96); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea, .admin-composer textarea { border: 0; outline: none; resize: none; min-height: 42px; max-height: 120px; flex: 1; background: #f3f6fa; border-radius: 16px; padding: 12px 14px; color: var(--ink); }
.attach-button { width: 42px; height: 42px; border-radius: 14px; background: #edf3fd; color: var(--blue); display: grid; place-items: center; font-size: 25px; font-weight: 300; cursor: pointer; }
.send-button { width: 44px; height: 44px; border: 0; border-radius: 15px; color: white; background: linear-gradient(135deg, var(--blue), #0bb4e8); box-shadow: 0 9px 20px rgba(18,100,255,.22); display: grid; place-items: center; font-size: 20px; }
.send-button:disabled { opacity: .55; cursor: wait; }
.composer small { display: block; text-align: center; color: #a1a9b7; font-size: 9px; margin-top: 7px; }
.photo-preview { margin: 0 0 10px 50px; width: 82px; height: 82px; border-radius: 15px; overflow: hidden; position: relative; border: 1px solid var(--line); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview button { position: absolute; top: 4px; right: 4px; width: 23px; height: 23px; border: 0; border-radius: 50%; background: rgba(4,16,38,.78); color: white; }

/* Admin */
.admin-shell { display: grid; grid-template-columns: 220px 1fr; height: 100dvh; background: #f4f6fa; }
.admin-sidebar { background: var(--navy); color: white; padding: 22px 14px 16px; display: flex; flex-direction: column; }
.admin-brand { padding: 2px 10px 22px; border-bottom: 1px solid rgba(255,255,255,.1); }
.admin-brand img { display: block; width: 134px; height: 64px; object-fit: contain; object-position: left center; background: white; border-radius: 12px; padding: 3px; }
.admin-brand span { display: block; margin: 7px 0 0 3px; color: rgba(255,255,255,.48); text-transform: uppercase; font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.admin-nav { display: grid; gap: 7px; margin-top: 22px; }
.admin-nav button { border: 0; color: rgba(255,255,255,.58); background: transparent; border-radius: 13px; padding: 12px 13px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; text-align: left; font-size: 13px; }
.admin-nav button.active { color: white; background: linear-gradient(90deg, rgba(18,100,255,.34), rgba(9,215,232,.1)); box-shadow: inset 3px 0 #29dce9; }
.admin-nav b { background: #1b71ff; color: white; min-width: 23px; height: 20px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; font-size: 10px; }
.operator-card { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding: 16px 7px 0; display: flex; gap: 10px; align-items: center; }
.operator-avatar, .avatar { width: 39px; height: 39px; flex: 0 0 auto; border-radius: 13px; color: white !important; display: grid !important; place-items: center; background: linear-gradient(135deg, #165cf1, #06cee2); font-weight: 800; font-size: 14px !important; }
.operator-card div { display: grid; gap: 3px; }
.operator-card b { font-size: 12px; }
.admin-panel { min-width: 0; min-height: 0; }
.dialogs-layout { display: grid; grid-template-columns: minmax(310px, 380px) 1fr; }
.chat-list-panel { min-width: 0; background: white; border-right: 1px solid var(--line); padding: 26px 20px 0; display: grid; grid-template-rows: auto auto auto auto 1fr; }
.chat-list-panel > header { display: flex; justify-content: space-between; align-items: center; }
.chat-list-panel h1, .section-header h1 { margin: 7px 0 0; font-size: 27px; letter-spacing: -.035em; }
.summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 14px; }
.summary-row div { padding: 10px; border: 1px solid var(--line); border-radius: 13px; display: grid; gap: 2px; }
.summary-row b { font-size: 18px; color: var(--navy); }
.summary-row span { color: var(--muted); font-size: 9px; }
.search-box { display: flex; gap: 8px; align-items: center; background: #f4f6fa; border-radius: 12px; padding: 0 12px; }
.search-box span { color: #9ca8ba; font-size: 21px; }
.search-box input { width: 100%; height: 40px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; }
.filter-row { display: flex; gap: 4px; margin: 12px 0 8px; overflow-x: auto; }
.filter-row button { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 8px 9px; white-space: nowrap; font-size: 10px; }
.filter-row button.active { color: var(--blue); border-color: var(--blue); font-weight: 700; }
.chat-list { overflow-y: auto; margin: 0 -8px; padding-bottom: 16px; }
.chat-row { width: 100%; border: 0; background: transparent; border-radius: 16px; padding: 12px 10px; display: grid; grid-template-columns: 43px 1fr auto; gap: 10px; text-align: left; color: var(--ink); }
.chat-row:hover, .chat-row.active { background: #f2f6fc; }
.chat-row .avatar { width: 43px; height: 43px; border-radius: 15px; }
.chat-copy { min-width: 0; display: grid; gap: 4px; }
.chat-copy b { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-copy span { color: var(--muted); font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-meta { display: grid; justify-items: end; align-content: space-between; color: #9aa4b4; font-size: 9px; }
.unread-dot { min-width: 19px; height: 19px; padding: 0 5px; color: white; border-radius: 99px; background: var(--blue); display: grid; place-items: center; font-weight: 700; }
.admin-conversation { min-width: 0; min-height: 0; display: grid; background: radial-gradient(circle at 50% 45%, #fff 0, #f6f8fb 48%, #edf2f8 100%); }
.admin-conversation.empty .empty-state { display: grid; }
.empty-state { display: none; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.signal-orbit { width: 74px; height: 74px; border: 1px solid #d6e4fa; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 0 0 13px rgba(18,100,255,.045), 0 0 0 26px rgba(9,215,232,.025); color: var(--blue); font-size: 26px; }
.empty-state h2 { color: var(--ink); margin: 32px 0 7px; font-size: 19px; }
.empty-state p { font-size: 12px; }
.conversation-content { min-height: 0; display: grid; grid-template-rows: auto 1fr auto; }
.conversation-header { height: 78px; display: flex; align-items: center; gap: 12px; padding: 0 25px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); }
.conversation-person { min-width: 0; display: grid; gap: 3px; flex: 1; }
.conversation-person b { font-size: 14px; }
.conversation-person span { color: var(--muted); font-size: 10px; }
.conversation-header select { border: 1px solid var(--line); border-radius: 11px; background: white; padding: 8px 10px; color: var(--ink); font-size: 10px; }
.admin-message-stream { padding: 26px max(24px, 7vw); }
.admin-composer { background: white; border-top: 1px solid var(--line); padding: 12px max(22px, 6vw) 14px; }
.quick-replies { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 9px; }
.quick-replies button { flex: 0 0 auto; border: 1px solid #dce5f4; background: #f6f9fd; color: #426083; border-radius: 99px; padding: 7px 10px; font-size: 9px; }
.admin-composer textarea { border: 1px solid var(--line); background: #f8fafc; border-radius: 14px; }
.composer-meta { color: #9aa4b3; font-size: 9px; display: flex; justify-content: space-between; padding: 7px 4px 0; }
kbd { font-family: inherit; border: 1px solid var(--line); border-radius: 5px; padding: 2px 5px; background: #f8fafc; }

/* Settings */
.automation-panel { height: 100dvh; overflow-y: auto; padding: 34px clamp(24px, 4vw, 58px); }
.section-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.section-header p { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.primary-button, .secondary-button, .ghost-button, .danger-button { border-radius: 12px; padding: 10px 15px; font-weight: 700; font-size: 11px; }
.primary-button { border: 0; color: white; background: linear-gradient(135deg, var(--blue), #0a9ee8); box-shadow: 0 9px 22px rgba(18,100,255,.2); }
.secondary-button { color: var(--blue); border: 1px solid #cfe0ff; background: #edf4ff; }
.ghost-button { color: var(--muted); border: 1px solid var(--line); background: white; }
.danger-button { color: var(--danger); border: 1px solid #f8cbd3; background: #fff3f5; }
.automation-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 18px; margin-top: 26px; }
.settings-card { background: white; border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: 0 13px 34px rgba(16,43,91,.06); }
.card-heading { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.card-heading h2 { font-size: 15px; margin: 0 0 5px; }
.card-heading p { color: var(--muted); font-size: 10px; margin: 0; }
.soft-badge { height: fit-content; border-radius: 99px; background: #e9fbf6; color: #16966a; padding: 6px 9px; font-size: 9px; font-weight: 800; }
.rule-list, .quick-settings { display: grid; gap: 8px; margin-top: 12px; }
.rule-row, .quick-setting-row { border: 1px solid var(--line); background: white; border-radius: 14px; padding: 13px; display: grid; grid-template-columns: 1fr auto; gap: 9px; text-align: left; }
.rule-row:hover { border-color: #c8d9f6; box-shadow: 0 7px 20px rgba(18,100,255,.06); }
.rule-row h3, .quick-setting-row b { margin: 0 0 4px; font-size: 12px; }
.rule-row p, .quick-setting-row span { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.4; }
.rule-state { color: var(--success); font-size: 9px; font-weight: 800; }
.rule-state.off { color: #9ca5b4; }
.stack-form { display: grid; gap: 8px; margin-top: 14px; }
.stack-form input, .stack-form textarea, .rule-dialog input, .rule-dialog textarea { width: 100%; border: 1px solid var(--line); outline: 0; border-radius: 11px; background: #f9fbfd; padding: 10px 12px; color: var(--ink); font-size: 11px; }
.stack-form textarea { min-height: 86px; resize: vertical; }
.quick-setting-row button { border: 0; background: transparent; color: var(--danger); font-size: 18px; }
.rule-dialog { width: min(540px, calc(100vw - 28px)); border: 0; border-radius: 22px; padding: 0; box-shadow: 0 35px 90px rgba(4,18,45,.28); }
.rule-dialog::backdrop { background: rgba(4,15,35,.62); backdrop-filter: blur(5px); }
.rule-dialog form { display: grid; gap: 15px; padding: 22px; }
.rule-dialog header { display: flex; justify-content: space-between; align-items: center; }
.rule-dialog h2 { margin: 6px 0 0; font-size: 19px; }
.rule-dialog label { display: grid; gap: 7px; color: #334563; font-size: 10px; font-weight: 700; }
.rule-dialog label small { color: #99a3b3; font-weight: 400; }
.rule-dialog textarea { resize: vertical; }
.form-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.switch-label { grid-template-columns: 1fr auto !important; align-items: center; padding: 0 4px 4px; }
.switch-label input { display: none; }
.switch { width: 38px; height: 22px; border-radius: 99px; background: #cad2df; position: relative; transition: .2s; }
.switch::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: .2s; box-shadow: 0 2px 5px rgba(0,0,0,.17); }
.switch-label input:checked + .switch { background: var(--blue); }
.switch-label input:checked + .switch::after { transform: translateX(16px); }
.rule-dialog footer { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.rule-dialog footer span { flex: 1; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #081a3c; color: white; border-radius: 12px; padding: 11px 15px; font-size: 11px; opacity: 0; pointer-events: none; transition: .25s; box-shadow: 0 12px 35px rgba(4,20,49,.28); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: #a92d45; }

@media (max-width: 840px) {
  body { overflow: auto; }
  .admin-shell { grid-template-columns: 1fr; grid-template-rows: 1fr 64px; }
  .admin-sidebar { grid-row: 2; z-index: 20; padding: 7px max(16px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); flex-direction: row; align-items: center; }
  .admin-brand, .operator-card { display: none; }
  .admin-nav { width: 100%; grid-template-columns: 1fr 1fr; margin: 0; gap: 7px; }
  .admin-nav button { grid-template-columns: 22px auto; justify-content: center; padding: 9px; }
  .admin-nav b { display: none; }
  .dialogs-layout { grid-row: 1; grid-template-columns: 1fr; height: calc(100dvh - 64px); }
  .chat-list-panel { border: 0; padding: max(18px, env(safe-area-inset-top)) 16px 0; }
  .admin-conversation { position: fixed; inset: 0 0 64px 0; z-index: 10; transform: translateX(100%); transition: transform .25s ease; }
  .admin-conversation.mobile-open { transform: translateX(0); }
  .mobile-only { display: grid; }
  .conversation-header { padding: max(10px, env(safe-area-inset-top)) 14px 10px; height: auto; min-height: 70px; }
  .admin-message-stream { padding: 18px 16px; }
  .admin-composer { padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
  .automation-panel { grid-row: 1; height: calc(100dvh - 64px); padding: max(22px, env(safe-area-inset-top)) 16px 24px; }
  .section-header { align-items: flex-start; }
  .automation-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .user-shell { padding-left: 10px; padding-right: 10px; gap: 10px; }
  .brand-lockup img { width: 68px; height: 42px; }
  .user-intro { padding: 20px; border-radius: 22px; }
  .user-intro p { font-size: 12px; }
  .topic-row { gap: 6px; margin-top: 14px; }
  .topic-row button { padding: 8px 10px; font-size: 10px; }
  .chat-card { border-radius: 22px; }
  .message-stream { padding: 16px 13px; }
  .message { max-width: 86%; }
  .section-header { display: grid; }
  .primary-button { width: fit-content; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
