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

:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e8ecf1;
  --text: #1e2a3a;
  --text-muted: #6b7a8d;
  --accent: #4361ee;
  --accent-hover: #3651d4;
  --accent-light: #eef1fd;
  --green: #10b981;
  --green-light: #ecfdf5;
  --red: #ef4444;
  --red-light: #fef2f2;
  --yellow: #f59e0b;
  --yellow-light: #fffbeb;
  --sidebar-width: 240px;
  --header-height: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Auth Screen ─── */
.auth-screen { display: none; min-height: 100vh; background: var(--bg); align-items: center; justify-content: center; }
.auth-screen.active { display: flex; }

.auth-box {
  width: 100%; max-width: 400px; padding: 2.5rem;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon {
  width: 48px; height: 48px; background: var(--accent-light); border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 0.75rem;
}
.auth-logo h1 { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

.auth-form h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 1.25rem; text-align: center; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.03em; }

input, select, textarea {
  width: 100%; padding: 0.65rem 0.85rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 0.9rem; font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67,97,238,0.12);
}
textarea { resize: vertical; min-height: 80px; }

.btn-primary {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 1.25rem; background: var(--accent); color: white;
  border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-full { width: 100%; justify-content: center; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 1.25rem; background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem;
  cursor: pointer; transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8rem; border-radius: 6px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm.btn-primary { background: var(--accent); color: white !important; border-color: var(--accent) !important; }
.btn-sm.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red) !important; border-color: var(--red) !important; }
.btn-danger:hover { background: var(--red-light) !important; }

.auth-switch { text-align: center; margin-top: 1.25rem; font-size: 0.85rem; color: var(--text-muted); }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error { color: var(--red); font-size: 0.85rem; text-align: center; margin-top: 0.75rem; min-height: 1.2em; }

/* ─── Dashboard Layout ─── */
.dashboard-layout { display: flex; min-height: 100vh; }

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width); background: var(--surface);
  border-right: 1px solid var(--border); position: fixed; top: 0; left: 0; bottom: 0;
  display: flex; flex-direction: column; z-index: 10;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1.25rem 1.25rem; border-bottom: 1px solid var(--border);
}
.logo-icon-sm {
  width: 36px; height: 36px; background: var(--accent-light); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-text { font-weight: 700; font-size: 1.05rem; color: var(--text); }

.sidebar-section { padding: 1rem 0.75rem; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); }
.sidebar-label {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted); padding: 0 0.5rem; margin-bottom: 0.5rem;
}

.sidebar-link {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.6rem 0.75rem; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 0.88rem; font-weight: 450;
  transition: all 0.12s; margin-bottom: 2px;
}
.sidebar-link:hover { color: var(--text); background: var(--bg); }
.sidebar-link.active { color: var(--accent); background: var(--accent-light); font-weight: 550; }
.sidebar-link svg { flex-shrink: 0; }

/* ─── Main Content ─── */
.main-content {
  margin-left: var(--sidebar-width); flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ─── Top Header ─── */
.top-header {
  height: var(--header-height); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; flex-shrink: 0;
}
.header-left h2 { font-size: 1.15rem; font-weight: 600; }
.header-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 1px; }

.header-user { display: flex; align-items: center; gap: 0.65rem; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: white; font-size: 0.75rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 0.85rem; font-weight: 550; }
.user-email { font-size: 0.72rem; color: var(--text-muted); }

/* ─── Tab Content ─── */
.tab-content { display: none; padding: 1.5rem 2rem 3rem; flex: 1; }
.tab-content.active { display: block; }

.tab-actions {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem;
}

/* ─── Stat Cards Row ─── */
.stat-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; box-shadow: var(--shadow);
}
.stat-card.accent { border-left: 3px solid var(--accent); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.35rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }

