/* =================================================================
   PACIENTES · DR. CARLOS SANTOS
   Inspirado en Doctocliq · Paleta de marca drcarlossantos.com
   ================================================================= */

:root {
    /* Colores de marca */
    --brand-blue: #0055FF;
    --brand-blue-hover: #0044CC;
    --brand-cyan: #66CCFF;
    --brand-cyan-light: #B3E6FF;

    /* Acento al estilo Doctocliq (turquesa para botones primarios y tabs) */
    --accent: #2EC4B6;
    --accent-hover: #25A89B;

    /* Neutros */
    --bg: #F4F8FB;
    --surface: #FFFFFF;
    --surface-2: #F9FAFB;
    --border: #E5E7EB;
    --border-strong: #D1D5DB;
    --text: #1F2937;
    --text-soft: #4B5563;
    --text-mute: #6B7280;
    --text-faint: #9CA3AF;

    /* Semánticos */
    --danger: #EF4444;
    --danger-soft: #FEE2E2;
    --success: #10B981;
    --success-soft: #D1FAE5;
    --warning: #F59E0B;
    --warning-soft: #FEF3C7;

    /* Odontograma */
    --caries: #EF4444;
    --restauracion: #2563EB;
    --extraccion: #EF4444;
    --faltante: #2563EB;

    /* Layout */
    --topbar-h: 64px;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 2px 8px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ============== LOGIN ============== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(102, 204, 255, 0.15), transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(0, 85, 255, 0.08), transparent 50%),
        var(--bg);
    padding: 24px;
}
.login-card {
    background: var(--surface);
    padding: 48px 40px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    text-align: center;
}
.login-logo {
    margin-bottom: 32px;
}
.login-logo img {
    max-width: 200px;
    height: auto;
}
.login-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--text);
}
.login-subtitle {
    color: var(--text-mute);
    margin: 0 0 28px;
    font-size: 14px;
}
.login-form {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.password-wrap {
    position: relative;
}
.password-wrap input {
    padding-right: 40px;
}
.toggle-password {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-mute);
    padding: 4px 8px;
}

/* ============== FORM PRIMITIVES ============== */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.field-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-soft);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(46, 196, 182, 0.15);
}
textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}
.form-error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* ============== BUTTONS ============== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .05s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
    background: transparent;
    color: var(--text-soft);
    border-color: var(--border);
}
.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}
.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover { background: #DC2626; border-color: #DC2626; }
.btn-danger-ghost {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger-soft);
}
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-block {
    width: 100%;
}
.btn-back {
    margin-bottom: 16px;
    padding: 6px 12px;
    font-size: 13px;
}

/* ============== TOPBAR ============== */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.topbar-logo {
    height: 36px;
    width: auto;
}
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 40px;
    flex: 1;
}
.nav-link {
    padding: 8px 14px;
    color: var(--text-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-radius: var(--radius-sm);
    transition: color .15s, background .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
    color: var(--accent);
    position: relative;
}
.nav-link.active::after {
    content: '';
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: -16px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}
.user-name {
    font-size: 14px;
    color: var(--text-soft);
    font-weight: 600;
}
.user-menu { position: relative; }
.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--surface-2);
    color: var(--text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.user-avatar:hover { background: var(--border); }
.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    overflow: hidden;
    z-index: 100;
}
.user-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-soft);
    cursor: pointer;
}
.user-dropdown button:hover { background: var(--surface-2); color: var(--text); }

/* ============== VIEWS ============== */
.view { display: none; }
.view.active { display: block; }

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
}

.page-header {
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.page-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    padding-bottom: 10px;
    display: inline-block;
    color: var(--text);
}
.tab-active {
    position: relative;
}
.tab-active::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

