/* /public/css/style.css (DEFINITIVE COMPLETE VERSION) */

/* --- FONT IMPORT --- */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* --- THEME COLOR VARIABLES --- */
/* Light Mode (Default) */
:root {
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --primary-accent: #0d6efd;
    --primary-accent-hover: #0b5ed7;
    --success-color: #198754;
    --danger-color: #dc3545;
    --danger-bg-color: #FFEBEE; /* ✅ ADDED Light mode danger bg */
    --warning-color: #ffc107;
    --shadow-color: rgba(0, 0, 0, 0.05);
    --archive-header-bg: #343a40;
    --archive-header-text: #ffffff;
    --archive-subheader-bg: #f0f2f5;
    --datetime-icon-invert: 0;
}

/* This rule applies dark mode variables if the OS is set to dark mode AND the user hasn't forced light mode */
@media (prefers-color-scheme: dark) {
    :root:not(.light-theme) {
        --bg-color: #121212;
        --surface-color: #1e1e1e;
        --text-primary: #e9ecef;
        --text-secondary: #adb5bd;
        --border-color: #495057;
        --primary-accent: #4dabf7;
        --primary-accent-hover: #74c0fc;
        --shadow-color: rgba(0, 123, 255, 0.1);
        --archive-header-bg: #2c3e50;
        --archive-header-text: #e9ecef;
        --archive-subheader-bg: #495057;
        --datetime-icon-invert: 1;
        --danger-bg-color: #2c1d1f; /* ✅ ADDED Dark mode danger bg */
    }
}

/* This rule applies dark mode variables if the user clicks the toggle button */
body.dark-theme {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-primary: #e9ecef;
    --text-secondary: #adb5bd;
    --border-color: #495057;
    --primary-accent: #4dabf7;
    --primary-accent-hover: #74c0fc;
    --shadow-color: rgba(0, 123, 255, 0.1);
    --archive-header-bg: #2c3e50;
    --archive-header-text: #e9ecef;
    --archive-subheader-bg: #495057;
    --datetime-icon-invert: 1;
    --danger-bg-color: #2c1d1f; /* ✅ ADDED Dark mode danger bg */
}

/* --- GLOBAL STYLES --- */
* { box-sizing: border-box; }
body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 20px;
    transition: background-color 0.2s, color 0.2s;
}
.container {
    max-width: 1400px;
    margin: 0 auto;
    background-color: var(--surface-color);
    padding: 20px 30px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px var(--shadow-color);
}
a { color: var(--primary-accent); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--primary-accent-hover); }
hr { border: none; border-top: 1px solid var(--border-color); margin: 20px 0; }
h1, h2, h3, h4 { margin-top: 0; }

/* --- HEADER & NAVIGATION --- */
.header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; margin-bottom: 20px; }
.header h1 { margin: 0; font-size: 1.5em; }
.header nav a { color: var(--text-secondary); padding: 8px 12px; border-radius: 5px; transition: all 0.2s; }
.header nav a:hover { color: var(--text-primary); background-color: var(--border-color); text-decoration: none; }

/* --- DROPDOWN MENU (FOR ADMIN) --- */
.dropdown { position: relative; display: inline-block; }
.dropdown-btn { font-weight: 500; }
.dropdown-content { display: none; position: absolute; background-color: var(--surface-color); min-width: 200px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; border-radius: 5px; border: 1px solid var(--border-color); padding: 5px 0; }
.dropdown-content a { color: var(--text-primary); padding: 12px 16px; display: block; }
.dropdown-content a:hover { background-color: var(--bg-color); }
.dropdown:hover .dropdown-content { display: block; }

/* --- TABLES --- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border-color); }
thead th { background-color: var(--bg-color); }
tbody tr:hover { background-color: rgba(108, 117, 125, 0.1) !important; }

/* --- DYNAMIC FORM LAYOUT --- */
.form-section-container { border: 1px solid var(--border-color); padding: 20px; margin-bottom: 20px; border-radius: 5px; }
legend { font-weight: 700; padding: 0 10px; color: var(--primary-accent); }
.form-section-grid { display: grid; gap: 20px; align-items: start; }
.grid-columns-1 { grid-template-columns: 1fr; }
.grid-columns-2 { grid-template-columns: 1fr 1fr; }
.grid-columns-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-columns-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.full-width { grid-column: 1 / -1; }

