/* Global styles and variables representing the MIW Group brand */
:root {
    --bg-primary: #101524;
    --bg-secondary: #162038;
    --color-primary: #333d6e;      /* MIW Deep Blue */
    --color-accent: #00bcd4;       /* MIW Cyan Blue Accent */
    --color-accent-hover: #00acc1;
    --color-success: #2ecc71;      /* Green for goal met */
    --color-warning: #f1c40f;
    --color-danger: #e74c3c;
    --text-main: #f8f9fa;
    --text-muted: #a0aec0;
    --glass-bg: rgba(22, 32, 56, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    --font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    background: radial-gradient(circle at top right, #25335d 0%, var(--bg-primary) 70%);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Glassmorphism card utility */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 var(--glass-shadow);
    padding: 24px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
    box-shadow: 0 12px 40px 0 rgba(0, 188, 212, 0.15);
    border-color: rgba(0, 188, 212, 0.25);
}

/* Navigation Layout */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: rgba(16, 21, 36, 0.8);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.brand-logo {
    width: 42px;
    height: 42px;
    background: var(--color-accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--bg-primary);
    font-size: 20px;
    box-shadow: 0 0 15px rgba(0, 188, 212, 0.5);
}

img.brand-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(0, 188, 212, 0.35);
    border: 1px solid rgba(0, 188, 212, 0.3);
    background: transparent;
}

.brand-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-text span {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.nav-links {
    display: flex;
    gap: 16px;
}

.nav-item {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.nav-item:hover, .nav-item.active {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
    border-left: 3px solid var(--color-accent);
}

/* Page wrapper */
.container {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 20px;
}

/* Grid system for dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 24px;
}

/* Standard columns sizes */
.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-4 { grid-column: span 4; }

@media (max-width: 1024px) {
    .col-8, .col-4 {
        grid-column: span 12;
    }
}

/* Section headers */
.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-main);
    border-left: 4px solid var(--color-accent);
    padding-left: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Stats summary grid */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.stat-sub {
    font-size: 13px;
    color: var(--color-accent);
    margin-top: 4px;
}

/* KPI progress cards */
.kpi-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rep-kpi-growth {
    font-weight: 700;
    font-size: 15px;
}

.rep-kpi-growth.success { color: var(--color-success); }
.rep-kpi-growth.warning { color: var(--color-warning); }

.progress-bar-bg {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    width: 100%;
    overflow: hidden;
    margin-top: 6px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
    border-radius: 4px;
    transition: width 0.5s ease-in-out;
}

.progress-bar-fill.success {
    background: linear-gradient(90deg, #1abc9c 0%, var(--color-success) 100%);
}

/* AI commentary styling */
.ai-commentary-box {
    position: relative;
    border-left: 4px solid var(--color-accent);
    background: rgba(0, 188, 212, 0.03);
}

.ai-bubble {
    font-style: italic;
    font-size: 15px;
    line-height: 1.7;
    color: #e2e8f0;
}

/* Control elements */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.btn {
    background: var(--color-primary);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, #1d264f 100%);
    border-color: rgba(0, 188, 212, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 0 15px rgba(0, 188, 212, 0.3);
    border-color: var(--color-accent);
}

.btn-accent {
    background: linear-gradient(135deg, #0097a7 0%, var(--color-accent) 100%);
    color: #101524;
    border: none;
}

.btn-accent:hover {
    background: linear-gradient(135deg, var(--color-accent) 0%, #26c6da 100%);
    box-shadow: 0 0 15px rgba(0, 188, 212, 0.5);
    color: #0b0f1a;
}

.btn-danger {
    background: #c0392b;
    border: none;
}

.btn-danger:hover {
    background: #e74c3c;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.4);
}

.select-input {
    background: var(--bg-secondary);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.select-input:focus {
    border-color: var(--color-accent);
}

/* Forms styling */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    background: rgba(16, 21, 36, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 12px 16px;
    color: var(--text-main);
    font-size: 14px;
    transition: all 0.3s ease;
}

.form-control:focus {
    border-color: var(--color-accent);
    outline: none;
    box-shadow: 0 0 10px rgba(0, 188, 212, 0.2);
}

/* Tables styling */
.custom-table-container {
    overflow-x: auto;
    margin-top: 15px;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.custom-table th, .custom-table td {
    padding: 16px;
    border-bottom: 1px solid var(--glass-border);
}

.custom-table th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.custom-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Spinner and loading */
.loader-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--color-accent);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 1000;
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* Grid layout for settings page */
.settings-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 30px;
}

.settings-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-nav-btn {
    text-align: left;
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.settings-nav-btn:hover, .settings-nav-btn.active {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.settings-nav-btn.active {
    border-color: rgba(0, 188, 212, 0.2);
    border-left: 4px solid var(--color-accent);
}

@media (max-width: 768px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Rep Cards Grid ─────────────────────────────── */
.rep-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.rep-card {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.rep-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 40px rgba(0, 188, 212, 0.18);
}

.rep-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
}

.rep-card-avatar-wrap {
    flex-shrink: 0;
}

.rep-card-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--color-accent);
    box-shadow: 0 0 12px rgba(0, 188, 212, 0.35);
}

.rep-card-avatar-placeholder {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 0 12px rgba(0, 188, 212, 0.35);
    text-transform: uppercase;
}

.rep-card-info h3 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.rep-card-handle {
    font-size: 12px;
    color: var(--text-muted);
}

.rep-card-headline {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rep-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.rep-card-more-btn {
    display: block;
    margin-top: 4px;
    padding: 0;
    border: none;
    background: none;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-accent);
    cursor: pointer;
}

.rep-card-more-btn:hover {
    text-decoration: underline;
}

.rep-card-extra[hidden] {
    display: none;
}

.rep-card-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-accent);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.rep-card-stats {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.rep-card-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.rep-card-stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-align: center;
}

/* --- Apify Token Status Badges & Controls --- */
.apify-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}
.apify-status-badge.ok {
    background: rgba(46, 125, 50, 0.15);
    color: #81c784;
    border: 1px solid rgba(46, 125, 50, 0.3);
}
.apify-status-badge.quota {
    background: rgba(229, 57, 53, 0.15);
    color: #ef5350;
    border: 1px solid rgba(229, 57, 53, 0.3);
}
.apify-status-badge.invalid {
    background: rgba(255, 152, 0, 0.15);
    color: #ffb74d;
    border: 1px solid rgba(255, 152, 0, 0.3);
}
.apify-usage-bar-wrap {
    width: 90px;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}
.apify-usage-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}
.apify-usage-bar.safe {
    background: #00bcd4;
}
.apify-usage-bar.warn {
    background: #ffb74d;
}
.apify-usage-bar.danger {
    background: #ef5350;
}

.rep-card-stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
}

.rep-kpi-growth.danger { color: var(--color-danger); }

/* Avatar upload preview */
.avatar-preview-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.avatar-preview-img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--color-accent);
    display: none;
}

