:root {
  --bg: #0F172A;
  --bg-card: #1E293B;
  --bg-input: #0F172A;
  --border: #334155;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --green: #22C55E;
  --green-bg: rgba(34,197,94,.12);
  --red: #EF4444;
  --red-bg: rgba(239,68,68,.12);
  --amber: #F59E0B;
  --amber-bg: rgba(245,158,11,.12);
  --purple: #A855F7;
  --purple-bg: rgba(168,85,247,.12);
  --blue-bg: rgba(59,130,246,.12);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform .2s;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 500;
  transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--blue-bg); color: var(--primary); }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.user-info { display: flex; justify-content: space-between; align-items: center; }
.user-name { font-size: .875rem; font-weight: 500; }
.logout-link { font-size: .75rem; color: var(--text-muted); }

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px;
  cursor: pointer;
}

/* Main */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 24px;
  max-width: 1200px;
}
.main-full {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.header-actions { display: flex; gap: 8px; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-header h2 { margin-bottom: 0; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--blue-bg); color: var(--primary); }
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon.amber { background: var(--amber-bg); color: var(--amber); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* Dashboard grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

/* Detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(51,65,85,.5);
}
tbody tr:hover { background: rgba(255,255,255,.02); }

/* Detail list */
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.detail-list dt { color: var(--text-muted); font-size: .875rem; }
.detail-list dd { font-size: .875rem; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-blue { background: var(--blue-bg); color: var(--primary); }
.badge-gray { background: rgba(100,116,139,.2); color: #94A3B8; }
.badge-red { background: var(--red-bg); color: var(--red); }

.capability-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 500;
  background: rgba(255,255,255,.06);
  color: var(--text-muted);
  margin-right: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: rgba(255,255,255,.08); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,.12); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-xs { padding: 4px 10px; font-size: .75rem; }
.btn-full { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .875rem;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea { resize: vertical; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 120px; }
.search-form { margin-bottom: 16px; }

.password-wrapper { position: relative; }
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

/* Alerts */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: .875rem;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,.2); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,.2); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 12px; }

/* Text utilities */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.text-link { font-size: .875rem; }
.font-mono { font-family: "SF Mono", "Menlo", "Consolas", monospace; font-size: .85em; }

/* Messages */
.message-list { display: flex; flex-direction: column; }
.message-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(51,65,85,.5);
}
.message-item:last-child { border-bottom: none; }
.message-direction { flex-shrink: 0; padding-top: 2px; }
.message-meta { display: flex; justify-content: space-between; font-size: .8rem; margin-bottom: 2px; }
.message-text { font-size: .875rem; color: var(--text-muted); }

/* Thread list */
.thread-list { display: flex; flex-direction: column; }
.thread-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid rgba(51,65,85,.5);
  color: var(--text);
  transition: background .1s;
}
.thread-item:hover { background: rgba(255,255,255,.03); text-decoration: none; }
.thread-item:last-child { border-bottom: none; }
.thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 600;
  flex-shrink: 0;
}
.thread-body { flex: 1; min-width: 0; }
.thread-header { display: flex; justify-content: space-between; gap: 8px; }
.thread-contact { font-weight: 500; font-size: .875rem; }
.thread-time { font-size: .75rem; color: var(--text-muted); flex-shrink: 0; }
.thread-preview { font-size: .8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-from { margin-right: 4px; }
.unread-badge {
  background: var(--primary);
  color: white;
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  height: calc(100vh - 180px);
  min-height: 400px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: .875rem;
}
.chat-bubble.outbound {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-bubble.inbound {
  align-self: flex-start;
  background: rgba(255,255,255,.08);
  border-bottom-left-radius: 4px;
}
.bubble-meta {
  font-size: .7rem;
  opacity: .6;
  margin-top: 4px;
}
.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input textarea {
  flex: 1;
  padding: 10px 12px;
  min-height: 42px;
  max-height: 120px;
}
.chat-input .btn { align-self: flex-end; }

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.6);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

/* Login */
.login-page { width: 100%; max-width: 400px; padding: 24px; }
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
}
.login-logo { margin-bottom: 16px; }
.login-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 24px; }
.login-card form { text-align: left; }

/* Action list */
.action-list { display: flex; flex-direction: column; gap: 8px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: block; }
  .main-content { margin-left: 0; padding: 16px; padding-top: 56px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 1.25rem; }
  .form-row { flex-direction: column; }
  .chat-container { height: calc(100vh - 160px); }
  table { font-size: .8rem; }
  thead th, tbody td { padding: 8px 8px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 12px; }
}
