:root {
    --bg: #0f1117;
    --bg-elevated: #171b26;
    --bg-card: #1c2230;
    --border: #2a3344;
    --text: #e8edf5;
    --text-muted: #8b97ab;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --warm: #f59e0b;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 10px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body.app-body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.app-boot {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.app-boot.hidden { display: none !important; }
.app-boot-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: var(--text-muted);
    font-size: 14px;
}
.app-boot-spinner {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    animation: boot-pulse 1.2s ease-in-out infinite;
}
@keyframes boot-pulse {
    0%, 100% { opacity: 0.5; transform: scale(0.92); }
    50% { opacity: 1; transform: scale(1); }
}

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-error {
    margin-top: 12px;
    font-size: 13px;
    color: #fca5a5;
}

.nav-ghost {
    margin-left: auto;
    background: transparent !important;
    border: 1px solid var(--border) !important;
    color: var(--text-muted) !important;
}

.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.service-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 6px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.service-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.service-status-dot.on {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}
.service-status-dot.off {
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.service-status-text {
    color: var(--text-muted);
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 10px; height: 36px;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--accent), #8b5cf6);
}
.brand-sub { display: block; font-size: 12px; color: var(--text-muted); }

.app-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav-btn, .nav-link {
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.nav-btn:hover, .nav-link:hover { background: var(--bg-card); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.app-main { padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto; }

.view-panel { display: none; }
.view-panel.active { display: block; }

/* Accounts layout */
.accounts-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    align-items: start;
}

.accounts-sidebar {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 90px);
    overflow-y: auto;
}

.label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 12px 0 6px;
}

.input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 8px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-sm { max-width: 140px; display: inline-block; width: auto; margin-right: 8px; }

.sidebar-stats {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 0;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

button.group-nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    margin-bottom: 4px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
}
button.group-nav-row:hover { background: var(--bg-card); }
button.group-nav-row.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent-hover);
}
.group-nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; margin-right: 6px; }
.group-nav-count { font-size: 12px; opacity: 0.85; flex-shrink: 0; }
.group-nav-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 8px;
}

.accounts-main { min-width: 0; }

