/* ============================================================
   SistemaConsultorio — Estilos globales
   ============================================================ */

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

:root {
  /* Paleta principal */
  --color-primary:       #1a6b8a;
  --color-primary-dark:  #0d4a63;
  --color-primary-light: #e8f4f8;
  --color-accent:        #2ecc9b;

  /* Grises */
  --color-bg:       #f0f4f8;
  --color-surface:  #ffffff;
  --color-border:   #e2e8f0;
  --color-text:     #1e293b;
  --color-muted:    #64748b;
  --color-subtle:   #94a3b8;

  /* Semánticos */
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger:  #dc2626;
  --color-info:    #0284c7;

  /* Sidebar */
  --sidebar-width:    240px;
  --sidebar-bg:       #0d4a63;
  --sidebar-text:     #cbd5e1;
  --sidebar-active:   #1a6b8a;
  --topbar-height:    56px;

  /* Tipografía */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', Consolas, monospace;

  /* Radios */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Sombras */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
}

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon { font-size: 1.5rem; }
.brand-name {
  font-size: .85rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  font-size: .9rem;
  color: var(--sidebar-text);
  transition: background .15s, color .15s;
  border-radius: 0;
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name {
  font-size: .82rem; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: .72rem; color: var(--sidebar-text); }
.btn-logout {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--sidebar-text);
  padding: 4px; border-radius: 4px;
  transition: color .15s;
  text-decoration: none;
}
.btn-logout:hover { color: #fff; }

/* ── Overlay (mobile) ──────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}

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

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--color-text); }
.menu-toggle {
  display: none;
  background: none; border: none;
  font-size: 1.3rem; cursor: pointer;
  color: var(--color-muted); padding: 4px;
}

.page-body { padding: 24px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .95rem; font-weight: 600; }
.card-body  { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  background: #fafbfc;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ── Stat cards (dashboard) ────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.stat-icon {
  font-size: 1.6rem;
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--color-primary-light);
  flex-shrink: 0;
}
.stat-info {}
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8rem; color: var(--color-muted); margin-top: 2px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); text-decoration: none; color: #fff; }
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; }
.btn-danger  { background: var(--color-danger);  color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { opacity: .85; text-decoration: none; color: #fff; }
.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-lg { padding: 11px 22px; font-size: 1rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .85rem; font-weight: 600; color: #374151;
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: .9rem; color: var(--color-text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
  font-family: var(--font-sans);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,107,138,.12);
}
.form-control::placeholder { color: var(--color-subtle); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: .78rem; color: var(--color-muted); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--color-danger); margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  background: #f8fafc;
  color: var(--color-muted);
  font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: .75rem; font-weight: 600;
  white-space: nowrap;
}
.badge-success   { background: #dcfce7; color: #166534; }
.badge-warning   { background: #fef9c3; color: #854d0e; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 16px;
}
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.alert-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }

/* ── Page header ────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 1.25rem; font-weight: 700; }

/* ── Search bar ─────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  flex: 1; max-width: 340px;
}
.search-bar input {
  border: none; outline: none; background: transparent;
  font-size: .9rem; width: 100%; color: var(--color-text);
}

/* ── Utilities ──────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-muted   { color: var(--color-muted); }
.text-center  { text-align: center; }
.text-danger  { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
  .main-content {
    margin-left: 0;
  }
  .menu-toggle {
    display: block;
  }
  .page-body {
    padding: 16px;
  }
  .form-row {
    flex-direction: column;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
