:root {
  --bg: #f2f3f7;
  --card-bg: #ffffff;
  --text: #1a1c23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --success: #22c55e;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

[data-theme="dark"] {
  --bg: #12131a;
  --card-bg: #1b1d27;
  --text: #e9eaf0;
  --text-muted: #9aa0ac;
  --border: #2a2d3a;
  --accent: #818cf8;
  --accent-soft: #262a45;
  --danger: #f87171;
  --danger-soft: #3a1f24;
  --success: #4ade80;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s, color .2s;
}

.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.status-widget {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  background: var(--bg); padding: 6px 12px; border-radius: 999px;
}
.status-widget .sep { opacity: .5; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.dot.online { background: var(--success); }
.dot.busy { background: #f59e0b; }
.dot.offline { background: var(--danger); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border); background: var(--card-bg);
  border-radius: 10px; width: 36px; height: 36px; cursor: pointer; font-size: 16px;
}

.bento {
  flex: 1; display: grid; gap: 16px; padding: 16px;
  grid-template-columns: 300px 1.6fr 260px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "dialogues chat process"
    "dialogues chat company";
  overflow: hidden;
}
.dialogues-panel { grid-area: dialogues; }
.chat-panel { grid-area: chat; }
.process-panel { grid-area: process; }
.company-panel { grid-area: company; overflow-y: auto; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.panel-header h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.badge {
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600;
}

.dialogues-list { overflow-y: auto; flex: 1; }
.dialogue-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.dialogue-item:hover { background: var(--bg); }
.dialogue-item.active { background: var(--accent-soft); }
.dialogue-item.needs-operator {
  background: var(--danger-soft);
  border-left: 3px solid var(--danger);
}
.dialogue-item .d-name { font-weight: 600; font-size: 14px; }
.dialogue-item .d-meta { font-size: 12px; color: var(--text-muted); }
.dialogue-item .d-flag { font-size: 11px; color: var(--danger); font-weight: 700; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 70%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.msg.user { background: var(--bg); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.ai { background: var(--accent-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.operator { background: var(--success); color: #06240f; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .msg-meta { font-size: 10px; opacity: .6; margin-top: 4px; }

.chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; background: var(--bg); color: var(--text); font-family: inherit;
}
.chat-input button, .company-form button, .login-card button {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 0 18px; font-weight: 600; cursor: pointer;
}
.chat-input button:disabled { opacity: .5; cursor: not-allowed; }

.ai-toggle { margin-left: auto; font-size: 12px; display: flex; align-items: center; gap: 6px; color: var(--text-muted); }

.process-log { list-style: none; margin: 0; padding: 10px 14px; overflow-y: auto; flex: 1; font-size: 12px; }
.process-log li { padding: 6px 0; border-bottom: 1px dashed var(--border); color: var(--text-muted); }
.process-log li .t { color: var(--text); }

.company-form { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.company-form label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.company-form input, .company-form textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 13px;
}
.company-form button { padding: 8px 0; }
.save-hint { font-size: 11px; color: var(--success); }

.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 320px; padding: 28px; gap: 12px; }
.login-card h1 { font-size: 18px; margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.login-card input {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  background: var(--bg); color: var(--text);
}
.login-card .error { color: var(--danger); font-size: 12px; min-height: 16px; }

@media (max-width: 1000px) {
  .bento {
    grid-template-columns: 1fr;
    grid-template-areas:
      "dialogues"
      "chat"
      "process"
      "company";
  }
}
