:root {
    --bg: var(--tg-theme-bg-color, #1a1a2e);
    --text: var(--tg-theme-text-color, #e0e0e0);
    --hint: var(--tg-theme-hint-color, #888);
    --link: var(--tg-theme-link-color, #5b9bd5);
    --btn-bg: var(--tg-theme-button-color, #5b9bd5);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #232342);
    --section-bg: var(--tg-theme-section-bg-color, var(--secondary-bg));
    --green: #34c759;
    --yellow: #ff9500;
    --red: #ff3b30;
    --nav-height: 58px;
}

/* Auth gate spinner */
.spinner {
    width: 36px; height: 36px; margin: 0 auto 14px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: var(--btn-bg);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-bottom: calc(var(--nav-height) + 12px);
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
    font-size: 14px;
    line-height: 1.4;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 10px 12px;
}

/* ===== Cards ===== */
.cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.card {
    background: var(--section-bg);
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s;
    border-left: 3px solid transparent;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.card-icon {
    width: 14px;
    height: 14px;
    color: var(--hint);
    flex-shrink: 0;
    stroke-width: 1.5;
}

.card-label {
    font-size: 11px;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.card-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
}

.card-value-sm {
    font-size: 15px;
}

.card-sub {
    font-size: 11px;
    color: var(--hint);
    margin-top: 2px;
}

.card.level-ok { border-left-color: var(--green); }
.card.level-warn { border-left-color: var(--yellow); }
.card.level-crit { border-left-color: var(--red); }

/* ===== Charts ===== */
.chart-container {
    background: var(--section-bg);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.chart-container h3 {
    font-size: 12px;
    color: var(--hint);
    margin-bottom: 6px;
    font-weight: 500;
}

.chart-container canvas {
    width: 100% !important;
    height: 140px !important;
}

/* ===== Tabs ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Tab title ===== */
.tab-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.tab-title h2 {
    font-size: 18px;
    font-weight: 600;
}

/* ===== Services ===== */
.service-item {
    background: var(--section-bg);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.svc-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.svc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.svc-dot.active { background: var(--green); }
.svc-dot.inactive { background: var(--red); }

.svc-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.svc-mem {
    font-size: 11px;
    color: var(--hint);
}

.svc-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.svc-status {
    font-size: 11px;
    color: var(--hint);
}

/* ===== Sections ===== */
.section {
    margin-bottom: 16px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.section-icon {
    width: 14px;
    height: 14px;
    color: var(--hint);
    flex-shrink: 0;
    stroke-width: 1.5;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.sub-section {
    margin-bottom: 12px;
}

.sub-section h4 {
    font-size: 12px;
    color: var(--hint);
    margin-bottom: 6px;
    font-weight: 500;
}

/* ===== Ban form ===== */
.ban-form {
    display: flex;
    gap: 8px;
}

.ban-form input {
    flex: 1;
    background: var(--section-bg);
    border: 1px solid rgba(128,128,128,0.3);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    color: var(--text);
    outline: none;
}

.ban-form input:focus {
    border-color: var(--link);
}

/* ===== Buttons ===== */
.btn {
    background: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn:active { opacity: 0.8; }
.btn-danger { background: var(--red); }

.btn-sm {
    padding: 5px 10px;
    font-size: 11px;
    border-radius: 6px;
}

.btn-ghost {
    background: transparent;
    color: var(--link);
    border: 1px solid var(--link);
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-ghost.danger {
    color: var(--red);
    border-color: var(--red);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--link);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.icon-btn:active { opacity: 0.6; }

/* Restart button for services */
.svc-restart-btn {
    background: none;
    border: 1px solid rgba(128,128,128,0.3);
    color: var(--hint);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.svc-restart-btn svg {
    width: 12px;
    height: 12px;
}

.svc-restart-btn:active { opacity: 0.6; }

/* ===== Processes toggle ===== */
.procs-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
    background: var(--section-bg);
    border-radius: 8px;
    overflow: hidden;
}

.toggle-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--hint);
    font-size: 12px;
    font-weight: 500;
    padding: 7px;
    cursor: pointer;
}

.toggle-btn.active {
    background: var(--btn-bg);
    color: var(--btn-text);
}

/* Process item */
.proc-item {
    background: var(--section-bg);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.proc-name {
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}

.proc-user {
    color: var(--hint);
    font-size: 11px;
}

.proc-val {
    font-weight: 600;
    font-family: monospace;
    white-space: nowrap;
}

/* ===== SSH / Blocked items ===== */
.list-item {
    background: var(--section-bg);
    border-radius: 8px;
    padding: 9px 10px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.ip-addr {
    font-weight: 600;
    font-family: monospace;
    font-size: 12px;
}

.ssh-user {
    font-size: 11px;
    color: var(--hint);
}

.ssh-time {
    font-size: 11px;
    color: var(--hint);
}

/* ===== MySQL info ===== */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.info-cell {
    background: var(--section-bg);
    border-radius: 8px;
    padding: 8px 10px;
}

.info-label {
    font-size: 10px;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.info-value {
    font-size: 14px;
    font-weight: 600;
    margin-top: 2px;
}

.db-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.db-tag {
    background: var(--section-bg);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--hint);
    font-family: monospace;
}

/* ===== Network ===== */
.net-stats {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.net-stat {
    flex: 1;
    background: var(--section-bg);
    border-radius: 8px;
    padding: 8px 10px;
    text-align: center;
}

.net-stat-label {
    font-size: 10px;
    color: var(--hint);
    text-transform: uppercase;
}

.net-stat-value {
    font-size: 16px;
    font-weight: 600;
    margin-top: 2px;
}

/* ===== Disk breakdown ===== */
.disk-item {
    background: var(--section-bg);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.disk-name {
    font-family: monospace;
    font-size: 12px;
    font-weight: 500;
}

.disk-size {
    font-size: 12px;
    color: var(--hint);
    font-family: monospace;
}

/* ===== Logs ===== */
.log-output {
    background: var(--section-bg);
    border-radius: 8px;
    padding: 8px 10px;
    max-height: 250px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--section-bg);
    border-top: 1px solid rgba(128,128,128,0.15);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    background: none;
    border: none;
    color: var(--hint);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    padding: 6px 12px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
}

.nav-btn.active { color: var(--link); }

.nav-svg {
    width: 18px;
    height: 18px;
}

.nav-label {
    font-size: 10px;
    font-weight: 500;
}

/* ===== Utilities ===== */
.loading {
    text-align: center;
    color: var(--hint);
    padding: 16px;
    font-size: 13px;
}

.empty {
    text-align: center;
    color: var(--hint);
    padding: 16px;
    font-size: 13px;
}

.toast {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 8px 18px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
}

.toast.show { opacity: 1; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.3); border-radius: 3px; }
