:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-muted: #f9fafb;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #111827;
    --muted: #6b7280;
    --muted-strong: #4b5563;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --radius: 12px;
    --shadow: 0 12px 30px rgba(15, 23, 42, .05);
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img, svg { display: block; max-width: 100%; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; line-height: 1.2; margin-bottom: 0; }
h2 { font-size: 22px; line-height: 1.25; margin-bottom: 8px; }
h3 { font-size: 17px; line-height: 1.3; margin-bottom: 8px; }
p { color: var(--muted); }
.muted-text { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Layout */
.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}
.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
    padding: 28px 18px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.brand, .sidebar-brand {
    display: grid;
    gap: 4px;
    color: var(--text);
}
.brand-logo {
    display: inline-flex;
    align-items: center;
    color: var(--text);
    font-size: 30px;
    line-height: 1;
    font-weight: 800;
}
.brand-logo span { color: var(--primary); }
.sidebar-brand small {
    color: var(--muted);
    font-size: 13px;
}
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 42px;
    padding: 0 12px;
    color: var(--muted-strong);
    border-radius: 9px;
    font-weight: 600;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: var(--primary);
    background: var(--primary-soft);
}
.sidebar-nav a.strong-link:not(.active) { color: var(--text); }
.sidebar-nav a.muted-link:not(.active) { color: var(--muted); }
.nav-separator {
    height: 1px;
    margin: 10px 4px;
    background: var(--border);
}
.nav-lock, .nav-extra { margin-left: auto; color: #9ca3af; }
.nav-lock .icon { width: 16px; height: 16px; }
.sidebar-profile {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.profile-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
}
.profile-card b { display: block; }
.profile-card span:not(.avatar) { color: var(--muted); font-size: 13px; }
.profile-card a { color: var(--primary); font-weight: 700; }
.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    color: var(--muted-strong);
    background: #eef0f3;
    border-radius: 50%;
    font-weight: 700;
}
.logout-button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 0 14px;
    color: var(--muted-strong);
    background: transparent;
    border: 0;
    border-top: 1px solid var(--border);
    cursor: pointer;
}
.app-main { min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 82px;
    padding: 0 32px;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.top-user, .balance-pill, .bell-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.balance-pill b { display: block; color: var(--primary); }
.bell-button { position: relative; width: 42px; justify-content: center; padding: 0; }
.bell-button i {
    position: absolute;
    right: 10px;
    top: 9px;
    width: 7px;
    height: 7px;
    background: var(--primary);
    border-radius: 50%;
}
.content {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 28px 32px 48px;
}
.mobile-only { display: none; }

/* Common UI */
.panel,
.work-card,
.active-plan-card,
.tariff-card,
.hero-card,
.install-card,
.auth-card,
.page-block,
.simple-page-card,
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel,
.work-card,
.active-plan-card,
.tariff-card,
.hero-card,
.install-card,
.auth-card,
.page-block,
.simple-page-card {
    padding: 22px;
}
.page-stack { display: grid; gap: 18px; }
.page-heading,
.panel-head,
.card-headline,
.tariff-top,
.install-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.page-heading p,
.panel-head p,
.card-headline p { margin-bottom: 0; }
.dashboard-grid,
.bot-top-grid,
.status-card-grid,
.analytics-grid,
.admin-grid,
.install-grid,
.server-connect-layout,
.settings-page {
    display: grid;
    gap: 18px;
}
.dashboard-grid.top,
.bot-top-grid,
.install-grid,
.server-connect-layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, .8fr);
}
.status-card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.admin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full-span { grid-column: 1 / -1; }
.narrow { max-width: 720px; }
.wide-card { grid-column: span 1; }

.button,
.icon-button,
.format-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.button:hover,
.icon-button:hover,
.format-button:hover { border-color: var(--border-strong); background: var(--surface-muted); }
.button-primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}
.button-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button-muted { color: var(--muted-strong); background: var(--surface-muted); }
.big-action { min-height: 46px; padding: 0 18px; }
.icon-button { width: 40px; padding: 0; }
.button:disabled,
button:disabled {
    opacity: .58;
    cursor: not-allowed;
}
.is-loading { pointer-events: none; }
.danger-action { color: var(--danger); }
.inline-actions,
.project-actions,
.command-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.command-actions { margin: 14px 0; }

