/* ============================================================
   Cartella Clinica Ostetrico-Pediatrica — Main CSS
   ============================================================ */

:root {
  --primary:      #1a6fc4;
  --primary-dark: #145599;
  --primary-light:#e8f1fb;
  --secondary:    #2ecc71;
  --danger:       #e74c3c;
  --warning:      #f39c12;
  --info:         #3498db;
  --dark:         #1e2a38;
  --gray-900:     #212529;
  --gray-700:     #495057;
  --gray-500:     #adb5bd;
  --gray-200:     #e9ecef;
  --gray-100:     #f8f9fa;
  --white:        #ffffff;
  --sidebar-w:    260px;
  --topbar-h:     60px;
  --radius:       8px;
  --shadow:       0 2px 8px rgba(0,0,0,.10);
  --shadow-md:    0 4px 16px rgba(0,0,0,.14);
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.6;
}

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

/* ---- LAYOUT ---- */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-logo h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.4;
}

.sidebar-logo span {
  font-size: 11px;
  color: var(--gray-500);
  display: block;
  margin-top: 2px;
}

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

.nav-section {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gray-500);
  padding: 12px 24px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  color: rgba(255,255,255,.75);
  font-size: 13.5px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.07);
  color: var(--white);
  text-decoration: none;
  border-left-color: var(--primary);
}

.nav-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
  color: var(--gray-500);
}

