/* ========================================
   RESET & BASE
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    min-height: 100vh;
}

/* ========================================
   PIN SCREEN
   ======================================== */
.pin-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.pin-overlay.hidden {
    display: none !important;
}

.pin-container {
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.pin-logo {
    max-width: 200px;
    height: auto;
    margin-bottom: 24px;
}

.pin-container h1 {
    font-size: 24px;
    margin-bottom: 12px;
    color: #f1f5f9;
}

.pin-container p {
    color: #94a3b8;
    margin-bottom: 24px;
}

#pin-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pin-input {
    width: 100%;
    padding: 14px;
    background: rgba(15, 23, 42, 0.6);
    border: 2px solid #334155;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 18px;
    text-align: center;
    letter-spacing: 8px;
    transition: all 0.3s;
}

.pin-input:focus {
    outline: none;
    border-color: #3b82f6;
    background: rgba(15, 23, 42, 0.8);
}

.pin-input::placeholder {
    letter-spacing: normal;
    color: #64748b;
}

.pin-submit {
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

.pin-error {
    color: #ef4444;
    font-size: 14px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    display: none;
}

/* ========================================
   SCREEN MANAGEMENT
   ======================================== */
.screen {
    min-height: 100vh;
}

.screen.hidden {
    display: none !important;
}

/* ========================================
   LOGIN SCREEN
   ======================================== */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-logo {
    display: block;
    max-width: 200px;
    height: auto;
    margin: 0 auto 24px;
}

.login-container h1 {
    text-align: center;
    margin-bottom: 12px;
    font-size: 28px;
    color: #f1f5f9;
}

.login-container > p {
    text-align: center;
    color: #94a3b8;
    margin-bottom: 32px;
}

.account-login-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.account-login-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid #334155;
    border-radius: 12px;
    transition: all 0.3s;
}

.account-login-item:hover {
    border-color: #475569;
    background: rgba(15, 23, 42, 0.7);
}

.account-info {
    flex: 1;
}

.account-name {
    font-weight: 600;
    color: #f1f5f9;
    margin-bottom: 4px;
}

.account-email {
    font-size: 13px;
    color: #94a3b8;
}

.login-status {
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    display: none;
}

.login-status.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.login-status.info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #3b82f6;
}

/* ========================================
   DASHBOARD HEADER
   ======================================== */
.dashboard-header {
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #334155;
    padding: 16px 24px;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

.header-logo {
    max-width: 150px;
    height: auto;
}

.header-content h1 {
    flex: 1;
    font-size: 24px;
    color: #f1f5f9;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* ========================================
   DASHBOARD MAIN
   ======================================== */
.dashboard-main {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    min-height: calc(100vh - 80px);
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 20px;
    height: fit-content;
    position: sticky;
    top: 24px;
}

.sidebar h3 {
    margin-bottom: 16px;
    font-size: 18px;
    color: #f1f5f9;
}

.properties-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.property-item {
    position: relative;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid #334155;
    border-radius: 8px;
    transition: all 0.2s;
    cursor: pointer;
}

.property-item:hover {
    background: rgba(15, 23, 42, 0.8);
    border-color: #475569;
}

.property-color-indicator {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 8px 0 0 8px;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-primary:disabled,
.btn-primary.authenticated {
    background: #22c55e;
    cursor: default;
    transform: none;
}

.btn-secondary {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid #3b82f6;
    color: #3b82f6;
}

.btn-secondary:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: #60a5fa;
    color: #60a5fa;
}

.btn-outline {
    background: transparent;
    border: 1px solid #334155;
    color: #cbd5e1;
}

.btn-outline:hover {
    border-color: #475569;
    background: rgba(51, 65, 85, 0.3);
}

/* ========================================
   DATE SELECTOR
   ======================================== */
.date-selector {
    padding-top: 20px;
    border-top: 1px solid #334155;
}

.date-selector h4 {
    margin-bottom: 12px;
    font-size: 14px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid #334155;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.form-select:focus {
    outline: none;
    border-color: #3b82f6;
    background: rgba(15, 23, 42, 0.8);
}

.form-select option {
    background: #1e293b;
    color: #e2e8f0;
}

/* ========================================
   CONTENT AREA
   ======================================== */
.content {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 24px;
}

.charts-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ========================================
   KPI CARDS
   ======================================== */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.kpi-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    transition: all 0.3s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: #3b82f6;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.15);
}

.kpi-label {
    font-size: 13px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.kpi-value {
    font-size: 32px;
    font-weight: 700;
    color: #f1f5f9;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ========================================
   CHARTS
   ======================================== */
.chart-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 24px;
}

.chart-card h3 {
    margin-bottom: 20px;
    font-size: 18px;
    color: #f1f5f9;
}

.chart-card canvas {
    max-height: 400px;
}

/* ========================================
   TOP PAGES SECTION
   ======================================== */
.top-pages-section {
    min-height: 400px;
}

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

.top-pages-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.form-select-small {
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid #334155;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 180px;
}

.form-select-small:focus {
    outline: none;
    border-color: #3b82f6;
    background: rgba(15, 23, 42, 0.8);
}

.form-select-small option {
    background: #1e293b;
    color: #e2e8f0;
}

.top-pages-content {
    min-height: 300px;
}

.top-pages-empty,
.top-pages-loading,
.top-pages-error {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: #94a3b8;
    font-size: 15px;
}

.top-pages-loading {
    gap: 12px;
}

.top-pages-error {
    color: #ef4444;
}

.top-pages-table-wrapper {
    overflow-x: auto;
}

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

.top-pages-table thead {
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 2px solid #334155;
}

.top-pages-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.top-pages-table th.rank-col {
    width: 60px;
    text-align: center;
}

.top-pages-table th.metric-col {
    width: 120px;
    text-align: right;
}

.top-page-row {
    border-bottom: 1px solid #334155;
    transition: all 0.2s;
}

.top-page-row:hover {
    background: rgba(15, 23, 42, 0.3);
    border-left: 3px solid var(--row-color);
}

.top-page-row td {
    padding: 16px;
}

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

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    border: 1px solid;
}

.page-col {
    max-width: 500px;
}

.page-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-title {
    color: #f1f5f9;
    font-weight: 500;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-path {
    color: #64748b;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-col {
    text-align: right;
}

.metric-value {
    color: #e2e8f0;
    font-weight: 600;
    font-size: 14px;
}

/* ========================================
   LOADING STATE
   ======================================== */
.loading {
    text-align: center;
    padding: 20px;
    color: #94a3b8;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #334155;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.cache-notification {
    animation: slideIn 0.3s ease-out;
}

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

/* ========================================
   SCROLLBAR STYLING
   ======================================== */
.properties-list::-webkit-scrollbar,
.top-pages-table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.properties-list::-webkit-scrollbar-track,
.top-pages-table-wrapper::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3);
    border-radius: 4px;
}

.properties-list::-webkit-scrollbar-thumb,
.top-pages-table-wrapper::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

.properties-list::-webkit-scrollbar-thumb:hover,
.top-pages-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1024px) {
    .dashboard-main {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: relative;
        top: 0;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .header-content h1 {
        font-size: 20px;
    }
    
    .header-logo {
        max-width: 120px;
    }
    
    .kpi-cards {
        grid-template-columns: 1fr;
    }
    
    .top-pages-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .top-pages-controls {
        width: 100%;
    }
    
    .form-select-small {
        width: 100%;
    }
    
    .page-col {
        max-width: 250px;
    }
    
    .top-pages-table th.metric-col,
    .top-pages-table td.metric-col {
        font-size: 12px;
        padding: 12px 8px;
    }
}