/* --- FORM ELEMENTS --- */
input, textarea, select {
    background-color: var(--bg-color); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 4px;
    padding: 10px; font-size: 1em; width: 100%;
}
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--primary-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-accent) 25%, transparent);
}
input:disabled, textarea:disabled, select:disabled {
    background-color: color-mix(in srgb, var(--surface-color) 50%, var(--bg-color));
    color: var(--text-secondary); cursor: not-allowed; opacity: 1;
}
input[type="radio"], input[type="checkbox"] { width: auto; }
.radio-group { display: flex; gap: 15px; align-items: center; }

/* --- BUTTONS --- */
.button-style, button {
    background-color: var(--primary-accent); color: #fff; border: none;
    border-radius: 5px; padding: 10px 15px; cursor: pointer; font-weight: 500;
    text-decoration: none; display: inline-block; text-align: center;
}
.button-style:hover, button:hover { background-color: var(--primary-accent-hover); color:#fff; text-decoration:none; }
.button-style-green { background-color: var(--success-color); }
.button-style-red { background-color: var(--danger-color); }
.button-style-gray { background-color: var(--text-secondary); }

/* --- STATUS BADGES (IMPROVED) --- */
.status {
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    color: #fff; /* White text for all badges for better contrast */
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2); /* Subtle shadow for readability */
}
.status-pending_supervisor, .status-pending_oim, .status-pending_closure_supervisor, .status-pending_closure_oim, .status-awaiting_revalidation {
    background-color: var(--warning-color);
    color: #212529; /* Dark text for yellow background */
    text-shadow: none;
}
.status-active { background-color: var(--success-color); }
.status-rejected { background-color: var(--danger-color); }
.status-closed { background-color: var(--text-secondary); }
.status-scheduled { background-color: var(--primary-accent); } /* New style for Scheduled */


/* --- SPECIFIC COMPONENT STYLES --- */
.action-form { margin-top: 20px; padding: 15px; border-radius: 5px; border: 1px solid var(--border-color); }
.signature-box { text-align: center; }
.certificate-view { border: 2px solid var(--primary-accent); border-radius: 5px; margin-bottom: 20px; }
.certificate-view h4 { background-color: var(--primary-accent); color: white; margin: 0; padding: 10px; }
.certificate-view-body { padding: 15px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

/* --- OIM DASHBOARD COLORS --- */
.dept-color-1 { background-color: rgba(13, 110, 253, 0.1); }
.dept-color-2 { background-color: rgba(25, 135, 84, 0.1); }
.dept-color-3 { background-color: rgba(255, 193, 7, 0.1); }
/* Add more as needed */

/* Style for aligning radio buttons horizontally */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

/* --- Styles for non-wrapping table cells --- */
table th,
table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- LOGIN PAGE STYLES --- */

/* This makes the body a full-height flex container to center the login box */
body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 0;
}

.login-container {
    background-color: var(--surface-color);
    padding: 40px 30px;
    border-radius: 10px;
    box-shadow: 0 4px 15px var(--shadow-color);
    width: 100%;
    max-width: 400px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.login-container h1 {
    margin-bottom: 25px;
    font-size: 1.8em;
}

.login-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    text-align: left;
}

.login-container input {
    margin-bottom: 20px;
}

.login-container button[type="submit"] {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    font-weight: 500;
}

/* Styles for the password show/hide button */
.password-wrapper {
    position: relative;
    width: 100%;
}

.password-wrapper input {
    padding-right: 45px; /* Make space for the button */
}

.toggle-password {
    position: absolute;
    top: 35px;
    right: 10px;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
    padding: 0;
}
.toggle-password:hover {
    color: var(--primary-accent);
}

/* --- Layout Fix for Form Elements --- */
.form-section-container, .action-form, .signature-box {
    box-sizing: border-box; /* This is the key property */
}

/* Style for highlighting fields that have been edited */
.field-changed {
    border: 2px solid var(--warning-color) !important;
    background-color: color-mix(in srgb, var(--warning-color) 10%, transparent) !important;
}


/* Add this to make the existing .field-changed style visible on labels */
label.field-changed {
    display: inline-block;
    padding: 3px 6px;
    border-radius: 4px;
}


