@media (max-width: 800px) {
    .ed-body { grid-template-columns: minmax(0, 1fr); }
    .ed-body .ed-help { display: none; }
    .ed-body:not(.ed-help-closed) .ed-help {
        display: flex;
        max-height: min(50vh, 360px);
    }
    .ed-chat { max-height: 36vh; }
    .ed-chat-msgs { max-height: 18vh; }
    .fm-list-head { display: none; }
    .fm-row { grid-template-columns: minmax(0, 1fr) auto; }
    .fm-size, .fm-mod { display: none; }
    .ed-filename { max-width: 50vw; }
    .ed-hint { display: none; }
}

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    padding: 10px 18px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    border: none;
    background: none;
    font-family: var(--font);
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 40px;
}
.tab:hover { color: var(--text-primary); background: var(--bg-card); }
.tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    background: rgba(91, 124, 250, 0.08);
}

/* ── Loading ── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toggle ── */
.toggle { position: relative; width: 44px; height: 24px; cursor: pointer; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 999px;
    transition: var(--transition);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.toggle input:checked + .toggle-slider { background: var(--accent); box-shadow: 0 0 10px rgba(91, 124, 250, 0.4); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Tooltip ── */
.tooltip { position: relative; }
.tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    z-index: 50;
}
.tooltip:hover::after { opacity: 1; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: clamp(28px, 6vw, 48px) 16px;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    background: rgba(91, 124, 250, 0.1);
    border: 1px solid rgba(91, 124, 250, 0.2);
    color: var(--accent);
}
.empty-state-icon .icon { width: 26px; height: 26px; }
.empty-state-text { font-size: 14px; word-break: break-word; }

/* ── Page title icons ── */
.page-title .icon {
    width: 26px;
    height: 26px;
    color: var(--accent);
}

/* ── Touch / coarse pointer ── */
@media (pointer: coarse) {
    input, select, textarea { font-size: 16px; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .nav-item { min-height: 48px; }
    .tab { min-height: 44px; }
}

/* ── Hover only on fine pointers ── */
@media (hover: none) {
    .card:hover,
    .metric-card:hover,
    .server-card:hover,
    .btn:hover,
    .preset-card:hover {
        transform: none;
    }
    .btn-primary:hover:not(:disabled),
    .btn-success:hover:not(:disabled),
    .btn-danger:hover:not(:disabled),
    .btn-warning:hover:not(:disabled) {
        transform: none;
        filter: none;
    }
    .btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #6b8aff, var(--accent)); }
    .tooltip::after { display: none; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Tablet: ≤1024px ── */
@media (max-width: 1024px) {
    :root { --content-pad: 20px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .limit-form { grid-template-columns: 1fr; }
}

/* ── Mobile: ≤900px — drawer sidebar + topbar ── */
@media (max-width: 900px) {
    :root { --content-pad: 16px; }

    .topbar { display: flex; }

    .sidebar {
        position: fixed;
        top: var(--safe-top);
        bottom: 0;
        left: 0;
        width: min(280px, 86vw);
        height: auto;
        transform: translateX(-105%);
        box-shadow: none;
        border-right: 1px solid var(--border-color);
        transition: transform 0.2s ease;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    }
    .sidebar-backdrop {
        display: block;
    }
    .sidebar-backdrop[hidden] { display: none !important; }

    .main-content {
        padding-top: 16px;
    }

    .page-title {
        font-size: clamp(18px, 5vw, 24px);
        flex-wrap: wrap;
    }

    .modal {
        width: 100%;
        max-height: min(90vh, 90dvh);
        border-radius: 16px 16px 12px 12px;
        padding: 20px 16px;
    }
    .modal-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }
    .modal-actions .btn { width: 100%; }

    .detail-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .server-card-actions .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 4px);
    }

    .backup-item,
    .script-item {
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .backup-actions,
    .script-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    table { min-width: 420px; }
    th, td { padding: 10px 12px; }
}

/* ── Phone: ≤600px ── */
@media (max-width: 600px) {
    :root { --content-pad: 12px; --topbar-h: 48px; }

    .card,
    .server-card,
    .metric-card { padding: 14px; border-radius: 12px; }

    .metric-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .metric-grid .metric-card:only-child {
        grid-column: 1 / -1;
    }

    .grid-2,
    .grid-3 { grid-template-columns: 1fr; }

    .login-card {
        border-radius: 16px;
        padding: 28px 18px;
    }

    .preset-grid {
        grid-template-columns: 1fr;
    }

    .detail-info {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .limit-form { grid-template-columns: 1fr; }

    .server-card-actions .btn {
        min-width: 100%;
    }

    .chart-container { height: 180px; }

    .console-header { flex-wrap: wrap; gap: 8px; }

    .empty-state { padding: 32px 12px; }

    .command-input-container { flex-direction: column; }
    .command-input-container .btn { width: 100%; }

    table { min-width: 360px; }
    td, th { font-size: 13px; padding: 10px; }

    .disk-item {
        flex-wrap: wrap;
    }
    .disk-info {
        min-width: 0;
        width: 100%;
        text-align: left;
        padding-left: calc(60px + 12px);
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 92dvh;
        border-radius: 18px 18px 0 0;
        margin: 0;
        padding-bottom: calc(20px + var(--safe-bottom));
    }
}

/* ── Tiny phones: ≤380px ── */
@media (max-width: 380px) {
    .metric-grid { grid-template-columns: 1fr; }
    .sidebar-title { font-size: 14px; }
    .server-card-actions .btn { min-width: 100%; }
}

/* ── Short screens / landscape phones ── */
@media (max-height: 500px) and (orientation: landscape) {
    .login-page { align-items: flex-start; padding-top: 12px; }
    .login-card { padding: 18px 16px; }
    .login-logo { width: 48px; height: 48px; margin-bottom: 10px; }
    .login-logo .icon { width: 24px; height: 24px; }
    .login-card h1 { margin-bottom: 14px; font-size: 18px; }
    .modal { max-height: 94vh; }
    .chart-container { height: 140px; }
}

/* ── Wide desktop ── */
@media (min-width: 1600px) {
    :root { --content-pad: 36px; }
    .metric-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* ── Print (rare, but don't explode) ── */
@media print {
    .sidebar, .topbar, .sidebar-backdrop, .debug-banner { display: none !important; }
    html, body, .app, .main-content { overflow: visible !important; height: auto !important; background: #fff !important; color: #000 !important; }
}