.accounts-toolbar-sticky {
    position: sticky;
    top: 56px;
    z-index: 55;
    background: var(--bg);
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
}
.accounts-toolbar-sticky .toolbar-row { margin-bottom: 8px; }
.accounts-toolbar-sticky .toolbar-row:last-child { margin-bottom: 0; }
.toolbar-row-select {
    justify-content: space-between;
}
.toolbar-row-work {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.toolbar-row-utils {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.toolbar-move {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.toolbar-move .input-sm { min-width: 130px; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }

.sel-badge {
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    background: var(--bg-card);
    border-radius: 20px;
}

.btn {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn-warm { background: var(--warm); color: #111; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline {
    color: var(--danger);
    border: 1px solid color-mix(in srgb, var(--danger) 55%, transparent);
}
.btn-danger-outline:hover {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.btn-action { color: #fff; border: none; }
.btn-action:disabled { opacity: 0.4; }
.btn-check { background: #0d9488; }
.btn-check:hover:not(:disabled) { background: #0f766e; }
.btn-bio { background: #7c3aed; }
.btn-bio:hover:not(:disabled) { background: #6d28d9; }
.btn-mailing { background: #16a34a; }
.btn-mailing:hover:not(:disabled) { background: #15803d; }
.btn-warming { background: #d97706; color: #111; }
.btn-warming:hover:not(:disabled) { background: #b45309; }
.btn-invite { background: #db2777; }
.btn-invite:hover:not(:disabled) { background: #be185d; }
.btn-admin { background: #7c3aed; }
.btn-admin:hover:not(:disabled) { background: #6d28d9; }
.btn-parser { background: #2563eb; }
.btn-parser:hover:not(:disabled) { background: #1d4ed8; }
.btn-reindex { background: #4f46e5; }
.btn-reindex:hover:not(:disabled) { background: #4338ca; }
.btn-auto { background: #0d9488; }
.btn-auto:hover:not(:disabled) { background: #0f766e; }

.status-progress {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--accent);
}
.status-progress-list {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    max-height: 160px;
    overflow-y: auto;
    font-size: 12px;
}
.status-progress-list li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.status-progress-list li.ok { color: #86efac; }
.status-progress-list li.err { color: #fca5a5; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.file-btn { cursor: pointer; display: inline-block; }

/* Account groups */
.accounts-groups { display: flex; flex-direction: column; gap: 12px; }

.account-group {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    background: var(--bg-card);
}
.group-header:hover { filter: brightness(1.05); }
.group-title { font-weight: 600; flex: 1; }
.group-meta { font-size: 12px; color: var(--text-muted); }
.group-toggle { font-size: 12px; color: var(--text-muted); }

.group-table-wrap {
    overflow-x: auto;
    padding: 0;
}
.group-table-wrap[hidden] { display: none; }

.account-group.group-by-marker {
    border-left: 4px solid var(--group-color, var(--border));
}

.accounts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.accounts-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-card);
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.accounts-table tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(42, 51, 68, 0.6);
    vertical-align: middle;
}
.accounts-table tbody tr.account-row {
    cursor: pointer;
    transition: background 0.1s;
}
.accounts-table tbody tr.account-row:hover {
    background: rgba(59, 130, 246, 0.06);
}
.accounts-table tbody tr.account-row.selected {
    background: rgba(59, 130, 246, 0.22) !important;
    box-shadow: inset 3px 0 0 var(--accent);
}
.accounts-groups.is-dragging {
    user-select: none;
    cursor: crosshair;
}
.accounts-groups.is-dragging .account-row { cursor: crosshair; }

.col-marker { width: 36px; }
.cell-marker { width: 36px; text-align: center; }
.marker-dot {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    padding: 0;
}
.cell-phone { font-weight: 700; white-space: nowrap; }
.cell-name, .cell-user { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-proxy {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 12px;
}
.cell-proxy-copy {
    cursor: copy;
    color: #93c5fd;
}
.cell-proxy-copy:hover {
    text-decoration: underline;
    color: var(--accent);
}

.btn-group-select {
    margin-left: auto;
    margin-right: 8px;
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
}
.btn-group-select:hover { background: rgba(59, 130, 246, 0.12); border-color: var(--accent); }

.module-pill {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fcd34d;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-code {
    font-size: 10px;
    font-weight: 500;
    opacity: 0.65;
    text-transform: uppercase;
}

/* Row accent by status */
tr.status-stop { --row-accent: #64748b; }
tr.status-rip { --row-accent: #6b7280; }
tr.status-connect_error { --row-accent: #f97316; }
tr.status-mailing_work { --row-accent: #22c55e; }
tr.status-warning_work { --row-accent: #f59e0b; }
tr.status-parsing { --row-accent: #38bdf8; }
tr.status-invite { --row-accent: #a78bfa; }
tr.status-auto_work { --row-accent: #14b8a6; }
tr.status-check_work { --row-accent: #2dd4bf; }
tr.status-update_bio { --row-accent: #34d399; }

tr.account-row[class*="status-"] {
    box-shadow: inset 4px 0 0 #ffffff00;
}

.status-stop .status-pill { border-color: #64748b; color: #cbd5e1; }
.status-stop .status-dot { background: #94a3b8; }

.status-rip .status-pill {
    border-color: #7f1d1d;
    background: rgba(127, 29, 29, 0.35);
    color: #fca5a5;
}
.status-rip .status-dot { background: #ef4444; }
tr.status-rip { opacity: 0.75; }

.status-connect_error .status-pill {
    border-color: #9a3412;
    background: rgba(154, 52, 18, 0.35);
    color: #fdba74;
}
.status-connect_error .status-dot { background: #f97316; }
tr.status-connect_error { opacity: 0.85; }

.status-mailing_work .status-pill {
    border-color: #166534;
    background: rgba(22, 101, 52, 0.45);
    color: #86efac;
}
.status-mailing_work .status-dot {
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
    animation: status-pulse 1.4s ease-in-out infinite;
}

.status-warning_work .status-pill {
    border-color: #b45309;
    background: rgba(180, 83, 9, 0.35);
    color: #fde68a;
}
.status-warning_work .status-dot {
    background: #f59e0b;
    animation: status-pulse 1.6s ease-in-out infinite;
}

.status-parsing .status-pill {
    border-color: #0369a1;
    background: rgba(3, 105, 161, 0.35);
    color: #7dd3fc;
}
.status-parsing .status-dot { background: #38bdf8; animation: status-pulse 1.5s ease-in-out infinite; }

.status-invite .status-pill {
    border-color: #6d28d9;
    background: rgba(109, 40, 217, 0.35);
    color: #ddd6fe;
}
.status-invite .status-dot { background: #a78bfa; animation: status-pulse 1.5s ease-in-out infinite; }
.status-auto_work .status-pill {
    background: rgba(20, 184, 166, 0.15);
    color: #5eead4;
    border-color: rgba(20, 184, 166, 0.35);
}
.status-auto_work .status-dot { background: #14b8a6; animation: status-pulse 1.5s ease-in-out infinite; }

.status-check_work .status-pill,
.status-update_bio .status-pill {
    border-color: #0f766e;
    background: rgba(15, 118, 110, 0.35);
    color: #99f6e4;
}
.status-check_work .status-dot,
.status-update_bio .status-dot { background: #2dd4bf; animation: status-pulse 1.8s ease-in-out infinite; }

@keyframes status-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.85); }
}

.flag-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    margin-right: 4px;
}
.flag-tag.flag-warn { border-color: var(--danger); color: #fca5a5; }

/* Upload preview */
.upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 8px 0;
    line-height: 1.5;
}
.upload-summary {
    font-size: 13px;
    font-weight: 600;
    margin: 10px 0;
}
.upload-progress {
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 8px;
}
.upload-preview-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.upload-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
}
.upload-row.upload-ok { border-color: rgba(34, 197, 94, 0.45); }
.upload-row.upload-warn { border-color: rgba(245, 158, 11, 0.5); }
.upload-row.upload-err { border-color: rgba(239, 68, 68, 0.55); background: rgba(239, 68, 68, 0.06); }
.upload-row-main { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.upload-row-files { font-size: 12px; color: var(--text-muted); }
.upload-row-meta { grid-column: 1 / -1; font-size: 11px; color: var(--text-muted); }
.upload-row-tags { grid-column: 1; display: flex; flex-wrap: wrap; gap: 4px; }
.upload-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
}
.upload-tag.ok { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.upload-tag.warn { background: rgba(245, 158, 11, 0.2); color: #fde68a; }
.upload-tag.err { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.upload-remove { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
.upload-empty { color: var(--text-muted); font-size: 13px; }

/* Data tabs */
.data-layout {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.data-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}
.data-tab {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
}
.data-tab.active { background: var(--accent); color: #fff; }
.data-content { padding: 20px; min-height: 400px; }
.data-panel { display: none; }
.data-panel.active { display: block; }

.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.panel-card h3 { margin: 0 0 12px; font-size: 16px; }

/* Logs */
.logs-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.logs-toolbar .logs-live-hint {
    margin: 0;
}
.logs-live-hint {
    font-size: 12px;
    color: var(--muted);
}
.logs-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    min-height: 500px;
}
.logs-sidebar {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    max-height: 70vh;
    overflow-y: auto;
}
.log-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.log-tab {
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
}
.log-tab.active { background: var(--accent); color: #fff; }
.account-log-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    margin-bottom: 2px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
}
.account-log-item:hover, .account-log-item.active { background: var(--bg-card); }

.logs-content {
    display: flex;
    flex-direction: column;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    max-height: 70vh;
    min-height: 400px;
    overflow: hidden;
    font-family: ui-monospace, monospace;
    font-size: 12px;
}
.log-container.system-logs {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}
#accountLogsPanel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
#accountLogsPanel h3 {
    margin: 0 0 8px;
    font-size: 14px;
    flex-shrink: 0;
}
#accountLogContent {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}
.log-line { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.03); }
.log-block.error .log-line { color: #fca5a5; }
.log-block.warning .log-line { color: #fcd34d; }

/* Data config (service/data) */
.data-config-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    min-height: calc(100vh - 120px);
}
.data-config-sidebar {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.data-sidebar-title { margin: 0 0 4px; font-size: 16px; }
.data-sidebar-hint { margin: 0 0 12px; font-size: 12px; color: var(--text-muted); }
.data-block-nav { display: flex; flex-direction: column; gap: 6px; }
.data-block-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.data-block-btn:hover { border-color: var(--accent); }
.data-block-btn.active {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.12);
}
.data-block-title { font-weight: 600; font-size: 14px; }
.data-block-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.data-config-main {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 500px;
}
.data-config-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.data-config-header h2 { margin: 0; font-size: 18px; }
.data-config-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.data-mode-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    padding: 3px;
    border-radius: 8px;
}
.data-mode-tab {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
}
.data-mode-tab.active { background: var(--accent); color: #fff; }
.data-config-panel {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}
.data-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
    max-width: 720px;
}
.data-form-grid .label { grid-column: span 1; margin-bottom: -4px; }
.data-form-grid .input { grid-column: span 1; }
.data-form-grid .checkbox-row { grid-column: span 2; }
@media (max-width: 700px) {
    .data-config-layout { grid-template-columns: 1fr; }
    .data-form-grid { grid-template-columns: 1fr; }
}
.data-textarea {
    width: 100%;
    min-height: 280px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    resize: vertical;
}
.data-textarea-sm { min-height: 100px; }

.bio-avatar-actions { margin-bottom: 16px; max-width: 720px; }
.bio-avatar-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    max-width: 900px;
}
.bio-avatar-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.bio-avatar-title { margin: 0 0 6px; font-size: 15px; }
.bio-avatar-count { font-size: 12px; color: var(--text-muted); }
.bio-avatar-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 10px 0 12px;
}
.bio-avatar-input { font-size: 12px; max-width: 280px; }
.bio-avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}
.bio-avatar-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-card);
}
.bio-avatar-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--bg-elevated);
}
.bio-avatar-card-foot {
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.bio-avatar-name {
    font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Statistics */
.stats-layout {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 20px 32px;
}
.stats-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.stats-page-title { margin: 0 0 4px; font-size: 22px; }
.stats-sub { margin: 0; font-size: 13px; color: var(--text-muted); }
.stats-header-actions { display: flex; gap: 10px; align-items: center; }
.stats-search { width: 220px; }
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-card-label { font-size: 12px; color: var(--text-muted); display: block; }
.stat-card-value { font-size: 28px; display: block; margin: 6px 0; }
.stat-card-meta { font-size: 11px; color: var(--text-muted); }
.stat-card-invite { border-left: 3px solid #6366f1; }
.stat-card-warming { border-left: 3px solid #22c55e; }
.stat-card-parsing { border-left: 3px solid #38bdf8; }
.stats-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}
.stats-tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
}
.stats-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.stats-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    overflow-x: auto;
}
.stats-panel.hidden { display: none; }
.stats-module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.stats-module-card h3, .stats-module-card h4 { margin: 0 0 10px; font-size: 15px; }
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.stats-table th, .stats-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.stats-table-wide { min-width: 640px; }
.stats-table td.err { color: #f87171; }
.stats-ev-cell { font-size: 11px; max-width: 320px; word-break: break-word; }
.stats-detail {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
}
.stats-detail.hidden { display: none; }
.stats-detail-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.stats-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 800px) {
    .stats-detail-grid { grid-template-columns: 1fr; }
}
.stats-table .muted { color: var(--text-muted); }
.data-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 12px;
    line-height: 1.45;
}
.data-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin: 16px 0;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    font-size: 13px;
}
.invite-admin-section {
    margin: 16px 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
}
.invite-admin-title { margin: 0 0 8px; font-size: 15px; }
.invite-admin-subtitle { margin: 14px 0 8px; font-size: 14px; }
.admin-picker-list {
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}
.admin-picker-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}
.admin-picker-item:hover { background: var(--bg-elevated); border-color: var(--border); }
.admin-picker-item.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.12);
}
.admin-picker-meta { font-size: 11px; color: var(--text-muted); }
.admin-picker-selected { margin-top: 4px; }
.admin-rights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px 12px;
}
.admin-right-item { font-size: 13px; }

.data-check-row { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }
.data-placeholder { color: var(--text-muted); }

/* Contact bases (service/contact_base) */
.cb-layout { display: flex; flex-direction: column; gap: 16px; }
.cb-totals {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.cb-total-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cb-total-label { font-size: 12px; color: var(--text-muted); }
.cb-total-card strong { font-size: 20px; }
.cb-total-sub { font-size: 11px; color: var(--text-muted); }
.cb-upload {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.cb-overwrite { font-size: 13px; margin: 0; }
.cb-table-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 360px;
}
.cb-preview-table { max-height: 420px; }
.cb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.cb-table th,
.cb-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.cb-table th {
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 1;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted);
}
.cb-table-sm { font-size: 12px; }
.cb-table code { font-size: 12px; }
.cb-file-title { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.cb-format { font-size: 12px; color: var(--text-muted); }
.cb-actions { white-space: nowrap; display: flex; gap: 4px; flex-wrap: wrap; }
.cb-empty, .cb-err { color: var(--text-muted); }
.cb-row-invalid td { background: rgba(239, 68, 68, 0.06); }
.cb-preview {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    background: var(--bg-card);
}
.cb-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.cb-preview-head h3 { margin: 0; font-size: 15px; }
.cb-preview-pager {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    flex-wrap: wrap;
}
.cb-pager-hint { font-size: 12px; color: var(--text-muted); }
.input.input-sm { max-width: 88px; padding: 4px 8px; font-size: 12px; }
.cb-resource {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: baseline;
}
.cb-res-user { color: var(--accent); }
.cb-res-meta { font-size: 12px; color: var(--text-muted); }
.cb-extra { font-size: 11px; color: var(--text-muted); max-width: 200px; }
.cb-preview-host.hidden { display: none !important; }

.cb-root-panel { min-height: 60vh; }
.cb-page { display: flex; flex-direction: column; gap: 16px; }
.cb-page-embedded { padding: 0; }
.cb-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.cb-page-title { margin: 0; font-size: 20px; }
.cb-page-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-muted); }
.cb-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.cb-search { min-width: 200px; max-width: 280px; }
.cb-sort { width: auto; min-width: 120px; }
.cb-totals-hero .cb-total-card-accent {
    border-color: rgba(59, 130, 246, 0.45);
    background: rgba(59, 130, 246, 0.08);
}
.cb-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}
.cb-dropzone.cb-drop-active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.06);
}
.cb-dropzone-inner p { margin: 6px 0; font-size: 14px; }
.cb-drop-hint { font-size: 12px !important; color: var(--text-muted) !important; }
.cb-drop-icon { font-size: 28px; color: var(--accent); display: block; margin-bottom: 4px; }
.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    font: inherit;
}
.cb-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.cb-toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
}
.cb-col-check { width: 36px; }
.cb-fname { word-break: break-all; }
.cb-file-mtime { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.cb-row-selected { background: rgba(59, 130, 246, 0.06); }
.cb-cov { min-width: 88px; }
.cb-cov-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--text-muted);
    margin: 2px 0;
}
.cb-cov-row span { width: 12px; flex-shrink: 0; }
.cb-cov-track {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.cb-cov-fill { height: 100%; border-radius: 2px; }
.cb-cov-fill.cb-cov-u { background: var(--accent); }
.cb-cov-fill.cb-cov-p { background: var(--success); }
.cb-format-users_list { color: #a78bfa; }
.cb-format-compact { color: var(--warm); }
.cb-format-full { color: var(--accent); }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
}
.modal {
    position: fixed; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 210;
    padding: 20px;
}
.modal.hidden, .modal-overlay.hidden, .hidden { display: none !important; }

.modal-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.modal-lg { max-width: 720px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 24px; cursor: pointer;
}
.modal-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.modal-tab {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
}
.modal-tab.active { background: var(--accent); color: #fff; }
.modal-body { overflow-y: auto; flex: 1; }
.modal-footer { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

.confirm-action-modal { max-width: 480px; }
.confirm-action-desc {
    margin: 0 0 10px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.45;
}
.confirm-action-meta { margin: 0 0 8px; font-size: 14px; }
.confirm-action-phones {
    margin: 0 0 12px;
    padding: 10px 12px;
    max-height: 140px;
    overflow-y: auto;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
}
.confirm-action-phones li { padding: 2px 0; }
.confirm-action-phones .more { color: var(--text-muted); font-style: italic; }
.confirm-action-warn {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.35);
    color: #fcd34d;
    font-size: 13px;
}
.confirm-action-warn.hidden { display: none !important; }

/* Editor modal */
.editor-modal .modal-header { align-items: flex-start; gap: 12px; }
.editor-meta { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); }
.editor-tabs { border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.editor-body {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    min-height: 200px;
}
.editor-file-hint {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--text-muted);
}
.editor-file-hint code {
    background: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    color: #93c5fd;
}
.editor-form {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}
.editor-field { margin: 0; }
.editor-field-wide { grid-column: 1 / -1; }
.editor-field label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.editor-type {
    text-transform: none;
    letter-spacing: 0;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--bg-card);
    color: #93c5fd;
}
.editor-json {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    line-height: 1.45;
    min-height: 72px;
    resize: vertical;
}
.editor-empty { color: var(--text-muted); font-size: 13px; }

/* Global form controls */
input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
    transition: border-color 0.15s, background 0.15s;
}
input[type="checkbox"] { border-radius: 5px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}
input[type="checkbox"]:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.5'%3E%3Cpath d='M3 8l3 3 7-7'/%3E%3C/svg%3E");
    background-size: 12px;
    background-position: center;
    background-repeat: no-repeat;
}
input[type="radio"]:checked {
    box-shadow: inset 0 0 0 3px var(--bg-card);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input[type="range"] {
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
}

select.input,
select,
.modal-card select,
.editor-field select {
    appearance: none;
    background-color: var(--bg-card);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b97ab' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}
select.input:focus,
select:focus,
.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

label:has(input[type="checkbox"]),
label:has(input[type="radio"]),
.radio-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

/* Scrollbars — app-wide */
* {
    scrollbar-width: thin;
    scrollbar-color: #3b4a63 var(--bg);
}
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
*::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 6px;
}
*::-webkit-scrollbar-thumb {
    background: #3b4a63;
    border-radius: 6px;
    border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover {
    background: #4b5e7a;
}
*::-webkit-scrollbar-corner {
    background: var(--bg);
}

.color-picker {
    position: fixed;
    z-index: 300;
    pointer-events: auto;
    padding: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 400;
    box-shadow: var(--shadow);
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

.list-items { list-style: none; padding: 0; margin: 0; }
.list-items li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.resource-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
}
.chip:hover { border-color: var(--danger); }

@media (max-width: 900px) {
    .accounts-layout, .logs-layout { grid-template-columns: 1fr; }
    .accounts-sidebar { position: static; max-height: none; }
    .group-cards { grid-template-columns: 1fr 1fr; }
}
