/* ==========================================
   VARIABLES Y RESET
   ========================================== */
:root {
    --primary-color: #00a9e0;
    --secondary-color: #2ECC71;
    --accent-color: #3498db;
    --danger-color: #e74c3c;
    --warning-color: #f39c12;
    --dark-color: #2c3e50;
    --light-bg: #f8f9fa;
    --white: #ffffff;
    --border-color: #ddd;
    --text-color: #333;
    --text-light: #666;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-color);
    background: #fff;
    line-height: 1.5;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 30px;
}

/* ==========================================
   HEADER
   ========================================== */
.header {
    background: var(--white);
    padding: 15px 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo-img {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-main {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo-sub {
    font-size: 0.85rem;
    color: var(--text-light);
}

.header-nav {
    display: flex;
    gap: 10px;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--white);
}

.btn-primary:hover {
    background: #0088b3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 169, 224, 0.3);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--white);
    border-color: var(--primary-color);
}

/* ==========================================
   PATIENT INFO
   ========================================== */
.patient-info {
    background: #f8f9fa;
    padding: 20px 30px;
    margin-top: 0;
    border-bottom: 2px solid #ddd;
}

.patient-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.title-fecha-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.perio-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    padding: 0;
    color: #333;
}

.fecha-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fecha-field label {
    font-size: 0.9rem;
    font-weight: 500;
}

.fecha-field input {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.patient-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 12px;
}

.exam-clinic-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    align-items: center;
}

.field-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-group label {
    font-size: 0.9rem;
    font-weight: 400;
    white-space: nowrap;
    min-width: fit-content;
}

.field-group input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.checkbox-group {
    display: flex;
    gap: 20px;
    align-items: center;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    border: 1px solid #999;
}

/* ==========================================
   CHART SECTION
   ========================================== */
.chart-section {
    margin-top: 0;
}

.arch-container {
    background: var(--white);
    padding: 0;
    margin-bottom: 0;
    border: 1px solid #ddd;
    border-bottom: none;
}

/* ==========================================
   CHART ROWS
   ========================================== */
.data-row {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #ddd;
    min-height: 26px;
    background: var(--white);
}

.data-row:last-child {
    border-bottom: 1px solid #ddd;
}

.bleeding-row,
.plaque-row {
    min-height: 28px;
}

.measurement-row,
.margin-row,
.depth-row {
    min-height: 28px;
}

.row-label {
    width: 120px;
    font-size: 0.8rem;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 2px 6px;
    border-right: 1px solid #ddd;
    background: #f8f9fa;
    font-weight: 400;
    flex-shrink: 0;
}

.teeth-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 0;
    flex: 1;
    border-left: 0;
}

.visual-section {
    border-top: 1px solid #ddd;
    padding: 0;
    background: var(--white);
}

.view-label {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    padding: 6px;
    background: #f8f9fa;
    margin: 0;
    border-bottom: 1px solid #ddd;
    color: #333;
}

/* ==========================================
   TOOTH CELLS
   ========================================== */
.tooth-cell {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0;
    border-right: 1px solid var(--border-color);
    background: var(--white);
    padding: 0;
}

.tooth-cell:last-child {
    border-right: none;
}

/* Inputs para mediciones - 3 por fila */
.measurement-row .tooth-cell,
.margin-row .tooth-cell,
.depth-row .tooth-cell {
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: center;
    padding: 0;
}

.measurement-row .site-input,
.margin-row .site-input,
.depth-row .site-input {
    width: 22px;
    height: 22px;
    padding: 1px;
    text-align: center;
    border: 1px solid #ccc;
    font-size: 0.75rem;
    font-weight: 400;
    font-family: 'Inter', sans-serif;
    background: var(--white);
    border-radius: 2px;
}

.measurement-row .site-input:focus,
.margin-row .site-input:focus,
.depth-row .site-input:focus {
    outline: none;
    border-color: #00a9e0;
    box-shadow: 0 0 0 2px rgba(0, 169, 224, 0.2);
}

/* Checkboxes para Sangrado y Placa - 3 por fila */
.bleeding-row .tooth-cell,
.plaque-row .tooth-cell {
    display: flex;
    flex-direction: row;
    justify-content: space-evenly;
    align-items: center;
    padding: 1px 0;
}

.site-input {
    width: 100%;
    padding: 1px;
    text-align: center;
    border: none;
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    -moz-appearance: textfield;
}

/* Ocultar flechas de input number */
.site-input::-webkit-outer-spin-button,
.site-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.site-input:focus {
    outline: none;
    background: #fffacd;
}

.site-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin: 0;
    border: 1px solid #999;
    appearance: none;
    -webkit-appearance: none;
    border-radius: 2px;
    position: relative;
}

.site-checkbox:checked {
    background-color: #e74c3c;
    border-color: #c0392b;
}

.site-checkbox:checked::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
    position: absolute;
    top: -2px;
    left: 2px;
}

.plaque-row .site-checkbox:checked {
    background-color: #3498db;
    border-color: #2980b9;
}

.single-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border-color);
    padding: 0;
    min-height: 0;
}

.single-cell:last-child {
    border-right: none;
}