.avatar-preview-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
}

/* ── Sidebar Layout & Single-screen View ────────── */
html, body {
    overflow: hidden;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    padding: 0;
}

.app-layout {
    display: flex;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar styling */
.app-sidebar {
    width: 220px;
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: clamp(12px, 1.6vh, 18px) 14px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    flex-shrink: 0;
    z-index: 100;
}

.app-sidebar.collapsed {
    width: 68px;
    padding: 16px 8px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: clamp(12px, 1.8vh, 20px);
}

.app-sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.app-sidebar.collapsed .sidebar-header .brand-text {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 32px;
    height: 32px;
    font-size: 16px;
    border-radius: 8px;
}

.brand-text h1 {
    font-size: 16px;
    line-height: 1.1;
}

.brand-text span {
    font-size: 10px;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: rgba(0, 188, 212, 0.1);
    color: var(--color-accent);
    border-color: rgba(0, 188, 212, 0.3);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.app-sidebar.collapsed .sidebar-item {
    justify-content: center;
    padding: 10px;
}

.app-sidebar.collapsed .sidebar-item .sidebar-label {
    display: none;
}

.sidebar-item:hover, .sidebar-item.active {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-item.active {
    border-left-color: var(--color-accent);
    background: rgba(0, 188, 212, 0.08);
    color: var(--color-accent);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--glass-border);
    padding-top: 14px;
}

.app-sidebar.collapsed .sidebar-footer {
    align-items: center;
}

.app-sidebar.collapsed .sidebar-footer #adminBadgeLabel {
    display: none;
}

.app-sidebar.collapsed .sidebar-footer .btn-logout {
    font-size: 0;
    padding: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-sidebar.collapsed .sidebar-footer .btn-logout::before {
    content: '🚪';
    font-size: 13px;
}

/* Main Content Area */
.app-main-content {
    flex: 1;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: clamp(8px, 1.2vh, 14px) clamp(12px, 1.2vw, 20px);
    min-width: 0;
    box-sizing: border-box;
}

/* Full height-flex, zero margin/padding container */
.container {
    width: 100%;
    max-width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: clamp(6px, 0.9vh, 10px);
    overflow: hidden;
}

/* Controls row sizing */
.controls-row {
    margin-bottom: 0;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.controls-row label {
    font-size: 11px !important;
}

.select-input {
    padding: 4px 8px;
    font-size: 12px;
    height: 30px;
    border-radius: 6px;
    background: rgba(22, 32, 56, 0.85);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}

#triggerScrapeBtn {
    padding: 5px 12px;
    font-size: 12px;
    height: 30px;
    gap: 6px;
}

.controls-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.apify-credits-widget {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: rgba(22, 32, 56, 0.85);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 3px 10px;
    min-width: 175px;
    height: 30px;
    box-sizing: border-box;
    cursor: default;
    transition: all 0.2s ease;
}

.apify-credits-widget:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(28, 40, 70, 0.95);
}

.credits-widget-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    line-height: 1.1;
    margin-bottom: 3px;
}

