@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Kanit:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #0f1422;
    --card-bg: rgba(22, 29, 49, 0.65);
    --card-border: rgba(255, 255, 255, 0.05);
    --card-hover-border: rgba(99, 102, 241, 0.2);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.15);
    
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.1);
    --info: #06b6d4;
    --info-glow: rgba(6, 182, 212, 0.1);

    --font-heading: 'Kanit', sans-serif;
    --font-body: 'Sarabun', 'Inter', sans-serif;
    
    --sidebar-width: 260px;
    --transition-speed: 0.25s;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(6, 182, 212, 0.07) 0px, transparent 50%),
        radial-gradient(at 50% 100%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
}

/* Scrollbar Style */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Styling */
aside {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
}

.logo-container {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--card-border);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px var(--primary-glow);
}

.logo-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(to right, #fff, #9ca3af);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}

.nav-links {
    list-style: none;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-family: var(--font-heading);
    font-weight: 400;
    font-size: 0.95rem;
    transition: all var(--transition-speed) ease;
}

.nav-item a:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.03);
}

.nav-item.active a {
    color: white;
    background: linear-gradient(90deg, var(--primary-glow), transparent);
    border-left: 3px solid var(--primary);
    padding-left: 13px; /* Offset original padding slightly */
}

.nav-item svg {
    width: 18px;
    height: 18px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--card-border);
}

.demo-badge {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition-speed);
}

.demo-badge:hover {
    border-color: var(--warning);
    box-shadow: 0 0 10px var(--warning-glow);
}

.demo-dot {
    width: 8px;
    height: 8px;
    background-color: var(--warning);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

/* Main Content Area */
main {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 32px;
    max-width: 1400px;
    width: calc(100% - var(--sidebar-width));
}

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

.header-title h1 {
    font-family: var(--font-heading);
    font-size: 1.85rem;
    font-weight: 600;
    color: white;
    margin-bottom: 4px;
}

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

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

/* Generic Utilities */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    border: none;
    outline: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

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

.btn-icon-only {
    padding: 10px;
    border-radius: var(--radius-md);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

/* Cards & Grid Styling */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: border-color var(--transition-speed), transform var(--transition-speed);
}

.card:hover {
    border-color: var(--card-hover-border);
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
}

.stat-card.primary::after { background: var(--primary); }
.stat-card.success::after { background: var(--success); }
.stat-card.warning::after { background: var(--warning); }
.stat-card.info::after { background: var(--info); }

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card.primary .stat-icon { background: rgba(99, 102, 241, 0.1); color: var(--primary); }
.stat-card.success .stat-icon { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.stat-card.warning .stat-icon { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.stat-card.info .stat-icon { background: rgba(6, 182, 212, 0.1); color: var(--info); }

.stat-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: white;
    font-family: var(--font-heading);
}

.stat-change {
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }
.stat-change.neutral { color: var(--text-muted); }

/* Dashboard Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

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

.chart-card {
    height: 380px;
    display: flex;
    flex-direction: column;
}

.card-title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 500;
    color: white;
}

.chart-container {
    flex-grow: 1;
    position: relative;
    width: 100%;
    height: 100%;
}

.top-movers-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 280px;
    overflow-y: auto;
}

.mover-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
}

.mover-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mover-kw {
    font-weight: 500;
    font-size: 0.9rem;
    color: white;
}

.mover-site {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mover-rank {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rank-badge {
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: var(--font-heading);
    font-weight: 500;
}

.mover-diff {
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
}

.mover-diff.up { color: var(--success); }
.mover-diff.down { color: var(--danger); }

/* Table Section & Filters */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input-wrapper {
    position: relative;
    flex-grow: 1;
    min-width: 200px;
}

.search-input-wrapper svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 16px;
    height: 16px;
}

.input-field {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    padding-left: 38px;
    color: white;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: all var(--transition-speed);
}

.input-field:focus, .select-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary-glow);
    background-color: rgba(255, 255, 255, 0.06);
}

.select-field {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    min-width: 150px;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.select-field option {
    background-color: var(--bg-secondary);
    color: white;
}

/* Table Style */
.table-card {
    padding: 0;
    overflow: hidden;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

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

th {
    background-color: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 0.85rem;
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
}

td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.9rem;
    color: var(--text-primary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.01);
}

.site-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.site-url {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.badge {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-top3 {
    background-color: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-top10 {
    background-color: rgba(6, 182, 212, 0.15);
    color: var(--info);
    border: 1px solid rgba(6, 182, 212, 0.3);
}

.badge-top30 {
    background-color: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-notfound {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-normal {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
}

.rank-diff-text {
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.rank-diff-text.up { color: var(--success); }
.rank-diff-text.down { color: var(--danger); }
.rank-diff-text.neutral { color: var(--text-muted); }

.actions-cell {
    display: flex;
    gap: 8px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background-color: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    transform: translateY(20px);
    transition: transform var(--transition-speed) ease;
    overflow: hidden;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-large {
    max-width: 750px;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-speed);
}

.modal-close:hover {
    color: white;
}

.modal-close svg {
    width: 20px;
    height: 20px;
}

.modal-body {
    padding: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

.form-group label {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-helper {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    background-color: rgba(255, 255, 255, 0.01);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* API Setup / Settings Guide Tab styling */
.guide-card {
    padding: 28px;
}

.guide-step {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.step-number {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.step-content h3 {
    font-family: var(--font-heading);
    color: white;
    font-size: 1rem;
    margin-bottom: 6px;
}

.step-content p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.5;
}

.step-content code {
    background: rgba(255,255,255,0.05);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    color: var(--info);
    font-family: monospace;
    font-size: 0.85rem;
}

/* Loading Indicator */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 16px;
}

.loading-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-family: var(--font-heading);
}

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
    gap: 16px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    border: 1px solid var(--card-border);
}

.empty-icon svg {
    width: 32px;
    height: 32px;
}

.empty-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 500;
    color: white;
}

.empty-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 320px;
    line-height: 1.5;
}

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

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.5; }
}

/* Views display logic */
.view-section {
    display: none;
}

.view-section.active {
    display: block;
}

/* Responsive sidebars */
@media (max-width: 768px) {
    aside {
        width: 60px;
        overflow: hidden;
    }
    .logo-text, .nav-text, .demo-badge span {
        display: none;
    }
    .logo-container {
        padding: 10px;
        justify-content: center;
    }
    .nav-links {
        padding: 10px 4px;
    }
    .nav-item a {
        padding: 12px;
        justify-content: center;
    }
    .nav-item.active a {
        padding-left: 12px;
    }
    .demo-badge {
        padding: 10px;
        justify-content: center;
        border-radius: 50%;
    }
    main {
        margin-left: 60px;
        width: calc(100% - 60px);
        padding: 20px;
    }
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* Tag & Location cell styling */
.badge-tag {
    background-color: rgba(99, 102, 241, 0.08);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.18);
    font-size: 0.72rem;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    margin: 2px;
    font-family: var(--font-heading);
    font-weight: 400;
}
.location-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    font-size: 0.85rem;
}
.tag-container {
    max-width: 140px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.url-text-muted {
    font-size: 0.72rem;
    color: var(--text-muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    margin-top: 2px;
}
.url-text-link {
    color: var(--info);
    text-decoration: none;
}
.url-text-link:hover {
    text-decoration: underline;
}

/* Quick volume update elements styling */
.btn-volume-quick-refresh:hover {
    color: var(--info) !important;
}

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

.loading-spinner-tiny {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top: 2px solid white;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    display: inline-block;
    animation: spin 1s linear infinite;
    vertical-align: middle;
}