.tooth-number {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #333;
    background: var(--white);
    border-right: 1px solid #e0e0e0;
    cursor: pointer;
    transition: background 0.15s ease;
    position: relative;
    min-height: 26px;
}

.tooth-number:hover {
    background: #f8f9fa;
}

.tooth-number.absent {
    background: #e8e8e8;
    text-decoration: line-through;
    color: #999;
}

.tooth-number.implant {
    background: #d32f2f;
    color: var(--white);
    font-weight: 700;
}

.tooth-number.implant::before {
    content: "✓";
    position: absolute;
    top: 1px;
    right: 1px;
    font-size: 0.7rem;
    color: var(--white);
}

.furcation-btn, .mobility-btn {
    width: 100%;
    padding: 1px 1px;
    text-align: center;
    border: none;
    background: var(--white);
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s ease;
}

.furcation-btn:hover, .mobility-btn:hover {
    background: #f0f0f0;
}

.furcation-btn.grade-1 {
    background: #fff;
    border-bottom: 2px solid var(--text-color);
}

.furcation-btn.grade-2 {
    background: linear-gradient(180deg, var(--text-color) 50%, #fff 50%);
    color: var(--white);
}

.furcation-btn.grade-3 {
    background: var(--text-color);
    color: var(--white);
}

.mobility-btn.active {
    background: #ffeb3b;
    font-weight: 700;
}

/* ==========================================
   VISUAL CHART (CANVAS)
   ========================================== */
.visual-chart {
    border: 1px solid #ddd;
    padding: 0;
    margin: 10px 0;
    background: #fafafa;
    position: relative;
    min-height: 250px;
    width: 100%;
    overflow-x: auto;
}

.data-block {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 10px 0;
}

.svg-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: 100% auto;
    background-repeat: no-repeat;
    opacity: 0.5;
    pointer-events: none;
    z-index: 1;
}

.visual-chart h4 {
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;
    padding: 6px 10px;
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    color: #333;
}

.canvas-container {
    border: 1px solid #ddd;
    overflow: visible;
    background: #ffffff;
    height: 250px;
    position: relative;
    margin: 5px 0;
}

canvas {
    display: block;
    width: 100%;
    min-width: 100%;
    background: #ffffff;
    position: relative;
    z-index: 2;
    height: 100%;
}

/* ==========================================
   LEGEND BAR
   ========================================== */
.legend-bar {
    background: #1a1a1a;
    color: var(--white);
    padding: 10px 30px;
    margin: 0;
    border-top: 2px solid #000;
    border-bottom: 2px solid #000;
}

.legend-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    max-width: 1400px;
    margin: 0 auto;
}

.legend-item {
    font-size: 0.85rem;
    color: var(--white);
    white-space: nowrap;
}

.legend-item strong {
    font-weight: 700;
    font-size: 0.9rem;
    margin: 0 4px;
    color: #fff;
}

/* ==========================================
   MODAL
   ========================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: var(--white);
    margin: 50px auto;
    padding: 40px;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.close {
    color: var(--text-light);
    float: right;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: var(--danger-color);
}

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 25px;
}

.manual-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.manual-section:last-child {
    border-bottom: none;
}

.manual-section h3 {
    color: var(--accent-color);
    margin-bottom: 15px;
}

.manual-section ul {
    margin-left: 20px;
}

.manual-section li {
    margin-bottom: 10px;
}

.formula {
    background: var(--light-bg);
    padding: 15px;
    border-left: 4px solid var(--primary-color);
    font-family: 'Courier New', monospace;
    margin: 15px 0;
}

/* ==========================================
   FOOTER
   ========================================== */
.footer {
    background: var(--dark-color);
    color: var(--white);
    text-align: center;
    padding: 30px 20px;
    margin-top: 50px;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    body {
        background: white;
    }
    
    .header, .footer, .btn-primary, .btn-secondary, 
    .summary-section, .legend-section {
        display: none !important;
    }
    
    .arch-container {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .patient-info {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 1200px) {
    .teeth-grid {
        gap: 0px;
    }
    
    .site-input {
        font-size: 0.75rem;
        padding: 0px;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 15px;
    }
    
    .header-nav {
        width: 100%;
        justify-content: space-around;
    }
    
    .info-row, .exam-row {
        grid-template-columns: 1fr;
    }
    
    .row-label {
        width: 100px;
        font-size: 0.7rem;
    }
    
    .tooth-number {
        font-size: 0.8rem;
    }
    
    .site-input {
        font-size: 0.65rem;
        padding: 1px;
    }
    
    .modal-content {
        width: 95%;
        padding: 20px;
        margin: 20px auto;
    }
}

@media (max-width: 480px) {
    .teeth-grid {
        grid-template-columns: repeat(8, 1fr);
    }
    
    .legend-content {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    .header-nav,
    .btn-primary,
    .btn-secondary {
        display: none !important;
    }
    
    body {
        background: white;
        padding: 0;
    }
    
    .container {
        max-width: 100%;
        padding: 10px;
    }
    
    .patient-info,
    .arch-container {
        border: 2px solid black;
        page-break-inside: avoid;
    }
    
    .arch-container {
        page-break-after: auto;
    }
    
    .site-input,
    .tooth-number,
    .furcation-btn,
    .mobility-btn {
        border: 1px solid black !important;
        background: white !important;
    }
}
