/* TikTok Stream Manager - theme on top of Bootstrap 5.3 */

:root,
[data-bs-theme="light"] {
    --accent: #4f46e5;
    --accent-rgb: 79, 70, 229;
    --accent-hover: #4338ca;
    --accent-text: #4338ca;
    --page-bg: #f4f5fa;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --line: #e3e6ef;
    --input-bg: #ffffff;
    --text-muted: #667085;
    --live: #16a34a;
    --running: #d97706;
    --connected: #2563eb;
    --danger-soft: #fef2f2;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);

    --bs-body-bg: var(--page-bg);
    --bs-body-color: #1d2433;
    --bs-secondary-color: var(--text-muted);
    --bs-border-color: var(--line);
    --bs-link-color-rgb: var(--accent-rgb);
    --bs-link-hover-color-rgb: 67, 56, 202;
}

[data-bs-theme="dark"] {
    --accent: #6366f1;
    --accent-rgb: 99, 102, 241;
    --accent-hover: #7577f5;
    --accent-text: #a5b4fc;
    --page-bg: #0d1017;
    --surface: #151a24;
    --surface-2: #1a202c;
    --line: #262d3c;
    --input-bg: #0f131b;
    --text-muted: #9aa4b8;
    --live: #22c55e;
    --running: #f59e0b;
    --connected: #60a5fa;
    --danger-soft: #2a1618;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);

    --bs-body-bg: var(--page-bg);
    --bs-body-color: #e6e9f2;
    --bs-secondary-color: var(--text-muted);
    --bs-border-color: var(--line);
    --bs-link-color-rgb: 165, 180, 252;
    --bs-link-hover-color-rgb: 199, 210, 254;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--page-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-main { flex: 1 0 auto; }

/* ---------- Navigation ---------- */
.app-nav {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.app-nav .navbar { padding: .6rem 0; }
.app-container { max-width: 1080px; }

.brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    font-weight: 650;
    font-size: 1.05rem;
    color: var(--bs-body-color);
    text-decoration: none;
}
.brand:hover { color: var(--bs-body-color); }
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: .9rem;
    background: linear-gradient(135deg, #4f46e5, #9333ea);
    box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
    flex: none;
}

.app-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .85rem;
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
.app-nav .nav-link:hover { color: var(--bs-body-color); background: rgba(var(--accent-rgb), .07); }
.app-nav .nav-link.active {
    color: var(--accent-text);
    background: rgba(var(--accent-rgb), .13);
}

.icon-btn {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-muted);
}
.icon-btn:hover { color: var(--bs-body-color); background: var(--surface-2); }

.user-btn {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .25rem .6rem .25rem .3rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--bs-body-color);
    font-weight: 500;
}
.user-btn:hover, .user-btn.show { background: var(--surface-2); color: var(--bs-body-color); }
.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: .8rem;
    font-weight: 650;
    color: #fff;
    background: linear-gradient(135deg, #4f46e5, #9333ea);
    text-transform: uppercase;
}
.dropdown-menu {
    border-color: var(--line);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
    padding: .4rem;
    background: var(--surface);
}
.dropdown-menu { min-width: 12rem; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    border-radius: 8px;
    padding: .6rem .85rem;
}
.dropdown-item i { width: 1.1rem; text-align: center; color: var(--text-muted); }
.dropdown-item.active, .dropdown-item.active i { background: rgba(var(--accent-rgb), .13); color: var(--accent-text); }
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-divider { margin: .4rem .25rem; border-color: var(--line); opacity: 1; }

/* ---------- Page ---------- */
.page-header { margin: 2rem 0 1.5rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.page-header p { margin: .25rem 0 0; color: var(--text-muted); }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    --bs-card-cap-bg: transparent;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    border-radius: 15px 15px 0 0 !important;
}
.card-header h2, .card-header h5 { font-size: 1rem; font-weight: 650; margin: 0; }
.card-header .card-icon {
    width: 28px; height: 28px; border-radius: 8px; display: inline-grid; place-items: center;
    background: rgba(var(--accent-rgb), .13); color: var(--accent-text); font-size: .8rem; margin-right: .6rem;
}
.card-body { padding: 1.25rem; }
.card-footer { background: var(--surface-2); border-top: 1px solid var(--line); padding: 1rem 1.25rem; border-radius: 0 0 15px 15px; }

