:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #13231f;
  --muted: #64746f;
  --line: #dde6e2;
  --brand: #0b7a55;
  --brand-2: #075e54;
  --brand-soft: #e8f6f0;
  --danger: #c23b3b;
  --warning: #a66b00;
  --shadow: 0 10px 30px rgba(20, 45, 38, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(11,122,85,.14), transparent 28%),
    radial-gradient(circle at 90% 90%, rgba(7,94,84,.12), transparent 30%),
    var(--bg);
}
.login-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: white;
  font-weight: 900;
  font-size: 22px;
  margin-bottom: 18px;
}
.login-card h1 { margin: 0 0 8px; font-size: 26px; }
.login-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 750; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  padding: 12px 13px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11,122,85,.12);
}
.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 15px;
  font-weight: 800;
}
.primary-btn { background: var(--brand); color: white; }
.primary-btn:hover { background: var(--brand-2); }
.secondary-btn { background: var(--brand-soft); color: var(--brand-2); }
.ghost-btn { background: transparent; color: var(--text); border: 1px solid var(--line); }
.danger-btn { background: #fff0f0; color: var(--danger); }
.full { width: 100%; }
.login-note { margin-top: 16px !important; font-size: 12px; }
.legal-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 18px;
  font-size: 12px;
}
.legal-links a, .legal-page a { color: var(--brand-2); }
.legal-body {
  min-height: 100%;
  padding: 32px 18px;
  background:
    radial-gradient(circle at 10% 10%, rgba(11,122,85,.12), transparent 28%),
    var(--bg);
}
.legal-page {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  line-height: 1.65;
}
.legal-page h1 { margin: 18px 0 4px; line-height: 1.2; }
.legal-page h2 { margin: 28px 0 6px; font-size: 18px; }
.legal-page p, .legal-page li { color: #40514c; }
.legal-page ul { padding-left: 22px; }
.legal-back { font-weight: 800; text-decoration: none; }
.legal-updated { margin-top: 0; color: var(--muted) !important; font-size: 13px; }

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
}
.topbar {
  min-height: 68px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar .logo {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: white;
  display: grid; place-items: center;
  font-weight: 900;
}
.topbar-title { min-width: 0; }
.topbar-title strong { display: block; }
.topbar-title span { display: block; color: var(--muted); font-size: 12px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.connection-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 250px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 750;
}
.connection-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--warning); }
.connection-chip.connected .connection-dot { background: var(--brand); box-shadow: 0 0 0 3px rgba(11,122,85,.12); }
.connection-chip.error .connection-dot { background: var(--danger); }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: white; background: var(--brand);
  font-size: 12px; font-weight: 900;
}

.kpis {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 15px;
  box-shadow: 0 3px 14px rgba(20,45,38,.04);
}
.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi strong { display: block; margin-top: 4px; font-size: 26px; }

.workspace {
  padding: 0 18px 18px;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
}
.panel {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.queue-panel { display: grid; grid-template-rows: auto 1fr; }
.queue-toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
}
.search-wrap { position: relative; }
.search-wrap input {
  width: 100%;
  padding: 11px 12px 11px 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.search-wrap .search-icon {
  position: absolute; left: 13px; top: 50%;
  transform: translateY(-50%); color: var(--muted);
}
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters select {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: white;
}
.conversation-list { overflow: auto; }
.conversation-card {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: start;
}
.conversation-card:hover { background: #fafcfb; }
.conversation-card.active { background: var(--brand-soft); }
.contact-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #d9e8e2;
  display: grid; place-items: center;
  font-weight: 900; color: var(--brand-2);
}
.card-main { min-width: 0; }
.card-head { display: flex; align-items: center; gap: 6px; }
.card-head strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-snippet {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.card-meta { text-align: right; font-size: 11px; color: var(--muted); }
.badge-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.badge {
  display: inline-flex; align-items: center;
  border-radius: 999px; padding: 4px 7px;
  font-size: 10px; font-weight: 850;
  background: var(--surface-2); border: 1px solid var(--line);
}
.badge.pending { background: #fff6df; color: #815600; border-color: #f0d79c; }
.badge.open { background: #e8f6f0; color: #075e54; border-color: #bce3d3; }
.badge.waiting { background: #eaf1ff; color: #315b9a; border-color: #c7d8fa; }
.badge.resolved { background: #eef1f0; color: #58625f; }
.badge.high { background: #fff0f0; color: #a92e2e; border-color: #f0c2c2; }

.chat-panel { display: grid; grid-template-rows: auto 1fr auto; }
.empty-chat {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 30px;
}
.empty-chat strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.chat-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.chat-contact { min-width: 0; }
.chat-contact strong { display: block; }
.chat-contact span { color: var(--muted); font-size: 12px; }
.chat-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.chat-actions select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: white;
}
.messages {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(rgba(255,255,255,.88), rgba(255,255,255,.88)),
    radial-gradient(circle at 1px 1px, rgba(11,122,85,.15) 1px, transparent 0);
  background-size: auto, 22px 22px;
}
.message-row { display: flex; margin: 8px 0; }
.message-row.outbound { justify-content: flex-end; }
.message {
  max-width: min(680px, 82%);
  border-radius: 14px;
  padding: 10px 12px 7px;
  box-shadow: 0 2px 8px rgba(20,45,38,.07);
  background: white;
  border: 1px solid var(--line);
}
.message-row.outbound .message { background: #dcf8c6; border-color: #cceab9; }
.message-text { white-space: pre-wrap; line-height: 1.45; }
.message-meta { text-align: right; margin-top: 5px; font-size: 10px; color: var(--muted); }
.composer {
  padding: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
  background: white;
}
.service-window-warning {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid #f0d9a5;
  border-radius: 12px;
  background: #fff8e8;
  color: #765000;
  font-size: 12px;
  line-height: 1.4;
}
.composer textarea {
  min-height: 46px;
  max-height: 130px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px;
  outline: none;
}
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(11,122,85,.11); }
.composer button { align-self: end; height: 46px; }

.note-bar {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 2px;
}
.note-bar input {
  flex: 1;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}

.toast {
  position: fixed;
  right: 20px; bottom: 20px;
  background: #13231f; color: white;
  padding: 12px 15px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 50;
}
.mobile-back { display: none; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .workspace { grid-template-columns: 320px minmax(0,1fr); }
}
@media (max-width: 720px) {
  .topbar-title span, .user-chip .user-name { display: none; }
  .kpis { padding: 10px 12px; gap: 8px; }
  .kpi { padding: 11px; }
  .kpi strong { font-size: 21px; }
  .workspace {
    padding: 0 12px 12px;
    display: block;
  }
  .queue-panel, .chat-panel { height: calc(100vh - 214px); }
  .chat-panel { display: none; }
  .workspace.chat-open .queue-panel { display: none; }
  .workspace.chat-open .chat-panel { display: grid; }
  .mobile-back { display: inline-flex; }
  .chat-header { align-items: flex-start; }
  .chat-actions { gap: 5px; }
  .chat-actions .secondary-btn, .chat-actions .danger-btn { padding: 9px 10px; font-size: 12px; }
  .chat-actions select { max-width: 125px; font-size: 12px; }
  .message { max-width: 90%; }
}