.status-badge,
.badge,
.hint-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 10px;
    color: var(--muted-strong);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}
.status-badge.success,
.badge.success { color: var(--success); background: var(--success-soft); border-color: #bbf7d0; }
.status-badge.warning { color: var(--warning); background: var(--warning-soft); border-color: #fde68a; }
.status-badge.danger { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }
.status-badge.muted { color: var(--muted); }
.dot,
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
}
.dot.success,
.status-dot.success { background: var(--success); }
.dot.muted,
.status-dot.muted { background: #9ca3af; }

/* Forms */
.form-stack {
    display: grid;
    gap: 16px;
}
label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}
label span,
label small {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}
input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
}
textarea { min-height: 120px; resize: vertical; }
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.form-panel {
    display: grid;
    gap: 16px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.settings-page {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
}
.settings-main { display: grid; gap: 18px; min-width: 0; }
.rules-panel {
    position: sticky;
    top: 104px;
    display: grid;
    gap: 14px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.form-actions,
.sticky-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.dirty-note {
    display: none;
    color: var(--warning);
    font-weight: 700;
}
.dirty-note.visible { display: inline-flex; }
.check-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.check-row input { width: auto; min-height: auto; margin-top: 4px; }
.inline-form,
.admin-inline {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.admin-inline input,
.admin-inline select,
.short-input { width: auto; min-width: 90px; }

/* Telegram editor */
.telegram-editor {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}
.telegram-editor textarea {
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
}
.format-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: var(--surface-muted);
}
.format-button {
    min-height: 32px;
    min-width: 34px;
    padding: 0 10px;
    font-weight: 800;
}
.format-button.wide { min-width: 86px; }
.full-editor { margin-top: 16px; }

/* Details, lists, tables */
.clean-details,
.details {
    display: grid;
    grid-template-columns: minmax(120px, .7fr) minmax(0, 1fr);
    gap: 10px 18px;
    margin: 0;
}
.clean-details dt,
.details dt {
    color: var(--muted);
    font-weight: 600;
}
.clean-details dd,
.details dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 700;
}
.compact-details { margin-top: 18px; }
.wide-details { grid-template-columns: minmax(180px, .35fr) minmax(0, 1fr); }
.clean-list,
.list,
.project-list,
.plain-steps {
    display: grid;
    gap: 10px;
}
.plain-steps {
    margin: 0;
    padding-left: 20px;
}
.plain-steps li span {
    display: block;
    color: var(--muted);
}
.list-row,
.project-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.project-card h3,
.project-card p { margin-bottom: 4px; }
.inline-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}
.inline-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}
table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    background: var(--surface);
}
th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
th {
    color: var(--muted);
    background: var(--surface-muted);
    font-size: 13px;
    font-weight: 800;
}
tr:last-child td { border-bottom: 0; }
.error-cell {
    max-width: 360px;
    color: var(--danger);
    white-space: normal;
}

/* Dashboard */
.intro-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.price-xl,
.price-lg {
    color: var(--text);
    font-weight: 800;
    line-height: 1.1;
}
.price-xl { font-size: 34px; }
.price-lg { font-size: 26px; margin: 8px 0 14px; }
.price-xl span,
.price-lg span { color: var(--muted); font-size: 15px; font-weight: 600; }
.feature-grid,
.pricing-strip,
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}
.feature-grid article,
.stat-card,
.price-card,
.payment-placeholder,
.mini-feature {
    padding: 16px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.feature-grid ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted-strong); }
.round-icon,
.simple-page-icon {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin-bottom: 10px;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 10px;
}

