/* Visor Analytics Dashboard — Light SaaS theme (v4.3.0)
   Single-theme rewrite: purge of legacy dark-glassmorphism base + v4.1/v4.2 override stack.
   Palette: ink #17231e + lime #b8f52f. Display font: Fraunces (headings, stat numbers). */

:root {
    --bg-main: #f4f5f1;
    --bg-card: #ffffff;
    --bg-card-hover: #fafbf7;
    --bg-inset: #f1f4ef;
    --border-color: #e6e8df;
    --border-strong: #d8ddd2;

    --primary: #b8f52f;
    --primary-hover: #a5df20;
    --primary-light: #efffc9;
    --primary-ink: #3f6212;

    --ink: #17231e;
    --ink-soft: #1e2b25;
    --secondary: #1e2b25;
    --success: #1a7f4b;
    --success-bg: #e7f8ee;
    --warning: #b97a0c;
    --danger: #d43d3d;
    --danger-bg: #fdeeee;
    --teal: #0d9488;
    --code: #0e7490;

    --text-primary: #18201c;
    --text-secondary: #66716b;
    --text-muted: #929b96;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --shadow: 0 16px 40px rgba(29, 43, 36, 0.07);
    --shadow-sm: 0 4px 12px rgba(29, 43, 36, 0.08);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 24px 28px 48px;
    line-height: 1.5;
}

.dashboard-container {
    max-width: 1540px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

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

code, pre { color: var(--code); font-size: 0.92em; }

/* ---------- Header ---------- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 72px;
    margin-bottom: 28px;
    padding: 4px 8px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-badge {
    width: 48px;
    height: 48px;
    background: var(--primary);
    color: var(--ink);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}

.header-title h1 {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--text-primary);
}

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

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

/* ---------- Tab views ---------- */
.tab-view { display: none; }
.tab-view.active {
    display: block;
    animation: fadeInTab 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ---------- Buttons ---------- */
.btn-primary {
    background: var(--primary);
    color: var(--ink);
    border: 1px solid #a9e52a;
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 8px 20px rgba(159, 211, 38, 0.25);
    transform: translateY(-1px);
}

.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
    background: var(--bg-inset);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-secondary:hover { background: #e7ebe2; }
.btn-secondary:active { transform: scale(0.97); }

.btn-icon-round {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

.btn-logout {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #f3c8c8;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-logout:hover { background: #f9dede; }

/* ---------- User badge ---------- */
.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ---------- Period selector ---------- */
.period-selector {
    display: flex;
    background: #edf0e9;
    border: 1px solid #e0e4dc;
    padding: 4px;
    border-radius: var(--radius-md);
    gap: 4px;
}

.period-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.period-btn:hover { color: var(--text-primary); }
.period-btn.active {
    background: #fff;
    color: var(--ink);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* ---------- Sticky detail header ---------- */
.sticky-detail-header {
    position: sticky;
    top: 12px;
    z-index: 90;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 34px rgba(29, 43, 36, 0.1);
    margin-bottom: 22px;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
}

.analytics-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.analytics-site-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 240px;
}

.analytics-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.site-switcher-dropdown {
    height: 38px;
    font-size: 12px;
    cursor: pointer;
    min-width: 170px;
    max-width: 220px;
}

/* ---------- Live badge ---------- */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--success-bg);
    border: 1px solid #caecd8;
    color: #287b4d;
    padding: 7px 12px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
}

.live-badge.offline {
    background: var(--danger-bg);
    border-color: #f3c8c8;
    color: var(--danger);
}

.live-dot {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--success);
    animation: pulse 1.5s infinite;
    display: inline-block;
    flex-shrink: 0;
}

.live-dot.offline {
    background-color: var(--danger);
    box-shadow: 0 0 10px var(--danger);
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.25); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}

/* ---------- Cards & grids ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

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

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.card h2, .card h3, .card h4,
.analytics-site-info h2,
.sites-header-toolbar h2 { color: var(--text-primary); }

.grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin-bottom: 24px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 18px;
    border-radius: var(--radius-lg);
}

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

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 30px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    margin: 4px 0;
}

/* ---------- Forms ---------- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-input {
    background: #f7f8f4;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 9px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

.form-input:focus {
    border-color: #9fd326;
    box-shadow: 0 0 0 4px rgba(184, 245, 47, 0.18);
}

select.form-input { cursor: pointer; }

/* ---------- Tables ---------- */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-md);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.custom-table th {
    background: #f7f8f4;
    color: #7c8681;
    font-weight: 600;
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.custom-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #edf0e9;
    color: var(--text-primary);
}