.sidebar-footer strong { color: var(--white); display: block; }

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-title { font-size: 16px; font-weight: 600; color: var(--dark); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.lang-switcher { display: flex; gap: 4px; }

.lang-btn {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
  background: var(--white);
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
}

.lang-btn.active, .lang-btn:hover {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
  text-decoration: none;
}

/* Main content */
.main {
  margin-left: var(--sidebar-w);
  padding-top: var(--topbar-h);
  min-height: 100vh;
  flex: 1;
}

.page-content { padding: 28px 32px; }

/* ---- CARDS ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--dark);
}

/* ---- STAT CARDS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue   { background: #e8f1fb; }
.stat-icon.green  { background: #e8f8ef; }
.stat-icon.orange { background: #fef3e2; }
.stat-icon.red    { background: #fdecea; }

.stat-num { font-size: 28px; font-weight: 800; color: var(--dark); line-height: 1; }
.stat-lbl { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { opacity: .88; text-decoration: none; }

.btn-primary   { background: var(--primary); color: var(--white); border-color: var(--primary); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); border-color: var(--gray-200); }
.btn-success   { background: var(--secondary); color: var(--white); border-color: var(--secondary); }
.btn-danger    { background: var(--danger); color: var(--white); border-color: var(--danger); }
.btn-warning   { background: var(--warning); color: var(--white); border-color: var(--warning); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-lg        { padding: 12px 24px; font-size: 15px; }

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

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.form-label .req { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  font-family: var(--font);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,111,196,.12);
}

textarea.form-control { resize: vertical; min-height: 90px; }

select.form-control { cursor: pointer; }

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 8px;
  margin-top: 8px;
  border-top: 1px solid var(--gray-200);
}

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.table th, table.table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

table.table th {
  background: var(--gray-100);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-700);
  white-space: nowrap;
}

table.table tbody tr:hover { background: var(--primary-light); }

table.table td .actions { display: flex; gap: 6px; }

/* ---- BADGES ---- */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #e8f8ef; color: #1a8a4a; }
.badge-warning { background: #fef3e2; color: #b36a00; }
.badge-danger  { background: #fdecea; color: #c0392b; }
.badge-gray    { background: var(--gray-200); color: var(--gray-700); }

/* ---- ALERTS / FLASH ---- */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 13.5px;
  border-left: 4px solid;
}

.alert-success { background: #e8f8ef; border-color: var(--secondary); color: #1a8a4a; }
.alert-error   { background: #fdecea; border-color: var(--danger); color: #c0392b; }
.alert-warning { background: #fef3e2; border-color: var(--warning); color: #b36a00; }
.alert-info    { background: #e8f1fb; border-color: var(--info); color: #1a5a99; }

/* ---- SEARCH BAR ---- */
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-bar .form-control { max-width: 320px; }

/* ---- PAGINATION ---- */
.pagination { display: flex; gap: 6px; margin-top: 20px; justify-content: center; }

.page-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
  font-size: 13px;
  background: var(--white);
  text-decoration: none;
}

.page-btn:hover, .page-btn.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
  text-decoration: none;
}

/* ---- BREADCRUMB ---- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 20px;
}

.breadcrumb a { color: var(--primary); }
.breadcrumb .sep { color: var(--gray-500); }
.breadcrumb .current { color: var(--gray-700); font-weight: 600; }

/* ---- TABS ---- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--gray-200); margin-bottom: 24px; }

.tab-btn {
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--gray-500);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  text-decoration: none;
  transition: color .15s;
}

.tab-btn:hover { color: var(--primary); text-decoration: none; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- LOGIN PAGE ---- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e2a38 0%, #1a6fc4 100%);
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img {
  display: block;
  margin: 0 auto 12px;
  filter: drop-shadow(0 4px 12px rgba(26,111,196,.25));
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--dark);
  line-height: 1.3;
}

.login-logo p {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ---- ERROR PAGE ---- */
body.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
}

.error-card {
  text-align: center;
  padding: 60px 40px;
}

.error-code {
  font-size: 80px;
  font-weight: 900;
  color: var(--primary);
  display: block;
  line-height: 1;
}

.error-card h1 { font-size: 24px; margin: 12px 0 8px; }
.error-card p  { color: var(--gray-500); margin-bottom: 24px; }

/* ---- PATIENT HEADER ---- */
.patient-header {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.patient-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  flex-shrink: 0;
}

.patient-info h2 { font-size: 18px; font-weight: 700; }
.patient-info p  { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ---- TIMELINE ---- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--gray-200);
}

.timeline-item { position: relative; margin-bottom: 24px; }

.timeline-dot {
  position: absolute;
  left: -24px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--primary);
}

.timeline-date { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; }
.timeline-content { background: var(--gray-100); border-radius: 6px; padding: 12px 16px; }

/* ---- MODAL / REMINDER POPUP ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: modal-fade .15s ease-out;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--white);
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  width: 100%; max-width: 580px;
  max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column;
  animation: modal-pop .18s ease-out;
}
@keyframes modal-pop { from { transform: translateY(8px) scale(.98); } to { transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: transparent; border: 0; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--gray-500);
  padding: 0 4px;
}
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px; border-top: 1px solid var(--gray-200);
  background: var(--gray-100);
}
.reminder-intro { color: var(--gray-700); font-size: 14px; margin-bottom: 14px; }
.reminder-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.reminder-item {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 12px; align-items: center;
  background: var(--gray-100);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 10px 12px;
}
.reminder-date { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.reminder-day { font-weight: 700; font-size: 14px; color: var(--gray-700); }
.reminder-details { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.reminder-details strong { font-size: 14px; color: var(--gray-700); }
.reminder-int { font-size: 12px; color: var(--gray-500); }

/* ---- PATIENT PICKER (autocomplete) ---- */
.patient-picker { position: relative; }
.patient-picker__list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  z-index: 50;
  list-style: none;
  margin: 0; padding: 4px 0;
  background: #fff;
  border: 1px solid var(--gray-300, #ced4da);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  max-height: 280px;
  overflow-y: auto;
}
.patient-picker__item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--gray-700, #495057);
}
.patient-picker__item:hover { background: var(--gray-100, #f1f3f5); color: var(--primary, #1a6fc4); }
.patient-picker__empty {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--gray-500, #adb5bd);
  font-style: italic;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { left: 0; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .reminder-item { grid-template-columns: 1fr; }
  .reminder-date { flex-direction: row; align-items: center; }
}
