/* style.css - Rajavithi Hospital Consult Form Overlay CSS */

:root {
    --bg-dark: #000000;
    --bg-sidebar: rgba(18, 18, 18, 0.92);
    --bg-card: #1a1a1a;
    --border-color: #333333;
    --text-primary: #ffffff;
    --text-secondary: #a7a7a7;
    --accent-color: #76b900; /* NVIDIA Green */
    --accent-hover: #8ed300;  /* Lighter Green for Hover */
    --accent-pressed: #5a8d00; /* Pressed NVIDIA Green */
    --success-color: #76b900; 
    --success-hover: #8ed300;
    --danger-color: #e52020; /* NVIDIA Red */
    --font-ui: 'Inter', 'Sarabun', -apple-system, sans-serif;
    --font-print: 'THSarabunNew', 'Sarabun', sans-serif;
    
    /* Layout Variables */
    --sidebar-width: 480px;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
}

/* App Container Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* Sidebar Controls */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 10;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.logo-pulse {
    width: 12px;
    height: 12px;
    background-color: var(--success-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success-color);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(118, 185, 0, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(118, 185, 0, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(118, 185, 0, 0); }
}

.logo-text {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #76b900, #ffffff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.sidebar-header p {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Navigation Tabs */
.sidebar-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background-color: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    padding: 12px 4px;
    font-size: 11px;
    font-family: var(--font-ui);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all 0.25s ease;
}

.tab-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-color);
    background-color: rgba(118, 185, 0, 0.06);
}

/* Tab Content Scroll Container */
.tab-content-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Input Fields Grid */
.input-group-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
}

.col-full { grid-column: span 12; }
.col-half { grid-column: span 6; }
.col-third { grid-column: span 4; }
.col-quarter { grid-column: span 3; }

.section-divider {
    grid-column: span 12;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-hover);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(118, 185, 0, 0.25);
    padding-bottom: 6px;
    margin-top: 12px;
    margin-bottom: 4px;
}

.input-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-field input, 
.input-field textarea, 
.input-field select {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    color: var(--text-primary);
    padding: 10px 14px;
    font-family: var(--font-ui);
    font-size: 13.5px;
    outline: none;
    transition: all 0.2s ease;
}

.input-field textarea {
    resize: vertical;
    line-height: 1.5;
}

.input-field input:focus, 
.input-field textarea:focus, 
.input-field select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(118, 185, 0, 0.25);
    background-color: #0c0c0c;
}

.helper-text {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Buttons */
.btn {
    font-family: var(--font-ui);
    font-weight: 700;
    padding: 10px 18px;
    border-radius: 2px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--accent-color);
    color: #000000;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(118, 185, 0, 0.4);
}

.btn-primary:active {
    background-color: var(--accent-pressed);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-success {
    background-color: var(--success-color);
    color: #000000;
}

.btn-success:hover {
    background-color: var(--success-hover);
    box-shadow: 0 2px 8px rgba(118, 185, 0, 0.4);
}

.btn-success:active {
    background-color: var(--accent-pressed);
}

.btn-full { width: 100%; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Calibration Settings Styles */
.calibration-settings {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.cal-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    padding: 16px;
    position: relative;
    overflow: hidden;
}

.cal-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 8px;
    height: 8px;
    background-color: var(--accent-color);
}

.cal-section h3 {
    font-size: 14.5px;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-num {
    background-color: var(--accent-color);
    color: #000000;
    width: 18px;
    height: 18px;
    border-radius: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 11.5px;
    margin-bottom: 12px;
    line-height: 1.4;
}

.control-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.num-control {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.num-control label {
    font-size: 11px;
    color: var(--text-secondary);
}

.input-nudge-wrapper {
    display: flex;
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.input-nudge-wrapper input {
    flex: 1;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    text-align: center;
    font-family: var(--font-ui);
    font-size: 13px;
    padding: 6px 4px;
    outline: none;
}

/* Remove up/down spinners on input type number */
.input-nudge-wrapper input::-webkit-outer-spin-button,
.input-nudge-wrapper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.input-nudge-wrapper input[type=number] {
    -moz-appearance: textfield;
}

.nudge-btn {
    background-color: rgba(255, 255, 255, 0.04);
    border: none;
    color: var(--text-secondary);
    padding: 0 8px;
    font-size: 11px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.1s ease;
}

.nudge-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.info-alert {
    background-color: rgba(118, 185, 0, 0.08);
    border: 1px dashed rgba(118, 185, 0, 0.3);
    color: var(--text-secondary);
    padding: 12px;
    border-radius: 2px;
    font-size: 12px;
    text-align: center;
    line-height: 1.5;
}

.selected-field-badge {
    background-color: rgba(118, 185, 0, 0.15);
    border: 1px solid rgba(118, 185, 0, 0.35);
    border-radius: 2px;
    padding: 8px 12px;
    font-size: 12px;
    margin-bottom: 12px;
}

.selected-field-badge strong {
    color: var(--accent-hover);
}

/* Nudge Pad UI */
.nudge-pad-wrapper {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.nudge-pad-wrapper label {
    font-size: 11px;
    color: var(--text-secondary);
    align-self: flex-start;
}

.nudge-pad {
    display: grid;
    grid-template-areas: 
        ".    up    ."
        "left center right"
        ".    down  .";
    gap: 6px;
    width: 140px;
    height: 140px;
}

.np-btn {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
}

.np-btn:hover {
    background-color: var(--accent-color);
    border-color: var(--accent-hover);
    box-shadow: 0 0 10px rgba(118, 185, 0, 0.5);
    color: #000000;
}

.np-up { grid-area: up; }
.np-left { grid-area: left; }
.np-center { 
    grid-area: center; 
    font-size: 16px; 
    color: var(--danger-color);
}
.np-center:hover {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: var(--danger-color);
    box-shadow: none;
    color: var(--danger-color);
}
.np-right { grid-area: right; }
.np-down { grid-area: down; }

.nudge-tip {
    font-size: 10.5px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
    font-style: italic;
}

.profile-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* Preview Area Panel */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #111111;
}

/* Top Controls Bar */
.preview-controls-bar {
    background-color: rgba(18, 18, 18, 0.8);
    border-bottom: 1px solid var(--border-color);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    backdrop-filter: blur(10px);
}

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

.slider-item {
    flex: 1;
    max-width: 320px;
}

.slider-item label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.slider-item input[type=range] {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 0;
    outline: none;
    -webkit-appearance: none;
}

.slider-item input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 2px;
    background: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    transition: background 0.15s ease;
}

.slider-item input[type=range]::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

#bg-opacity-val {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 600;
    width: 35px;
    text-align: right;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

/* Switch Styles */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.slider-round {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
    transition: .3s;
}

.slider-round:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 2px;
    transition: .3s;
}

.toggle-switch input:checked + .slider-round {
    background-color: var(--success-color);
}

.toggle-switch input:checked + .slider-round:before {
    transform: translateX(16px);
}

.toggle-switch .label-text {
    font-size: 12px;
    color: var(--text-secondary);
    user-select: none;
}

.toggle-switch:hover .label-text {
    color: var(--text-primary);
}

/* A4 Sheet Container / Viewport */
.sheet-viewport {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: grab;
    user-select: none;
}

.a4-sheet {
    width: 210mm;
    height: 297mm;
    background-color: white;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
    transform-origin: center center;
    flex-shrink: 0;
}

/* Background overlay of the scanned A4 paper */
.bg-form-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    z-index: 1;
    pointer-events: none;
    opacity: 0.8; /* Controlled by slider */
    transition: opacity 0.1s ease;
}

/* Centimeter Grid Overlay for visual calibration */
.calibration-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    display: none;
    background-image: 
        linear-gradient(to right, rgba(118, 185, 0, 0.08) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(118, 185, 0, 0.08) 1px, transparent 1px),
        linear-gradient(to right, rgba(118, 185, 0, 0.25) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(118, 185, 0, 0.25) 1px, transparent 1px);
    background-size: 1mm 1mm, 1mm 1mm, 10mm 10mm, 10mm 10mm;
}

