/* ────────────────────────────────────────
   ArchivoCH — Sistema de Historias Clínicas
   Variables y reset
──────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
  --sidebar-bg:     #0a1929;
  --sidebar-hover:  #112240;
  --sidebar-active: #0d2e4d;
  --sidebar-accent: #1de9b6;
  --sidebar-text:   #8ab4cc;
  --sidebar-w:      236px;

  --bg:         #f1f5f9;
  --surface:    #ffffff;
  --border:     #d0dbe8;
  --border-2:   #e8eef5;

  --text:       #0f1f2e;
  --text-2:     #3d5a72;
  --text-3:     #7a95a8;
  --text-muted: #9eb5c4;

  --teal:       #0d8e7a;
  --teal-light: #e0f5f1;
  --teal-dark:  #096759;

  --amber:      #b45309;
  --amber-light:#fef3c7;
  --red:        #b91c1c;
  --red-light:  #fee2e2;
  --green:      #166534;
  --green-light:#dcfce7;
  --blue:       #1d4ed8;
  --blue-light: #dbeafe;

  --radius:     7px;
  --radius-lg:  11px;
  --shadow:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 12px rgba(0,0,0,.09), 0 2px 4px rgba(0,0,0,.05);

  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
}

/* ── Layout ── */
body { background: var(--bg); min-height: 100vh; }

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(180deg, #0a1929 0%, #071523 100%);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,.05);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #1de9b6, #0d8e7a);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(29,233,182,.25);
}

.brand-name {
  font-size: 15.5px;
  font-weight: 800;
  color: #fff;
  letter-spacing: .2px;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--sidebar-text);
  display: block;
  margin-top: 1px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.nav-section-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(138,180,204,.35);
  padding: 18px 18px 5px;
}

.nav-menu {
  list-style: none;
  flex: 1;
  padding: 6px 0;
  overflow-y: auto;
}

.nav-menu::-webkit-scrollbar { width: 3px; }
.nav-menu::-webkit-scrollbar-track { background: transparent; }
.nav-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px 8px 18px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
  border-left: 2px solid transparent;
  margin: 1px 8px 1px 0;
  border-radius: 0 6px 6px 0;
}

.nav-link:hover {
  background: rgba(255,255,255,.06);
  color: #c8e4f0;
}

.nav-link.active {
  background: rgba(29,233,182,.1);
  color: var(--sidebar-accent);
  border-left-color: var(--sidebar-accent);
  font-weight: 600;
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12px;
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-footer .user-name {
  font-weight: 600;
  color: #c8dfe9;
  font-size: 13px;
}

.sidebar-footer .user-role {
  font-size: 10.5px;
  text-transform: capitalize;
  color: var(--sidebar-text);
  margin-bottom: 6px;
  opacity: .7;
}

.sidebar-footer a {
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 12px;
  padding: 3px 0;
  transition: color .12s;
}
.sidebar-footer a:hover { color: #ddeef7; }

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

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

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

.page-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
  font-weight: 400;
}

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

/* ── Search bar (header) ── */
.header-search {
  position: relative;
  flex: 1;
  max-width: 380px;
}

/* Icono SVG embebido como fondo — no hay emoji que solape */
.header-search input {
  width: 100%;
  padding: 8px 14px 8px 38px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%237a95a8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 12px center;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.header-search input:focus {
  border-color: var(--teal);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px rgba(13,142,122,.1);
}

.header-search input::placeholder { color: var(--text-muted); }

/* Ocultar el span de icono emoji (ya no se usa) */
.header-search .search-icon { display: none; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 300px;
  overflow-y: auto;
  display: none;
}

.search-dropdown.visible { display: block; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  border-bottom: 1px solid var(--border-2);
  transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg); }

.search-result-num { font-weight: 600; }
.search-result-ub { color: var(--text-3); font-size: 12px; margin-left: auto; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.card-body { padding: 20px; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--border);
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card.ok    { border-top-color: var(--teal); }
.stat-card.aviso { border-top-color: var(--amber); }
.stat-card.alerta{ border-top-color: var(--red); }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  font-weight: 700;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -1px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
}

.stat-card.alerta .stat-value { color: var(--red); }
.stat-card.aviso .stat-value  { color: var(--amber); }
.stat-card.ok .stat-value     { color: var(--teal); }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }

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

