/* SessionManager — тёмная тема */
:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-input: #0d1117;
    --bg-hover: #1c2128;
    --border: #30363d;
    --border-strong: #484f58;
    --text: #e6edf3;
    --text-dim: #a8b1b8;
    --text-muted: #9ca3af;
    --accent: #2ea043;
    --accent-hover: #3fb950;
    --warn: #d29922;
    --danger: #da3633;
    --green: #2ea043;
    --yellow: #d29922;
    --red: #da3633;
    --blue: #58a6ff;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Focus-visible — клавиатурная навигация */
*:focus { outline: none; }
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}
.btn:focus-visible,
.vtab:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Утилиты */
.hidden { display: none !important; }
.flex-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* SVG Icons */
svg.icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
    position: relative;
    top: -1px;
}
svg.icon-lg { width: 17px; height: 17px; }

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    color: var(--text);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    min-width: 240px;
    max-width: 420px;
    pointer-events: auto;
    animation: toast-in 0.25s ease-out;
}
.toast.toast-err { border-left-color: var(--danger); }
.toast.toast-warn { border-left-color: var(--warn); }
.toast.toast-ok { border-left-color: var(--green); }
.toast.toast-out { animation: toast-out 0.2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(40px); } }

/* Undo toast */
.toast-undo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 16px 16px;
    position: relative;
    overflow: hidden;
}
.undo-msg { flex: 1; font-size: 13px; }
.undo-btn {
    flex-shrink: 0;
    padding: 4px 10px;
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 4px;
    background: rgba(255,255,255,.08);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.1s;
}
.undo-btn:hover { background: rgba(255,255,255,.16); }
.undo-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
}
.undo-fill {
    height: 100%;
    background: var(--warn);
    animation: undo-drain linear forwards;
    transform-origin: left;
}
@keyframes undo-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* Topbar */
.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    background: rgba(22, 27, 34, 0.92);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}
.brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
    text-decoration: none;
}
.brand-sub {
    color: var(--text-dim);
    font-size: 13px;
}
.topbar-right {
    margin-left: auto;
    display: flex;
    gap: 16px;
    align-items: center;
}
.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 14px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.nav-link:hover { color: var(--text); }
.nav-logout { color: var(--danger); }

/* Main */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 26px; line-height: 1.2; letter-spacing: -0.3px; flex: 1; font-weight: 700; }
h2 { font-size: 17px; line-height: 1.3; letter-spacing: -0.2px; font-weight: 600; }