/* ---------- Forms & buttons ---------- */
.form-label { font-weight: 550; font-size: .9rem; margin-bottom: .35rem; }
.form-control, .form-select, .input-group-text {
    background: var(--input-bg);
    border-color: var(--line);
    border-radius: 10px;
    padding: .6rem .8rem;
    color: var(--bs-body-color);
}
.input-group > .form-control:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .form-control:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group > .btn { border-radius: 0; border-color: var(--line); background: var(--input-bg); color: var(--text-muted); }
.input-group > .btn:last-child { border-top-right-radius: 10px; border-bottom-right-radius: 10px; }
.input-group > .btn:hover { background: var(--surface-2); color: var(--bs-body-color); }
.form-control:focus, .form-select:focus {
    background: var(--input-bg);
    border-color: var(--accent);
    box-shadow: 0 0 0 .22rem rgba(var(--accent-rgb), .2);
    color: var(--bs-body-color);
}
.form-control[readonly] { background: var(--surface-2); }
.form-control:disabled { opacity: .6; }
.form-text { color: var(--text-muted); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { border-color: var(--accent); box-shadow: 0 0 0 .22rem rgba(var(--accent-rgb), .2); }
.form-switch { padding-left: 3.1em; }
.form-switch .form-check-input { width: 2.5em; height: 1.35em; margin-left: -3.1em; }
.card-header .form-switch { padding-left: 0; }
.card-header .form-switch .form-check-input { margin-left: 0; }

.btn { border-radius: 10px; font-weight: 550; padding: .55rem 1rem; }
.btn-lg { padding: .75rem 1.25rem; border-radius: 12px; }
.btn-sm { padding: .3rem .65rem; border-radius: 8px; }
.btn-primary {
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-hover);
    --bs-btn-hover-border-color: var(--accent-hover);
    --bs-btn-active-bg: var(--accent-hover);
    --bs-btn-active-border-color: var(--accent-hover);
    --bs-btn-disabled-bg: var(--accent);
    --bs-btn-disabled-border-color: var(--accent);
    --bs-btn-focus-shadow-rgb: var(--accent-rgb);
}
.btn-outline-danger { --bs-btn-border-color: rgba(220, 53, 69, .5); }
.btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--line);
    --bs-btn-hover-bg: var(--surface-2);
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-hover-border-color: var(--line);
    --bs-btn-active-bg: var(--surface-2);
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-active-border-color: var(--line);
}
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--bs-body-color); }

.alert { border-radius: 12px; border: 1px solid transparent; display: flex; align-items: flex-start; gap: .65rem; }
.alert .alert-icon { margin-top: .15rem; }
.alert .btn-close { margin-left: auto; }

/* ---------- Status hero ---------- */
.status-hero .card-body { display: flex; align-items: center; gap: 1.1rem; padding: 1.4rem 1.5rem; }
.status-dot {
    width: 14px; height: 14px; border-radius: 50%; flex: none; background: #94a3b8;
    box-shadow: 0 0 0 5px rgba(148, 163, 184, .18);
}
.status-title { font-size: 1.2rem; font-weight: 650; }
.status-sub { color: var(--text-muted); margin-top: .1rem; }
.status-hero[data-state="live"] .status-dot { background: var(--live); box-shadow: 0 0 0 5px rgba(34, 197, 94, .2); animation: pulse 1.8s infinite; }
.status-hero[data-state="running"] .status-dot { background: var(--running); box-shadow: 0 0 0 5px rgba(245, 158, 11, .2); }
.status-hero[data-state="connected"] .status-dot { background: var(--connected); box-shadow: 0 0 0 5px rgba(96, 165, 250, .2); }
.status-hero[data-state="error"] .status-dot { background: #dc3545; box-shadow: 0 0 0 5px rgba(220, 53, 69, .2); }
.status-hero[data-state="live"] { border-color: color-mix(in srgb, var(--live) 45%, var(--line)); }
.status-hero[data-state="error"] { border-color: rgba(220, 53, 69, .5); }
.status-hero[data-state="error"] .status-sub { color: #dc3545; }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .45); }
    70% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none !important; } }

/* ---------- Lists, badges ---------- */
.kv { display: grid; gap: .85rem; margin: 0; }
.kv > div { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.kv dt { color: var(--text-muted); font-weight: 500; font-size: .9rem; margin: 0; }
.kv dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }
.pill {
    display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px;
    font-size: .8rem; font-weight: 600; background: rgba(148, 163, 184, .18); color: var(--bs-body-color);
}
.pill-ok { background: rgba(34, 197, 94, .15); color: var(--live); }
.pill-warn { background: rgba(245, 158, 11, .17); color: var(--running); }

.suggestions-list {
    position: absolute;
    left: 0; right: 0; top: 100%;
    z-index: 20;
    margin-top: .3rem;
    max-height: 240px;
    overflow-y: auto;
    display: none;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(16, 24, 40, .16);
}
.suggestions-list .list-group-item {
    background: transparent; border: 0; color: var(--bs-body-color); cursor: pointer; padding: .55rem .9rem;
}
.suggestions-list .list-group-item:hover { background: rgba(var(--accent-rgb), .12); }

.secret-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.section-title { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); font-weight: 650; margin: 1.5rem 0 .75rem; }
.app-footer { color: var(--text-muted); font-size: .8rem; padding: 1.5rem 0 2rem; text-align: center; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { padding: .5rem; margin-bottom: 1rem; }
.auth-card .brand-mark { width: 52px; height: 52px; border-radius: 15px; font-size: 1.3rem; margin: 0 auto 1rem; }
.auth-card h1 { font-size: 1.4rem; font-weight: 700; text-align: center; margin-bottom: .25rem; }
.auth-card .lead-sm { text-align: center; color: var(--text-muted); font-size: .95rem; margin-bottom: 1.25rem; }

/* ---------- Connection assistant ---------- */
.check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; }
.check-item { display: flex; gap: .85rem; align-items: flex-start; }
.check-icon {
    width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: .8rem;
}
.check-ok { background: rgba(34, 197, 94, .15); color: var(--live); }
.check-bad { background: rgba(220, 53, 69, .14); color: #dc3545; }
.check-title { font-weight: 600; }
.check-detail { color: var(--text-muted); font-size: .9rem; }
.help-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; font-size: .9rem; }
.help-box summary { cursor: pointer; font-weight: 600; }
.help-box code { word-break: break-all; }
