/* ═══════════ Keepa Panel — Professional UI ═══════════ */

/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #059669;
    --success-hover: #047857;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-mid: #475569;
    --text-light: #94a3b8;
    --radius: 8px;
    --radius-sm: 6px;
    --sidebar-w: 300px;
    --topbar-h: 72px;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .05);
    --shadow: 0 1px 3px rgb(0 0 0 / .08), 0 1px 2px rgb(0 0 0 / .04);
    --shadow-lg: 0 4px 12px rgb(0 0 0 / .1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
}

/* ── Views ── */
.view { display: block; }
.hidden { display: none !important; }

/* ── Login ── */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1e40af 100%);
}

.login-card {
    background: var(--card);
    padding: 2.5rem 2rem;
    border-radius: 16px;
    box-shadow: 0 25px 60px rgb(0 0 0 / .3);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-logo { font-size: 2.5rem; margin-bottom: 0.5rem; }

.login-card h1 {
    font-size: 1.5rem;
    color: var(--text);
    margin-bottom: 0.25rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 0.8125rem;
}

.form-group { margin-bottom: 1rem; text-align: left; }

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--text-mid);
}

.form-group input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    transition: border-color .15s, box-shadow .15s;
    background: var(--bg);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / .12);
    background: white;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    line-height: 1.4;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-hover); }
.btn-ghost { background: transparent; color: var(--text-mid); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-mid); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 0.375rem 0.625rem; font-size: 0.75rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.6875rem; }
.btn-full { width: 100%; padding: 0.625rem; }

/* ══════════════════════════════════════
   TOP BAR
   ══════════════════════════════════════ */
.topbar {
    background: #333333;
    border-bottom: none;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: 1.25rem;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 8px rgb(0 0 0 / .3);
}

.topbar-brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: #ffffff;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: -0.01em;
}

.topbar-country {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0 0.5rem;
}

.topbar-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: rgba(255,255,255,.5);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Country cards */
.country-cards {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.country-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.375rem 0.75rem;
    border: 1.5px solid rgba(255,255,255,.15);
    border-radius: 10px;
    cursor: pointer;
    color: rgba(255,255,255,.75);
    transition: all .15s;
    white-space: nowrap;
    user-select: none;
    background: rgba(255,255,255,.07);
    flex-shrink: 0;
    min-width: 60px;
}