/* Install progress */
.install-grid {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    align-items: start;
}
.progress-summary {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.progress-summary strong {
    color: var(--primary);
    font-size: 28px;
    line-height: 1;
}
.progress-bar {
    width: 100%;
    height: 10px;
    overflow: hidden;
    margin: 16px 0 18px;
    background: #e5e7eb;
    border-radius: 999px;
}
.progress-bar i {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    border-radius: inherit;
    transition: width .2s ease;
}
.install-step-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.progress-step {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.progress-step b { display: block; }
.progress-step small { display: block; color: var(--muted); }
.progress-step em {
    color: var(--muted);
    font-size: 13px;
    font-style: normal;
    font-weight: 700;
}
.step-state {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    color: var(--muted);
    background: #eef0f3;
    border-radius: 50%;
}
.progress-step.running {
    background: var(--primary-soft);
    border-color: #bfdbfe;
}
.progress-step.running .step-state,
.progress-step.running em { color: var(--primary); }
.progress-step.success .step-state,
.progress-step.success em { color: var(--success); }
.progress-step.error {
    background: var(--danger-soft);
    border-color: #fecaca;
}
.progress-step.error .step-state,
.progress-step.error em { color: var(--danger); }
.install-error,
.install-output {
    display: none;
    margin-bottom: 14px;
    padding: 12px;
    color: var(--danger);
    background: var(--danger-soft);
    border: 1px solid #fecaca;
    border-radius: 10px;
}
.install-error.visible,
.install-output.visible { display: grid; gap: 4px; }
.install-output {
    max-height: 260px;
    overflow: auto;
    color: #7f1d1d;
    white-space: pre-wrap;
}

/* Notices and flash */
.notice,
.flash,
.alert {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--muted-strong);
}
.notice.error,
.flash.error,
.alert-danger {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: #fecaca;
}
.flash.success,
.alert-success {
    color: var(--success);
    background: var(--success-soft);
    border-color: #bbf7d0;
}
.flash { margin-bottom: 16px; white-space: pre-wrap; }

/* Guest/public */
.guest-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.site-header,
.site-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.site-footer {
    justify-content: center;
    flex-wrap: wrap;
    color: var(--muted);
    border-top: 1px solid var(--border);
    border-bottom: 0;
}
.site-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--muted-strong);
    font-weight: 700;
}
.guest-main {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 44px 24px;
    flex: 1;
}
.auth-card {
    width: 100%;
    max-width: 440px;
    margin: 40px auto;
}
.hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding: 34px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.hero h1 { font-size: 48px; margin-bottom: 12px; }
.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}
.eyebrow {
    color: var(--primary);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: .08em;
}
.section-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 18px;
}
.section-grid article {
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.page-block { max-width: 820px; }
.status-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}
.status-list div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
}

/* Remove old decorative elements if any old view still renders them */
.soft-illustration,
.hero-panel,
.server-card-shape,
.glass-icon,
.mini-chart,
.activity-chart,
.donut-wrap,
.load-lines,
.metric-strip,
.info-strip,
.bot-avatar,
.big-check,
.periods {
    display: none !important;
}

@media (max-width: 1120px) {
    .app-shell { grid-template-columns: 230px minmax(0, 1fr); }
    .content { padding: 22px; }
    .dashboard-grid.top,
    .bot-top-grid,
    .install-grid,
    .server-connect-layout,
    .settings-page,
    .status-card-grid,
    .feature-grid,
    .pricing-strip,
    .section-grid,
    .stat-grid,
    .admin-grid {
        grid-template-columns: 1fr;
    }
    .rules-panel { position: static; }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .mobile-only { display: inline-flex; }
    .sidebar {
        position: fixed;
        z-index: 20;
        inset: 0 auto 0 0;
        width: min(320px, 88vw);
        transform: translateX(-105%);
        transition: transform .18s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .topbar {
        min-height: 68px;
        padding: 0 16px;
    }
    .topbar h1 { font-size: 22px; }
    .topbar-actions { gap: 8px; }
    .balance-pill span:last-child,
    .top-user b { display: none; }
    .content { padding: 18px 14px 32px; }
    .page-heading,
    .panel-head,
    .card-headline,
    .intro-panel,
    .tariff-top {
        flex-direction: column;
        align-items: stretch;
    }
    .field-grid,
    .clean-details,
    .details,
    .wide-details {
        grid-template-columns: 1fr;
    }
    .project-card,
    .list-row,
    .progress-step {
        grid-template-columns: 1fr;
        align-items: start;
    }
    .progress-step em { justify-self: start; }
    .site-header { padding: 16px; }
    .site-nav {
        display: none;
        position: absolute;
        top: 70px;
        left: 12px;
        right: 12px;
        flex-direction: column;
        align-items: stretch;
        padding: 14px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }
    .site-nav.open { display: flex; }
    .guest-main { padding: 24px 14px; }
    .hero { padding: 24px; }
    .hero h1 { font-size: 36px; }
}
