/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:    #2D7DD2;
  --brand-dk: #1a5fa0;
  --bg:       #FFFFFF;
  --sidebar:  #F4F6F8;
  --border:   #E2E8F0;
  --text:     #1A1A2E;
  --muted:    #6B7280;
  --success:  #16A34A;
  --danger:   #DC2626;
  --warning:  #D97706;
  --purple:   #7C3AED;
  --radius:   6px;
}

html, body { height: 100%; font-family: Inter, system-ui, sans-serif; font-size: 14px; line-height: 1.6; color: var(--text); background: var(--bg); }

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

/* ── Layout ───────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px; min-width: 240px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 6px;
}
.brand-name { font-size: 18px; font-weight: 600; color: var(--brand); }
.brand-tag  { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--text); font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(45,125,210,.08); color: var(--brand); text-decoration: none; }
.nav-link.active { background: rgba(45,125,210,.12); color: var(--brand); border-left-color: var(--brand); }
.nav-icon { font-size: 15px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-user-name { font-weight: 500; font-size: 13px; }
.sidebar-user-role  { font-size: 11px; color: var(--muted); text-transform: capitalize; margin-bottom: 8px; }
.btn-logout {
  font-size: 12px; color: var(--danger);
  padding: 4px 0;
}
.btn-logout:hover { text-decoration: underline; }

.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.top-bar {
  height: 56px; min-height: 56px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.top-bar-left { display: flex; align-items: center; gap: 12px; }
.page-title   { font-size: 16px; font-weight: 600; }
.clinic-name  { font-size: 13px; color: var(--muted); }
.sidebar-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  font-size: 12px; font-weight: 600; color: var(--brand-dk);
  cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
}
.btn-back .btn-back-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 11px; line-height: 1;
  transition: transform .15s;
}
.btn-back:hover {
  background: #EAF2FB; border-color: var(--brand);
  box-shadow: 0 1px 4px rgba(45, 125, 210, .25);
}
.btn-back:hover .btn-back-icon { transform: translateX(-2px); }
.btn-back:active { transform: scale(.96); }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Flash messages ───────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
}
.flash-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }
.flash-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }

/* ── Page header ──────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: none;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn-primary   { background: var(--brand); color: #fff; }
.btn-secondary { background: var(--sidebar); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-value { font-size: 28px; font-weight: 600; color: var(--brand); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Tables ───────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--sidebar);
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #F8FAFC; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Forms ────────────────────────────────────────── */
.form-wrapper { max-width: 640px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(45,125,210,.15); }
textarea.form-control { min-height: 120px; resize: vertical; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }

.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-danger { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }

/* ── Badges ───────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.badge-scheduled  { background: #DBEAFE; color: #1E40AF; }
.badge-confirmed  { background: #DCFCE7; color: #166534; }
.badge-completed  { background: #EDE9FE; color: #5B21B6; }
.badge-cancelled  { background: #F3F4F6; color: #6B7280; }
.badge-pending     { background: #FEF3C7; color: #92400E; }
.badge-in_progress { background: #DBEAFE; color: #1E40AF; }
.badge-no_show    { background: #FEE2E2; color: #991B1B; }
.badge-active     { background: #DCFCE7; color: #166534; }
.badge-inactive   { background: #F3F4F6; color: #6B7280; }
.badge-admin      { background: #FEF3C7; color: #92400E; }
.badge-professional { background: #DBEAFE; color: #1E40AF; }
.badge-receptionist { background: #E0E7FF; color: #3730A3; }
.badge-viewer     { background: #F3F4F6; color: #6B7280; }
.badge-paciente   { background: #D1FAE5; color: #065F46; }

/* ── Empty state ──────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── Search bar ───────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar .form-control { max-width: 320px; }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 100; transform: translateX(-100%); height: 100vh; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
