:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #11151a;
  --surface-2: #171c22;
  --surface-3: #1d242c;
  --line: #29313a;
  --text: #edf1f5;
  --muted: #8f9ba8;
  --brand: #42c2a6;
  --brand-soft: #153c35;
  --warning: #e5b567;
  --danger: #df7373;
  --sidebar: #171a1f;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; }
h2 { margin-bottom: 4px; font-size: 16px; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #0b0d10; }
.login-panel { width: min(380px, 100%); display: grid; gap: 15px; padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 8px; background: var(--brand-soft); color: var(--brand); }
.brand-mark svg { width: 24px; height: 24px; }
.login-panel label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.form-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }

.app { min-height: 100vh; }
.main-shell { min-height: 100vh; margin-left: 248px; transition: margin-left .2s ease; }
.sidebar.collapsed + * {}
.app:has(.sidebar.collapsed) .main-shell { margin-left: 72px; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); background: rgba(11, 13, 16, .94); position: sticky; top: 0; z-index: 4; }
.top-actions { display: flex; gap: 8px; }
.icon-button { width: 40px; height: 40px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); color: var(--text); }
.icon-button svg { width: 18px; height: 18px; }
.primary { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #43b99f; border-radius: 6px; background: var(--brand); color: #07120f; font-weight: 800; }
.soft-button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); color: var(--text); font-size: 12px; font-weight: 700; }
.soft-button:hover { border-color: #32665d; color: var(--brand); }
.soft-button svg { width: 15px; height: 15px; }

.sidebar { width: 248px; position: fixed; z-index: 5; inset: 0 auto 0 0; display: flex; flex-direction: column; padding: 16px 12px; border-right: 1px solid var(--line); background: var(--sidebar); transition: width .2s ease; }
.sidebar.collapsed { width: 72px; }
.profile { min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 4px; margin-bottom: 24px; overflow: hidden; }
.avatar { min-width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 800; }
.profile-copy { display: grid; gap: 2px; white-space: nowrap; }
.profile-copy strong { font-size: 13px; }
.profile-copy span { color: var(--muted); font-size: 11px; }
nav { display: grid; gap: 6px; }
.nav-item { width: 100%; height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); overflow: hidden; white-space: nowrap; }
.nav-item svg { min-width: 18px; width: 18px; height: 18px; }
.nav-item:hover, .nav-item.active { background: var(--surface-3); color: var(--text); }
.nav-item.active { color: var(--brand); }
.sidebar-bottom { margin-top: auto; }
.sidebar.collapsed .profile-copy, .sidebar.collapsed .nav-item span { display: none; }