.credits-widget-title {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
}

.credits-widget-value {
    font-weight: 600;
    font-size: 11px;
    color: #e2e8f0;
}

.credits-progress-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
    overflow: hidden;
}

.credits-progress-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease, background-color 0.4s ease;
}

.credits-progress-bar.bg-success {
    background: #10b981;
}

.credits-progress-bar.bg-warning {
    background: #f59e0b;
}

.credits-progress-bar.bg-danger {
    background: #ef4444;
}

/* Stats summary sizing */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: clamp(6px, 0.8vw, 10px);
    margin-bottom: 0;
    flex-shrink: 0;
}

.stat-box {
    padding: clamp(6px, 0.8vh, 9px) clamp(8px, 0.8vw, 12px);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 10px;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 1px;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    font-size: clamp(16px, 1.25vw, 22px);
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-sub {
    font-size: 10px;
    color: var(--color-accent);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Rep Cards Grid: Single-row Auto-fit Without Horizontal Scroll */
.rep-cards-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr)) !important;
    gap: clamp(6px, 0.8vw, 10px);
    overflow: hidden;
    padding-bottom: 0;
    margin-bottom: 0;
    flex-shrink: 0;
}

.rep-card {
    min-width: 0;
    max-width: none;
    flex-shrink: 1;
    padding: clamp(6px, 0.7vh, 8px) clamp(8px, 0.7vw, 10px);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rep-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 188, 212, 0.16);
}

.rep-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rep-card-avatar-wrap {
    flex-shrink: 0;
}

.rep-card-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--color-accent);
    box-shadow: 0 0 8px rgba(0, 188, 212, 0.25);
}

.rep-card-avatar-placeholder {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 0 8px rgba(0, 188, 212, 0.25);
    text-transform: uppercase;
}

.rep-card-info {
    min-width: 0;
    flex: 1;
}

.rep-card-info h3 {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rep-card-handle {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.rep-card-stats {
    display: flex;
    justify-content: space-between;
    gap: 4px;
    margin-top: 2px;
}

.rep-card-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.rep-card-stat-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0;
    color: var(--text-muted);
    margin-bottom: 1px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rep-card-stat-value {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    white-space: nowrap;
    line-height: 1.1;
}

.progress-bar-bg {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    width: 100%;
    overflow: hidden;
    margin-top: 3px !important;
}

/* Redefining Dashboard Grid: chart on top, AI commentary below */
.dashboard-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1.8fr 1.2fr !important;
    gap: clamp(8px, 0.9vw, 12px);
    flex: 1;
    min-height: 0;
    margin-top: 0;
    height: 100%;
    overflow: hidden;
}

.chart-column {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: clamp(8px, 1vh, 12px) clamp(10px, 1vw, 14px);
    border-radius: 12px;
    overflow: hidden;
}

.chart-column .section-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px !important;
    padding-left: 8px;
    border-left-width: 3px;
    flex-shrink: 0;
}

.chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.rep-kpi-growth {
    font-weight: 700;
    font-size: 11px;
}

.ai-commentary-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: clamp(8px, 1vh, 12px) clamp(10px, 1vw, 14px);
    border-radius: 12px;
    overflow: hidden;
}

.ai-commentary-panel .section-title {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px !important;
    padding-left: 8px;
    border-left-width: 3px;
    flex-shrink: 0;
}

.ai-bubble-scroll {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    font-size: 11.5px;
    line-height: 1.4;
    min-height: 0;
}

/* Scrollbar customizations for glassmorphism */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 188, 212, 0.25);
    border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 188, 212, 0.45);
}

/* Settings Page layout tweaks */
.settings-grid {
    display: grid !important;
    grid-template-columns: 220px 1fr !important;
    gap: 16px;
    flex: 1;
    min-height: 0;
    height: 100%;
}

.settings-sidebar {
    height: 100%;
    overflow-y: auto;
}

main.glass-card {
    height: 100%;
    min-height: 0 !important;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px 20px;
}

/* Responsive fallback modifications for smaller screens / low height */
@media (max-width: 1200px), (max-height: 720px) {
    html, body {
        overflow: auto;
        height: auto;
        max-height: none;
    }
    .app-layout {
        height: auto;
        max-height: none;
        overflow: visible;
    }
    .app-main-content {
        height: auto;
        max-height: none;
        overflow: visible;
    }
    .container {
        height: auto;
        overflow: visible;
    }
    .rep-cards-grid {
        display: flex !important;
        overflow-x: auto !important;
        padding-bottom: 6px;
    }
    .rep-card {
        min-width: 200px;
        max-width: 220px;
        flex-shrink: 0;
    }
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: none !important;
        height: auto;
        overflow: visible;
    }
    .chart-column {
        height: 380px;
    }
    .ai-commentary-panel {
        flex: none;
        height: auto;
        max-height: 280px;
    }
}

