/* ========================================
   BizniSoft Replikacija - Statistika
   ======================================== */

:root {
    --primary: #2b579a;
    --primary-dark: #1e3d6e;
    --primary-light: #e8eef5;
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --success: #87b601;
    --success-light: #f0f6e0;
    --error: #ef4444;
    --error-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========================================
   Header
   ======================================== */

header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.header-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

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

.header-user-info {
    display: flex;
    gap: 8px;
}

.header-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* ========================================
   Steps & Transitions
   ======================================== */

main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

.step {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.step.active {
    display: block;
}

.step.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   Cards
   ======================================== */

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-narrow {
    max-width: 440px;
}

.card-medium {
    max-width: 600px;
}

.card-wide {
    max-width: 700px;
}

.card-center {
    margin-left: auto;
    margin-right: auto;
}

.card-header {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.card-footer {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
}

/* ========================================
   Forms
   ======================================== */

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--bg-card);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input-with-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-with-label input {
    flex: 1;
}

.inline-label {
    font-size: 0.8rem;
    color: var(--primary);
    white-space: nowrap;
    font-weight: 500;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-loader {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Alerts
   ======================================== */

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid #fca5a5;
}

.alert-success {
    background: var(--success-light);
    color: #5a7a01;
    border: 1px solid #6ee7b7;
}

/* ========================================
   BSLive List (Step 2)
   ======================================== */

.search-box {
    margin-bottom: 16px;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.bslive-list {
    max-height: 400px;
    overflow-y: auto;
}

.bslive-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.bslive-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: var(--shadow);
}

.bslive-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bslive-id {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
}

.bslive-name {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 500;
}

.bslive-item-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bslive-arrow {
    color: var(--text-light);
    font-size: 1.1rem;
}

/* ========================================
   Selected BSLive Info (Step 3)
   ======================================== */

.selected-bslive-info {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.selected-bslive-info .bslive-id {
    font-weight: 700;
    color: var(--primary-dark);
}

.selected-bslive-info .bslive-name {
    color: var(--primary);
}

/* ========================================
   Dashboard (Step 4)
   ======================================== */

.dashboard {
    width: 100%;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}

.summary-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 4px;
}

.summary-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Filters */

.filters-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-group {
    flex: 1;
    min-width: 150px;
}

.filter-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.filter-group select {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.85rem;
}

.filter-actions {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
    min-width: auto;
    align-self: flex-end;
    padding-bottom: 2px;
}

/* Charts */

.chart-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 3px;
}

.tab-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow);
}

.tab-btn:hover:not(.active) {
    color: var(--text);
    background: var(--border);
}

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 16px;
}

.charts-container.charts-3col {
    grid-template-columns: 1fr 1fr 1fr;
}

.chart-wrapper {
    position: relative;
    min-height: 250px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 250px !important;
}

/* Data Table */

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

.data-table tr:hover td {
    background: var(--primary-light);
}

.data-table .text-center {
    text-align: center;
}

.data-table .text-right,
.data-table th.text-right {
    text-align: right;
}

.table-info {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.event-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.event-badge.etSync {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.event-badge.etStart {
    background: var(--success-light);
    color: #5a7a01;
}

.event-badge.etStop {
    background: var(--error-light);
    color: var(--error);
}

/* Selection List */

.selection-list {
    max-height: 500px;
    overflow-y: auto;
}

/* BSLive Accordion (Level 1) */

.bslive-accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
}

.bslive-acc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
    background: var(--bg-card);
}

.bslive-acc-header:hover {
    background: var(--primary-light);
}

.bslive-acc-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bslive-acc-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.bslive-acc-body {
    display: none;
    border-top: 1px solid var(--border);
    background: var(--bg);
    padding: 8px;
}

.bslive-accordion.open > .bslive-acc-body {
    display: block;
}

.bslive-acc-body .loader {
    padding: 16px;
    font-size: 0.85rem;
}

/* Firm Accordion (Level 2) - nested inside BSLive */

.firm-accordion {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
}

.firm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
}

.firm-header:hover {
    background: var(--primary-light);
}

.firm-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.firm-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.expand-icon {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    display: inline-block;
    width: 14px;
    text-align: center;
}

.bslive-accordion.open > .bslive-acc-header .expand-icon,
.firm-accordion.open > .firm-header .expand-icon {
    transform: rotate(90deg);
}

.firm-num-badge {
    font-size: 0.7rem;
    color: var(--text-light);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
}

.firm-years-panel {
    display: none;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.firm-accordion.open .firm-years-panel {
    display: block;
}

.year-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 10px 44px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid var(--border);
}

.year-item:last-child {
    border-bottom: none;
}

.year-item:hover {
    background: var(--primary-light);
}

.year-value {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.year-arrow {
    color: var(--text-light);
    font-size: 1.1rem;
}

.firm-years {
    font-size: 0.75rem;
    color: var(--text-light);
    font-style: italic;
}

.location-info-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.location-info-inline .btn-icon {
    border: 0;
    padding: 2px;
    flex-shrink: 0;
}

.location-id {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.location-name {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 500;
}

/* Column widths */
.data-table .col-lokacija { min-width: 200px; }

.loc-table th.text-right,
.loc-table td.text-right {
    font-size: 0.8rem;
    padding-left: 8px;
    padding-right: 8px;
}

/* Refresh bar */

.refresh-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.refresh-info {
    flex: 1;
}

.refresh-countdown {
    font-size: 0.75rem;
    color: var(--text-light);
}

.refresh-bar .btn svg {
    transition: transform 0.3s ease;
}

.refresh-bar .btn:hover svg {
    transform: rotate(180deg);
}

/* Status indicators */

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: default;
    background: var(--text-light);
}

.status-dot.status-ok { background: var(--success); }
.status-dot.status-warn { background: var(--warning); }
.status-dot.status-error { background: var(--error); }
.status-dot.status-unknown { background: var(--text-light); }

.status-error td:first-child {
    border-left: 3px solid var(--error);
}

.status-warn td:first-child {
    border-left: 3px solid var(--warning);
}

.status-ok td:first-child {
    border-left: 3px solid var(--success);
}

/* Pagination */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}

.pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.dashboard-footer {
    text-align: center;
    padding: 16px 0;
}

/* ========================================
   Modal
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 90%;
    max-width: 400px;
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}

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

.modal-body {
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ========================================
   Utilities
   ======================================== */

.text-muted {
    color: var(--text-muted);
}

.text-sm {
    font-size: 0.8rem;
}

.text-center {
    text-align: center;
}

.loader {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.95rem;
    margin-top: 8px;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    main {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    .charts-container {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        flex-direction: column;
    }

    .filter-group {
        min-width: 100%;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .data-table {
        font-size: 0.78rem;
    }

    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }

    .header-user-info {
        flex-direction: column;
        gap: 4px;
    }
}
