:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #65726a;
  --line: #dfe5e1;
  --soft: #f4f7f5;
  --panel: #ffffff;
  --green: #087a4f;
  --green-dark: #05613e;
  --green-soft: #e7f5ee;
  --amber: #9b6a12;
  --amber-soft: #fff6dd;
  --red: #c9362b;
  --red-soft: #fceceb;
  --shadow: 0 14px 40px rgba(24, 46, 33, .10);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #eef3ef; color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(64, 162, 112, .22), transparent 32%),
    radial-gradient(circle at 85% 88%, rgba(214, 174, 84, .16), transparent 30%),
    #eff5f1;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--green);
  color: white;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(8, 122, 79, .24);
}
.brand-mark.small { width: 36px; height: 36px; border-radius: 11px; font-size: 17px; }
.login-card h1, .admin-head h1 { margin: 4px 0 8px; letter-spacing: -.035em; }
.login-card label { display: grid; gap: 7px; margin-top: 18px; font-size: 13px; font-weight: 700; color: #435047; }
.login-card input, .filters input, .filters select, select, input, textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  outline: none;
}
.login-card input { padding: 12px 13px; }
input:focus, select:focus, textarea:focus { border-color: #67ad8d; box-shadow: 0 0 0 3px rgba(8,122,79,.09); }
.eyebrow { margin: 18px 0 0; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.muted { color: var(--muted); }
.error { min-height: 18px; color: var(--red); font-size: 13px; }

.primary, .secondary, .icon-btn, .nav-btn {
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  font-weight: 750;
}
.primary { background: var(--green); color: white; }
.primary:hover { background: var(--green-dark); }
.secondary { background: var(--soft); color: #314038; border: 1px solid var(--line); }
.secondary:hover { background: #eaf0ec; }
.danger { color: var(--red) !important; }
.wide { width: 100%; padding: 12px; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0; background: none; border: 0; text-align: left; }
.brand strong, .brand small, .user-chip strong, .user-chip small { display: block; }
.brand strong { font-size: 14px; }
.brand small, .user-chip small { color: var(--muted); font-size: 10px; margin-top: 1px; }
.main-nav { display: flex; align-self: stretch; }
.nav-btn { border-radius: 0; background: transparent; color: var(--muted); border-bottom: 2px solid transparent; }
.nav-btn.active { color: var(--green); border-bottom-color: var(--green); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.business-picker { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.business-picker select { min-width: 170px; padding: 8px 30px 8px 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.user-chip strong { font-size: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #d9eee3; color: var(--green); display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.icon-btn { background: transparent; color: var(--muted); font-size: 12px; }

.inbox-layout { height: calc(100vh - 64px); display: grid; grid-template-columns: 370px minmax(0, 1fr); background: #f8faf8; }
.conversation-sidebar { background: white; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; justify-content: space-between; align-items: end; padding: 20px 18px 12px; }
.sidebar-head .eyebrow { margin: 0; }
.sidebar-head h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.count { min-width: 30px; padding: 5px 8px; border-radius: 15px; background: var(--green-soft); color: var(--green); text-align: center; font-size: 12px; font-weight: 800; }
.queue-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px 14px 10px; }
.queue { border: 0; border-radius: 8px; padding: 8px; background: var(--soft); color: var(--muted); font-size: 11px; font-weight: 750; }
.queue.active { background: var(--green-soft); color: var(--green); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 0 14px 12px; border-bottom: 1px solid var(--line); }
.filters input, .filters select { min-width: 0; padding: 8px; font-size: 11px; }
.conversation-list { overflow-y: auto; flex: 1; }
.conversation-item { width: 100%; border: 0; border-bottom: 1px solid #eef1ef; background: white; text-align: left; padding: 13px 15px; }
.conversation-item:hover, .conversation-item.active { background: #f0f8f4; }
.conversation-item.active { box-shadow: inset 3px 0 var(--green); }
.item-top, .item-meta, .detail-title { display: flex; align-items: center; gap: 7px; }
.item-top { justify-content: space-between; }
.item-top strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-time { color: #8b958e; font-size: 10px; flex: none; }
.item-number { margin: 4px 0 7px; color: var(--muted); font-size: 11px; }
.item-meta { flex-wrap: wrap; }
.badge, .tag, .status { display: inline-flex; align-items: center; border-radius: 999px; font-size: 10px; font-weight: 750; padding: 3px 7px; }
.badge.business { background: #e9eef9; color: #385b9a; }
.badge.channel { background: #edf1f3; color: #53636b; }
.badge.assigned { background: #f2eafb; color: #7944aa; }
.tag { background: #f0f2f1; color: #4f5c54; gap: 4px; }
.tag button { border: 0; padding: 0; background: none; color: inherit; }
.status.humano { background: var(--amber-soft); color: var(--amber); }
.status.bot { background: var(--green-soft); color: var(--green); }
.list-empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 13px; }

.empty-detail { display: grid; place-content: center; text-align: center; color: var(--muted); padding: 30px; }
.empty-detail h2 { color: var(--ink); margin: 12px 0 4px; }
.empty-detail p { max-width: 410px; }
.empty-icon { width: 54px; height: 54px; margin: auto; display: grid; place-items: center; border-radius: 18px; background: white; border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--green); font-size: 24px; }
.conversation-detail { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; background: #f5f8f6; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 20px; background: white; border-bottom: 1px solid var(--line); }
.mobile-back { display: none; border: 0; background: none; color: var(--green); font-size: 28px; padding: 0 4px; }
.detail-head h2 { margin: 0; font-size: 18px; }
.detail-head p { margin: 5px 0 0; font-size: 11px; }
.detail-actions { display: flex; gap: 8px; align-items: center; }
.detail-actions select { max-width: 190px; padding: 8px; font-size: 11px; }
.tag-row { min-height: 42px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 7px 20px; background: white; border-bottom: 1px solid var(--line); }
.tag-row input { width: 130px; padding: 5px 8px; font-size: 11px; }
.detail-tabs { height: 43px; display: flex; align-items: stretch; gap: 4px; padding: 0 18px; background: white; border-bottom: 1px solid var(--line); }
.detail-tab { border: 0; background: none; color: var(--muted); padding: 0 11px; font-size: 12px; font-weight: 750; border-bottom: 2px solid transparent; }
.detail-tab.active { color: var(--green); border-bottom-color: var(--green); }
.rating { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.rating button { width: 31px; height: 29px; border-radius: 8px; border: 1px solid var(--line); background: white; opacity: .65; }
.rating button.active { opacity: 1; border-color: #7ab796; background: var(--green-soft); }
.messages, .notes { overflow-y: auto; padding: 22px 24px; }
.message { max-width: min(680px, 78%); padding: 9px 12px; border-radius: 11px; margin-bottom: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.05); font-size: 13px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { background: white; border: 1px solid #e4e9e6; margin-right: auto; border-top-left-radius: 3px; }
.message.assistant, .message.humano { background: #dcf4e6; margin-left: auto; border-top-right-radius: 3px; }
.message.humano { background: #e6effb; }
.message small { display: block; margin-top: 5px; color: #77847c; font-size: 9px; text-align: right; }
.message a { color: #086d9c; text-decoration: underline; }
.notes { display: flex; flex-direction: column; gap: 9px; }
.note { max-width: 720px; background: #fffdf6; border: 1px solid #eee0b8; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.note small { display: block; color: #9a7b2f; font-weight: 700; margin-bottom: 4px; }
.composer, .note-form { position: relative; display: flex; gap: 9px; align-items: end; padding: 12px 18px; background: white; border-top: 1px solid var(--line); }
.composer textarea, .note-form textarea { flex: 1; resize: none; padding: 10px 12px; min-height: 42px; max-height: 130px; }
.shortcut-btn { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.shortcut-popover { position: absolute; left: 18px; bottom: 64px; width: 330px; max-height: 350px; overflow: auto; background: white; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); padding: 8px; z-index: 10; }
.shortcut-item { width: 100%; text-align: left; border: 0; border-radius: 8px; background: white; padding: 9px; }
.shortcut-item:hover { background: var(--soft); }
.shortcut-item strong, .shortcut-item small { display: block; }
.shortcut-item strong { color: var(--green); font-size: 11px; }
.shortcut-item small { color: var(--muted); margin-top: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.shortcut-manage { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 7px; }

.admin-view { min-height: calc(100vh - 64px); padding: 28px; max-width: 1500px; margin: auto; }
.admin-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.admin-head .eyebrow { margin: 0; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.admin-card { background: white; border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 5px 18px rgba(28, 48, 36, .04); }
.admin-card.full { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; gap: 15px; align-items: start; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 16px; }
.card-head p { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.admin-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; padding: 11px; background: var(--soft); border-radius: 11px; }
.admin-form.triple { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.admin-form input, .admin-form select { min-width: 0; padding: 8px 9px; font-size: 11px; }
.admin-form button { justify-self: start; }
.admin-list { display: flex; flex-direction: column; gap: 7px; }
.admin-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; border: 1px solid #edf0ee; border-radius: 9px; padding: 9px 10px; }
.admin-row strong, .admin-row small { display: block; }
.admin-row strong { font-size: 12px; }
.admin-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.row-actions { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; justify-content: end; }
.row-actions button { border: 0; background: var(--soft); color: #435047; padding: 5px 8px; border-radius: 7px; font-size: 10px; font-weight: 750; }
.secret-box { padding: 10px; border: 1px solid #e6d49d; background: #fff9e8; border-radius: 9px; overflow-wrap: anywhere; font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.status-pill { border-radius: 999px; padding: 5px 9px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-pill.ok { background: var(--green-soft); color: var(--green); }
.status-pill.warning { background: var(--amber-soft); color: var(--amber); }
.setup-warning { margin: 0 0 13px; padding: 10px 12px; border-radius: 9px; background: var(--amber-soft); color: #72501b; font-size: 11px; }
.meta-business-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.meta-business { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; border: 1px solid #e7ece9; border-radius: 10px; padding: 11px; }
.meta-business strong, .meta-business small { display: block; }
.meta-business strong { font-size: 12px; }
.meta-business small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.meta-business .primary { padding: 5px 8px; font-size: 10px; }
.meta-footnote { margin: 12px 0 0; color: var(--muted); font-size: 10px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: 420px; background: #183b2c; color: white; padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: 12px; }
.toast.error { background: #8f2d27; }

.demo-view {
  min-height: calc(100vh - 64px);
  padding: 28px;
  max-width: 1500px;
  margin: auto;
}
.demo-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 20px;
}
.demo-head h1 { margin: 4px 0 6px; }
.demo-head .eyebrow { margin: 0; }
.demo-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: end; }
.demo-pill { padding: 6px 9px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: 10px; font-weight: 800; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-card, .demo-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 17px;
  box-shadow: 0 5px 18px rgba(28, 48, 36, .04);
}
.metric-card span, .metric-card small { display: block; color: var(--muted); font-size: 11px; }
.metric-card strong { display: block; margin: 8px 0 5px; font-size: 28px; }
.demo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.demo-card h2 { margin: 0 0 13px; font-size: 16px; }
.demo-card p { border-bottom: 1px solid #edf0ee; padding-bottom: 10px; }
.demo-card p:last-child { border-bottom: 0; }
.demo-card p span { float: right; }
.table-wrap { overflow-x: auto; }
.demo-table { width: 100%; border-collapse: collapse; }
.demo-table th, .demo-table td { padding: 11px 9px; border-bottom: 1px solid #edf0ee; text-align: left; font-size: 12px; white-space: nowrap; }
.demo-table th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.compact { padding: 5px 8px; font-size: 10px; }
.kanban { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; }
.kanban-column { min-height: 420px; background: #e9efeb; border-radius: 13px; padding: 10px; }
.kanban-column > header { display: flex; justify-content: space-between; padding: 5px 4px 11px; font-size: 12px; }
.kanban-column > header span { width: 22px; height: 22px; display: grid; place-items: center; background: white; border-radius: 50%; font-size: 10px; }
.lead-card { background: white; border-radius: 10px; padding: 12px; margin-bottom: 8px; box-shadow: 0 2px 7px rgba(0,0,0,.04); }
.lead-card strong, .lead-card small, .lead-card b { display: block; }
.lead-card small { color: var(--muted); margin: 4px 0 10px; }
.lead-card b { font-size: 11px; }
.lead-card div { display: flex; justify-content: space-between; margin-top: 10px; }
.lead-card button { border: 0; border-radius: 7px; padding: 5px 7px; color: var(--green); background: var(--green-soft); font-size: 10px; font-weight: 750; }
body[data-crm-mode="demo"] .topbar { position: relative; }
body[data-crm-mode="demo"] .main-nav { overflow-x: auto; }
body[data-crm-mode="demo"] .nav-btn { white-space: nowrap; padding-inline: 10px; }

@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .brand span:last-child, .business-picker span, .user-chip span:last-child { display: none; }
  .business-picker select { min-width: 120px; max-width: 155px; }
  .inbox-layout { grid-template-columns: minmax(290px, 42%) minmax(0, 1fr); }
  .detail-head { align-items: start; }
  .detail-actions { flex-direction: column; align-items: stretch; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-card.full { grid-column: auto; }
  .meta-business-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .main-nav { display: none; }
  body[data-crm-mode="demo"] .main-nav {
    display: flex;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    height: 54px;
    padding: 0 8px;
    overflow-x: auto;
    background: white;
    border-top: 1px solid var(--line);
  }
  body[data-crm-mode="demo"] .nav-btn { flex: 0 0 auto; }
  body[data-crm-mode="demo"] .inbox-layout,
  body[data-crm-mode="demo"] .admin-view,
  body[data-crm-mode="demo"] .demo-view { padding-bottom: 70px; }
  .inbox-layout { display: block; height: calc(100vh - 64px); }
  .conversation-sidebar { height: 100%; }
  .conversation-detail { position: fixed; inset: 64px 0 0; z-index: 20; }
  .conversation-detail[hidden] { display: none !important; }
  .conversation-detail:not([hidden]) { display: grid; }
  .empty-detail { display: none; }
  .detail-head { padding: 11px 13px; }
  .mobile-back { display: block; }
  .detail-actions select { max-width: 130px; }
  .message { max-width: 90%; }
  .admin-view { padding: 16px; }
  .admin-form, .admin-form.triple { grid-template-columns: 1fr; }
  .demo-view { padding: 16px; }
  .demo-head { align-items: start; flex-direction: column; }
  .demo-grid, .metric-grid { grid-template-columns: 1fr; }
}
