:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: rgba(15, 23, 42, 0.09);
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-soft: #ecfdf5;
  --danger: #dc2626;
  --amber-soft: #fffbeb;
  --amber-border: #fde68a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: 'Inter', system-ui, sans-serif; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
.mono { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }

h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--text-secondary); }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; }
.brand-mark { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; margin-bottom: 16px; }
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); display: inline-block; }

/* App Shell */
.app-shell { display: grid; grid-template-columns: 240px 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; justify-content: space-between; padding: 16px 12px; }
.sidebar-top { display: flex; flex-direction: column; gap: 12px; }
.tenant-switcher { display: flex; flex-direction: column; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.tenant-switcher label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 0; background: transparent; color: var(--text-secondary); border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 500; text-align: left; transition: background 140ms var(--ease), color 140ms var(--ease); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-subtle); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--text-muted); }

/* Main */
.main-area { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.tab-panel { flex: 1; min-height: 0; overflow-y: auto; }
.page-pad { padding: 24px 28px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }

/* Inputs & Buttons */
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; font-size: 13.5px; color: var(--text); background: var(--surface); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid transparent; font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: background 140ms var(--ease), border-color 140ms var(--ease); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-subtle); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-subtle); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-full { width: 100%; }

.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; }

/* Inbox 3-Column */
.inbox-layout { display: grid; grid-template-columns: 310px 1fr 260px; height: 100%; overflow: hidden; }
.conv-list-pane { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.pane-header { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.filter-pills { display: flex; gap: 4px; }
.pill { flex: 1; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); font-size: 12px; font-weight: 500; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer; }
.pill.active { background: var(--text); color: #fff; border-color: var(--text); }

.conv-list { flex: 1; overflow-y: auto; }
.conv-item { padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--accent-soft); }
.conv-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badges { display: flex; gap: 6px; align-items: center; margin-top: 2px; }

.badge { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 5px; font-size: 11px; font-weight: 500; background: var(--surface-subtle); color: var(--text-secondary); }
.badge-bot { background: #eff6ff; color: #1d4ed8; }
.badge-open { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--amber-soft); color: #b45309; }

/* Chat Pane */
.chat-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-contact-name { font-weight: 600; font-size: 14.5px; }
.chat-contact-meta { font-size: 12px; color: var(--text-muted); }
.chat-header-actions { display: flex; gap: 8px; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; padding: 9px 12px; border-radius: var(--radius-md); font-size: 13.5px; border: 1px solid var(--border); }
.msg-inbound { align-self: flex-start; background: var(--surface); }
.msg-outbound { align-self: flex-end; background: var(--accent-soft); border-color: rgba(5, 150, 105, 0.2); }
.msg-internal { align-self: center; max-width: 85%; background: var(--amber-soft); border-color: var(--amber-border); font-size: 12.5px; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; display: flex; justify-content: space-between; gap: 12px; }
.msg-body { white-space: pre-wrap; word-break: break-word; }

.chat-composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.composer-modes { display: flex; gap: 6px; }
.mode-tab { border: 0; background: transparent; color: var(--text-muted); font-size: 12px; font-weight: 500; padding: 4px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.mode-tab.active { background: var(--surface-subtle); color: var(--text); }
.composer-row { display: flex; gap: 8px; }

.detail-pane { background: var(--surface); border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.detail-meta { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.detail-meta > div { display: flex; justify-content: space-between; font-size: 12.5px; }

/* Cards & Lists */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--border); }

.simple-list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.list-row:last-child { border-bottom: 0; }

.code-line { display: flex; align-items: center; justify-content: space-between; background: var(--surface-subtle); padding: 10px 12px; border-radius: var(--radius-sm); }
.code-block-wrap { margin-top: 8px; }
.code-block { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: 12px; line-height: 1.5; margin: 0; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 500px; max-height: 88vh; overflow-y: auto; padding: 20px; border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0; }
.qr-box img { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: var(--radius-md); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .inbox-layout { grid-template-columns: 1fr; }
  .detail-pane { display: none; }
  .split-grid { grid-template-columns: 1fr; }
}