/* ============== PATIENTS LIST ============== */
.patients-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
    flex-wrap: wrap;
}
.patients-count {
    font-size: 14px;
    color: var(--text-soft);
}
.patients-count strong { color: var(--text); font-weight: 700; }
.separator { margin: 0 12px; color: var(--text-faint); }
.patients-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.search-wrap {
    position: relative;
    width: 280px;
}
.search-wrap input {
    padding-left: 38px;
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.patients-table-wrap {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.patients-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.patients-table thead {
    background: #2F4858;
    color: white;
}
.patients-table th {
    text-align: left;
    padding: 14px 20px;
    font-weight: 600;
    font-size: 13px;
}
.patients-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .15s;
    cursor: pointer;
}
.patients-table tbody tr:hover {
    background: rgba(46, 196, 182, 0.04);
}
.patients-table tbody tr:last-child { border-bottom: none; }
.patients-table td {
    padding: 14px 20px;
    color: var(--text-soft);
}
.patient-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}
.patient-cell-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-cyan), var(--brand-blue));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.patient-cell-name {
    color: var(--text);
    font-weight: 600;
}
/* v1.7: badge de número de expediente en la lista */
.patient-cell-expediente {
    display: inline-block;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-blue);
    background: rgba(0, 85, 255, 0.08);
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}
.muted { color: var(--text-faint); }

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-mute);
}
.empty-state p { margin: 0 0 16px; }

/* ============== PATIENT DETAIL ============== */
.patient-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
}
.patient-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.patient-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    text-align: center;
    padding-bottom: 20px;
}
.patient-banner {
    height: 70px;
    background: linear-gradient(135deg, var(--brand-cyan) 0%, var(--brand-blue) 100%);
}
.patient-avatar-wrap {
    margin-top: -40px;
    margin-bottom: 8px;
}
.patient-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-cyan), var(--brand-blue));
    border: 4px solid white;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}
.patient-card h3 {
    margin: 8px 16px 4px;
    font-size: 17px;
    color: var(--text);
}
.patient-created {
    margin: 0 16px;
    font-size: 13px;
    color: var(--text-mute);
}
/* v1.7: badge de expediente en sidebar */
.patient-expediente {
    display: inline-block;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-blue);
    background: rgba(0, 85, 255, 0.10);
    padding: 3px 10px;
    border-radius: 4px;
    letter-spacing: 0.4px;
    margin: 0 16px 6px;
}
.patient-expediente:empty {
    display: none;
}
/* v1.7: inputs readonly (genérico, suave) */
input[readonly] {
    background: var(--bg);
    color: var(--text-soft);
    cursor: default;
}
input[readonly]:focus {
    border-color: var(--border);
    box-shadow: none;
}
/* v1.7: estilo específico del campo Nº de expediente (monoespaciado y prominente) */
input[name="numero_expediente"][readonly] {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: var(--brand-blue);
}
.patient-quick-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}
.qa-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.qa-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.qa-btn.qa-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

.patient-nav {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.pn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 18px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-soft);
    cursor: pointer;
    text-align: left;
    transition: background .15s, color .15s;
}
.pn-item:last-child { border-bottom: none; }
.pn-item:hover { background: var(--surface-2); color: var(--text); }
.pn-item.active {
    background: var(--accent);
    color: white;
}
.pn-item.active:hover { background: var(--accent-hover); }

/* Patient content */
.patient-content {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}
.tab-content {
    display: none;
    padding: 24px 28px;
}
.tab-content.active {
    display: block;
}
.tab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.tab-header h2 {
    font-size: 18px;
    margin: 0;
    color: var(--text);
}

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}
.fieldset {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}
.fieldset legend {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-soft);
    padding: 0 8px;
}
.checks-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.check-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-soft);
    transition: all .15s;
}
.check-pill:hover { background: white; border-color: var(--border-strong); }
.check-pill input { display: none; }
.check-pill input:checked + span { color: var(--accent); font-weight: 600; }
.check-pill:has(input:checked) {
    background: rgba(46, 196, 182, 0.08);
    border-color: var(--accent);
}

