/**
 * WardMate Patient Chart Styles
 * Interactive timeline visualization for patient data
 */

/* ============================================
   CHART CONTAINER
   ============================================ */
.patient-chart {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ============================================
   CHART HEADER
   ============================================ */
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chart-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.chart-title .material-symbols-rounded {
    font-size: 24px;
    color: var(--primary);
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-btn:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.chart-btn:active {
    transform: scale(0.96);
}

.chart-btn .material-symbols-rounded {
    font-size: 18px;
}

.chart-btn-today {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.chart-btn-today:hover {
    background: var(--primary-dark, #004d66);
    border-color: var(--primary-dark, #004d66);
    color: white;
}

/* ============================================
   TIME AXIS
   ============================================ */
.chart-time-axis-container {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chart-time-axis-wrapper {
    flex: 1;
    overflow: hidden;
}

#chartTimeAxis {
    display: block;
    cursor: default;
}

/* ============================================
   CHART BODY
   ============================================ */
.chart-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-x;
}

.chart-body:active {
    cursor: grabbing;
}

/* ============================================
   CHART SECTIONS
   ============================================ */
.chart-section {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chart-section:last-child {
    border-bottom: none;
}

.chart-section-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    min-width: 60px;
    padding: 8px 4px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    font-size: 10px;
    font-weight: 500;
    color: var(--text-sec);
    text-align: center;
    gap: 4px;
}

.chart-section-label .material-symbols-rounded {
    font-size: 20px;
    color: var(--primary);
}



/* ============================================
   CHART LEGEND
   ============================================ */
.chart-section-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.chart-canvas {
    display: block;
    width: 100%;
    flex: 1;
    min-height: 0;
}

.chart-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 6px 12px;
    background: var(--surface);
    font-size: 10px;
    color: var(--text-sec);
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ============================================
   CROSSHAIR
   ============================================ */
.chart-crosshair {
    position: fixed;
    pointer-events: none;
    z-index: 100;
    display: none;
}

.crosshair-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background: var(--primary);
    opacity: 0.8;
}

.crosshair-line::before,
.crosshair-line::after {
    content: '';
    position: absolute;
    left: -4px;
    width: 9px;
    height: 9px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    background: var(--bg);
}

.crosshair-line::before {
    top: 0;
}

.crosshair-line::after {
    bottom: 0;
}

.crosshair-tooltip {
    position: absolute;
    top: -10px;
    left: 10px;
    transform: translateY(-100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 12px;
    min-width: 150px;
    max-width: 280px;
}

.crosshair-time {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.crosshair-section {
    margin-top: 4px;
    color: var(--text);
    line-height: 1.4;
}

.crosshair-section b {
    color: var(--text-sec);
    font-weight: 500;
}

/* ============================================
   TOOLTIP
   ============================================ */
.chart-tooltip {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 12px;
    pointer-events: none;
    z-index: 101;
    max-width: 250px;
}

/* ============================================
   RESPONSIVE STYLES
   ============================================ */

/* Tablet Portrait */
@media (max-width: 768px) {
    .chart-header {
        padding: 10px 12px;
    }

    .chart-title {
        font-size: 14px;
    }

    .chart-btn {
        padding: 5px 10px;
        font-size: 12px;
    }

    .chart-btn-today span:last-child {
        display: none;
    }

    .chart-section-label {
        width: 50px;
        min-width: 50px;
        font-size: 9px;
    }

    .chart-section-label .material-symbols-rounded {
        font-size: 18px;
    }

    .chart-legend {
        gap: 8px;
        font-size: 9px;
    }

    .legend-color {
        width: 8px;
        height: 8px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .chart-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .chart-controls {
        width: 100%;
        justify-content: flex-end;
    }

    .chart-section-label {
        width: 40px;
        min-width: 40px;
        padding: 4px 2px;
    }

    .chart-section-label span:last-child {
        display: none;
    }

    .chart-legend {
        flex-wrap: wrap;
        gap: 6px;
        padding: 4px 6px;
    }

    .legend-item {
        font-size: 8px;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    .chart-header {
        padding: 6px 12px;
    }

    .chart-section-label {
        width: 45px;
        min-width: 45px;
    }

    .chart-legend {
        display: none;
    }
}

/* ============================================
   DARK MODE ADJUSTMENTS
   ============================================ */
[data-theme="dark"] .patient-chart {
    background: var(--bg);
}

[data-theme="dark"] .chart-header,
[data-theme="dark"] .chart-section-label,
[data-theme="dark"] .chart-legend,
[data-theme="dark"] .chart-time-axis-container {
    background: var(--surface);
}

[data-theme="dark"] .crosshair-tooltip,
[data-theme="dark"] .chart-tooltip {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .chart-controls {
        display: none;
    }

    .chart-body {
        overflow: visible;
    }

    .patient-chart {
        break-inside: avoid;
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes chartPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

.chart-loading {
    animation: chartPulse 1.5s ease-in-out infinite;
}

/* ============================================
   DATA ENTRY FORM (for adding new values)
   ============================================ */
.chart-data-entry {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border-radius: 12px;
    margin-top: 12px;
}

.chart-data-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.chart-data-entry-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.chart-data-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.chart-data-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 80px;
}

.chart-data-field label {
    font-size: 11px;
    color: var(--text-sec);
    font-weight: 500;
}

.chart-data-field input,
.chart-data-field select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
}

.chart-data-field input:focus,
.chart-data-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-bg);
}

.chart-data-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* ============================================
   VITAL SIGNS QUICK ENTRY
   ============================================ */
.vital-quick-entry {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    padding: 12px;
    background: var(--surface);
    border-radius: 8px;
    margin-bottom: 12px;
}

.vital-input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.vital-input-group label {
    font-size: 10px;
    color: var(--text-sec);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.vital-input-group input {
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    text-align: center;
}

.vital-input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Color coding for vital inputs */
.vital-input-group[data-type="bp"] input:focus {
    border-color: #e53935;
}

.vital-input-group[data-type="pulse"] input:focus {
    border-color: #1976d2;
}

.vital-input-group[data-type="temp"] input:focus {
    border-color: #ff9800;
}

.vital-input-group[data-type="spo2"] input:focus {
    border-color: #4caf50;
}

/* ============================================
   MEDICATION ENTRY
   ============================================ */
.med-entry-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.med-entry-row .med-name {
    flex: 2;
    min-width: 150px;
}

.med-entry-row .med-dose {
    flex: 1;
    min-width: 80px;
}

.med-entry-row .med-route {
    flex: 0.5;
    min-width: 60px;
}

.med-type-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg);
    border-radius: 6px;
}

.med-type-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-sec);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.med-type-btn.active {
    background: var(--primary);
    color: white;
}

/* ============================================
   BALANCE ENTRY
   ============================================ */
.balance-entry-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

.balance-input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.balance-input-group.intake label {
    color: #2196f3;
}

.balance-input-group.output label {
    color: #ff5722;
}

.balance-total {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: var(--bg);
    border-radius: 8px;
    min-width: 100px;
}

.balance-total-label {
    font-size: 10px;
    color: var(--text-sec);
}

.balance-total-value {
    font-size: 18px;
    font-weight: 600;
}

.balance-total-value.positive {
    color: #2196f3;
}

.balance-total-value.negative {
    color: #ff5722;
}

/* ============================================
   TAB INTEGRATION
   ============================================ */
#tabKurve {
    padding: 0;
}

#tabKurve .patient-chart {
    border-radius: 0;
    border: none;
}

/* Chart container within edit modal */
#patientChartContainer {
    width: 100%;
    height: 100%;
    min-height: 400px;
    max-height: calc(100vh - 200px);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.chart-btn:focus-visible,
.vital-input-group input:focus-visible,
.med-entry-row input:focus-visible,
.balance-input-group input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .chart-section-label,
    .chart-legend {
        background: var(--bg);
    }

    .crosshair-line {
        width: 2px;
        background: var(--text);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chart-loading {
        animation: none;
    }

    .chart-btn,
    .med-type-btn {
        transition: none;
    }
}
