/* ==========================================
   1. CSS VARIABLES & RESET
   ========================================== */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #2ecc71;
    --bg-color: #f4f7f6;
    --text-color: #333;
    --border-color: #ddd;
    --sidebar-width: 250px;
    --header-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* ==========================================
   2. MAIN LAYOUT (GRID / FLEX)
   ========================================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* QA FIX: Vraćanje osnovne klase bočne trake koja je nedostajala */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    flex-shrink: 0; /* Osigurava da se bočna traka nikada ne skupi */
}

/* Stilovi za brendirani logotip - Agresivno uvećanje */
.sidebar .logo-container {
    height: var(--header-height); /* 60px */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.12); 
    padding: 0; /* Skroz uklanjamo margine kontejnera */
}

.sidebar .app-logo {
    height: 85%; /* Neka slika popuni skoro celu visinu zaglavlja */
    max-height: 50px;
    width: auto;
    object-fit: contain; 
}

.sidebar nav ul {
    list-style: none;
    padding-top: 20px;
}

.sidebar nav ul li a {
    display: block;
    padding: 15px 20px;
    color: #ecf0f1;
    text-decoration: none;
    transition: background 0.2s;
}

.sidebar nav ul li a:hover {
    background-color: var(--secondary-color);
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.topbar {
    height: var(--header-height);
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.topbar .controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Zaštita od izguravanja navigacije na mobilnim uređajima */
#user-name {
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}

main#app-content {
    padding: 30px;
    flex: 1;
}

/* ==========================================
   3. TYPOGRAPHY & COMPONENTS
   ========================================== */
.page-header {
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header h1 {
    font-size: 1.8rem;
    color: var(--primary-color);
}

button {
    cursor: pointer;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-weight: bold;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

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

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

select, input[type="text"], input[type="email"], input[type="number"], input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 1rem;
    outline: none;
}

select:focus, input:focus {
    border-color: var(--secondary-color);
}

/* ==========================================
   4. FORMS (NEW VISIT WIZARD)
   ========================================== */
.card-form {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

fieldset {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 25px;
}

legend {
    font-weight: bold;
    color: var(--primary-color);
    padding: 0 10px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.flex-row {
    display: flex;
    gap: 10px;
}

.hint {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 10px;
    display: block;
}

.fte-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border-color);
}

.input-suffix {
    display: flex;
    align-items: center;
}

.input-suffix input {
    width: 80px;
    text-align: right;
}

.input-suffix span {
    margin-left: 10px;
    font-weight: bold;
    color: #555;
}

.fte-total {
    margin-top: 15px;
    text-align: right;
    font-size: 1.2rem;
}

/* ==========================================
   5. DATA GRID & TABLES
   ========================================== */
.data-grid {
    overflow-x: auto;
}

.grid-table {
    width: 100%;
    border-collapse: collapse;
}

.grid-table th, .grid-table td {
    border: 1px solid var(--border-color);
    padding: 10px;
    text-align: left;
}

.grid-table th {
    background-color: var(--bg-color);
}

.grid-table td input.grid-input {
    width: 100%;
    border: none;
    background: transparent;
    text-align: right;
    font-family: monospace;
    font-size: 1.1rem;
}

.grid-table td input.grid-input:focus {
    background-color: #eef7ff;
}

/* ==========================================
   6. DASHBOARD KPIs & CARDS
   ========================================== */
.kpi-cards {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    flex: 1;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    text-align: center;
}

.card h3 {
    color: #7f8c8d;
    font-size: 1rem;
    margin-bottom: 10px;
}

.kpi-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* ==========================================
   7. GENERAL MOBILE RESPONSIVENESS
   ========================================== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar .logo-container {
        display: none; /* Sakrivamo kontejner logotipa na mobilnim uređajima radi uštede prostora */
    }

    .sidebar nav ul {
        display: flex;
        overflow-x: auto;
        padding: 0;
    }

    .sidebar nav ul li {
        flex: 1;
        text-align: center;
    }

    .sidebar nav ul li a {
        padding: 15px 10px;
        font-size: 0.9rem;
    }

    .kpi-cards {
        flex-direction: column;
    }

    .flex-row {
        flex-direction: column;
    }
}