thead th {
  padding: 9px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-2);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f7fafd; }

tbody td {
  padding: 10px 14px;
  vertical-align: middle;
}

.td-mono {
  font-family: 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .2px;
}

.badge-success { background: var(--green-light); color: var(--green); }
.badge-warning { background: var(--amber-light); color: var(--amber); }
.badge-danger  { background: var(--red-light);   color: var(--red);   }
.badge-info    { background: var(--blue-light);  color: var(--blue);  }
.badge-neutral { background: #e2e8f0; color: #475569; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .08s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal-dark);
  box-shadow: 0 1px 3px rgba(13,142,122,.3);
}
.btn-primary:hover { background: var(--teal-dark); box-shadow: 0 2px 6px rgba(13,142,122,.35); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border);
}
.btn-secondary:hover { background: #f4f8fb; border-color: #b0c4d4; }

.btn-danger {
  background: var(--red-light);
  color: var(--red);
  border-color: #f5a5a5;
}
.btn-danger:hover { background: #fccaca; }

.btn-sm {
  padding: 5px 11px;
  font-size: 12px;
}

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full-width { grid-column: 1 / -1; }

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .1px;
}

label .required { color: var(--red); margin-left: 2px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="url"],
select,
textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,142,122,.1);
}

textarea { resize: vertical; min-height: 80px; }

small, .form-hint {
  font-size: 11.5px;
  color: var(--text-3);
}

/* ── Alerts ── */
.alert {
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  margin-bottom: 14px;
  border-left: 3px solid;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-success { background: var(--green-light); color: var(--green);  border-color: #4ade80; }
.alert-warning { background: var(--amber-light); color: var(--amber);  border-color: #fbbf24; }
.alert-danger  { background: var(--red-light);   color: var(--red);    border-color: #f87171; }
.alert-info    { background: var(--blue-light);  color: var(--blue);   border-color: #60a5fa; }

/* ── Progress bar ── */
.progress-bar-wrap { display: flex; align-items: center; gap: 8px; }

.progress-bar {
  flex: 1;
  height: 5px;
  background: var(--border-2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--teal);
  transition: width .3s;
}

.progress-bar-fill.warn { background: var(--amber); }
.progress-bar-fill.full { background: var(--red); }

.progress-label {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  min-width: 42px;
  text-align: right;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-link {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-2);
  text-decoration: none;
  transition: background .1s;
}
.page-link:hover { background: var(--bg); }
.page-link.current { background: var(--teal); color: #fff; border-color: var(--teal); }
.page-link.disabled { opacity: .35; pointer-events: none; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-3);
}
.empty-state .empty-icon { font-size: 38px; margin-bottom: 12px; opacity: .6; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ── Movimientos log ── */
.movimiento-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-2);
  font-size: 13px;
}
.movimiento-item:last-child { border-bottom: none; }

.mov-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
}

.mov-body { flex: 1; }
.mov-desc { color: var(--text); margin-bottom: 2px; line-height: 1.4; }
.mov-meta { color: var(--text-3); font-size: 11.5px; }

/* ── Grosor indicator ── */
.grosor-bar { display: inline-flex; gap: 2px; align-items: center; }
.grosor-segment { width: 6px; height: 14px; border-radius: 2px; background: var(--border); }
.grosor-segment.filled { background: var(--teal); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #071523 0%, #0a2540 50%, #0d2e4d 100%);
}

.login-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.35);
}

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

.login-logo .icon {
  width: 54px; height: 54px;
  background: linear-gradient(135deg, #1de9b6, #0d8e7a);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  box-shadow: 0 4px 16px rgba(29,233,182,.3);
}

.login-logo h1 {
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.3px;
}

.login-logo p {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 4px;
}

/* ── Responsividad básica ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 200px; }
  .page-body { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