/* --- ARCHIVE PAGE STYLES (CORRECTED) --- */
.archive-container { 
    margin-bottom: 20px; 
}
.year-group, .month-group { 
    border: 1px solid var(--border-color); 
    border-radius: 5px; 
    margin-bottom: 10px; 
    overflow: hidden;
}
.year-header, .month-header { 
    padding: 10px 15px; 
    font-weight: bold; 
    cursor: pointer; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    transition: background-color 0.2s;
}
.year-header { 
    background-color: var(--archive-header-bg); 
    color: var(--archive-header-text); 
    font-size: 1.4em; 
}
.month-header { 
    background-color: var(--archive-subheader-bg); 
    color: var(--text-primary);
    font-size: 1.1em; 
    border-top: 1px solid var(--border-color); 
}
.year-header:hover { 
    background-color: color-mix(in srgb, var(--archive-header-bg) 85%, #000);
}
.month-header:hover { 
    background-color: color-mix(in srgb, var(--archive-subheader-bg) 85%, var(--text-primary));
}
.header-count { 
    background-color: var(--text-secondary); 
    color: var(--surface-color); 
    padding: 3px 8px; 
    border-radius: 10px; 
    font-size: 0.8em; 
}
.arrow { 
    transition: transform 0.2s ease-in-out; 
    font-size: 1.2em;
}
.collapsible-header.collapsed .arrow { 
    transform: rotate(-90deg); 
}
.collapsible-content { 
    display: none; 
    padding: 0;
    background-color: var(--surface-color);
}
.archive-table {
    margin-bottom: 0;
}
.archive-table td {
    white-space: normal; /* Allow regular cells to wrap */
}
/* This is the specific fix for the table header */
.archive-table thead th {
    background-color: var(--surface-color);
    white-space: normal; /* Allow header cells to wrap */
}

.status-awaiting_revalidation {
    background-color: #FFA500; /* Orange */
    color: #FFFFFF;
    padding: 5px 10px;
    border-radius: 12px;
    font-weight: bold;
    text-transform: capitalize;
}

/* --- PERMIT VIEW & ACTION STYLES --- */

/* Action-specific container borders */
.supervisor-action { border-color: var(--warning-color); }
.oim-action { border-color: var(--success-color); }
.closure-section { border-color: var(--text-secondary); }

/* Small tweak for signature box content */
.signature-box p { margin: 5px 0; }

/* Improved highlighting for complex changed fields like checklists */
.checklist-row.field-changed {
    padding: 10px;
    border-radius: 4px;
}

/* REVISED rule for checkbox/radio rows */
.checklist-row {
    display: flex;              /* Arrange items in a row */
    justify-content: space-between; /* <<< Pushes label to the left and options to the right */
    align-items: center;            /* Vertically aligns the text and buttons */
    width: 100%;                    /* Ensures the row uses the full available width */
    padding: 6px 0;                 /* Adds a little vertical spacing for breathing room */
}

/* This ensures single checkboxes align to the start of their container */
.checklist-row.single-checkbox {
    justify-content: flex-start;
}

/* --- CERTIFICATE STYLING --- */

/* Main certificate container */
.certificate-view {
    background-color: color-mix(in srgb, var(--surface-color) 95%, var(--bg-color));
    border: 1px solid var(--border-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-accent) 50%, transparent), 
                inset 0 0 15px rgba(0,0,0,0.1), 
                2px 2px 8px var(--shadow-color);
    border-radius: 5px;
    margin-bottom: 25px;
    position: relative; /* Needed for the optional seal */
    overflow: hidden;   /* Keeps the seal contained */
}

/* Formal header style */
.certificate-view h4 {
    background-color: var(--archive-header-bg);
    color: var(--archive-header-text);
    padding: 12px 20px;
    margin: 0;
    font-size: 1.1em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--primary-accent);
}

/* Adjusting the body padding */
.certificate-view-body {
    padding: 20px;
    font-family: Georgia, 'Times New Roman', Times, serif; /* A more formal font */
}

.certificate-view-body strong {
    color: var(--text-secondary);
}

.permit-notice {
    padding: 15px;
    background-color: color-mix(in srgb, var(--warning-color) 15%, transparent);
    border: 1px solid var(--warning-color);
    border-radius: 5px;
}