.custom-table tr:hover td { background: #f8faf4; }

.sortable-th {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.sortable-th:hover { background: #eef1ea; color: var(--text-primary); }
.sortable-th.active-sort { color: var(--primary-ink); font-weight: 700; }

.sort-icon {
    font-size: 11px;
    margin-left: 4px;
    opacity: 0.6;
    display: inline-block;
}

.sortable-th.active-sort .sort-icon { opacity: 1; color: var(--primary-ink); }

/* ---------- Badges ---------- */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    display: inline-block;
}

.badge-primary { background: var(--primary-light); color: var(--primary-ink); }
.badge-secondary { background: rgba(13, 148, 136, 0.12); color: var(--teal); }
.badge-success { background: var(--success-bg); color: #287b4d; }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- Sites toolbar ---------- */
.sites-header-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 14px;
}

.sites-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 620px;
    justify-content: flex-end;
}

.add-site-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.inline-add-site {
    display: none;
    background: var(--bg-inset);
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
}

/* ---------- Luxury lists ---------- */
.luxury-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.luxury-item {
    background: #f8faf6;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 11px 14px;
    transition: var(--transition);
}

.luxury-item:hover {
    background: #f1f5ed;
    border-color: var(--border-strong);
    transform: translateX(3px);
}

.luxury-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 7px;
    gap: 10px;
}