.view { padding: 20px 24px 32px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { min-height: 88px; display: flex; align-items: center; justify-content: space-between; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.metric div { display: grid; gap: 5px; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 25px; }
.metric svg { width: 20px; color: var(--brand); }

.filters { display: grid; grid-template-columns: minmax(240px, 1fr) repeat(3, minmax(150px, 190px)); gap: 10px; margin-bottom: 16px; }
input, select, textarea { width: 100%; min-height: 40px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: var(--surface-2); color: var(--text); }
textarea { padding: 10px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
.search-field { position: relative; }
.search-field svg { width: 17px; position: absolute; top: 11px; left: 11px; color: var(--muted); }
.search-field input { padding-left: 36px; }

.inbox-layout { min-height: calc(100vh - 245px); display: grid; grid-template-columns: minmax(360px, 43%) 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.queue { border-right: 1px solid var(--line); min-width: 0; }
.section-heading { height: 64px; display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid var(--line); }
.section-heading p, .dashboard-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.lead-list { max-height: calc(100vh - 310px); overflow-y: auto; }
.lead-row { width: 100%; display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 14px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; }
.lead-row:hover, .lead-row.selected { background: var(--surface-2); }
.lead-row.selected { box-shadow: inset 3px 0 var(--brand); }
.lead-attended, .lead-contacted, .lead-quoted, .lead-won, .lead-lost { background: rgba(255, 255, 255, .018); opacity: .76; }
.lead-new { background: rgba(229, 181, 103, .035); }
.queue-index { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--muted); font-size: 11px; }
.lead-copy { min-width: 0; }
.lead-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lead-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.lead-copy p { margin: 7px 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.phone-action { width: fit-content; display: inline-flex; align-items: center; gap: 6px; margin-top: 7px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--brand); font-size: 11px; }
.phone-action svg, .detail-phone svg { width: 13px; height: 13px; }
.detail-phone { display: inline-flex; align-items: center; gap: 6px; color: var(--brand) !important; }
.lead-meta { display: flex; justify-content: space-between; gap: 8px; color: #6f7c89; font-size: 11px; }
.status { padding: 3px 6px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.status-new { background: #322b18; color: var(--warning); }
.status-attended, .status-contacted { background: #17313d; color: #70bee2; }
.status-quoted { background: #2d253e; color: #b39bea; }
.status-won { background: var(--brand-soft); color: var(--brand); }
.status-lost { background: #3b2022; color: var(--danger); }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge { padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; color: #aeb8c2; font-size: 10px; }

.conversation { min-width: 0; display: grid; grid-template-rows: auto auto auto auto 1fr auto; }
.conversation-head { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.conversation-head h2 { margin: 0; }
.conversation-head span { color: var(--muted); font-size: 11px; }
.conversation-controls { display: flex; gap: 8px; }
.conversation-controls select { min-width: 130px; }
.event-summary { min-height: 42px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.ai-tools { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(66, 194, 166, .035); }
.ai-panel { padding: 12px 16px; border-bottom: 1px solid var(--line); background: #10161a; }
.ai-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-header div { display: grid; gap: 2px; }
.ai-header small, .ai-next { color: var(--muted); }
.ai-text { margin: 10px 0; color: #d9e2ea; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.ai-missing { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.ai-missing span { padding: 3px 6px; border-radius: 4px; background: var(--surface-3); color: var(--warning); font-size: 11px; }
.message-stream { min-height: 320px; max-height: calc(100vh - 405px); display: flex; flex-direction: column; gap: 10px; padding: 18px; overflow-y: auto; background: #0e1115; }
.message { max-width: 75%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); }
.message.out { align-self: flex-end; border-color: #23594e; background: #12332c; }
.message p { margin: 0 0 5px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.message span { color: var(--muted); font-size: 10px; }
.reply-box { display: grid; grid-template-columns: 1fr 40px; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.empty-detail, .empty-state { display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); text-align: center; }
.empty-detail svg, .empty-state svg { width: 26px; height: 26px; }
.empty-detail { min-height: 420px; }
.empty-state { min-height: 220px; }

.dashboard-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dashboard-toolbar select { width: 180px; }
.performance { border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.rate { width: 120px; height: 5px; display: inline-block; margin-right: 8px; overflow: hidden; border-radius: 4px; background: var(--surface-3); vertical-align: middle; }
.rate span { height: 100%; display: block; background: var(--brand); }
small { color: var(--muted); }

.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.catalog-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.catalog-head { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.catalog-head h2 { margin: 0; }
.catalog-form { display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)); gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: rgba(66, 194, 166, .03); }
.package-form { grid-template-columns: repeat(4, minmax(140px, 1fr)); }
.catalog-form textarea, .catalog-form .checkline, .catalog-form button { grid-column: span 2; }
.package-form textarea { grid-column: span 2; }
.package-form .checkline, .package-form button { grid-column: span 4; }
.checkline { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.checkline input { width: auto; min-height: auto; }
.catalog-list { display: grid; }
.catalog-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.catalog-row:last-child { border-bottom: 0; }
.catalog-row strong { display: block; margin-bottom: 5px; font-size: 14px; }
.catalog-row span, .catalog-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.row-actions { display: flex; align-items: center; gap: 8px; }

@media (max-width: 1050px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .inbox-layout { grid-template-columns: 1fr; }
  .conversation { border-top: 1px solid var(--line); }
  .queue { border-right: 0; }
  .lead-list { max-height: 420px; }
  .catalog-grid { grid-template-columns: 1fr; }
  .package-form { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .package-form .checkline, .package-form button { grid-column: span 2; }
}
@media (max-width: 760px) {
  .main-shell, .app:has(.sidebar.collapsed) .main-shell { margin-left: 0; padding-bottom: 68px; }
  .sidebar, .sidebar.collapsed { width: 100%; height: 64px; inset: auto 0 0 0; flex-direction: row; align-items: center; border-top: 1px solid var(--line); border-right: 0; }
  .profile { display: none; }
  nav { display: flex; }
  .sidebar-bottom { margin: 0 0 0 auto; }
  .sidebar .nav-item span { display: none; }
  .topbar { padding: 0 16px; }
  .view { padding: 14px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 1fr; }
  .conversation-head { align-items: flex-start; flex-direction: column; }
  .conversation-controls { width: 100%; }
  .conversation-controls select { min-width: 0; }
  .catalog-form, .package-form { grid-template-columns: 1fr; }
  .catalog-form textarea, .catalog-form .checkline, .catalog-form button, .package-form textarea, .package-form .checkline, .package-form button { grid-column: span 1; }
  .catalog-row { grid-template-columns: 1fr; }
  .row-actions { flex-wrap: wrap; }
}