/* ─── Cards ─── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 0.95rem; font-weight: 600; }
.card-subtitle { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.card-actions { display: flex; gap: 0.5rem; }

/* ─── Chart Row ─── */
.chart-row { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.chart-card { min-height: 240px; }
.chart-card.wide { /* takes 2fr */ }
.chart-area { min-height: 180px; display: flex; align-items: center; justify-content: center; }
.donut-area { min-height: 160px; display: flex; align-items: center; justify-content: center; }

/* ─── Bottom Row ─── */
.bottom-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.bottom-row.four-col { grid-template-columns: repeat(4, 1fr); }

/* ─── Empty State ─── */
.empty-state { color: var(--text-muted); font-size: 0.85rem; font-style: italic; text-align: center; padding: 1rem 0; }

/* ─── Data Table ─── */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
.data-table th {
  text-align: left; padding: 0.6rem 0.85rem; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
  font-weight: 600; background: var(--bg); border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #fafbfd; }

.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.inbound { background: #dbeafe; color: #1d4ed8; }
.badge.outbound { background: #fef3c7; color: #b45309; }
.badge.completed { background: var(--green-light); color: #059669; }
.badge.failed { background: var(--red-light); color: var(--red); }

.data-table td button {
  padding: 0.3rem 0.6rem; font-size: 0.78rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); cursor: pointer;
}
.data-table td button:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Form Grids ─── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }

/* ─── Input With Button ─── */
.input-with-btn { display: flex; gap: 0.5rem; align-items: flex-start; }
.input-with-btn input, .input-with-btn select, .input-with-btn textarea { flex: 1; }
.input-with-btn button {
  padding: 0.65rem 1rem; background: var(--accent); color: white;
  border: none; border-radius: 8px; font-size: 0.82rem; cursor: pointer;
  white-space: nowrap; flex-shrink: 0; transition: background 0.15s;
}
.input-with-btn button:hover { background: var(--accent-hover); }
.input-with-btn button.saved { background: var(--green); }

.input-lg { font-size: 1rem !important; padding: 0.75rem 1rem !important; }

/* ─── Search Input ─── */
.search-input { max-width: 280px; }

/* ─── Slider ─── */
.slider-wrap { margin: 0.5rem 0; }
.slider-wrap input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 6px;
  background: var(--border); border-radius: 3px; outline: none; border: none;
}
.slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
}
.slider-wrap input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; background: var(--accent);
  border-radius: 50%; cursor: pointer; border: none;
}
.slider-meta { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ─── Card Grid ─── */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

/* ─── Contact Card ─── */
.contact-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; cursor: pointer; box-shadow: var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.contact-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.contact-card .contact-name { font-weight: 600; font-size: 1rem; margin-bottom: 0.15rem; }
.contact-card .contact-phone { font-size: 0.82rem; color: var(--accent); margin-bottom: 0.35rem; }
.contact-card .contact-meta { font-size: 0.78rem; color: var(--text-muted); }
.contact-card .contact-greeting { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; font-style: italic; }

/* ─── Agent Card ─── */
.agent-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; box-shadow: var(--shadow);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.agent-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.agent-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; }
.agent-name { font-weight: 600; font-size: 1.05rem; }
.agent-meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.agent-prompt { font-size: 0.82rem; color: var(--text); line-height: 1.45; margin-bottom: 0.5rem;
  background: var(--bg); border-radius: 6px; padding: 0.5rem 0.75rem; }
.agent-greeting { font-size: 0.78rem; color: var(--text-muted); font-style: italic; margin-bottom: 0.5rem; }
.agent-features { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
.feature-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; font-weight: 600; background: #e8f0fe; color: #1a56db; }
.agent-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* ─── Detail Rows ─── */
.detail-rows {}
.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text-muted); font-weight: 450; }
.detail-row .value { font-weight: 500; text-align: right; max-width: 60%; word-break: break-word; min-width: 0; }

/* Stacked detail rows for narrow cards */
.bottom-row .detail-row {
  flex-direction: column; align-items: flex-start; gap: 0.15rem;
}
.bottom-row .detail-row .value { text-align: left; max-width: 100%; }
.detail-row .value.green { color: var(--green); }

/* ─── Schedule Card ─── */
.schedule-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; box-shadow: var(--shadow);
}
.schedule-card .sched-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; }
.schedule-card .sched-name { font-weight: 600; font-size: 1rem; }
.schedule-card .sched-detail { font-size: 0.82rem; color: var(--accent); margin-bottom: 0.25rem; }
.schedule-card .sched-brief { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.35rem; }
.schedule-card .sched-next { font-size: 0.78rem; color: var(--green); font-weight: 500; margin-bottom: 0.5rem; }
.schedule-card .sched-actions { display: flex; gap: 0.5rem; }