/* ============== ODONTOGRAMA ============== */
.odo-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--surface-2);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.odo-toolbar-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-soft);
    margin-right: 8px;
}
.odo-tool {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-soft);
    transition: all .15s;
}
.odo-tool:hover { border-color: var(--border-strong); }
.odo-tool.active {
    background: var(--text);
    color: white;
    border-color: var(--text);
}
.dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}
.dot-red { background: var(--caries); }
.dot-blue { background: var(--restauracion); }
.x-mark {
    display: inline-block;
    font-weight: 900;
    font-size: 18px;
    line-height: 1;
}
.x-red { color: var(--caries); }
.x-blue { color: var(--restauracion); }

.odo-instructions {
    font-size: 13px;
    color: var(--text-mute);
    margin-bottom: 16px;
    padding: 0 4px;
}

.odontograma {
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 24px 16px;
    overflow-x: auto;
}
.odo-arch {
    display: flex;
    justify-content: center;
    gap: 0;
    align-items: flex-start;
}
.odo-arch + .odo-arch {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px dashed var(--border-strong);
}
.odo-quadrant {
    display: flex;
    gap: 4px;
}
.odo-quadrant.left { margin-right: 16px; }
.odo-quadrant.right { margin-left: 16px; }
.odo-tooth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.odo-tooth-number {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-soft);
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    border: 1.5px solid var(--border);
    transition: all .1s;
    min-width: 26px;
    text-align: center;
}
.odo-tooth-number:hover { border-color: var(--accent); color: var(--accent); }
.odo-tooth-svg {
    width: 44px;
    height: 44px;
    cursor: pointer;
}
.odo-surface {
    fill: var(--surface);
    stroke: #94A3B8;
    stroke-width: 1;
    transition: fill .1s;
}
.odo-surface:hover { fill: #F0F4F8; }
.odo-surface.caries { fill: var(--caries); }
.odo-surface.restauracion { fill: var(--restauracion); }

.odo-tooth.extraccion .odo-tooth-x,
.odo-tooth.faltante .odo-tooth-x {
    display: block;
}
.odo-tooth-x {
    display: none;
    position: absolute;
    font-size: 38px;
    font-weight: 900;
    pointer-events: none;
    line-height: 1;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.odo-tooth-wrap {
    position: relative;
}
.odo-tooth.extraccion .odo-tooth-x { color: var(--extraccion); }
.odo-tooth.faltante .odo-tooth-x { color: var(--faltante); }
.odo-tooth.extraccion .odo-tooth-svg,
.odo-tooth.faltante .odo-tooth-svg {
    opacity: 0.5;
}

.odo-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-soft);
}
.odo-legend > div {
    display: flex;
    align-items: center;
    gap: 8px;
}
.legend-square {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
}
.sq-red { background: var(--caries); }
.sq-blue { background: var(--restauracion); }