.rank-badge {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-ink);
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rank-badge.top-1 { background: rgba(245, 158, 11, 0.18); color: #92600a; border: 1px solid rgba(245, 158, 11, 0.4); }
.rank-badge.top-2 { background: rgba(100, 116, 139, 0.14); color: #475569; border: 1px solid rgba(100, 116, 139, 0.35); }
.rank-badge.top-3 { background: rgba(180, 83, 9, 0.14); color: #9a3412; border: 1px solid rgba(180, 83, 9, 0.35); }

.item-name-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.item-count-badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-soft);
    background: var(--primary-light);
    padding: 3px 9px;
    border-radius: 20px;
    border: 1px solid #d9ecab;
    white-space: nowrap;
}

.progress-track {
    height: 6px;
    background: #e8ece5;
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill-glow {
    height: 100%;
    background: linear-gradient(90deg, var(--ink-soft), #65a30d);
    border-radius: 10px;
    transition: width 0.6s ease-in-out;
}

/* ---------- Live & logs headers ---------- */
.live-tab-header, .logs-tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.live-panel-card {
    border: 1px solid #bfe6cf;
    background: #f2fbf5;
}

.code-snippet {
    background: var(--ink);
    border: 1px solid var(--ink);
    color: var(--primary);
    padding: 14px;
    border-radius: var(--radius-md);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    word-break: break-all;
}

/* ---------- Mobile cards ---------- */
.mobile-only-cards {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.mobile-site-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.mobile-site-card:active { border-color: var(--border-strong); }

.mobile-site-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.mobile-site-card-domain {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.mobile-site-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    background: var(--bg-inset);
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    text-align: center;
}

.mobile-stat-box-num {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-stat-box-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

.mobile-site-card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ---------- Navigation: sidebar on desktop, bottom bar on mobile ---------- */
.bottom-nav {
    position: fixed;
    z-index: 9999;
    display: flex;
    align-items: center;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 10px;
    border-radius: 13px;
    color: #9aa8a1;
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 58px;
}

.nav-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.nav-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-label {
    font-size: 10px;
    font-weight: 650;
}

.nav-item:active { transform: scale(0.92); }
.nav-item.active {
    color: var(--ink);
    background: var(--primary);
    border-color: #9fd326;
}

.nav-item.active .nav-icon { transform: scale(1.12) translateY(-1px); }
.nav-item.active .nav-label { color: var(--ink); font-weight: 700; }

.nav-live-badge {
    position: absolute;
    top: -2px;
    right: -4px;
    width: 7px;
    height: 7px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
    animation: pulse 1.5s infinite;
}

.nav-live-badge.offline {
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

/* ---------- Desktop: fixed sidebar ---------- */
@media (min-width: 769px) {
    body { padding: 24px 28px 48px 252px; }

    body::before {
        content: "";
        position: fixed;
        inset: 0 auto 0 0;
        width: 224px;
        background: #14231d;
        z-index: 0;
    }

    .header { justify-content: flex-end; }

    .header-title-group {
        position: fixed;
        top: 28px;
        left: 24px;
        z-index: 10001;
        width: 176px;
        align-items: flex-start;
        gap: 10px;
    }

    .logo-badge {
        flex: 0 0 46px;
        width: 46px;
        height: 46px;
        font-size: 18px;
    }

    .header-title { min-width: 0; padding-top: 2px; }
    .header-title h1 {
        color: #fff;
        font-size: 21px;
        line-height: 1.15;
    }

    .header-title p {
        margin-top: 5px;
        color: #829088;
        font-size: 10px;
        line-height: 1.35;
    }

    .bottom-nav {
        top: 132px;
        left: 20px;
        width: 184px;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        gap: 6px;
        padding: 8px;
    }

    .bottom-nav .nav-item {
        width: 100%;
        min-height: 48px;
        padding: 0 13px;
        flex-direction: row;
        justify-content: flex-start;
        gap: 12px;
    }

    .bottom-nav .nav-label { font-size: 13px; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1200px) {
    .grid-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    body { padding: 12px 12px 96px; }

    .header { min-height: 58px; margin-bottom: 14px; padding: 0 4px; }
    .header-title-group { gap: 9px; }
    .logo-badge { width: 42px; height: 42px; border-radius: 13px; font-size: 18px; }
    .header-title h1 { font-size: 20px; }
    .header-title p { font-size: 10px; }
    .live-badge { padding: 8px 11px; font-size: 11px; }
    .user-badge { display: none; }

    .card { border-radius: 18px; }
    #viewSites > .card { padding: 17px; margin-bottom: 14px; }
    .sites-header-toolbar h2 { font-size: 18px; }
    .sites-header-toolbar p { font-size: 11px; }
    .sites-controls-row { gap: 9px; }
    .sites-controls-row > * { flex: 1 1 100%; }
    .sites-controls-row .form-input, .sites-controls-row .btn-primary { height: 44px; }
    .add-site-grid { grid-template-columns: 1fr; }

    .grid-5 { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .grid-5 .stat-card:last-child { grid-column: span 2; }
    .grid-3, .grid-2 { grid-template-columns: 1fr; gap: 14px; }

    .desktop-only-table { display: none; }
    .mobile-only-cards { display: flex; }
    .mobile-site-card { padding: 16px; border-radius: 18px; }

    .period-selector { width: 100%; overflow-x: auto; justify-content: space-between; }
    .site-switcher-dropdown { max-width: 100%; width: 100%; }
    .sticky-detail-header { top: 6px; padding: 12px 14px; }

    .bottom-nav {
        top: auto;
        right: 10px;
        bottom: 10px;
        left: 10px;
        height: 66px;
        padding: 6px;
        flex-direction: row;
        justify-content: space-around;
        background: rgba(23, 35, 30, 0.96);
        border: 1px solid rgba(255, 255, 255, 0.09);
        border-radius: 20px;
    }

    .bottom-nav .nav-item {
        min-width: 0;
        min-height: 52px;
        padding: 5px 2px;
        flex-direction: column;
        gap: 2px;
        border-radius: 15px;
    }

    .bottom-nav .nav-icon { width: 19px; height: 19px; }
    .bottom-nav .nav-label { font-size: 9px; }
}

/* ---------- Login page ---------- */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 460px;
    text-align: center;
    padding: 36px 28px;
    border-radius: 24px;
}

.login-logo {
    width: 60px;
    height: 60px;
    font-size: 22px;
    margin: 0 auto 18px;
}

.login-title {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 6px;
}

.login-alert { display: none; padding: 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 20px; text-align: left; }
.login-alert.success { background: var(--success-bg); border: 1px solid #bfe6cf; color: #287b4d; }
.login-alert.danger { background: var(--danger-bg); border: 1px solid #f3c8c8; color: var(--danger); }