.country-card:hover { border-color: rgba(255,255,255,.4); color: #ffffff; background: rgba(255,255,255,.12); }

.country-card.active {
    background: #ffffff;
    border-color: #ffffff;
    color: #333333;
    box-shadow: 0 2px 8px rgb(0 0 0 / .3);
}
.country-card.active .country-count { opacity: .7; color: #333333; }
.country-card.active .country-name { color: #333333; }

.country-flag { width: 32px; height: auto; border-radius: 2px; display: block; }
.country-name { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em; }
.country-count { font-size: 0.6rem; opacity: .5; font-weight: 500; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.topbar-user {
    font-size: 0.75rem;
    color: rgba(255,255,255,.7);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Topbar dark buttons */
.topbar .btn-ghost { color: rgba(255,255,255,.7); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); color: #ffffff; }

/* Sync status badge */
.sync-badge {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.sync-badge.idle { background: #f1f5f9; color: var(--text-light); }
.sync-badge.running { background: #dbeafe; color: var(--primary); animation: pulse-badge 2s infinite; }
.sync-badge.completed { background: #d1fae5; color: var(--success); }
.sync-badge.failed { background: #fee2e2; color: var(--danger); }
.sync-badge.stopped { background: #fef3c7; color: var(--warning); }
@keyframes pulse-badge { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.role-badge {
    font-size: 0.5625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    margin-left: 0.25rem;
}
.role-badge.admin { background: #fef3c7; color: #92400e; }
.role-badge.user { background: #e0e7ff; color: #3730a3; }

/* ══════════════════════════════════════
   APP LAYOUT — sidebar + content
   ══════════════════════════════════════ */
.app-layout {
    display: flex;
    height: calc(100vh - var(--topbar-h));
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header h3 {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-mid);
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    margin-top: auto;
}

/* ── Filter blocks ── */
.filter-block {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
}

.filter-block-title {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

/* Range input row */
.range-input-row {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
}

.range-input {
    flex: 1;
    min-width: 0;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    background: var(--bg);
    transition: border-color .15s;
}

.range-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.range-sep {
    color: var(--text-light);
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* Checkbox actions row */
.checkbox-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.375rem;
}

.check-count {
    margin-left: auto;
    font-size: 0.625rem;
    color: var(--text-light);
    font-weight: 600;
}

/* Checkbox list */
.checkbox-list {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg);
}

.checkbox-list::-webkit-scrollbar { width: 4px; }
.checkbox-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.check-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3125rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background .1s;
    user-select: none;
    border-bottom: 1px solid transparent;
}

.check-item:hover { background: white; }

.check-item input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.check-label { flex: 1; color: var(--text-mid); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-count-badge {
    font-size: 0.625rem;
    background: var(--border);
    color: var(--text-mid);
    padding: 1px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* ── Content area ── */
.content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Active filters bar */
.active-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary-light);
    border-bottom: 1px solid #dbeafe;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.active-filters-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary);
    flex-shrink: 0;
}

.active-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1875rem 0.5rem;
    background: white;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    font-size: 0.6875rem;
    color: var(--primary);
    font-weight: 500;
}

.chip-x {
    cursor: pointer;
    font-weight: 700;
    opacity: .5;
    font-size: 0.75rem;
    line-height: 1;
}

.chip-x:hover { opacity: 1; }

/* Results bar */
.results-bar {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.result-total { font-weight: 700; font-size: 0.8125rem; color: var(--text); }
.export-buttons { display: flex; gap: 0.375rem; }

/* Table */
.table-wrap {
    flex: 1;
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.data-table th {
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-weight: 700;
    color: var(--text-light);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table td {
    padding: 0.4375rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
    color: var(--text-mid);
}

.data-table tbody tr:hover { background: #f8fafc; }

.data-table a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.data-table a:hover { text-decoration: underline; }

.data-table .empty-msg {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: white;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.page-btn {
    padding: 0.3125rem 0.625rem;
    border: 1px solid var(--border);
    background: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all .15s;
    color: var(--text-mid);
}

.page-btn:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-dots { padding: 0.3125rem 0.375rem; color: var(--text-light); font-size: 0.75rem; }

/* ══════════════════════════════════════
   LOADING / TOAST / MODAL
   ══════════════════════════════════════ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / .25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid white;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.8125rem;
    font-weight: 600;
    z-index: 2000;
    transition: transform .3s;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
}

.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--primary); }
.toast.success { background: var(--success); }

.modal {
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / .4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.modal-content {
    background: var(--card);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 900px;
    width: 92%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-content h3 {
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
}

.detail-table th {
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    border-bottom: 2px solid var(--border);
}

.detail-table td {
    padding: 0.4375rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

/* Sync */
.sync-info { margin-top: 0.75rem; }
.sync-info p { margin-bottom: 0.25rem; font-size: 0.8125rem; }
.sync-info strong { color: var(--text); }

/* ── Tom Select overrides ── */
.ts-wrapper { font-size: 0.8125rem; }
.ts-control {
    border-color: var(--border) !important;
    border-radius: var(--radius-sm) !important;
    background: var(--bg) !important;
    min-height: 34px !important;
}
.ts-control:focus-within {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px rgb(37 99 235 / .1) !important;
    background: white !important;
}
.ts-dropdown { font-size: 0.8125rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 0.5rem; }
    .topbar-country { order: 3; width: 100%; padding: 0; }
    .country-cards { flex-wrap: wrap; }
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
    .checkbox-list { max-height: 120px; }
}