/* ============== CONSULTAS LIST ============== */
.consultas-list, .presupuestos-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.consulta-item, .presupuesto-item {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    cursor: pointer;
    transition: all .15s;
}
.consulta-item:hover, .presupuesto-item:hover {
    background: white;
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.consulta-head, .presu-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.consulta-date, .presu-date {
    font-weight: 700;
    color: var(--text);
    font-size: 14px;
}
.consulta-cost, .presu-total {
    font-weight: 700;
    color: var(--accent);
    font-size: 15px;
}
.consulta-treatment, .presu-desc {
    color: var(--text-soft);
    font-size: 14px;
    margin: 4px 0;
}
.presu-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.presu-badge.pendiente { background: var(--warning-soft); color: #B45309; }
.presu-badge.aceptado { background: var(--success-soft); color: #047857; }
.presu-badge.rechazado { background: var(--danger-soft); color: var(--danger); }
.presu-badge.completado { background: rgba(46, 196, 182, 0.15); color: var(--accent-hover); }

/* ============== MODALS ============== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}
.modal-dialog {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.modal-dialog.modal-sm { max-width: 420px; }
.modal-dialog.modal-lg { max-width: 760px; }
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 {
    margin: 0;
    font-size: 17px;
    color: var(--text);
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-mute);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body {
    padding: 24px;
    overflow-y: auto;
}
.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Presupuesto items table inside modal */
.presupuesto-items {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 12px;
    border: 1px solid var(--border);
}
.presupuesto-items-header,
.presupuesto-item-row {
    display: grid;
    grid-template-columns: 2.5fr 0.8fr 0.6fr 1fr 1fr 32px;
    gap: 8px;
    align-items: center;
}
.presupuesto-items-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.presupuesto-item-row {
    margin-bottom: 6px;
}
.presupuesto-item-row input {
    padding: 7px 10px;
    font-size: 13px;
}
.presupuesto-item-row .item-subtotal {
    font-weight: 700;
    color: var(--text);
    padding: 7px 10px;
    font-size: 13px;
}
.item-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 28px;
    height: 28px;
    border-radius: 4px;
}
.item-remove:hover { background: var(--danger-soft); }
.presupuesto-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 16px;
}
.presupuesto-total strong {
    font-size: 22px;
    color: var(--accent);
}

/* ============== TOAST ============== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    animation: slideUp 0.2s ease;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ============== RESPONSIVE ============== */
@media (max-width: 1024px) {
    .patient-layout {
        grid-template-columns: 240px 1fr;
    }
    .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
    .topbar { padding: 0 16px; }
    .topbar-nav { margin-left: 16px; }
    .container { padding: 16px; }
    .patient-layout {
        grid-template-columns: 1fr;
        padding: 16px;
    }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .patients-toolbar { flex-direction: column; align-items: stretch; }
    .search-wrap { width: 100%; }
    .patients-table th:nth-child(3),
    .patients-table td:nth-child(3),
    .patients-table th:nth-child(4),
    .patients-table td:nth-child(4),
    .patients-table th:nth-child(5),
    .patients-table td:nth-child(5) {
        display: none;
    }
    .presupuesto-items-header { display: none; }
    .presupuesto-item-row {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 8px;
        background: white;
        border: 1px solid var(--border);
        border-radius: 6px;
        margin-bottom: 8px;
    }
}

/* =================================================================
   v1.1 — Catálogo de tratamientos, email, badges
   ================================================================= */

.cat-badge {
    display: inline-block;
    padding: 3px 10px;
    background: rgba(0, 85, 255, 0.08);
    color: var(--brand-blue);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-info {
    background: rgba(46, 196, 182, 0.08);
    border-left: 3px solid var(--accent);
    padding: 12px 14px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-soft);
}
.form-info strong { color: var(--text); }

/* Botones de acción extra en modal de presupuesto */
.modal-actions .btn[id^="btn-pdf"],
.modal-actions .btn[id^="btn-email"] {
    background: white;
    border-color: var(--border);
    color: var(--text-soft);
}
.modal-actions .btn[id^="btn-pdf"]:hover,
.modal-actions .btn[id^="btn-email"]:hover {
    background: var(--surface-2);
    color: var(--accent);
    border-color: var(--accent);
}

/* Datalist styling (limited cross-browser support) */
input[list]::-webkit-calendar-picker-indicator {
    opacity: 0.4;
}

/* =================================================================
   v1.2 — Selector visual del catálogo + arreglos iPad/touch
   ================================================================= */

/* Botones para añadir items al presupuesto */
.presupuesto-add-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.presupuesto-add-actions .btn { flex: 1; }

/* Mejor feedback táctil en TODA la app (iPad/iPhone) */
* {
    -webkit-tap-highlight-color: rgba(46, 196, 182, 0.15);
}

/* Asegurar que las filas de tabla sean tappable en iPad */
.patients-table tbody tr {
    -webkit-tap-highlight-color: rgba(46, 196, 182, 0.2);
    touch-action: manipulation;
}
.patients-table tbody tr:active {
    background: rgba(46, 196, 182, 0.08) !important;
}

/* Botones también */
.btn, .pn-item, .odo-tool, .nav-link, .qa-btn,
.consulta-item, .presupuesto-item, .check-pill,
.user-avatar, .modal-close, .item-remove {
    touch-action: manipulation;
}

/* SELECTOR DE CATÁLOGO (modal anidado dentro de presupuesto) */
.selector-search-wrap {
    margin-bottom: 12px;
}
.selector-search-wrap input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
}
.selector-search-wrap input:focus {
    border-color: var(--accent);
}