/* --- Przycisk Poradnika Apify w controls-actions --- */
.btn-outline-info {
    background: rgba(0, 188, 212, 0.08);
    border: 1px solid rgba(0, 188, 212, 0.4);
    color: var(--color-accent);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-outline-info:hover {
    background: rgba(0, 188, 212, 0.18);
    border-color: var(--color-accent);
    color: #fff;
    box-shadow: 0 0 12px rgba(0, 188, 212, 0.25);
    transform: translateY(-1px);
}

/* --- Wspólne style Auth Overlay (dla index.html i settings.html) --- */
.auth-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 40, 0.92);
    backdrop-filter: blur(8px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.auth-overlay.active {
    display: flex;
}

.auth-modal {
    background: linear-gradient(135deg, #0d1b2e 0%, #162038 100%);
    border: 1px solid rgba(0, 188, 212, 0.25);
    border-radius: 20px;
    padding: 36px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 40px rgba(0, 188, 212, 0.08);
}

.auth-modal h2 {
    margin: 0 0 8px;
    font-size: 20px;
    color: #f8f9fa;
}

.auth-modal p {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.auth-modal .auth-logo {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #00bcd4, #333d6e);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 18px;
}

.auth-error {
    background: rgba(229, 57, 53, 0.12);
    border: 1px solid rgba(229, 57, 53, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: #ef5350;
    margin-bottom: 16px;
    display: none;
}

/* --- Apify Tutorial Modal Overlay --- */
.apify-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(8, 14, 30, 0.88);
    backdrop-filter: blur(8px);
    z-index: 9990;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.apify-modal-overlay.active {
    display: flex;
}

.apify-modal-content {
    background: linear-gradient(145deg, #0f1d35 0%, #162444 100%);
    border: 1px solid rgba(0, 188, 212, 0.3);
    border-radius: 18px;
    width: 100%;
    max-width: 980px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 50px rgba(0, 188, 212, 0.1);
    overflow: hidden;
    animation: modalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.apify-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
}

.apify-modal-title-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.apify-modal-icon {
    font-size: 26px;
    background: rgba(0, 188, 212, 0.15);
    border: 1px solid rgba(0, 188, 212, 0.3);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.apify-modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.2px;
}

.apify-modal-subtitle {
    margin: 3px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.apify-modal-close {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-size: 24px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
}

.apify-modal-close:hover {
    background: rgba(229, 57, 53, 0.2);
    border-color: rgba(229, 57, 53, 0.4);
    color: #ff6b6b;
}

.apify-modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* Sekcja kroków (cards grid) */
.apify-tutorial-steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.tutorial-step-card {
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.tutorial-step-card:hover {
    border-color: rgba(0, 188, 212, 0.35);
    transform: translateY(-2px);
}

.step-badge {
    align-self: flex-start;
    background: linear-gradient(135deg, rgba(0, 188, 212, 0.2) 0%, rgba(51, 61, 110, 0.3) 100%);
    border: 1px solid rgba(0, 188, 212, 0.4);
    color: var(--color-accent);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.step-title {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.step-desc {
    margin: 0 0 14px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
    flex: 1;
}

.step-desc a {
    color: var(--color-accent);
    text-decoration: underline;
}

.step-desc code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 11px;
    color: #ffca28;
}

.step-image-wrap {
    position: relative;
    background: #09101f;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
}

.step-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    transition: transform 0.3s ease;
}

.step-image-wrap:hover .step-image {
    transform: scale(1.04);
}

.step-image-zoom-hint {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

/* Wizard Box */
.apify-wizard-section {
    background: rgba(0, 188, 212, 0.03);
    border: 1px solid rgba(0, 188, 212, 0.25);
    border-radius: 14px;
    padding: 18px 20px;
}

.wizard-header {
    margin-bottom: 14px;
}

.wizard-title {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.wizard-desc {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.wizard-form-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 14px;
    margin-bottom: 14px;
}

.wizard-form-grid .form-group {
    margin-bottom: 0;
}

.wizard-form-grid label {
    font-size: 12px;
    font-weight: 600;
    color: #e0e6ed;
    margin-bottom: 6px;
    display: block;
}

.wizard-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 4px;
}

.wizard-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #cbd5e1;
    cursor: pointer;
}

.wizard-status-msg {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 500;
}

.wizard-status-msg.success {
    background: rgba(46, 125, 50, 0.2);
    color: #81c784;
    border: 1px solid rgba(46, 125, 50, 0.4);
}

.wizard-status-msg.error {
    background: rgba(229, 57, 53, 0.2);
    color: #ef5350;
    border: 1px solid rgba(229, 57, 53, 0.4);
}

/* Responsywność tutoriala */
@media (max-width: 900px) {
    .apify-tutorial-steps {
        grid-template-columns: 1fr;
    }
    .wizard-form-grid {
        grid-template-columns: 1fr;
    }
    .apify-modal-content {
        max-height: 95vh;
    }
}

/* --- Tutorial Screenshot Lightbox Modal --- */
.tutorial-lightbox-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 24, 0.94);
    backdrop-filter: blur(10px);
    z-index: 10050; /* wyżej niż apify-modal-overlay (9990) */
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    animation: lightboxFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.tutorial-lightbox-overlay.active {
    display: flex;
}

@keyframes lightboxFadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}

.tutorial-lightbox-dialog {
    background: linear-gradient(145deg, #0f1d35 0%, #162444 100%);
    border: 1px solid rgba(0, 188, 212, 0.4);
    border-radius: 16px;
    max-width: 92vw;
    max-height: 90vh;
    width: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8), 0 0 40px rgba(0, 188, 212, 0.15);
    overflow: hidden;
}

.tutorial-lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
}

.tutorial-lightbox-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.2px;
}

.tutorial-lightbox-close {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-size: 22px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    transition: all 0.2s ease;
}

.tutorial-lightbox-close:hover {
    background: rgba(229, 57, 53, 0.25);
    border-color: rgba(229, 57, 53, 0.5);
    color: #ff6b6b;
}

.tutorial-lightbox-body {
    padding: 16px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #080d1a;
}

.tutorial-lightbox-img {
    max-width: 86vw;
    max-height: 72vh;
    width: auto;
    height: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.tutorial-lightbox-footer {
    display: flex;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
}