/* --- SIGNATURE BOX HIGHLIGHTING --- */

/* Base style for all signature boxes */
.signature-box {
    padding: 15px;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s, border-color 0.3s;
    background-color: color-mix(in srgb, var(--surface-color) 50%, transparent);
}

/* Green highlight for approvals */
.signature-box.is-approved {
    border-left: 5px solid var(--success-color);
    background-color: color-mix(in srgb, var(--success-color) 10%, transparent);
}

/* Orange highlight for closures */
.signature-box.is-closed {
    border-left: 5px solid var(--warning-color);
    background-color: color-mix(in srgb, var(--warning-color) 10%, transparent);
}

/* --- DYNAMIC CERTIFICATE WATERMARK --- */

/* Base style for the watermark pseudo-element */
.certificate-view::after {
    content: '';
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 60px;
    height: 60px;
    background-repeat: no-repeat;
    background-size: contain;
    opacity: 0.1;
}

/* Style for ACTIVE certificates (Green Checkmark) */
.certificate-view.cert-status-active::after {
    background-image: url('https://api.iconify.design/mdi/shield-check.svg?color=%2328a745');
}

/* Style for CLOSED certificates (Red 'X') */
.certificate-view.cert-status-closed::after {
    background-image: url('https://api.iconify.design/mdi/shield-close.svg?color=%23dc3545');
}

.signature-box .signature-line {
    border-bottom: 1px solid var(--text-primary);
    height: 30px; /* Space for signature */
    margin-top: 15px;
    margin-bottom: 5px;
}

.reading-row {
    display: flex;
    align-items: center;
    gap: 10px; /* space between items */
    width: 100%;
}

.reading-row label {
    flex: 1; /* Allows the label to take up the remaining space */
    font-weight: bold;
    color: var(--text-secondary);
}

.reading-row input {
    flex: 0 0 120px; /* Gives the input fields a fixed width */
    text-align: center;
}

/*
--- Styles for Reject & Cancel ---
*/