.selector-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.cat-chip {
    padding: 6px 12px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
    cursor: pointer;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}
.cat-chip:hover { background: white; border-color: var(--border-strong); }
.cat-chip.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.selector-list {
    max-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}

.selector-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all .15s;
    -webkit-tap-highlight-color: rgba(46, 196, 182, 0.15);
    touch-action: manipulation;
}
.selector-item:hover {
    border-color: var(--accent);
    background: rgba(46, 196, 182, 0.04);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.selector-item:active {
    transform: translateY(0);
    background: rgba(46, 196, 182, 0.1);
}
.selector-item-info {
    flex: 1;
    min-width: 0;
}
.selector-item-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}
.selector-item-cat {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(0, 85, 255, 0.08);
    color: var(--brand-blue);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 2px 0;
}
.selector-item-desc {
    font-size: 13px;
    color: var(--text-mute);
    margin-top: 2px;
}
.selector-item-price {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
}

/* En tablet/móvil, los items se ven mejor */
@media (max-width: 768px) {
    .selector-item {
        padding: 12px 14px;
    }
    .selector-item-name {
        font-size: 14px;
    }
    .selector-item-price {
        font-size: 16px;
    }
    .presupuesto-add-actions {
        flex-direction: column;
    }
}

/* =================================================================
   v1.3 — Botón PDF destacado, mejoras UX
   ================================================================= */

/* Botón "Descargar PDF" — destacado en azul de marca */
.btn-pdf {
    background: var(--brand-blue);
    color: white;
    border-color: var(--brand-blue);
}
.btn-pdf:hover {
    background: var(--brand-blue-hover);
    border-color: var(--brand-blue-hover);
}

/* Modal-actions más responsive */
.modal-actions {
    flex-wrap: wrap;
}
@media (max-width: 600px) {
    .modal-actions .btn {
        flex: 1 1 calc(50% - 5px);
        min-width: 0;
    }
    .modal-actions .spacer { display: none; }
}

/* Indicador visual de "Editar" en las tarjetas de presupuesto */
.presupuesto-item {
    position: relative;
    padding-right: 50px !important;
}
.presupuesto-item::after {
    content: '✏️';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    opacity: 0.4;
    transition: opacity .15s;
}
.presupuesto-item:hover::after {
    opacity: 1;
}

/* Mensaje pequeño de ayuda debajo del título */
.modal-help-text {
    font-size: 12px;
    color: var(--text-mute);
    margin-top: 2px;
    margin-bottom: 8px;
}

/* =================================================================
   v1.6 — Historial de odontogramas + fixes iPad
   ================================================================= */

