:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --nav-bg: #1e293b;
  --radius: 8px;
}

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

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; }

/* ─── Login ─────────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%); }
.login-box { background: white; border-radius: 16px; padding: 40px; width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { font-size: 48px; text-align: center; margin-bottom: 8px; }
.login-box h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; }

/* ─── Navbar ─────────────────────────────────────────────────────────────── */
.navbar { background: var(--nav-bg); color: white; padding: 0 24px;
  display: flex; align-items: center; gap: 24px; height: 56px; position: sticky; top: 0; z-index: 100; }
.nav-brand { font-size: 18px; font-weight: 700; margin-right: auto; }
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a { color: rgba(255,255,255,.75); text-decoration: none; padding: 6px 12px;
  border-radius: var(--radius); transition: all .15s; font-size: 13px; }
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,.15); color: white; }
.btn-logout { color: rgba(255,255,255,.6) !important; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.main-content { padding: 24px; max-width: 1200px; margin: 0 auto; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header h2 { font-size: 22px; flex: 1; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group textarea, .form-select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; outline: none; transition: border-color .15s; }
.form-group input:focus, .form-group textarea:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-select { cursor: pointer; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--radius); border: none; cursor: pointer; font-size: 14px;
  font-weight: 500; text-decoration: none; transition: all .15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 11px; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 24px; }
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-decoration: none; color: var(--text); transition: all .15s; }
.card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(37,99,235,.1); }
.card-active { border-left: 4px solid var(--success); }
.card-done { border-left: 4px solid var(--text-muted); opacity: .8; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-id { font-weight: 700; font-size: 15px; }
.card-patient { font-size: 13px; margin-bottom: 4px; }
.card-date { font-size: 12px; color: var(--text-muted); }
.section-title { font-size: 15px; font-weight: 600; color: var(--text-muted);
  margin: 20px 0 12px; text-transform: uppercase; letter-spacing: .5px; }

/* ─── Stats ──────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 16px; text-align: center; }
.stat-card.stat-green { border-top: 3px solid var(--success); }
.stat-card.stat-blue { border-top: 3px solid var(--primary); }
.stat-card.stat-yellow { border-top: 3px solid var(--warning); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ─── Table ──────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; background: var(--card-bg);
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.data-table th { background: #f1f5f9; padding: 10px 14px; text-align: left;
  font-weight: 600; font-size: 12px; color: var(--text-muted); text-transform: uppercase; }
.data-table td { padding: 10px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: #f8fafc; }
.row-inactive td { opacity: .5; }
.actions { display: flex; gap: 6px; }

/* ─── Status Badges ──────────────────────────────────────────────────────── */
.status-badge, .stage-badge, .badge {
  display: inline-block; padding: 3px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; }
.status-active { background: #dcfce7; color: #16a34a; }
.status-waiting, .status-waiting_doctor { background: #fef9c3; color: #92400e; }
.status-done, .status-completed { background: #e2e8f0; color: #475569; }
.status-anamnesis { background: #dbeafe; color: #1d4ed8; }
.status-payment_pending { background: #fce7f3; color: #9d174d; }
.stage-started { background: #f1f5f9; color: #475569; }
.stage-anamnesis { background: #dbeafe; color: #1d4ed8; }
.stage-payment_pending { background: #fce7f3; color: #9d174d; }
.stage-completed { background: #dcfce7; color: #16a34a; }
.badge { background: var(--primary); color: white; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 12px;
       font-size: 12px; background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.nav-badge { display: inline-block; background: #ef4444; color: white;
             border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 700;
             vertical-align: middle; margin-left: 3px; }

/* ─── Chat ───────────────────────────────────────────────────────────────── */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; height: calc(100vh - 120px); }
.anamnesis-panel { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; overflow-y: auto; }
.anamnesis-panel h3 { margin-bottom: 16px; font-size: 15px; }
.anamnesis-card { margin-bottom: 16px; }
.anamnesis-item { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.anamnesis-item .label { font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; }
.anamnesis-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.anamnesis-status { margin-bottom: 12px; }

.chat-container { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.chat-header { padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex;
  flex-direction: column; gap: 10px; }
.message { display: flex; flex-direction: column; max-width: 70%; }
.message-patient { align-self: flex-start; }
.message-doctor { align-self: flex-end; }
.message-bubble { padding: 10px 14px; border-radius: 12px; line-height: 1.5; word-break: break-word; }
.message-patient .message-bubble { background: #f1f5f9; border-bottom-left-radius: 3px; }
.message-doctor .message-bubble { background: var(--primary); color: white; border-bottom-right-radius: 3px; }
.message-time { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.message-doctor .message-time { text-align: right; }
.chat-input-area { padding: 12px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end; }
.chat-input-area textarea { flex: 1; resize: none; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
.chat-closed { padding: 12px; text-align: center; color: var(--text-muted);
  border-top: 1px solid var(--border); font-style: italic; }

/* ─── Funnel ─────────────────────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.funnel-step { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.funnel-label { flex: 1; font-size: 13px; }
.funnel-count { font-weight: 700; font-size: 18px; width: 50px; text-align: right; }
.funnel-bar { height: 6px; background: var(--primary); border-radius: 3px; min-width: 4px; }

/* ─── Misc ───────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.text-muted { color: var(--text-muted); }
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; }
.broadcast-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 24px; }
.broadcast-form { background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; max-width: 600px; }
.broadcast-form h3 { margin-bottom: 20px; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: white; border-radius: 12px; padding: 28px;
  width: 420px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-content h3 { margin-bottom: 20px; }
