:root {
    --bg: #f3f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --border: #e6e9f0;
    --border-2: #d6dbe5;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-dark: #15803d;
    --warning: #d97706;
    --danger: #dc2626;
    --side-bg: #0f172a;
    --side-bg-2: #1e293b;
    --side-text: #94a3b8;
    --side-w: 256px;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html, body { margin: 0; }
body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1 { font-size: 24px; margin: 0; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 14px; font-weight: 650; }
h3 { font-size: 13.5px; margin: 18px 0 6px; font-weight: 650; }
code, .mono, pre { font-family: "JetBrains Mono", Consolas, Menlo, monospace; font-size: 12.5px; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; }
.icon { flex-shrink: 0; vertical-align: middle; }

/* ---------------- sidebar ---------------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--side-w);
    background: var(--side-bg); color: var(--side-text);
    display: flex; flex-direction: column; padding: 20px 14px; z-index: 50;
    transition: transform .25s ease; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 22px; color: #fff; }
.brand:hover { color: #fff; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
}
.brand-text { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-text small { display: block; font-weight: 500; font-size: 11.5px; color: var(--side-text); }

.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 0 12px 8px; color: #64748b; font-weight: 600; }
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--side-text); font-weight: 500; position: relative; transition: background .15s, color .15s;
}
.side-nav a:hover { background: var(--side-bg-2); color: #e2e8f0; }
.side-nav a.active { background: rgba(99, 102, 241, .16); color: #fff; }
.side-nav a.active::before {
    content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px;
    border-radius: 0 4px 4px 0; background: #818cf8;
}
.side-nav a.active .icon { color: #a5b4fc; }

.sidebar-foot { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.side-info { display: flex; gap: 10px; align-items: flex-start; background: var(--side-bg-2); border-radius: 12px; padding: 12px; }
.side-info .icon { color: #a5b4fc; margin-top: 2px; }
.side-info-title { color: #e2e8f0; font-weight: 600; font-size: 12.5px; }
.side-info-text { font-size: 12px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid #1e293b; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
}
.side-user-name { color: #e2e8f0; font-weight: 600; font-size: 13px; line-height: 1.25; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side-user-name small { display: block; color: var(--side-text); font-weight: 400; font-size: 11.5px; }
.side-logout { color: var(--side-text); padding: 8px; border-radius: 8px; display: grid; place-items: center; }
.side-logout:hover { color: #fca5a5; background: var(--side-bg-2); }

.sidebar-backdrop { display: none; }

/* ---------------- main area ---------------- */
.main { margin-left: var(--side-w); min-height: 100vh; min-width: 0; }
.content { max-width: 1280px; margin: 0 auto; padding: 32px 32px 56px; }
.mobile-bar { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-sub { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------- cards ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.form-card { padding: 22px 24px; margin-bottom: 22px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; }
.grid-2 > .card { margin-bottom: 22px; }

.empty { padding: 56px 24px; text-align: center; }
.empty h2 { margin: 14px 0 6px; }
.empty p { margin: 0 0 18px; }
.empty-icon { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-label { white-space: nowrap; }
.stat { padding: 18px; display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; }
.stat-value-sm { font-size: 16px; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.tone-blue { background: #e0f2fe; color: #0284c7; }
.tone-green { background: #dcfce7; color: #16a34a; }
.tone-purple { background: #ede9fe; color: #7c3aed; }
.tone-red { background: #fee2e2; color: #dc2626; }
.tone-gray { background: #f1f5f9; color: #64748b; }
.tone-amber { background: #fef3c7; color: #d97706; }
.text-danger { color: var(--danger); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 14px 20px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #f8fafc; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: #fafbff; }
.table tr:last-child td { border-bottom: none; }
.table tr.busy { background: var(--primary-soft) !important; }
.card > .table-wrap:first-child .table th:first-child { border-top-left-radius: var(--radius); }
.card > .table-wrap:first-child .table th:last-child { border-top-right-radius: var(--radius); }

.router-cell { display: flex; align-items: center; gap: 12px; }
.router-avatar { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; }
.router-avatar.off { background: #f1f5f9; color: #94a3b8; }
.chips { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 1px 8px; border-radius: 6px; background: #f1f5f9; color: var(--text-2); font-weight: 500; }
.status-line { display: flex; align-items: center; gap: 8px; }
.status-time { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.status-msg { max-width: 380px; color: var(--text-2); word-break: break-word; }
.status-note { margin-top: 6px; font-size: 12px; }
.status-error {
    margin-top: 7px; max-width: 320px; padding: 6px 10px; border-radius: 8px;
    background: #fef2f2; color: #b91c1c; font-size: 12.5px; line-height: 1.45; word-break: break-word;
}
.status-fix {
    display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; max-width: 320px;
    font-size: 12px; line-height: 1.45; color: #92400e;
}
.status-fix .icon { margin-top: 1px; color: #d97706; }
.chip-danger { background: #fee2e2; color: #b91c1c; font-weight: 600; }
.status-warn { margin-top: 6px; max-width: 340px; font-size: 12px; color: #b45309; line-height: 1.45; }
.file-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.file-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 6px;
    background: #f1f5f9; color: var(--text-2); font-size: 12px; white-space: nowrap;
}
.file-chip b { color: var(--primary); font-weight: 600; font-family: "JetBrains Mono", Consolas, monospace; font-size: 11.5px; }
.files-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.files-size { margin-top: 2px; padding-left: 21px; font-size: 12.5px; color: var(--muted); }

.router-table .col-status { min-width: 240px; }
.router-table .col-actions { width: 1%; }
.router-table td:first-child { max-width: 360px; }
.router-table th, .router-table td { padding-left: 16px; padding-right: 16px; }
.router-table th:first-child, .router-table td:first-child { padding-left: 20px; }
.router-table th:last-child, .router-table td:last-child { padding-right: 20px; }
.router-addr { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 3px 0 4px; }
.router-info { min-width: 0; }
.router-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 1px; }
.router-name strong { font-size: 14.5px; }
.router-meta {
    max-width: 300px; font-size: 12.5px; line-height: 1.45; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.host { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-right: 2px; }
.page-sub-icon { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-sub-icon strong { color: var(--text-2); font-weight: 600; }
.file-name { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.file-name .mono { color: var(--text); }
.row-actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; flex-wrap: nowrap; }

.text-right { text-align: right !important; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.req { color: var(--danger); }
.inline { display: inline; }

/* ---------------- buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 1px solid var(--border-2); background: #fff; color: var(--text-2);
    padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 550; cursor: pointer;
    line-height: 1.25; font-family: inherit; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
    white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: #c4cad6; color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .65; cursor: wait; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
.btn-icon { padding: 6px 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, .25); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; box-shadow: 0 2px 8px rgba(22, 163, 74, .2); }
.btn-success:hover { background: var(--success-dark); border-color: var(--success-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.icon-btn { background: none; border: none; padding: 6px; border-radius: 8px; color: var(--text); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: #eef1f6; }

.spinner {
    width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e0e7ff; color: #4338ca; }
.badge-muted { background: #f1f5f9; color: #475569; }

/* ---------------- alerts ---------------- */
.alert { padding: 13px 16px; border-radius: 12px; margin-bottom: 18px; border: 1px solid transparent; word-break: break-word; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ---------------- forms ---------------- */
label { display: block; margin-bottom: 16px; font-weight: 550; color: var(--text-2); font-size: 13.5px; }
input[type=text], input[type=password], input[type=number], select {
    display: block; width: 100%; margin-top: 6px; padding: 10px 13px; border: 1px solid var(--border-2);
    border-radius: 10px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); }
input::placeholder { color: #a0aabb; }
.filter select { min-width: 230px; margin-top: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 26px; margin: 4px 0 14px; }
label.check { display: flex; align-items: center; gap: 9px; font-weight: 500; margin-bottom: 6px; cursor: pointer; }
label.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.advanced { border: 1px dashed var(--border-2); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; background: #fafbfd; }
.advanced summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
.advanced[open] summary { margin-bottom: 14px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 6px; }

pre.cron-log { max-height: 320px; overflow-y: auto; font-size: 12px; white-space: pre-wrap; }
pre.code {background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.checklist { list-style: none; padding: 0; margin: 0 0 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; }
.checklist li { padding: 9px 12px; border-radius: 10px; background: #f8fafc; }
.checklist .ok { color: #15803d; }
.checklist .bad { color: #b91c1c; background: #fef2f2; font-weight: 600; }

/* ---------------- settings ---------------- */
.tabs {
    display: flex; gap: 4px; margin-bottom: 22px; box-shadow: inset 0 -1px 0 var(--border);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
    display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; color: var(--muted); font-weight: 550;
    border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.grid-wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
.avatar-sm { width: 32px; height: 32px; font-size: 13px; flex-shrink: 0; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title-row h2 { margin: 0; }
.switch-row { padding: 12px 14px; background: var(--primary-soft); border-radius: 10px; margin-bottom: 18px !important; font-weight: 600 !important; }
.hint { display: block; margin-top: 5px; font-weight: 400; }
.checks-col { flex-direction: column; gap: 2px; }
.tg-tools { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 14px; }
.chat-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.chat-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; width: 100%;
    padding: 10px 12px; border: 1px solid var(--border-2); border-radius: 10px; background: #fff; cursor: pointer; font-family: inherit; font-size: 13.5px;
}
.chat-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.chat-item .mono { color: var(--muted); }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); }
.steps li { margin-bottom: 8px; }
.tg-preview {
    background: #e7f0f8; border-radius: 12px; padding: 14px 16px; font-size: 13px; line-height: 1.55;
    border-left: 4px solid #2aabee; color: #1e293b;
}

/* ---------------- bulk progress ---------------- */
.bulk-progress { padding: 18px 20px; margin-bottom: 24px; }
.bulk-head { display: flex; justify-content: space-between; gap: 10px; }
.progress { height: 8px; background: #eef1f6; border-radius: 99px; margin: 12px 0; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #16a34a); border-radius: 99px; transition: width .35s; }
.bulk-log { margin: 0; padding: 0; list-style: none; font-size: 12.5px; max-height: 240px; overflow-y: auto; }
.bulk-log li { padding: 6px 0; border-top: 1px solid var(--border); }
.bulk-log .ok { color: #166534; }
.bulk-log .bad { color: #991b1b; }

/* ---------------- auth pages ---------------- */
.auth-page {
    min-height: 100vh;
    background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%),
                radial-gradient(900px 500px at 110% 110%, #ede9fe 0%, transparent 60%), var(--bg);
}
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-wrap > .alert { width: 100%; max-width: 400px; }
.auth-box { width: 100%; max-width: 400px; padding: 34px 32px; box-shadow: 0 20px 50px rgba(15, 23, 42, .08); }
.auth-box h1 { margin: 16px 0 4px; font-size: 22px; }
.auth-box > p { margin: 0 0 22px; }
.auth-logo {
    width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #6366f1, #8b5cf6); box-shadow: 0 8px 20px rgba(99, 102, 241, .35);
}
.auth-box .btn-block { padding: 11px; margin-top: 4px; }

/* ---------------- toast ---------------- */
.toast {
    position: fixed; right: 24px; bottom: 24px; max-width: 460px; padding: 14px 18px; border-radius: 12px;
    color: #fff; box-shadow: 0 16px 40px rgba(0, 0, 0, .22); opacity: 0; transform: translateY(12px);
    transition: all .25s; pointer-events: none; z-index: 100; word-break: break-word; font-weight: 500;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: #166534; }
.toast-bad { background: #991b1b; }

/* ---------------- responsive ---------------- */
@media (max-width: 960px) {
    .sidebar {
        transform: translateX(-100%); visibility: hidden; width: min(var(--side-w), 84vw);
        padding-top: calc(20px + env(safe-area-inset-top)); padding-bottom: calc(20px + env(safe-area-inset-bottom));
        transition: transform .35s cubic-bezier(.2, .8, .2, 1), visibility .35s, box-shadow .35s;
    }
    body.side-open { overflow: hidden; }
    body.side-open .sidebar { transform: none; visibility: visible; box-shadow: 0 0 60px rgba(0, 0, 0, .35); }
    .sidebar-backdrop {
        display: block; position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45);
        backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .3s ease;
    }
    body.side-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    body.side-open .side-nav a { animation: drawerItem .4s cubic-bezier(.2, .8, .2, 1) both; }
    body.side-open .side-nav a:nth-child(2) { animation-delay: .04s; }
    body.side-open .side-nav a:nth-child(3) { animation-delay: .08s; }
    body.side-open .side-nav a:nth-child(4) { animation-delay: .12s; }
    .main { margin-left: 0; }
    .mobile-bar {
        display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30;
        background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 10px 14px;
    }
    .mobile-title { font-weight: 650; }
    .content { padding: 20px 16px 48px; }
}
@media (max-width: 700px) {
    .grid-2, .grid-wide-left { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .stat { padding: 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; border-radius: 10px; }
    .stat-value { font-size: 18px; }
    .stat-value-sm { font-size: 14px; }
    .csv-cols { min-width: 640px; }
    .table th, .table td { padding: 12px 14px; }
    .filter select { min-width: 0; }
    .form-card { padding: 18px; }
    h1 { font-size: 21px; }
    .page-head { align-items: flex-start; }
}

/* ---------------- import / export ---------------- */
.form-card h2 .icon { color: var(--primary); margin-right: 4px; vertical-align: -3px; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
    padding: 26px 16px; border: 2px dashed var(--border-2); border-radius: 14px; background: #fafbfd;
    cursor: pointer; font-weight: 400; transition: border-color .2s, background .2s, transform .2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.drag { transform: scale(1.01); }
.dropzone.has-file { border-style: solid; border-color: #86efac; background: #f0fdf4; }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: #fff; color: var(--primary); box-shadow: var(--shadow); transition: transform .3s; }
.dropzone:hover .dropzone-icon { transform: translateY(-3px); }
.dropzone.has-file .dropzone-icon { color: var(--success); }
.dropzone-text { color: var(--text-2); }
.report-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.report-stat { padding: 12px 18px; border-radius: 12px; min-width: 110px; }
.report-stat strong { display: block; font-size: 24px; line-height: 1.1; }
.report-stat span { font-size: 12.5px; }
.report-errors { margin: 0 0 14px; padding: 10px 14px 10px 30px; background: #fffbeb; border-radius: 10px; color: #92400e; font-size: 12.5px; max-height: 220px; overflow-y: auto; }
.report-errors li { margin: 2px 0; }
.csv-cols td { padding-top: 9px; padding-bottom: 9px; font-size: 13px; }

/* ---------------- animations ---------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rowIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes popIn { 0% { opacity: 0; transform: scale(.92); } 60% { opacity: 1; transform: scale(1.02); } 100% { transform: none; } }
@keyframes flashOk { 0% { background: #bbf7d0; } 100% { background: transparent; } }
@keyframes flashBad { 0% { background: #fecaca; } 100% { background: transparent; } }
@keyframes shimmer { from { background-position: -600px 0; } to { background-position: 600px 0; } }
@keyframes stripes { from { background-position: 0 0; } to { background-position: 28px 0; } }
@keyframes pulseDot { 0%, 100% { box-shadow: 0 0 0 0 currentColor; } 50% { box-shadow: 0 0 0 4px transparent; } }
@keyframes toastIn { 0% { opacity: 0; transform: translateX(40px); } 70% { transform: translateX(-4px); } 100% { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* page content slides up, one block after another */
.content > * { animation: fadeUp .5s cubic-bezier(.2, .7, .3, 1) both; }
.content > *:nth-child(2) { animation-delay: .06s; }
.content > *:nth-child(3) { animation-delay: .12s; }
.content > *:nth-child(4) { animation-delay: .18s; }
.content > *:nth-child(5) { animation-delay: .24s; }
.content > *:nth-child(n+6) { animation-delay: .3s; }
.stats .stat { animation: popIn .5s cubic-bezier(.2, .7, .3, 1) both; }
.stats .stat:nth-child(2) { animation-delay: .08s; }
.stats .stat:nth-child(3) { animation-delay: .16s; }
.stats .stat:nth-child(4) { animation-delay: .24s; }
.table tbody tr.row-anim { animation: rowIn .45s cubic-bezier(.2, .7, .3, 1) both; }
.auth-box { animation: popIn .55s cubic-bezier(.2, .7, .3, 1) both; }
.auth-logo, .empty-icon { animation: float 3.5s ease-in-out infinite; }

/* hover feedback (only on devices with a real mouse, so taps don't leave things "stuck") */
.stat { transition: transform .2s, box-shadow .2s; }
.stat-icon { transition: transform .3s; }
.router-avatar { transition: transform .25s, background .25s; }
.side-nav a .icon { transition: transform .2s; }
.tabs a { transition: color .2s, border-color .25s; }
.btn .icon { transition: transform .2s; }
.chat-item { transition: border-color .15s, background .15s, transform .15s; }
@media (hover: hover) {
    .stat:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(15, 23, 42, .08); }
    .stat:hover .stat-icon { transform: scale(1.08) rotate(-4deg); }
    .table tbody tr:hover .router-avatar { transform: scale(1.08); }
    .side-nav a:hover .icon { transform: translateX(2px); }
    .btn:hover .icon { transform: scale(1.1); }
    .btn-primary:hover, .btn-success:hover { box-shadow: 0 6px 16px rgba(79, 70, 229, .28); transform: translateY(-1px); }
    .btn-success:hover { box-shadow: 0 6px 16px rgba(22, 163, 74, .28); }
    .chat-item:hover { transform: translateX(3px); }
}
.btn:active { transform: translateY(1px) scale(.97); }
.stat:active { transform: scale(.98); }

/* live states */
.badge-danger .dot { animation: pulseDot 1.6s ease-in-out infinite; }
.table tr.busy td {
    background: linear-gradient(90deg, transparent 0%, rgba(99, 102, 241, .10) 50%, transparent 100%) var(--primary-soft);
    background-size: 600px 100%; animation: shimmer 1.3s linear infinite;
}
.table tr.flash-ok td { animation: flashOk 1.6s ease-out; }
.table tr.flash-bad td { animation: flashBad 1.6s ease-out; }
.status-cell > *, .files-cell > * { animation: fadeIn .35s ease both; }
.progress-bar {
    background-image: linear-gradient(45deg, rgba(255, 255, 255, .22) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .22) 50%, rgba(255, 255, 255, .22) 75%, transparent 75%), linear-gradient(90deg, #22c55e, #16a34a);
    background-size: 28px 28px, 100% 100%;
    animation: stripes .8s linear infinite;
}
.bulk-progress.done .progress-bar { animation: none; }
.bulk-progress { animation: fadeUp .35s ease both; }
.bulk-log li { animation: rowIn .3s ease both; }
.toast.show { animation: toastIn .45s cubic-bezier(.2, .7, .3, 1) both; }
.alert { animation: fadeUp .4s ease both; }

/* ---------------- touch feedback & loading ---------------- */
@keyframes drawerItem { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }
@keyframes navLoad { 0% { width: 0; } 15% { width: 40%; } 100% { width: 92%; } }
@keyframes toastUp { 0% { opacity: 0; transform: translateY(24px) scale(.96); } 100% { opacity: 1; transform: none; } }
@keyframes toastTimer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes pillIn { from { opacity: 0; transform: scaleX(.3); } to { opacity: 1; transform: none; } }

html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: none; }

/* table rows waiting to scroll into view (added by JS) */
.table tbody tr.reveal { opacity: 0; }

.btn, .bottom-nav a { position: relative; overflow: hidden; }
.ripple {
    position: absolute; border-radius: 50%; background: currentColor; opacity: .22; pointer-events: none;
    transform: scale(0); animation: ripple .6s cubic-bezier(.2, .7, .3, 1) forwards;
}

/* thin bar at the top while the next page loads */
.nav-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 200; opacity: 0; pointer-events: none;
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #22d3ee); box-shadow: 0 0 10px rgba(99, 102, 241, .6);
    border-radius: 0 3px 3px 0; transition: opacity .3s;
}
.nav-progress.run { opacity: 1; animation: navLoad 6s cubic-bezier(.1, .7, .1, 1) forwards; }

.toast { cursor: pointer; overflow: hidden; }
.toast.show { pointer-events: auto; }
.toast::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .45);
    transform-origin: left; transform: scaleX(0);
}
.toast.show::after { animation: toastTimer 7s linear forwards; }

.bulk-head { flex-wrap: wrap; }
.bulk-log { scroll-behavior: smooth; }
.mobile-bar { transition: box-shadow .25s, background .25s; }
.mobile-bar.scrolled { box-shadow: 0 6px 20px rgba(15, 23, 42, .08); }

.bottom-nav { display: none; }

/* ---------------- phones ---------------- */
@media (max-width: 700px) {
    .mobile-bar { padding-top: calc(10px + env(safe-area-inset-top)); }
    .app .content { padding: 18px 14px calc(96px + env(safe-area-inset-bottom)); }

    /* bottom tab bar */
    .bottom-nav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; gap: 4px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px) saturate(1.4);
        border-top: 1px solid var(--border); box-shadow: 0 -6px 24px rgba(15, 23, 42, .06);
    }
    .bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0 4px;
        border-radius: 14px; color: var(--muted); font-size: 11px; font-weight: 600; transition: color .2s;
    }
    .bottom-nav a::before {
        content: ""; position: absolute; top: 3px; left: 50%; width: 56px; height: 30px; margin-left: -28px;
        border-radius: 99px; background: var(--primary-soft); opacity: 0; transform: scaleX(.3);
        transition: opacity .25s, transform .3s cubic-bezier(.2, .8, .2, 1);
    }
    .bottom-nav a .icon, .bottom-nav a span:not(.ripple) { position: relative; }
    .bottom-nav a .icon { margin-top: 2px; transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
    .bottom-nav a:active .icon { transform: scale(.88); }
    .bottom-nav a.active { color: var(--primary); }
    .bottom-nav a.active::before { opacity: 1; transform: none; animation: pillIn .45s cubic-bezier(.2, .8, .2, 1) both; }

    .toast {
        left: 12px; right: 12px; max-width: none; bottom: calc(80px + env(safe-area-inset-bottom));
        padding: 13px 16px; font-size: 13.5px;
    }
    .toast.show { animation: toastUp .4s cubic-bezier(.2, .8, .2, 1) both; }
    .auth-page .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

    /* bigger tap targets; 16px inputs stop iOS from zooming in */
    input[type=text], input[type=password], input[type=number], select { font-size: 16px; padding: 11px 13px; }
    .btn { padding: 11px 16px; }
    .btn-sm { min-height: 38px; padding: 8px 12px; font-size: 13px; }
    .btn-icon { min-width: 38px; padding: 8px; }
    .icon-btn { padding: 8px; }

    .page-head { margin-bottom: 18px; }
    .page-head .actions, .page-head > form { width: 100%; }
    .page-head .actions .btn { flex: 1; }
    .page-head > form .btn { width: 100%; }
    .filter select { width: 100%; }

    .stats { gap: 10px; margin-bottom: 18px; }
    .stat { flex-direction: column; align-items: flex-start; gap: 10px; }
    .stat-label { white-space: normal; }

    .card-head { padding: 14px 16px 12px; }
    .bulk-progress { padding: 16px; }
    .tabs { margin-left: -14px; margin-right: -14px; padding: 0 10px; }
    .tabs a { padding: 12px 14px; }

    /* tables become a list of cards */
    .stack-table, .stack-table tbody { display: block; }
    .stack-table thead { display: none; }
    .table.stack-table tr {
        display: grid; gap: 8px 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .table.stack-table tr:last-child { border-bottom: none; }
    .table.stack-table td { display: block; padding: 0; border: 0; min-width: 0; max-width: none; text-align: left; }
    .stack-table td[data-label]::before {
        content: attr(data-label); display: block; margin-bottom: 1px;
        font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
    }
    /* switching pages from the tab bar: only fade, nothing slides up */
    .app .content > *, .app .stats .stat, .app .bulk-progress, .app .alert { animation: fadeIn .25s ease both; animation-delay: 0s; }
    .table.stack-table tbody tr.row-anim { animation-name: fadeIn; animation-duration: .3s; }
    .table.stack-table tr.busy td { animation: none; background: none; }
    .table.stack-table tr.busy {
        background: linear-gradient(90deg, transparent 0%, rgba(99, 102, 241, .12) 50%, transparent 100%) var(--primary-soft) !important;
        background-size: 600px 100% !important; animation: shimmer 1.3s linear infinite;
    }
    .table.stack-table tr.flash-ok td, .table.stack-table tr.flash-bad td { animation: none; }
    .table.stack-table tr.flash-ok { animation: flashOk 1.6s ease-out; }
    .table.stack-table tr.flash-bad { animation: flashBad 1.6s ease-out; }

    /* dashboard routers */
    .router-table tr { grid-template-areas: "router files" "status status" "actions actions"; }
    .router-table td:nth-child(1) { grid-area: router; }
    .router-table td:nth-child(2) { grid-area: status; }
    .router-table td:nth-child(3) { grid-area: files; text-align: right; }
    .router-table td:nth-child(4) { grid-area: actions; }
    .router-table .router-meta { max-width: none; }
    .router-table .status-cell { min-width: 0; padding: 10px 12px; border-radius: 10px; background: #f8fafc; }
    .table.stack-table tr.busy .status-cell { background: rgba(255, 255, 255, .7); }
    .router-table .status-error, .router-table .status-fix, .router-table .status-warn { max-width: none; }
    .router-table .files-size { padding-left: 0; }
    .router-table .row-actions { display: flex; width: 100%; }
    .router-table .row-actions [data-backup] { flex: 1; }

    /* backup files */
    .backup-table tr { grid-template-areas: "router type" "file file" "size actions" "created actions"; }
    .backup-table td:nth-child(1) { grid-area: router; }
    .backup-table td:nth-child(2) { grid-area: file; }
    .backup-table td:nth-child(3) { grid-area: type; justify-self: end; }
    .backup-table td:nth-child(4) { grid-area: size; font-weight: 600; }
    .backup-table td:nth-child(5) { grid-area: created; font-size: 12.5px; color: var(--muted); }
    .backup-table td:nth-child(5) .small { display: inline; }
    .backup-table td:nth-child(5) .small::before { content: "· "; }
    .backup-table td:nth-child(6) { grid-area: actions; align-self: center; }
    .backup-table .file-name { display: flex; align-items: flex-start; font-size: 12px; }
    .backup-table .file-name .mono { word-break: break-all; font-size: 11.5px; }

    /* logs */
    .table.log-table tr { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "level router time" "msg msg msg"; align-items: center; gap: 6px 10px; }
    .log-table td:nth-child(1) { grid-area: time; font-size: 11.5px; color: var(--muted); }
    .log-table td:nth-child(2) { grid-area: level; }
    .log-table td:nth-child(3) { grid-area: router; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
    .log-table td:nth-child(4) { grid-area: msg; word-break: break-word; color: var(--text-2); }

    /* users */
    .user-table tr { grid-template-areas: "user actions" "created last"; align-items: center; }
    .user-table td:nth-child(1) { grid-area: user; }
    .user-table td:nth-child(2) { grid-area: created; }
    .user-table td:nth-child(3) { grid-area: last; }
    .user-table td:nth-child(4) { grid-area: actions; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    html { scroll-behavior: auto; }
    .ripple { display: none; }
}