/* ============== Selector de odontogramas ============== */
.odo-selector-wrap {
    margin-bottom: 14px;
}
.odo-selector-wrap > .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.odo-selector-wrap .odo-selector-field {
    flex: 1;
    min-width: 0;
}
/* Cuando hay odontogramas: layout selector + acciones en línea */
.odo-selector-wrap:has(.odo-selector-field) {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.odo-selector-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
/* Empty state cuando todavía no hay odontogramas */
.odo-selector-empty {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}

/* Botones tamaño chico (usados en selector de odontograma) */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* ============== FIX iPad portrait: layouts apretados ============== */

/* min-width: 0 en grid children permite que se compriman bien en iOS Safari */
.patient-content,
.tab-content {
    min-width: 0;
}

/* En anchos típicos de iPad portrait (820-834px), el sidebar de 240px deja
   muy poco espacio para los grids de 2 o 3 columnas, y Safari termina
   solapando inputs. Colapsamos a 1 columna en todo ese rango. */
@media (max-width: 900px) {
    .patient-content .grid-2,
    .patient-content .grid-3 {
        grid-template-columns: 1fr;
    }
    /* Modal de consulta (Fecha + Costo, Próxima cita + Observaciones)
       también se aprieta en iPad portrait. */
    .modal-body .grid-2,
    .modal-body .grid-3 {
        grid-template-columns: 1fr;
    }
    /* Selector de odontograma en una sola columna en pantallas chicas */
    .odo-selector-wrap:has(.odo-selector-field) {
        flex-direction: column;
        align-items: stretch;
    }
    .odo-selector-actions {
        justify-content: flex-end;
    }
}

/* =================================================================
   v1.7 — Consentimientos Informados
   ================================================================= */

.consentimientos-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.consentimiento-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    background: var(--surface-2);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all .15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(46,196,182,0.15);
}
.consentimiento-item:hover {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transform: translateY(-1px);
}
.consentimiento-item.pendiente {
    border-left: 4px solid #F59E0B;
}
.consentimiento-item.pendiente:hover {
    border-color: #F59E0B;
    border-left-color: #F59E0B;
}
.consentimiento-item.firmado {
    border-left: 4px solid #10B981;
    background: rgba(209,250,229,0.3);
}
.consentimiento-item.firmado:hover {
    border-color: #10B981;
    border-left-color: #10B981;
    background: #F0FDF4;
}

.consentimiento-icon {
    font-size: 28px;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.consentimiento-item.firmado .consentimiento-icon {
    background: #D1FAE5;
}

.consentimiento-info {
    flex: 1;
    min-width: 0;
}
.consentimiento-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.consentimiento-meta {
    font-size: 13px;
    color: var(--text-mute);
}
.consentimiento-diente {
    display: inline-block;
    padding: 1px 8px;
    background: rgba(0,85,255,0.08);
    color: var(--brand-blue);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.consentimiento-status {
    flex-shrink: 0;
}

.badge-pendiente {
    display: inline-block;
    padding: 4px 12px;
    background: #FEF3C7;
    color: #B45309;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-firmado {
    display: inline-block;
    padding: 4px 12px;
    background: #D1FAE5;
    color: #047857;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Plantillas — grid de cards (modal de gestión) */
.plantillas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}
.plantilla-card {
    padding: 14px 16px;
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all .15s;
    touch-action: manipulation;
}
.plantilla-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.plantilla-card.inactive {
    opacity: 0.5;
}
.plantilla-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
.plantilla-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Responsive — móvil */
@media (max-width: 600px) {
    .consentimiento-item {
        padding: 12px 14px;
        gap: 10px;
    }
    .consentimiento-icon {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }
    .consentimiento-name {
        font-size: 14px;
    }
    .consentimiento-meta {
        font-size: 12px;
    }
}

/* =================================================================
   v1.7 — Modal de firma fullscreen (reemplaza firma.php)
   ================================================================= */

#modal-firma-fullscreen.modal {
    background: #F4F8FB !important;
    z-index: 9000 !important;
}
#modal-firma-fullscreen.modal:not(.hidden) {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    overflow-y: auto !important;
    padding: 0 !important;
    align-items: initial !important;
    justify-content: initial !important;
}
#modal-firma-fullscreen .modal-dialog,
#modal-firma-fullscreen .modal-backdrop {
    display: none !important;
}

.firma-fs-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #F4F8FB;
}

