/* ============================================================
   PsicoPed · app.css — Hoja de estilos completa
   ============================================================ */

:root {
    --bg: #F7F5F0;
    --surface: #FFFFFF;
    --surface2: #F0EDE6;
    --border: #E2DDD4;
    --border-soft: #EAE7E0;
    --accent: #3C6E47;
    --accent-light: #EDF4EF;
    --accent-mid: #B8D4BF;
    --accent-dark: #762c91; /*#2A4E32;*/
    --text: #1C1A17;
    --text-2: #5A5650;
    --text-3: #9A9590;
    --danger: #C0392B;
    --danger-light: #FDECEA;
    --warn: #D68910;
    --warn-light: #FEF9EC;
    --info: #1A6B9A;
    --info-light: #EAF4FB;
    --success: #1E7A40;
    --success-light: #EAF5ED;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,.12);
    --font-display: 'Lora', Georgia, serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font-body); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── App Shell ── */
.app-shell    { display: flex; height: 100vh; overflow: hidden; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

/* ── Sidebar ── */
.sidebar { width: 220px; min-width: 220px; background: var(--accent-dark); display: flex; flex-direction: column; border-right: 1px solid #1E3D26; overflow-y: auto; }
.sidebar-logo { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,.1); flex-shrink: 0; }
.sidebar-logo h1 { font-family: var(--font-display); font-size: 20px; color: #fff; font-weight: 600; letter-spacing: -.3px; }
.sidebar-logo p { font-size: 11px; color: rgba(255,255,255,.45); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; }
.entidad-selector { padding: 12px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.entidad-selector-label { display: block; font-size: 10px; color: rgba(255,255,255,.4); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.entidad-selector select { width: 100%; background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); padding: 6px 8px; font-size: 12.5px; }
.entidad-selector select option { background: #1e1e1e; color: #fff; }
.entidad-selector-single { color: rgba(255,255,255,.85); font-size: 13px; font-weight: 500; }
.sidebar-nav { flex: 1; padding: 10px 0; }
.nav-section { padding: 14px 20px 3px; font-size: 10px; color: rgba(255,255,255,.3); letter-spacing: 1px; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 20px; cursor: pointer; color: rgba(255,255,255,.65); font-size: 13.5px; text-decoration: none; transition: all .15s; border-left: 2px solid transparent; }
.nav-item:hover  { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 500; border-left-color: var(--accent-mid); }
.nav-item svg { flex-shrink: 0; opacity: .75; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); flex-shrink: 0; }
.sidebar-footer p { font-size: 11px; color: rgba(255,255,255,.25); }

/* ── Page content ── */
.page-content { flex: 1; overflow-y: auto; padding: 28px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 16px; }
.page-title { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.page-header-actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

/* ── Stat cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; }
.stat-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.stat-value { font-size: 26px; font-weight: 600; font-family: var(--font-display); }
.stat-sub { font-size: 11px; color: var(--text-3); margin-top: 3px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.card-title { font-family: var(--font-display); font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.card-subtitle { font-size: 12px; color: var(--text-3); margin-bottom: 14px; }
.two-col   { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.three-col { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }

/* ── Spacing ── */
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-family: var(--font-body); font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: all .15s; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface2); }
.btn-secondary.active { background: var(--accent-light); color: var(--accent-dark); border-color: var(--accent-mid); }
.btn-danger    { background: var(--danger-light); color: var(--danger); border-color: rgba(192,57,43,.3); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 9px 14px; font-size: 11px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); background: var(--surface2); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
.td-actions { display: flex; gap: 6px; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-3); }
.text-danger { color: var(--danger); }
.font-medium { font-weight: 500; }
.text-sm     { font-size: 12px; }

/* ── Badges ── */
.badge       { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-amber { background: var(--warn-light);    color: var(--warn); }
.badge-red   { background: var(--danger-light);  color: var(--danger); }
.badge-blue  { background: var(--info-light);    color: var(--info); }
.badge-gray  { background: var(--surface2);      color: var(--text-2); }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.toolbar-left { display: flex; align-items: center; gap: 8px; }
.search-bar   { position: relative; }
.search-icon  { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-input { padding-left: 32px !important; width: 220px; }

/* ── Forms ── */
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols1 { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span2 { grid-column: span 2; }
.form-section-title { font-size: 12px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: .5px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.form-hint { font-size: 11px; color: var(--text-3); }
.required  { color: var(--danger); }
.text-link { color: var(--accent); text-decoration: none; }
.text-link:hover { text-decoration: underline; }

label { font-size: 12px; font-weight: 500; color: var(--text-2); }

input, select, textarea, .form-control {
  font-family: var(--font-body); font-size: 13px;
  padding: 8px 11px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  color: var(--text); outline: none; width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus, .form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
textarea { resize: vertical; min-height: 70px; }
select   { cursor: pointer; }
.form-readonly { background: var(--surface2) !important; cursor: default; }
.validation-message { font-size: 11px; color: var(--danger); margin-top: 3px; }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-info    { background: var(--info-light);    color: var(--info);    border: 1px solid rgba(26,107,154,.2); }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(30,122,64,.2); }
.alert-warn    { background: var(--warn-light);    color: var(--warn);    border: 1px solid rgba(214,137,16,.2); }

/* ── Horario drag & drop ── */
.cal-body.dragging [data-sesion] { pointer-events: none !important; }
.chip-horario[draggable="true"]  { cursor: grab; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,18,14,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal    { background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-sm { max-width: 420px; }
.modal-header { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title  { font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.modal-body   { padding: 18px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.modal-overlay-top { z-index: 1100; }

/* SearchableSelect */
.ss-wrap { position: relative; }
.ss-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); max-height: 220px; overflow-y: auto; z-index: 200; }
.ss-option { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.ss-option:hover, .ss-option.ss-selected { background: var(--hover, #f5f5f5); color: var(--accent); }
.ss-empty { padding: 10px 12px; font-size: 13px; color: var(--text-muted); }

/* ── Invoice ── */
.invoice-card    { max-width: 780px; }
.invoice-header  { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.invoice-brand   { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: var(--accent-dark); }
.invoice-number  { font-size: 22px; font-weight: 600; color: var(--text); text-align: right; }
.invoice-meta    { text-align: right; }
.invoice-receptor { background: var(--surface2); padding: 14px 16px; border-radius: var(--radius); margin-bottom: 24px; }
.invoice-table   { width: 100%; margin-bottom: 16px; }
.invoice-totals  { max-width: 320px; margin-left: auto; }
.invoice-total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; color: var(--text-2); }
.invoice-total-final { font-weight: 600; font-size: 16px; color: var(--text); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.invoice-legal-note { margin-top: 20px; font-size: 11px; color: var(--text-3); border-top: 1px solid var(--border-soft); padding-top: 10px; }
.invoice-notes  { margin-top: 12px; font-size: 12px; color: var(--text-2); }

/* ── Presupuesto form ── */
.lineas-add-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.presup-total { display: flex; justify-content: space-between; align-items: center; }
.presup-total-value { font-size: 16px; font-weight: 600; color: var(--accent-dark); }
.tarifa-quick-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background .1s; border-radius: 4px; }
.tarifa-quick-row:hover { background: var(--accent-light); }
.tarifa-quick-row:last-child { border-bottom: none; }

/* ── Misc ── */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.empty-state-inline { padding: 24px; text-align: center; color: var(--text-3); font-size: 13px; }
.loading-state { padding: 40px; text-align: center; color: var(--text-3); }
.detail-row { display: flex; padding: 8px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 150px; color: var(--text-2); flex-shrink: 0; font-size: 12px; }
.preview-block { background: var(--surface2); padding: 14px; border-radius: var(--radius); }
.flex { display: flex; }
.gap-2 { gap: 8px; }

/* ── Scrollbar ── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Print ── */
@media print {
  .sidebar, .page-header-actions, .no-print, .btn, .td-actions,
  .blazored-toast-container { display: none !important; }
  .app-shell, .main-content, .page-content { display: block !important; overflow: visible !important; height: auto !important; }
  .invoice-card { box-shadow: none !important; border: none !important; max-width: 100% !important; }
  body { background: #fff; }
}

/* ── Sidebar user block ── */
.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.sidebar-user-info {
  display: flex; align-items: center; gap: 9px;
  flex: 1; min-width: 0; text-decoration: none;
  padding: 4px; border-radius: var(--radius);
  transition: background .15s;
}
.sidebar-user-info:hover { background: rgba(255,255,255,.08); }
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-mid); color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.sidebar-user-data { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name {
  font-size: 12px; font-weight: 500; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,.4); }
.sidebar-logout-btn {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.4); padding: 6px; border-radius: var(--radius);
  transition: all .15s; display: flex; align-items: center;
}
.sidebar-logout-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-footer-text { font-size: 11px; color: rgba(255,255,255,.25); }

/* ── Login page ── */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 40px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-md);
}
.login-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 28px;
}
.login-logo-icon {
  width: 48px; height: 48px; border-radius: 14px;
  background: var(--accent-light); color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.login-logo h1 {
  font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--text);
}
.login-logo p { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.login-title { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 20px; }
.login-error {
  display: flex; align-items: center; gap: 7px;
  background: var(--danger-light); color: var(--danger);
  border: 1px solid rgba(192,57,43,.2);
  padding: 9px 12px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 14px;
}
.btn-login { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }
.input-error { border-color: var(--danger) !important; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 40px; }
.pwd-toggle {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px; display: flex; align-items: center;
}
.pwd-toggle:hover { color: var(--text); }

/* ── Spinner ── */
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Plan de cuotas ── */
.plan-preview {
  background: var(--accent-light); border: 1px solid var(--accent-mid);
  border-radius: var(--radius); padding: 14px 16px;
}
.plan-preview-title {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .5px; color: var(--accent-dark); margin-bottom: 10px;
}
.plan-preview-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 13px; border-bottom: 1px solid var(--accent-mid);
}
.plan-preview-row:last-child { border-bottom: none; }
.plan-preview-row span:first-child { color: var(--accent-dark); font-size: 12px; }

/* ── Pagos / Saldos ── */
tfoot td { padding: 10px 14px; font-size: 13px; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger);  }

/* ── Auditoría ── */
.auditoria-json {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.sidebar-logout-form {
    margin: 0;
}

.sidebar-logout-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
}
/* ── Horario Semanal ────────────────────────────────────────────────────── */

/* Chip de sesión pendiente (panel izquierdo) */
.chip-horario {
  display: block;
  border: 2px solid;
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-horario:hover  { opacity: .85; transform: translateX(2px); }

/* Slot del calendario en modo "drop" (chip seleccionado) */
.cal-slot-drop:hover { background: rgba(79,134,198,.12); }

/* Sesión en el calendario (hover) */
.cal-ses:hover { filter: brightness(1.1); }

/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

/* Topbar móvil (botón hamburguesa) — oculto en escritorio */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    background: var(--sidebar-bg, #1a2236);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 200;
}
.mobile-topbar .app-brand { font-weight: 700; font-size: 1rem; }

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: .25rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: .2s;
}

/* Overlay oscuro detrás del menú en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 299;
}
.sidebar-overlay.open { display: block; }

/* ── Tablet (≤ 900px) ── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Móvil (≤ 768px) ── */
@media (max-width: 768px) {

    /* Topbar visible */
    .mobile-topbar { display: flex; }

    /* Shell */
    .app-shell {
        flex-direction: column;
    }

    /* Sidebar: panel lateral off-canvas */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        width: 260px;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform .25s ease;
        overflow-y: auto;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.35);
    }

    /* Contenido principal ocupa todo */
    .main-content {
        margin-left: 0;
        min-height: calc(100vh - 48px);
        padding: .75rem;
    }

    /* Grids a 1 columna */
    .stats-grid { grid-template-columns: 1fr; }
    .two-col, .grid-2col { grid-template-columns: 1fr !important; }

    /* Tablas: scroll horizontal */
    .table-responsive, .card { overflow-x: auto; }
    table { min-width: 540px; }

    /* Modales: bottom sheet */
    .modal-dialog {
        margin: auto 0 0 0;
        max-width: 100%;
        border-radius: 1rem 1rem 0 0;
    }

    /* Formularios: labels arriba */
    .form-group label { display: block; margin-bottom: .25rem; }

    /* Botones: ancho completo en grupos pequeños */
    .btn-group-mobile .btn { width: 100%; margin-bottom: .35rem; }

    /* Cards de paciente/tutor apiladas */
    .detail-grid { grid-template-columns: 1fr !important; }

    /* Cabecera de página */
    .page-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
    .page-header .actions { width: 100%; }
    .page-header .actions .btn { width: 100%; }
}

/* ── Muy pequeño (≤ 480px) ── */
@media (max-width: 480px) {
    .main-content { padding: .5rem; }
    .card { padding: .75rem; }
    h1, .page-title { font-size: 1.2rem; }
    .stats-card .stat-value { font-size: 1.6rem; }
}
