/* ── File Sync Tool — modern UI ─────────────────────────────────────────── */

:root {
    --bg-deep: #0f172a;
    --bg-mid: #1e293b;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: rgba(99, 102, 241, 0.12);
    --accent-glow: rgba(99, 102, 241, 0.35);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --card-bg: #ffffff;
    --card-border: rgba(148, 163, 184, 0.2);
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
}

*, *::before, *::after { box-sizing: border-box; }

.sync-app {
    font-family: "Inter", "Segoe UI", system-ui, sans-serif;
    font-size: 0.925rem;
    color: var(--text);
    min-height: 100vh;
    position: relative;
    background: var(--bg-deep);
}

.sync-bg {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.25), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(16, 185, 129, 0.08), transparent),
        linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    z-index: 0;
}

.sync-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
}

.page-header-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px var(--accent-glow);
    flex-shrink: 0;
}

.page-header-icon svg {
    width: 26px;
    height: 26px;
}

.sync-title {
    font-size: 1.65rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    letter-spacing: -0.02em;
}

.sync-subtitle {
    font-size: 0.875rem;
    color: #94a3b8;
    margin: 0.15rem 0 0;
}

.status-pill {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    color: #e2e8f0;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(8px);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    animation: pulse-dot 2s ease-in-out infinite;
}

body.sync-running .status-dot {
    background: var(--warning);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
    animation: pulse-dot 0.8s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.9); }
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.sync-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s ease;
}

.sync-card:hover {
    box-shadow: var(--shadow-lg);
}

.card-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card-section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.section-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.45rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
}

/* ── Source ─────────────────────────────────────────────────────────────── */

.source-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.source-path {
    flex: 1;
    min-width: 0;
    padding: 0.65rem 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 0.8rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.alert-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

.alert-banner-danger {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-banner-warning {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

.alert-banner-info {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.admin-banner {
    align-items: flex-start;
}

.admin-banner strong {
    color: #92400e;
}

.admin-banner code {
    font-size: 0.8rem;
    color: #78350f;
}

.admin-banner p {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn-soft {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.btn-soft:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: var(--text);
}

.btn-soft-primary {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: rgba(99, 102, 241, 0.25);
}

.btn-soft-primary:hover {
    background: rgba(99, 102, 241, 0.2);
    color: var(--accent-hover);
    border-color: rgba(99, 102, 241, 0.35);
}

.btn-group-soft {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-icon {
    font-size: 0.9em;
    opacity: 0.85;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.35rem;
    font-size: 0.925rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.btn-action-primary {
    background: linear-gradient(135deg, var(--accent), #818cf8);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-action-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-hover), #6366f1);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-action-secondary {
    background: #fff;
    color: var(--accent);
    border: 2px solid var(--accent);
}

.btn-action-secondary:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.action-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.spinner-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 500;
}

.spinner-wrap .spinner-border {
    color: var(--accent);
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid #e2e8f0;
}

.filter-field {
    flex: 1;
    min-width: 140px;
}

.filter-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.filter-field .form-control {
    border-radius: var(--radius-sm);
    border: 1px solid #e2e8f0;
    font-size: 0.875rem;
    padding: 0.45rem 0.75rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-field .form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

/* ── Sites table ────────────────────────────────────────────────────────── */

.sites-table-wrap {
    max-height: 260px;
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
}

.sites-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.sites-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f1f5f9;
    padding: 0.65rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 2px solid #e2e8f0;
}

.sites-table tbody tr {
    transition: background 0.12s ease;
}

.sites-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.sites-table tbody tr:hover {
    background: var(--accent-soft);
}

.sites-table tbody td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.sites-table .col-check {
    width: 3rem;
    text-align: center;
}

.site-name {
    font-weight: 600;
    color: var(--text);
}

.path-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.pool-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: #f1f5f9;
    color: #475569;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.form-check-input {
    width: 1.1em;
    height: 1.1em;
    cursor: pointer;
    accent-color: var(--accent);
}

.form-check-input:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

/* ── Modules ────────────────────────────────────────────────────────────── */

.sync-card-modules {
    background: linear-gradient(180deg, #fafbff 0%, #fff 100%);
}

.modules-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 0.25rem 0;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.modules-header:hover {
    background: var(--accent-soft);
}

.modules-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chevron {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.modules-panel.collapsed {
    display: none;
}

.modules-header.collapsed .chevron {
    transform: rotate(-90deg);
}

.modules-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 180px;
    overflow: auto;
    padding-top: 0.25rem;
}

.module-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
    margin: 0;
}

.module-chip:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.module-chip:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 500;
}

/* ── Log & Summary ──────────────────────────────────────────────────────── */

.sync-card-log {
    padding-bottom: 1rem;
}

.log-box {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: var(--radius-sm);
    min-height: 240px;
    max-height: 340px;
    overflow: auto;
    font-family: "JetBrains Mono", Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.55;
    padding: 1rem;
    margin: 0;
    color: #e2e8f0;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-line-error { color: #fca5a5; }
.log-line-warning { color: #fcd34d; }
.log-line-debug { color: #94a3b8; }

.summary-box {
    min-height: 240px;
    padding: 0.5rem 0;
}

.summary-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-muted);
    text-align: center;
}

.summary-empty-icon {
    font-size: 2rem;
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.summary-empty p {
    margin: 0;
    font-size: 0.9rem;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
}

.stat-item {
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    border: 1px solid #e2e8f0;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.stat-item.stat-success .stat-value { color: var(--success); }
.stat-item.stat-warning .stat-value { color: var(--warning); }
.stat-item.stat-danger .stat-value { color: var(--danger); }

.summary-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.summary-mode {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

.summary-mode.dry-run {
    background: #fef3c7;
    color: #b45309;
}

.summary-mode.sync {
    background: #d1fae5;
    color: #047857;
}

/* ── Running state ──────────────────────────────────────────────────────── */

body.sync-running .site-check,
body.sync-running .module-check,
body.sync-running #sitesTable input,
body.sync-running .filter-bar input,
body.sync-running .filter-bar button,
body.sync-running #selectAllBtn,
body.sync-running #clearAllBtn,
body.sync-running #modulesSelectAllBtn,
body.sync-running #modulesClearAllBtn,
body.sync-running #reloadBtn,
body.sync-running #copyBtn,
body.sync-running #previewBtn {
    pointer-events: none;
    opacity: 0.6;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────── */

.sites-table-wrap::-webkit-scrollbar,
.modules-checkboxes::-webkit-scrollbar,
.log-box::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.sites-table-wrap::-webkit-scrollbar-thumb,
.modules-checkboxes::-webkit-scrollbar-thumb,
.log-box::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.log-box::-webkit-scrollbar-thumb {
    background: #475569;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .status-pill {
        margin-left: 0;
    }

    .filter-count {
        width: 100%;
        margin-left: 0;
        text-align: left;
    }

    .summary-stats {
        grid-template-columns: 1fr;
    }
}