/* New Red Button */
.button-style-red {
    background-color: var(--danger-color, #D32F2F);
    color: #ffffff;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.2s ease;
    vertical-align: middle; /* Aligns it with other buttons */
}
.button-style-red:hover {
    background-color: var(--danger-color-hover, #B71C1C);
}

/* Danger Zone Box for Cancellation */
.danger-zone {
    border: 1px solid var(--danger-color, #D32F2F);
    background-color: var(--danger-bg-color, #FFEBEE);
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
}
.danger-zone h3 {
    color: var(--danger-color, #D32F2F);
    margin-top: 0;
}
/* ✅ ADDED THIS RULE FOR READABILITY */
.danger-zone p {
    color: var(--text-primary);
    opacity: 0.9;
}


/* New Status Badges */
.status-cancelled,
.status-rejected {
    background-color: var(--danger-color, #D32F2F);
    color: #fff;
}
/* New Issued/Pending Status Badge */
.status-issued_pending {
    background-color: #0288D1; /* Blue */
    color: #fff;
}


/*
--- TRA Modal Styles (THIS IS THE CORRECT, FINAL BLOCK) ---
*/

/* Modal styles (re-using isolation modal styles) */
.modal-backdrop {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; top: 0; 
    width: 100%; height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.5);
}
.modal-content {
    background-color: var(--surface-color);
    color: var(--text-primary);
    margin: 10% auto; 
    padding: 20px; 
    border: 1px solid var(--border-color); 
    width: 80%; 
    max-width: 700px; 
    border-radius: 5px;
}
.modal-footer {
    text-align: right;
    margin-top: 20px;
}

/* Specific styles for the TRA checklist inside the modal */
.tra-checklist-modal {
    max-height: 400px; /* Taller for the modal */
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 4px;
    background-color: var(--background-color);
}
.tra-checklist-modal label {
    display: block;
    margin-bottom: 8px;
    padding: 5px;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.tra-checklist-modal label:hover {
    background-color: var(--border-color);
}

/* Summary box that appears under the button */
.tra-summary {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-top: 10px;
    padding: 10px;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    min-height: 40px;
}
.tra-summary ul {
    margin: 0;
    padding-left: 20px;
}

/*
--- DATETIME-LOCAL INPUT FIXES (SINGLE, CORRECTED BLOCK) ---
*/

/* 1. Base style for the input */
input[type="datetime-local"] {
    position: relative; /* Allows us to position the icon */
    cursor: pointer;
}

/* 2. Style the calendar picker icon */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    /* Position it absolutely within the input */
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    
    /* Make it larger and easier to click */
    padding: 5px;
    width: 25px;
    height: 25px;
    
    /* Ensure it's clickable */
    cursor: pointer;
    
    /* Fix for dark mode using a CSS variable */
    filter: invert(var(--datetime-icon-invert, 0));
}

/* 3. Fix for Firefox (less common issue, but good to have) */
input[type="datetime-local"]::-moz-calendar-picker-indicator {
    filter: invert(var(--datetime-icon-invert, 0));
}

/* --- VIEW PERMIT HEADER --- 
*/
.view-permit-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Aligns items to the top */
    flex-wrap: wrap; /* Allows button to wrap on small screens */
    gap: 15px; /* Adds spacing between title and button */
    margin-bottom: 15px; /* Space below the header area */
}
.view-permit-header h1 {
    margin: 0; /* Remove default h1 margin */
    flex-grow: 1; /* Allows title to take available space */
}

/* --- Highlight for active, disabled selected fields --- */
.checklist-row label:has(input[type="radio"]:disabled:checked),
.checklist-row label:has(input[type="checkbox"]:disabled:checked) {
    color: var(--success-color);
    font-weight: 700;
    background-color: color-mix(in srgb, var(--success-color) 10%, transparent);
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid color-mix(in srgb, var(--success-color) 30%, transparent);
}


/* --- ✅ NEW STYLE: Red status for out-of-hours --- */
.status-warning-danger {
    background-color: var(--danger-color) !important;
    color: #fff !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2) !important;
}


/* =================================================================== */
/* PRINT-SPECIFIC STYLES - Place at the VERY END of your style.css     */
/* =================================================================== */
@media print {

    /* --- Page & Browser Chrome Control --- */
    @page {
        size: A4;
        margin: 10mm; /* A safe minimum margin for the paper edge */
    }

    /* --- Hide Unwanted Elements --- */
    body > .container > .header,
    .action-form,
    .action-buttons,
    .certificate-action-footer,
    #save-reading-btn,
    #isolation-modal,
    #deisolation-modal,
    #tra-modal,
    .view-permit-header form { /* Hide the cancel button form when printing */
        display: none !important;
    }

    /* --- Force Content to Fill the Page --- */
    body,
    .container,
    .main-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background-color: #fff !important; /* Ensure white background */
    }
    
    /* --- General Print Appearance --- */
    .form-section-container,
    .signature-box {
        box-shadow: none !important;
        border: 1px solid #ccc;
    }

    /* --- Page Break Utility --- */
    .page-break {
        page-break-before: always;
        border-top: 2px dashed #ccc;
        padding-top: 10mm;
    }
}
      
      /*
--- STATUS BADGE FIXES ---
*/

/* This makes "Awaiting Revalidation" orange/warning */
.status-awaiting_revalidation {
    background-color: var(--warning-color);
    color: #212529; 
    text-shadow: none;
}

/* This makes "Offshift" (which is issued_pending) RED */
.status-offshift {
    background-color: var(--danger-color);
    color: #fff;
}
/* --- Add this to /public/css/style.css --- */

/* Sortable Table Header Links */
th a.sort-header {
    color: var(--text-primary);
    text-decoration: none;
    position: relative;
    display: block;
    padding-right: 20px; /* Make space for the arrow */
}

th a.sort-header:hover {
    color: var(--primary-color);
}

/* Arrow styling */
th a.sort-header::after {
    content: ' ';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    opacity: 0.3; /* Default "dimmed" arrow */
}

th a.sort-header:hover::after {
     opacity: 0.6;
}

/* "Ascending" arrow (points up) */
th a.sort-asc::after {
    border-bottom-color: var(--text-primary);
    opacity: 1;
}

/* "Descending" arrow (points down) */
th a.sort-desc::after {
    border-top-color: var(--text-primary);
    opacity: 1;
}
      /* Primjer za style.css */
.status-expired {
    background-color: #2c3e50; /* Tamno siva/crna */
    color: white;
    border: 1px solid #000;
}