/* Details/summary (Advanced section) */
.advanced-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    margin-bottom: 14px;
    background: rgba(0,0,0,.15);
}
.advanced-section summary {
    cursor: pointer;
    padding: 10px 14px;
    color: var(--text-dim);
    font-size: 13px;
    -webkit-user-select: none;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.advanced-section summary::-webkit-details-marker { display: none; }
.advanced-section summary::before { content: '▸'; transition: transform 0.15s; font-size: 10px; }
.advanced-section[open] summary::before { transform: rotate(90deg); }
.advanced-section summary:hover { color: var(--text); }
.advanced-section[open] { padding: 0 14px 10px; }
.advanced-section[open] summary { margin-bottom: 10px; padding: 10px 0; }
.back-link { color: var(--text-dim); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--text); }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 360px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; text-align: center; }
.login-sub { color: var(--text-dim); font-size: 13px; text-align: center; margin-bottom: 20px; }
.login-card input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    margin-bottom: 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin-bottom: 14px; color: var(--text); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    background: none;
    color: var(--text);
    text-decoration: none;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.btn-warn { background: var(--warn); color: #000; }
.btn-warn:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

/* Accounts list */
.accounts-list { display: flex; flex-direction: column; gap: 12px; }
.account-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}
.account-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.account-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}
.account-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
}
.account-status.status-idle { background: var(--green); }
.account-status.status-exporting { background: var(--blue); animation: pulse 2s infinite; }
.account-status.status-error { background: var(--danger); }
.account-status.status-banned { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.account-main { flex: 1; }
.account-phone { font-weight: 600; font-size: 15px; }
.account-name { color: var(--text-dim); font-size: 13px; }
.muted { color: var(--text-muted); }
.account-meta { display: flex; gap: 8px; }
.account-actions { display: flex; gap: 8px; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.2px;
    line-height: 1.4;
}
.badge-ok { background: rgba(46,160,67,.15); color: var(--green); }
.badge-wait { background: rgba(210,153,34,.15); color: var(--yellow); }
.badge-running { background: rgba(88,166,255,.15); color: var(--blue); }
.badge-done { background: rgba(46,160,67,.15); color: var(--green); }
.badge-stopped { background: rgba(110,118,129,.15); color: var(--text-dim); }
.badge-error { background: rgba(218,54,51,.15); color: var(--danger); }
.badge-paused { background: rgba(210,153,34,.15); color: var(--yellow); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { margin-bottom: 20px; }

/* Add page */
.add-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px;
    max-width: 600px;
}
.add-step { padding-bottom: 24px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.add-step:last-child { border-bottom: none; margin-bottom: 0; }
.add-step h2 { font-size: 16px; margin-bottom: 8px; }
.hint { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
.hint b { color: var(--text); }

.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
}
.field .req { color: var(--danger); }
.field input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }

.status {
    margin-top: 10px;
    font-size: 12px;
    min-height: 16px;
}
.status.ok { color: var(--green); }
.status.err { color: var(--danger); }
.status.warn { color: var(--yellow); }

/* Account detail */
.account-detail { display: flex; flex-direction: column; gap: 16px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; font-size: 13px; }
.kv b { color: var(--text-dim); font-weight: 500; margin-right: 6px; }

.status-text { font-weight: 500; }
.status-text.status-idle { color: var(--green); }
.status-text.status-exporting { color: var(--blue); }
.status-text.status-error { color: var(--danger); }
.status-text.status-banned { color: var(--danger); }

.ok-box, .warn-box, .err-box {
    display: flex;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid;
    border-left-width: 4px;
    position: relative;
}
.ok-box {
    background: linear-gradient(90deg, rgba(46,160,67,.14), rgba(46,160,67,.04));
    border-color: rgba(46,160,67,.25);
    border-left-color: var(--green);
    color: var(--green);
}
.warn-box {
    background: linear-gradient(90deg, rgba(210,153,34,.14), rgba(210,153,34,.04));
    border-color: rgba(210,153,34,.25);
    border-left-color: var(--warn);
    color: var(--warn);
}
.err-box {
    background: linear-gradient(90deg, rgba(218,54,51,.14), rgba(218,54,51,.04));
    border-color: rgba(218,54,51,.25);
    border-left-color: var(--danger);
    color: var(--danger);
}
.ok-box::before { content: '✓'; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.warn-box::before { content: '⚠'; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.err-box::before { content: '✕'; font-weight: 700; font-size: 15px; flex-shrink: 0; }

/* Skip link */
.skip-link {
    position: absolute;
    top: -60px;
    left: 8px;
    background: var(--accent);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 600;
    z-index: 1000;
    transition: top 0.2s;
}
.skip-link:focus { top: 8px; }

/* Sticky progress bar */
.sticky-progress {
    position: sticky;
    top: 58px;
    z-index: 40;
    background: linear-gradient(135deg, rgba(88,166,255,.12), rgba(88,166,255,.04));
    border: 1px solid rgba(88,166,255,.3);
    border-left: 4px solid var(--blue);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.sticky-progress .sp-label { color: var(--blue); font-weight: 600; }
.sticky-progress .sp-phase { color: var(--text); }
.sticky-progress .sp-detail { color: var(--text-dim); font-size: 12px; }
.sticky-progress .sp-bar {
    flex: 1;
    min-width: 120px;
    max-width: 300px;
    height: 6px;
    background: rgba(0,0,0,.3);
    border-radius: 3px;
    overflow: hidden;
}
.sticky-progress .sp-fill {
    height: 100%;
    width: 30%;
    background: var(--blue);
    transition: width 0.3s;
    animation: pulse 2s infinite;
}
.sticky-progress .sp-actions { display: flex; gap: 6px; }

/* Tabs — glow на активной */
.vtab { position: relative; }
.vtab.active {
    box-shadow: 0 2px 8px rgba(46,160,67,.25);
}

/* Depth для dark theme */
.card, .account-card, .login-card, .add-card, .viewer-sidebar, .viewer-header, .viewer-tabs {
    box-shadow: 0 1px 2px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.02);
}

/* Export progress */
.phase { font-size: 14px; margin-bottom: 8px; }
.phase span { font-weight: 600; color: var(--blue); }
.progress-text { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; min-height: 18px; }
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.stats > div b { color: var(--blue); }

.size-bar {
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    height: 28px;
    overflow: hidden;
}
.size-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--green);
    transition: width 0.3s;
}
.size-bar-fill.green { background: var(--green); }
.size-bar-fill.yellow { background: var(--yellow); }
.size-bar-fill.red { background: var(--danger); animation: pulse 1s infinite; }
.size-bar-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

/* Devices */
.devices-table { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.device-row {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
}
.device-row.current { border-color: var(--accent); }

/* Exports table */
.exports-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exports-table th, .exports-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.exports-table th { color: var(--text-dim); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.exports-table tbody tr { transition: background 0.12s; }
.exports-table tbody tr:hover { background: var(--bg-hover); }

/* Input улучшения */
input[type="text"], input[type="password"], input[type="tel"], input[type="number"], input[type="search"] {
    font-family: inherit;
}
input::placeholder { color: var(--text-muted); }

/* Responsive */
@media (max-width: 1024px) {
    .main { padding: 20px 16px; }
}
@media (max-width: 768px) {
    .main { padding: 16px 12px; }
    .topbar { padding: 12px 16px; }
    .brand-sub { display: none; }
    .page-header h1 { font-size: 20px; }

    /* Exports table → cards на мобильном */
    .exports-table thead { display: none; }
    .exports-table, .exports-table tbody, .exports-table tr, .exports-table td { display: block; width: 100%; }
    .exports-table tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 12px;
        margin-bottom: 10px;
    }
    .exports-table td { border: none; padding: 4px 0; }
    .exports-table td::before {
        content: attr(data-label);
        display: inline-block;
        min-width: 80px;
        color: var(--text-dim);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: .5px;
        margin-right: 8px;
    }

    /* Contact row → stacked */
    .contact-row { grid-template-columns: 1fr !important; gap: 4px !important; }

    /* File row */
    .file-row { grid-template-columns: 24px 1fr auto !important; }
    .file-row .date { display: none; }

    /* Topbar nav */
    .topbar-right { gap: 10px; }
    .nav-link { font-size: 13px; }
}