.badge-active { background: var(--green-light); color: #059669; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; border: none; cursor: pointer; }
.badge-paused { background: var(--bg); color: var(--text-muted); padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; border: 1px solid var(--border); cursor: pointer; }

/* ─── Usage Banner ─── */
.usage-banner {
  border-radius: var(--radius); padding: 0.85rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; font-size: 0.88rem;
}
.usage-banner.max-plan {
  background: linear-gradient(135deg, #eef1fd 0%, #e8ecfd 100%);
  border: 1px solid #c7d2fe;
}
.usage-banner.api-mode {
  background: linear-gradient(135deg, #fef9ec 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
}
.usage-badge {
  padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.72rem;
  font-weight: 700; white-space: nowrap;
}
.usage-badge.max { background: var(--accent); color: white; }
.usage-badge.api { background: var(--yellow); color: #78350f; }

/* ─── Usage Bar ─── */
.usage-bar { height: 8px; background: var(--bg); border-radius: 4px; margin: 0.5rem 0; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.usage-bar-fill.low { background: var(--green); }
.usage-bar-fill.mid { background: var(--yellow); }
.usage-bar-fill.high { background: var(--red); }

/* ─── Dial Form ─── */
.dial-form { display: flex; gap: 0.75rem; align-items: center; }
.dial-form input { flex: 1; }
.status-msg { margin-top: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

/* ─── Modal ─── */
.modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 100;
  justify-content: center; align-items: center;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--surface); border-radius: var(--radius);
  padding: 2rem; max-width: 640px; width: 92%;
  max-height: 80vh; overflow-y: auto; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: none; border: none; color: var(--text-muted);
  font-size: 1.5rem; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }

.transcript-msg { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.transcript-msg:last-child { border-bottom: none; }
.transcript-msg .role {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 600; margin-bottom: 0.2rem;
}
.transcript-msg .role.user { color: var(--accent); }
.transcript-msg .role.assistant { color: var(--green); }
.transcript-msg .text { font-size: 0.88rem; line-height: 1.5; }

/* ─── Insights List ─── */
.insights-list {}
.insight-item {
  display: flex; gap: 0.65rem; padding: 0.6rem 0;
  border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.insight-item:last-child { border-bottom: none; }
.insight-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.insight-text { color: var(--text); }

/* ─── Table Area ─── */
.table-area { max-height: 300px; overflow-y: auto; }

/* ─── SMS ─── */
.sms-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1rem; align-items: start; }
.sms-list-card { max-height: 600px; overflow-y: auto; }
.sms-conv-item { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; }
.sms-conv-item:hover { background: var(--hover); }
.sms-conv-item.active { background: #eef2ff; border-left: 3px solid var(--accent); }
.sms-conv-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.sms-conv-name { font-weight: 600; font-size: 0.88rem; }
.sms-conv-time { font-size: 0.72rem; color: var(--text-muted); }
.sms-conv-preview { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sms-conv-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.15rem; }

.sms-thread-card { display: flex; flex-direction: column; }
.sms-messages { flex: 1; max-height: 450px; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.sms-bubble { max-width: 75%; padding: 0.6rem 0.9rem; border-radius: 1rem; font-size: 0.88rem; line-height: 1.4; }
.sms-bubble.inbound { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 0.25rem; }
.sms-bubble.outbound { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 0.25rem; }
.sms-bubble-meta { font-size: 0.68rem; margin-top: 0.2rem; opacity: 0.7; }
.sms-bubble.outbound .sms-bubble-meta { color: rgba(255,255,255,0.7); }
.sms-reply-bar { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); }
.sms-reply-bar input { flex: 1; }

@media (max-width: 900px) {
  .sms-layout { grid-template-columns: 1fr; }
}

/* ─── Responsive ─── */
@media (max-width: 1200px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .bottom-row { grid-template-columns: 1fr; }
  .bottom-row.four-col { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; }
  .top-header { padding: 0 1rem; }
  .tab-content { padding: 1rem; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .header-user .user-info { display: none; }
}

@media (max-width: 600px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
}
