/* =========================================================
   IMAP Sync Tool — Main Stylesheet
   ========================================================= */

:root {
    --primary:        #2563eb;
    --primary-dark:   #1d4ed8;
    --primary-light:  #eff6ff;
    --success:        #059669;
    --success-light:  #ecfdf5;
    --danger:         #dc2626;
    --danger-light:   #fef2f2;
    --warning:        #d97706;
    --warning-light:  #fffbeb;
    --source-color:   #7c3aed;
    --source-light:   #f5f3ff;
    --dest-color:     #0891b2;
    --dest-light:     #ecfeff;
    --bg:             #f1f5f9;
    --surface:        #ffffff;
    --border:         #e2e8f0;
    --border-strong:  #cbd5e1;
    --text:           #0f172a;
    --text-muted:     #64748b;
    --text-light:     #94a3b8;
    --radius:         12px;
    --radius-sm:      8px;
    --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow:         0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg:      0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono:           'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================================
   HEADER
   ========================================================= */
.app-header {
    background: linear-gradient(135deg, #1e3a5f 0%, #1d4ed8 100%);
    color: #fff;
    padding: 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px 32px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.logo svg {
    width: 28px;
    height: 28px;
    color: #93c5fd;
}

.header-subtitle {
    color: #93c5fd;
    font-size: 0.875rem;
    font-weight: 400;
}

/* =========================================================
   MAIN LAYOUT
   ========================================================= */
.app-main {
    flex: 1;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 32px;
}

.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* =========================================================
   SERVER CARDS LAYOUT
   ========================================================= */
.servers-layout {
    display: grid;
    grid-template-columns: 1fr 56px 1fr;
    gap: 0;
    align-items: start;
    margin-bottom: 24px;
}

.server-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.server-card-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.source-header { background: linear-gradient(135deg, #5b21b6, #7c3aed); color: #fff; }
.dest-header   { background: linear-gradient(135deg, #0e7490, #0891b2); color: #fff; }

.server-label { display: flex; flex-direction: column; gap: 4px; }
.server-label h2 { font-size: 1.1rem; font-weight: 600; }

.server-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: 999px;
}

.source-badge { background: rgba(255,255,255,.2); color: #fff; }
.dest-badge   { background: rgba(255,255,255,.2); color: #fff; }

.server-icon { width: 36px; height: 36px; opacity: .35; }

.server-card-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

/* =========================================================
   FORM ELEMENTS
   ========================================================= */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-row-inline {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"],
input[type="number"],
input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: border-color .2s, box-shadow .2s;
    outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

input::placeholder { color: var(--text-light); }

/* Password field */
.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

.password-field input { padding-right: 44px; }

.toggle-pw-btn {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
    transition: color .15s;
}

.toggle-pw-btn:hover { color: var(--primary); }
.toggle-pw-btn svg { width: 18px; height: 18px; }

/* Toggle switch */
.toggle-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 64px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    cursor: pointer;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: 999px;
    transition: background .2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* =========================================================
   LOAD FOLDERS BUTTON & FOLDER LIST
   ========================================================= */
.folder-list {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-top: 4px;
}

.folder-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.folder-list-title { font-weight: 600; color: var(--text-muted); }

.folder-list-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-light);
}

.folder-items {
    max-height: 200px;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.folder-item-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background .15s;
}

.folder-item-label:hover { background: var(--bg); }

.folder-item-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* =========================================================
   SWAP COLUMN
   ========================================================= */
.swap-col {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 80px;
}

.swap-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    background: var(--surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    transition: all .2s;
}

.swap-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
    transform: rotate(180deg);
}

.swap-btn svg { width: 20px; height: 20px; }

/* =========================================================
   INFO BOX
   ========================================================= */
.dest-info-box {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    background: var(--dest-light);
    border: 1px solid #a5f3fc;
    border-radius: var(--radius-sm);
    color: #0e7490;
    font-size: 0.85rem;
    line-height: 1.5;
}

.dest-info-box svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }

/* =========================================================
   OPTIONS CARD
   ========================================================= */
.options-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
    overflow: hidden;
}

.options-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    transition: background .15s;
}

.options-toggle:hover { background: var(--bg); }

.options-toggle > span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.options-toggle > span svg { width: 16px; height: 16px; color: var(--text-muted); }

.chevron-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: transform .2s;
}

.options-toggle.open .chevron-icon { transform: rotate(180deg); }

.options-body {
    border-top: 1px solid var(--border);
    padding: 20px 24px;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.option-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.option-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.option-info strong { font-size: 0.9rem; color: var(--text); }
.option-info span   { font-size: 0.8rem; color: var(--text-muted); }

.batch-input {
    width: 80px !important;
    text-align: center;
    padding: 8px 10px !important;
}

/* =========================================================
   START BAR
   ========================================================= */
.start-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 20px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.start-bar-note {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.start-bar-note svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--success); }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-outline {
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    color: var(--text);
}

.btn-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-outline:disabled { opacity: .5; cursor: not-allowed; }

.btn-start {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    color: #fff;
    padding: 13px 32px;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(37,99,235,.3);
}

.btn-start:hover { background: linear-gradient(135deg, #1e40af, #1d4ed8); box-shadow: 0 6px 20px rgba(37,99,235,.4); transform: translateY(-1px); }
.btn-start:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled { opacity: .5; cursor: not-allowed; }

.link-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 500;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background .15s;
}

.link-btn:hover { background: var(--primary-light); }

/* =========================================================
   PROGRESS VIEW
   ========================================================= */
.progress-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.progress-title-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.progress-title-group h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.running {
    background: var(--primary);
    animation: pulse-dot 1.5s ease-in-out infinite;
}

.status-dot.completed { background: var(--success); }
.status-dot.error     { background: var(--danger); }
.status-dot.stopped   { background: var(--warning); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(37,99,235,.4); }
    50%       { opacity: .8; box-shadow: 0 0 0 6px rgba(37,99,235,.0); }
}

.progress-topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.elapsed-time {
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Progress Bar */
.progress-bar-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.progress-bar-track {
    flex: 1;
    height: 12px;
    background: var(--bg);
    border-radius: 999px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #2563eb, #7c3aed);
    border-radius: 999px;
    transition: width .4s ease;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-pct {
    font-family: var(--mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 52px;
    text-align: right;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    word-break: break-word;
}

.stat-status { color: var(--primary); }
.stat-errors { color: var(--danger); }

/* Console */
.console-card {
    background: #0d1117;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
}

.console-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #8b949e;
}

.console-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.console-dot.red    { background: #ff5f56; }
.console-dot.yellow { background: #ffbd2e; }
.console-dot.green  { background: #27c93f; }

.console-header .link-btn { color: #8b949e; }
.console-header .link-btn:hover { color: #e6edf3; background: #21262d; }

.console-output {
    padding: 16px;
    min-height: 280px;
    max-height: 420px;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
}

.console-output::-webkit-scrollbar { width: 6px; }
.console-output::-webkit-scrollbar-track { background: transparent; }
.console-output::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }

.console-line { padding: 1px 0; word-break: break-all; }
.console-line.info    { color: #79c0ff; }
.console-line.success { color: #56d364; }
.console-line.error   { color: #f85149; }
.console-line.warning { color: #e3b341; }
.console-line.default { color: #e6edf3; }

.progress-footer {
    display: flex;
    justify-content: flex-start;
}

/* =========================================================
   FOOTER
   ========================================================= */
.app-footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

/* =========================================================
   TOASTS
   ========================================================= */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-lg);
    animation: slideIn .25s ease;
    max-width: 380px;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info    { background: var(--primary); }

@keyframes slideIn {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(110%); opacity: 0; }
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
    .app-main { padding: 20px 16px; }

    .servers-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .swap-col { padding-top: 0; }

    .swap-btn { transform: rotate(90deg); }
    .swap-btn:hover { transform: rotate(270deg); }

    .options-grid { grid-template-columns: 1fr; }

    .start-bar { flex-direction: column; align-items: stretch; }
    .btn-start { justify-content: center; }
}

@media (max-width: 640px) {
    .header-inner { padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 4px; }
    .header-subtitle { display: none; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    .progress-topbar { flex-direction: column; align-items: flex-start; }
    .progress-topbar-actions { width: 100%; justify-content: space-between; }

    .form-row-inline { flex-direction: column; gap: 12px; }
    .toggle-group { flex-direction: row; align-items: center; justify-content: space-between; min-width: auto; width: 100%; }
}
