:root {
  --ink: #17152c;
  --muted: #6d7085;
  --line: #e1e3ec;
  --canvas: #f5f6fa;
  --panel: #ffffff;
  --nav: #201758;
  --violet: #6d28d9;
  --violet-soft: #f1eafe;
  --amber: #f59e0b;
  --green: #0f9f6e;
  --green-soft: #eaf9f3;
  --red: #d63b4a;
  --blue: #2577d8;
  --shadow: 0 14px 40px rgba(33, 25, 76, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: var(--canvas); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 5px; color: #79758e; font-size: 11px; font-weight: 800; letter-spacing: .08em; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, .8fr) minmax(460px, 1.2fr); background: #f8f8fb; }
.login-brand { padding: clamp(32px, 6vw, 88px); display: flex; align-items: flex-start; gap: 14px; color: white; background: var(--nav); position: relative; overflow: hidden; }
.login-brand::after { content: ""; position: absolute; width: 520px; height: 520px; border: 110px solid rgba(255,255,255,.06); border-radius: 50%; right: -280px; bottom: -260px; }
.login-brand img { width: 54px; height: 54px; position: relative; z-index: 1; }
.login-brand div { position: relative; z-index: 1; display: grid; }
.login-brand strong { font-size: 31px; line-height: 1; }
.login-brand span { margin-top: 7px; color: #cfcaec; font-weight: 700; }
.login-panel { align-self: center; justify-self: center; width: min(420px, calc(100% - 40px)); display: grid; gap: 17px; }
.login-panel h1 { margin: 0; font-size: 38px; }
.login-copy { margin: -8px 0 8px; color: var(--muted); }

label { display: grid; gap: 7px; color: #4b4d62; font-size: 13px; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid #d9dbe5; border-radius: 6px; background: white; color: var(--ink); padding: 11px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(109,40,217,.11); }
.form-error { min-height: 18px; margin: -5px 0; color: var(--red); font-size: 13px; }

.button { border: 1px solid transparent; border-radius: 6px; padding: 10px 14px; font-weight: 800; transition: transform .12s, box-shadow .12s, background .12s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: wait; transform: none; }
.button.primary { color: white; background: var(--violet); box-shadow: 0 8px 18px rgba(109,40,217,.17); }
.button.secondary { color: #39364f; background: #f2f3f7; border-color: #e0e2e9; box-shadow: none; }
.button.subtle { color: #dbd8ef; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); box-shadow: none; }
.button.wide { width: 100%; }
.text-button { border: 0; background: transparent; color: var(--violet); font-weight: 800; padding: 7px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--nav); color: white; display: flex; flex-direction: column; z-index: 20; }
.sidebar-brand { min-height: 84px; padding: 20px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid rgba(255,255,255,.09); }
.sidebar-brand img { width: 39px; height: 39px; }
.sidebar-brand div { display: grid; }
.sidebar-brand strong { font-size: 19px; line-height: 1; }
.sidebar-brand span { margin-top: 4px; color: #bbb5df; font-size: 12px; font-weight: 700; }
.main-nav { padding: 17px 12px; display: grid; gap: 5px; }
.nav-item { min-height: 43px; border: 0; border-radius: 6px; background: transparent; color: #d4d0e7; padding: 0 12px; display: flex; align-items: center; gap: 11px; text-align: left; font-size: 14px; font-weight: 750; }
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: white; color: var(--nav); }
.nav-symbol { width: 22px; color: #9b94c8; font-size: 10px; font-variant-numeric: tabular-nums; }
.nav-item.active .nav-symbol { color: var(--violet); }
.nav-count { margin-left: auto; min-width: 20px; height: 20px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--red); font-size: 11px; }
.sidebar-foot { margin-top: auto; padding: 14px 12px; display: grid; gap: 13px; border-top: 1px solid rgba(255,255,255,.09); }
.advisor { display: flex; align-items: center; gap: 10px; padding: 5px; }
.advisor div { display: grid; }
.advisor strong { font-size: 13px; }
.advisor small { color: #aca6cf; font-size: 11px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #42d39c; box-shadow: 0 0 0 4px rgba(66,211,156,.12); }

.workspace { min-width: 0; }
.topbar { min-height: 84px; padding: 15px 24px; background: white; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 15; }
.topbar h2 { margin: 0; font-size: 24px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.connection-badge { min-height: 34px; padding: 0 12px; border: 1px solid #dfe1e9; border-radius: 18px; display: flex; align-items: center; gap: 8px; color: #55586b; background: #fafafa; font-size: 12px; font-weight: 750; }
.connection-badge i { width: 7px; height: 7px; border-radius: 50%; background: #a7a9b4; }
.connection-badge.ready { color: #087451; background: var(--green-soft); border-color: #bcebd9; }
.connection-badge.ready i { background: var(--green); }
.menu-button { display: none; border: 0; background: transparent; font-size: 22px; }

main { padding: 22px; }
.view { display: none; }
.view.active { display: block; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-height: 132px; padding: 19px; border: 1px solid var(--line); border-top: 3px solid var(--violet); border-radius: 7px; background: white; display: grid; align-content: space-between; }
.metric:nth-child(2) { border-top-color: var(--blue); }
.metric:nth-child(3) { border-top-color: var(--amber); }
.metric.success { border-top-color: var(--green); }
.metric span { color: var(--muted); font-size: 13px; font-weight: 700; }
.metric strong { font-size: 35px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric small { color: #9597a6; }
.dashboard-grid { margin-top: 14px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.surface { border: 1px solid var(--line); border-radius: 7px; background: white; box-shadow: var(--shadow); }
.pipeline-summary, .inbox-summary { min-height: 360px; padding: 20px; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.section-head h3 { margin: 0; font-size: 18px; }
.stage-bars { margin-top: 25px; display: grid; gap: 17px; }
.stage-row { display: grid; grid-template-columns: 105px minmax(80px, 1fr) 34px; gap: 12px; align-items: center; }
.stage-row label { color: #56586b; font-size: 12px; text-transform: capitalize; }
.stage-track { height: 8px; border-radius: 4px; background: #eeeff4; overflow: hidden; }
.stage-track i { display: block; height: 100%; background: var(--violet); }
.stage-row:nth-child(2n) .stage-track i { background: var(--blue); }
.stage-row:nth-child(3n) .stage-track i { background: var(--amber); }
.stage-row strong { text-align: right; font-size: 13px; }
.pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 14px; background: #f0eff7; color: #56526d; font-size: 12px; font-weight: 800; }
.recent-list { margin-top: 16px; display: grid; }
.recent-item { min-height: 63px; padding: 10px 0; border-bottom: 1px solid #ececf2; display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; cursor: pointer; }
.recent-item:last-child { border-bottom: 0; }
.recent-item .avatar, .contact-avatar { border-radius: 50%; display: grid; place-items: center; background: #e8e5f7; color: var(--nav); font-weight: 850; }
.recent-item .avatar { width: 38px; height: 38px; }
.recent-item div { min-width: 0; display: grid; }
.recent-item strong, .recent-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item small { color: var(--muted); }
.empty-mini { padding: 45px 10px; text-align: center; color: var(--muted); }

.inbox-view.active { height: calc(100vh - 128px); }
.inbox-layout { height: 100%; min-height: 560px; border: 1px solid var(--line); border-radius: 7px; background: white; display: grid; grid-template-columns: 296px minmax(390px, 1fr) 300px; overflow: hidden; }
.contact-column { min-width: 0; display: grid; grid-template-rows: auto 1fr; border-right: 1px solid var(--line); }
.contact-tools { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); background: #fbfbfd; }
.contact-tools input, .contact-tools select { padding: 9px 10px; font-size: 12px; }
.contact-list { min-height: 0; overflow: auto; }
.contact-item { min-height: 72px; padding: 11px 12px; border: 0; border-bottom: 1px solid #eeeff3; background: white; display: grid; grid-template-columns: 40px 1fr auto; gap: 9px; align-items: center; text-align: left; }
.contact-item:hover, .contact-item.active { background: #f3f0fb; }
.contact-avatar { width: 40px; height: 40px; flex: 0 0 auto; }
.contact-copy { min-width: 0; display: grid; gap: 3px; }
.contact-copy strong, .contact-copy small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.contact-copy small { color: var(--muted); }
.unread-badge { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; display: grid; place-items: center; color: white; background: var(--green); font-size: 11px; font-weight: 850; }
.conversation-column { min-width: 0; background: #f2efe9; position: relative; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 30px; }
.empty-state img { width: 64px; height: 64px; opacity: .82; }
.empty-state h3 { margin: 14px 0 3px; color: var(--ink); }
.empty-state p { margin: 0; }
.conversation-content { height: 100%; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto auto; }
.conversation-head { padding: 10px 14px; display: flex; align-items: center; gap: 10px; background: white; border-bottom: 1px solid var(--line); }
.conversation-head > div:nth-of-type(2) { min-width: 0; display: grid; }
.conversation-head strong, .conversation-head small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-head small { color: var(--muted); }
.window-badge { margin-left: auto; padding: 6px 9px; border-radius: 4px; background: var(--green-soft); color: #087451; font-size: 11px; font-weight: 850; }
.window-badge.closed { background: #fff2df; color: #975800; }
.back-button { display: none; border: 0; background: transparent; font-size: 30px; line-height: 1; }
.messages-list { min-height: 0; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 9px; }
.message { max-width: min(640px, 82%); padding: 9px 11px; border-radius: 6px; box-shadow: 0 1px 2px rgba(29,27,43,.12); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; font-size: 14px; }
.message.in { align-self: flex-start; background: white; }
.message.out { align-self: flex-end; background: #dcf8c6; }
.message small { display: block; margin-top: 5px; color: #72747f; text-align: right; font-size: 10px; }
.composer { min-height: 66px; padding: 10px; display: grid; grid-template-columns: minmax(120px, 1fr) auto auto; gap: 8px; align-items: end; background: white; border-top: 1px solid var(--line); }
.composer textarea { min-height: 42px; max-height: 120px; resize: none; }
.composer-notice { padding: 8px 12px; color: #855100; background: #fff5dd; border-top: 1px solid #f4d595; font-size: 12px; }
.template-composer { padding: 10px; background: #fffaf0; border-top: 1px solid #f1d9a3; display: grid; grid-template-columns: 1fr 85px 1.2fr auto; gap: 7px; }
.template-composer input { font-size: 12px; padding: 9px; }
.detail-column { min-width: 0; border-left: 1px solid var(--line); background: #fbfbfd; overflow: auto; }
.detail-empty { padding: 40px 18px; color: var(--muted); text-align: center; }
.detail-content { padding: 16px; display: grid; gap: 16px; }
.detail-profile { display: grid; justify-items: center; text-align: center; gap: 5px; }
.detail-profile .contact-avatar { width: 56px; height: 56px; font-size: 18px; }
.detail-profile h3 { margin: 4px 0 0; }
.detail-profile p { margin: 0; color: var(--muted); font-size: 12px; }
.detail-fields { display: grid; gap: 10px; }
.detail-fields label { font-size: 11px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.consent-box { padding: 10px; border: 1px solid #bcebd9; border-radius: 6px; color: #087451; background: var(--green-soft); font-size: 12px; line-height: 1.4; }
.consent-box.off { color: #9b2634; border-color: #f0bac1; background: #fff1f2; }

.pipeline-toolbar { margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.pipeline-toolbar input { max-width: 380px; }
.pipeline-toolbar .pill { margin-left: auto; }
.pipeline-board { min-height: calc(100vh - 180px); display: grid; grid-template-columns: repeat(7, minmax(210px, 1fr)); gap: 10px; overflow-x: auto; align-items: start; padding-bottom: 12px; }
.pipeline-lane { min-height: 520px; border: 1px solid var(--line); border-radius: 7px; background: #f0f1f5; }
.lane-head { min-height: 48px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: white; border-radius: 7px 7px 0 0; }
.lane-head strong { font-size: 13px; text-transform: capitalize; }
.lane-head span { color: var(--muted); font-size: 12px; }
.lane-list { padding: 8px; display: grid; gap: 8px; }
.lead-card { border: 1px solid #dddfe7; border-radius: 6px; background: white; padding: 11px; display: grid; gap: 8px; cursor: pointer; box-shadow: 0 4px 10px rgba(32,23,88,.04); }
.lead-card:hover { border-color: #b9aedf; }
.lead-card h4 { margin: 0; font-size: 13px; }
.lead-card p { margin: 0; color: var(--muted); font-size: 11px; }
.lead-card select { padding: 7px; font-size: 11px; }

.settings-layout { display: grid; grid-template-columns: minmax(460px, 1fr) 340px; gap: 14px; align-items: start; }
.settings-form { padding: 22px; display: grid; gap: 16px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.webhook-box { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: #f7f7fa; display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; align-items: center; }
.webhook-box span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.webhook-box code { min-width: 0; grid-column: 1; overflow-wrap: anywhere; font-size: 12px; }
.webhook-box button { grid-column: 2; grid-row: 1 / span 2; }
.section-divider { height: 1px; background: var(--line); margin: 4px 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.settings-side { display: grid; gap: 12px; }
.status-panel { padding: 20px; }
.status-panel h3 { margin: 0 0 16px; }
.check-list { margin: 0; padding: 0; list-style: none; display: grid; }
.check-list li { min-height: 45px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #ececf2; color: var(--muted); font-size: 13px; }
.check-list li:last-child { border-bottom: 0; }
.check-list i { width: 16px; height: 16px; border: 2px solid #c4c6cf; border-radius: 50%; }
.check-list li.done { color: var(--ink); }
.check-list li.done i { border: 5px solid var(--green); }
.compliance-band { border-left: 4px solid var(--amber); border-radius: 5px; padding: 15px; background: #fff7e6; display: grid; gap: 6px; }
.compliance-band span { color: #72571f; font-size: 12px; line-height: 1.5; }

.modal { width: min(580px, calc(100% - 30px)); border: 0; border-radius: 8px; padding: 0; box-shadow: 0 30px 100px rgba(20,17,42,.28); }
.modal::backdrop { background: rgba(20,17,42,.58); }
.modal form { padding: 21px; display: grid; gap: 14px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 22px; }
.close-button { border: 0; background: transparent; font-size: 28px; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 380px; padding: 12px 15px; border-radius: 6px; color: white; background: #242137; box-shadow: 0 14px 40px rgba(0,0,0,.2); opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s; z-index: 100; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 1150px) {
  .inbox-layout { grid-template-columns: 280px minmax(380px, 1fr); }
  .detail-column { display: none; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-side { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -245px; width: 232px; transition: left .2s; box-shadow: 20px 0 50px rgba(0,0,0,.18); }
  .sidebar.open { left: 0; }
  .menu-button { display: block; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .topbar { padding: 13px 16px; }
  .connection-badge { display: none; }
  main { padding: 14px; }
  .inbox-view.active { height: calc(100vh - 112px); }
  .inbox-layout { grid-template-columns: minmax(0, 1fr); }
  .conversation-column { display: none; }
  .inbox-layout.chat-open .contact-column { display: none; }
  .inbox-layout.chat-open .conversation-column { display: block; }
  .conversation-content { height: 100%; }
  .back-button { display: block; }
  .settings-side { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 130px; padding: 28px; }
  .login-brand::after { display: none; }
  .login-panel { padding: 36px 0; }
  .topbar h2 { font-size: 20px; }
  .top-actions .button { padding: 9px 10px; font-size: 12px; }
  .metric-grid { gap: 8px; }
  .metric { min-height: 112px; padding: 14px; }
  .metric strong { font-size: 29px; }
  .dashboard-grid { gap: 9px; }
  .pipeline-summary, .inbox-summary { min-height: auto; padding: 15px; }
  .stage-row { grid-template-columns: 80px 1fr 26px; gap: 7px; }
  .field-grid { grid-template-columns: 1fr; }
  .settings-form { padding: 15px; }
  .webhook-box { grid-template-columns: 1fr; }
  .webhook-box button { grid-column: 1; grid-row: auto; justify-self: start; }
  .composer { grid-template-columns: 1fr auto; }
  .composer textarea { grid-column: 1 / -1; }
  .template-composer { grid-template-columns: 1fr; }
}