/* Container for printable absolute-positioned text blocks */
.text-fields-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
}

/* Dynamic text element in preview */
.text-overlay-element {
    position: absolute;
    color: #111; /* Dark grey/black for printed ink */
    font-family: var(--font-print);
    line-height: 1.1;
    white-space: pre-wrap;
    word-break: break-word;
    user-select: none;
    cursor: pointer;
    border: 1px solid transparent;
    padding: 1px 2px;
}

/* Show outlines during calibration */
body.show-outlines .text-overlay-element {
    border: 1px dashed rgba(118, 185, 0, 0.35);
    background-color: rgba(118, 185, 0, 0.02);
}

body.show-outlines .text-overlay-element:hover {
    border-color: rgba(118, 185, 0, 0.6);
    background-color: rgba(118, 185, 0, 0.05);
}

/* Active selected element */
.text-overlay-element.selected {
    border: 1px dashed var(--danger-color) !important;
    background-color: rgba(239, 68, 68, 0.08) !important;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.3);
    z-index: 100;
}

/* Priority mark design (circle markers) */
.priority-checkbox-mark {
    font-family: var(--font-ui);
    font-weight: bold;
    color: #000;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: var(--success-color);
    color: #000000;
    padding: 12px 24px;
    border-radius: 2px;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* ==========================================================================
   PRINT STYLES (@media print)
   ========================================================================== */

@media print {
    /* Base print resets */
    html, body {
        background-color: #fff;
        color: #000;
        width: 210mm;
        height: 297mm;
        overflow: visible;
    }

    body * {
        visibility: hidden;
    }

    .app-container {
        display: block;
        padding: 0;
        margin: 0;
        width: 210mm;
        height: 297mm;
        border: none;
    }

    /* Print only the sheet viewport and A4 sheet */
    .sheet-viewport,
    .sheet-viewport * {
        visibility: visible;
    }

    .sidebar,
    .preview-controls-bar,
    .toast {
        display: none !important;
    }

    .sheet-viewport {
        padding: 0 !important;
        margin: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        overflow: hidden !important;
        display: block !important;
        position: absolute;
        top: 0;
        left: 0;
    }

    .a4-sheet {
        position: absolute;
        top: 0;
        left: 0;
        width: 210mm !important;
        height: 297mm !important;
        box-shadow: none !important;
        transform: scale(1) !important; /* Force scale 1 in print */
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        page-break-after: avoid;
        page-break-before: avoid;
        background-color: white !important;
    }

    /* Background image visibility toggle */
    .bg-form-overlay {
        display: none; /* Default: hide background when printing */
    }

    /* If user checked "print background" */
    body.print-background .bg-form-overlay {
        display: block !important;
        opacity: 1 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .calibration-grid-overlay {
        display: none !important;
    }

    .text-overlay-element {
        border: none !important;
        background: none !important;
        color: #000 !important;
    }

    /* Page Setup */
    @page {
        size: A4 portrait;
        margin: 0;
    }
}