.firma-fs-topbar {
    background: white;
    border-bottom: 2px solid var(--brand-blue);
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.firma-fs-doc {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.firma-fs-patient {
    font-size: 12px;
    color: var(--text-mute);
}
.firma-fs-close {
    background: #F3F4F6 !important;
    border: 1px solid var(--border) !important;
    color: #374151 !important;
    width: 40px;
    height: 40px;
    font-size: 22px;
    border-radius: 8px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.firma-fs-close:active { background: #E5E7EB !important; }

.firma-fs-content {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 20px 40px;
    width: 100%;
}

.firma-fs-doc-box {
    background: white;
    padding: 28px 32px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
}
.firma-fs-doc-box h2 {
    font-size: 18px;
    color: var(--brand-blue);
    margin-bottom: 16px;
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.firma-fs-doc-box h3 {
    font-size: 15px;
    margin-top: 14px;
    margin-bottom: 8px;
}
.firma-fs-doc-box p { margin: 10px 0; }
.firma-fs-doc-box ul { margin: 10px 0 10px 22px; }
.firma-fs-doc-box li { margin: 6px 0; }
.firma-fs-doc-box strong { color: var(--text); }

.firma-fs-signature-box {
    margin-top: 24px;
    background: white;
    padding: 24px;
    border-radius: 10px;
    border: 2px solid var(--accent);
    box-shadow: 0 4px 16px rgba(46,196,182,0.15);
}
.firma-fs-signature-box h3 {
    font-size: 16px;
    color: var(--brand-blue);
    margin-bottom: 4px;
}
.firma-fs-instruction {
    font-size: 13px;
    color: var(--text-mute);
    margin-bottom: 12px;
}

.firma-fs-canvas-wrap {
    position: relative;
    width: 100%;
    background: #F9FAFB;
    border: 2px dashed #94A3B8;
    border-radius: 8px;
    margin: 8px 0;
    overflow: hidden;
    height: 220px;
}
.firma-fs-canvas-wrap.has-signature {
    border-style: solid;
    border-color: var(--accent);
    background: white;
}
#firma-fs-canvas {
    display: block;
    width: 100%;
    height: 220px;
    touch-action: none;
    cursor: crosshair;
}
.firma-fs-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #9CA3AF;
    font-size: 16px;
    pointer-events: none;
    text-align: center;
}
.firma-fs-canvas-wrap.has-signature .firma-fs-placeholder { display: none; }

.firma-fs-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}
.firma-fs-actions .btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 15px;
}

.firma-fs-legal {
    font-size: 12px;
    color: var(--text-mute);
    margin-top: 14px;
    padding: 10px 12px;
    background: #F9FAFB;
    border-radius: 6px;
    line-height: 1.5;
}

@media (max-width: 600px) {
    .firma-fs-doc-box { padding: 18px 20px; }
    .firma-fs-signature-box { padding: 16px; }
    .firma-fs-actions { flex-direction: column; }
}

/* =================================================================
   v1.7.1 — Mi firma (firma del doctor)
   ================================================================= */

#mi-firma-canvas-wrap {
    height: 180px;
    position: relative;
    width: 100%;
    background: #F9FAFB;
    border: 2px dashed #94A3B8;
    border-radius: 8px;
    margin: 8px 0;
    overflow: hidden;
}
#mi-firma-canvas-wrap.has-signature {
    border-style: solid;
    border-color: var(--accent);
    background: white;
}
#mi-firma-canvas {
    display: block;
    width: 100%;
    height: 180px;
    touch-action: none;
    cursor: crosshair;
}

/* Z-index importantísimo para confirmDialog encima de cualquier otro modal */
#modal-confirm {
    z-index: 99999 !important;
}
#modal-confirm .modal-backdrop {
    z-index: 99998 !important;
}

/* =================================================================
   v1.7.2+ — PDF Preview Modal (Safari iOS compatible)
   ================================================================= */

#modal-pdf-preview.modal {
    z-index: 9000 !important;
}
#modal-pdf-preview.modal:not(.hidden) {
    display: flex !important;
}

.pdf-preview-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
    pointer-events: auto;
}

.pdf-preview-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pdf-preview-toolbar .modal-close {
    padding: 8px 12px;
    background: #F3F4F6;
    border: 1px solid var(--border);
    color: #6B7280;
    border-radius: 6px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.pdf-preview-toolbar .btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.pdf-preview-iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
    display: block;
}

@media (max-width: 768px) {
    .pdf-preview-toolbar {
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 8px;
    }
    .pdf-preview-toolbar .btn {
        flex: 1;
        min-width: 120px;
    }
}