/* ==========================================
   8. MODAL STYLES (NEW DOCTOR DIALOG)
   ========================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent overlay */
    z-index: 1000;
}

.modal-content {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==========================================
   9. TOAST NOTIFICATIONS
   ========================================== */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 250px;
    padding: 15px 20px;
    border-radius: 5px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 6px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease-out;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-success {
    background-color: var(--success-color, #2ecc71);
}

.toast-error {
    background-color: var(--accent-color, #e74c3c);
}

.toast-warning {
    background-color: #f39c12;
}

.toast.fade-out {
    opacity: 0;
    transform: translateY(-10px);
}

@keyframes slideIn {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================
   10. ACTIVE MENU STATES
   ========================================== */
.sidebar nav ul li a.active {
    background-color: var(--secondary-color);
    border-left: 4px solid white;
    padding-left: 16px; /* Smooth indented look */
    font-weight: bold;
}

/* ==========================================
   11. MOBILE BOTTOM TAB NAVIGATION
   ========================================== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column-reverse; /* Pushes sidebar container to the bottom */
    }

    .sidebar {
        width: 100%;
        height: 60px; /* Fixed height bar on the bottom */
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 999;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    }

    .sidebar .logo {
        display: none; /* Logo is hidden on mobile layout to save space */
    }

    .sidebar nav {
        width: 100%;
    }

    .sidebar nav ul {
        display: flex;
        flex-direction: row;
        padding-top: 0;
        height: 60px;
        align-items: center;
    }

    .sidebar nav ul li {
        flex: 1;
        text-align: center;
        height: 100%;
    }

    .sidebar nav ul li a {
        padding: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-size: 0.8rem;
    }

    /* Active state on bottom bar */
    .sidebar nav ul li a.active {
        background-color: var(--secondary-color);
        border-left: none;
        border-top: 4px solid white; /* Accent line shifts to the top of active tab */
        padding-left: 0;
    }

    .main-wrapper {
        margin-bottom: 60px; /* Safe space margin to prevent bottom bar from overlapping content */
    }

    main#app-content {
        padding: 15px; /* Compact padding for smaller screens */
    }
}

/* ==========================================
   12. GLOBAL LOADING SPINNER
   ========================================== */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================
   13. VISUAL CONNECTION STATUS INDICATOR
   ========================================== */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 15px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.status-indicator.online {
    background-color: rgba(46, 204, 113, 0.15);
    color: #27ae60;
}

.status-indicator.offline {
    background-color: rgba(231, 76, 60, 0.15);
    color: #c0392b;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background-color: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.status-indicator.online .status-dot {
    animation: pulse-green 2s infinite;
}

.status-indicator.offline .status-dot {
    animation: pulse-red 2s infinite;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* ==========================================
   14. REPRESENTATIVE DASHBOARD STYLES
   ========================================== */
.subtitle {
    color: #7f8c8d;
    font-size: 1rem;
    margin-top: -10px;
    margin-bottom: 20px;
}

.hint {
    color: #95a5a6;
    font-style: italic;
}

/* ==========================================
   15. ACTIVITY TIMELINE
   ========================================== */
.timeline {
    border-left: 3px solid var(--secondary-color);
    padding-left: 20px;
    margin-top: 20px;
}
.timeline-item {
    position: relative;
    margin-bottom: 25px;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -28px;
    top: 5px;
    width: 14px;
    height: 14px;
    background: white;
    border: 3px solid var(--secondary-color);
    border-radius: 50%;
}
.timeline-date {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 5px;
}
.timeline-content {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

/* ==========================================
   16. TIMELINE STATUS BADGES
   ========================================== */
.badge-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 10px;
    text-transform: uppercase;
}
.badge-completed {
    background-color: var(--success-color, #2ecc71);
}
.badge-planned {
    background-color: var(--secondary-color, #3498db);
}


/* ==========================================
   17. ADMIN PANEL TABS & ACTION BUTTONS
   ========================================== */
.admin-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.admin-tab {
    padding: 10px 20px;
    cursor: pointer;
    font-weight: bold;
    color: #7f8c8d;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}

.admin-tab:hover {
    color: var(--primary-color);
}

.admin-tab.active {
    color: var(--secondary-color);
    border-bottom-color: var(--secondary-color);
}

.admin-tab-content {
    display: none;
    animation: slideIn 0.3s ease-out;
}

.admin-tab-content.active {
    display: block;
}

.btn-danger {
    background-color: var(--accent-color);
    color: white;
    padding: 5px 10px;
    font-size: 0.8rem;
    border-radius: 4px;
}

.table-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

/* ==========================================
   18. WIZARD PROGRESS BAR (NEW VISIT)
   ========================================== */
.wizard-progress {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Pomeramo elemente ka vrhu */
    margin-bottom: 30px;
    position: relative;
    padding: 0;
}

.wizard-progress::before {
    content: '';
    position: absolute;
    top: 17px; /* Linija ide tačno po sredini krugova (35px / 2) */
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border-color);
    z-index: 1;
}

.wizard-step {
    position: relative;
    z-index: 2;
    background: transparent; /* UKLONJENA RUŽNA SIVA POZADINA */
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #95a5a6;
    transition: all 0.3s ease;
    flex: 1;
}

.wizard-step span {
    margin-top: 8px;
    font-size: 0.9rem;
}


.wizard-step.active { color: var(--secondary-color); font-weight: bold; }
.wizard-step.completed { color: var(--success-color); }

.step-circle {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid #ddd;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    margin-bottom: 5px;
    transition: all 0.3s ease;
}

.wizard-step.active .step-circle { border-color: var(--secondary-color); background: var(--secondary-color); color: white; }
.wizard-step.completed .step-circle { border-color: var(--success-color); background: var(--success-color); color: white; }

.wizard-panel {
    display: none;
    animation: slideIn 0.4s ease-out forwards;
}

.wizard-panel.active { display: block; }
.d-none { display: none !important; }

/* ==========================================
   19. STYLED DATE INPUT (FLATPICKR)
   ========================================== */
.styled-date-input {
    width: 100%;
    padding: 12px 15px;
    padding-right: 40px; /* Mesto za ikonicu */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    background-color: #fff;
    /* Custom SVG Calendar Icon ubačena preko CSS-a */
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%233498db" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
    transition: all 0.3s ease;
    cursor: pointer;
}

.styled-date-input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    outline: none;
}


/* ==========================================
   20. MODERN CHECKBOXES & HR TREE VIEW
   ========================================== */
.hr-tree-view {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    padding: 15px;
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.02);
}

.hr-group-title {
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
    margin-top: 15px;
    font-size: 0.95rem;
}
.hr-group-title:first-child { margin-top: 0; }

.modern-checkbox-label {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #475569;
    transition: color 0.2s;
    padding-left: 5px;
}
.modern-checkbox-label:hover { color: var(--secondary-color); }

.modern-checkbox-label input {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    accent-color: var(--secondary-color);
    cursor: pointer;
}

.terr-badge {
    background: #f1f5f9;
    color: #475569;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    margin-right: 4px;
    margin-bottom: 4px;
    display: inline-block;
    border: 1px solid #e2e8f0;
}

/* ==========================================
   20. ENTERPRISE SCROLL UX (ANTI-SELECTION)
   ========================================== */
th, .badge, button, .wizard-progress, .admin-tabs, .sidebar, .admin-tab, #lang-switcher {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}