/* Светлая тема. Все цвета и размеры — через токены */
:root {
    --bg: #f6f7f9;
    --bg-sidebar: #ffffff;
    --card: #ffffff;
    --surface: #f2f4f7;
    --surface-hover: #e9ecf1;
    --border: #e6e8ec;
    --border-strong: #d4d8df;
    --text: #0f1729;
    --text-2: #475467;
    --text-3: #8a94a6;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef0ff;
    --primary: #111827;
    --primary-hover: #1f2937;
    --online: #12b76a;
    --online-text: #067647;
    --online-soft: #ecfdf3;
    --offline: #f04438;
    --offline-text: #b42318;
    --offline-soft: #fef3f2;
    --warning: #f79009;
    --warning-text: #b54708;
    --warning-soft: #fffaeb;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
    --radius-lg: 16px;
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 264px;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 12px 24px -6px rgba(16, 24, 40, 0.12), 0 4px 8px -4px rgba(16, 24, 40, 0.05);
    --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.22);
    --ring: 0 0 0 4px rgba(79, 70, 229, 0.14);
    color-scheme: light;
}

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

body {
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}

.i {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

svg {
    display: block;
}

.app {
    display: flex;
    height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 4px 8px 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #4f46e5 55%, #4338ca);
    box-shadow: 0 4px 12px -2px rgba(79, 70, 229, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.logo-mark svg {
    width: 18px;
    height: 18px;
}

.logo-text {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.nav-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 0 10px;
    margin-bottom: 8px;
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

.sections-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sections-empty {
    padding: 12px 10px;
    color: var(--text-3);
    font-size: 13px;
}

.section-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-2);
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
}

.section-item:hover {
    background: var(--surface);
    color: var(--text);
}

.section-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.section-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--surface);
    color: var(--text-3);
    flex-shrink: 0;
}

.section-item.active .section-icon {
    background: #fff;
    color: var(--accent);
    box-shadow: var(--shadow-xs);
}

.section-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.section-name {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-host {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Main ---------- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 28px 40px 0;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.main-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-actions {
    display: flex;
    gap: 2px;
}

.header-actions .icon-btn:disabled {
    display: none;
}

.subtitle {
    margin-top: 4px;
    color: var(--text-3);
    font-size: 13px;
    font-family: var(--font-mono);
}

.last-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-2);
    padding: 6px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow-xs);
    white-space: nowrap;
}

.last-check::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--online);
    animation: pulse 2s infinite;
}

.last-check:empty {
    display: none;
}

/* ---------- Empty state ---------- */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
    gap: 10px;
    text-align: center;
}

.empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
    margin-bottom: 6px;
}

.empty-icon svg {
    width: 26px;
    height: 26px;
}

.empty-state h2 {
    color: var(--text);
    font-size: 18px;
    font-weight: 650;
}

/* ---------- Monitor panel ---------- */
.monitor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 40px 0;
    overflow: hidden;
    min-height: 0;
}

.status-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.status-summary:empty {
    display: none;
}

.stat-tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
}

.stat-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
}

.stat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.stat-tile.online .stat-dot { background: var(--online); box-shadow: 0 0 0 3px var(--online-soft); }
.stat-tile.offline .stat-dot { background: var(--offline); box-shadow: 0 0 0 3px var(--offline-soft); }

.stat-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

.stat-value small {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-3);
}

.panel-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.search-box {
    position: relative;
    flex: 1 1 260px;
    max-width: 420px;
}

.search-box svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-3);
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 36px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    outline: none;
    box-shadow: var(--shadow-xs);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder {
    color: var(--text-3);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.category-filter {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.category-filter:empty {
    display: none;
}

.filter-chip {
    --chip-color: var(--accent);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-2);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-chip:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.filter-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chip-color);
}

.projects-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 28px;
    margin: 0 -8px;
    padding: 2px 8px 32px;
}

/* ---------- Groups ---------- */
.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.group-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 650;
    cursor: pointer;
    padding: 4px 0;
    min-width: 0;
}

.group-caret {
    color: var(--text-3);
    transition: transform 0.2s ease;
}

.project-group.collapsed .group-caret {
    transform: rotate(-90deg);
}

.project-group.collapsed .projects-grid {
    display: none;
}

.group-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.group-count,
.group-stat {
    font-size: 11.5px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.group-count { color: var(--text-2); background: var(--surface); }
.group-stat.online { color: var(--online-text); background: var(--online-soft); }
.group-stat.offline { color: var(--offline-text); background: var(--offline-soft); }

.group-tools {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.group-header:hover .group-tools,
.group-tools:focus-within {
    opacity: 1;
}

.group-empty {
    grid-column: 1 / -1;
    padding: 28px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    color: var(--text-3);
    font-size: 13px;
    text-align: center;
}

/* ---------- Square project cards ---------- */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.project-card {
    aspect-ratio: 1 / 1;
    min-height: 280px;
    display: flex;
    flex-direction: column;
    padding: 16px 18px;
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.project-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.project-card.offline {
    background: linear-gradient(180deg, #fffbfa 0%, #fff 40%);
    border-color: #fbe4e1;
}

.project-card.offline .project-name {
    color: var(--text-2);
}

.card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    margin-bottom: 10px;
}

.card-tools {
    display: flex;
    gap: 2px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.project-card:hover .card-tools,
.card-tools:focus-within {
    opacity: 1;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    white-space: nowrap;
}

.status-badge.online { background: var(--online-soft); color: var(--online-text); }
.status-badge.offline { background: var(--offline-soft); color: var(--offline-text); }
.status-badge.checking { background: var(--warning-soft); color: var(--warning-text); }

.project-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.project-status-dot.online { background: var(--online); animation: pulse-ring 2.4s infinite; }
.project-status-dot.offline { background: var(--offline); }
.project-status-dot.checking { background: var(--warning); animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0.45); }
    70% { box-shadow: 0 0 0 6px rgba(18, 183, 106, 0); }
    100% { box-shadow: 0 0 0 0 rgba(18, 183, 106, 0); }
}

.response-time {
    font-size: 11.5px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.category-chip {
    --chip-color: var(--accent);
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: color-mix(in srgb, var(--chip-color) 70%, #000);
    background: color-mix(in srgb, var(--chip-color) 12%, #fff);
    border: 1px solid color-mix(in srgb, var(--chip-color) 22%, #fff);
    padding: 2px 8px;
    border-radius: 6px;
    margin-bottom: 8px;
}

.category-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chip-color);
}

.project-name {
    font-size: 16.5px;
    font-weight: 650;
    letter-spacing: -0.25px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.project-url {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-3);
    text-decoration: none;
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-url:hover {
    color: var(--accent);
}

.project-comment {
    flex: 1;
    min-height: 0;
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-2);
    overflow-y: auto;
    word-break: break-word;
    white-space: pre-line;
    scrollbar-width: none;
    /* длинное описание мягко уходит в прозрачность и прокручивается */
    -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 18px), transparent);
    mask-image: linear-gradient(180deg, #000 calc(100% - 18px), transparent);
    padding-bottom: 12px;
}

.project-comment::-webkit-scrollbar {
    display: none;
}

.project-comment.empty {
    color: var(--text-3);
    font-style: italic;
}

.project-error {
    margin-top: 8px;
    font-size: 11.5px;
    color: var(--offline-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-footer {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.card-footer .btn-run {
    flex: 1;
}

.btn-start,
.btn-stop {
    height: 34px;
    padding: 0 10px;
    font-size: 12.5px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}

.btn-start .i,
.btn-stop .i {
    width: 12px;
    height: 12px;
}

.btn-start .i { color: var(--online); }
.btn-stop .i { color: var(--offline); }

.btn-start:hover:not(:disabled) {
    background: var(--online-soft);
    border-color: #abefc6;
    color: var(--online-text);
}

.btn-stop:hover:not(:disabled) {
    background: var(--offline-soft);
    border-color: #fecdca;
    color: var(--offline-text);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.btn .i,
.btn svg {
    width: 15px;
    height: 15px;
}

.btn:focus-visible,
.btn-icon:focus-visible,
.icon-btn:focus-visible,
.filter-chip:focus-visible,
.group-toggle:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-sm {
    height: 38px;
    padding: 0 14px;
    font-size: 13.5px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--border-strong);
}

.btn-danger {
    background: var(--offline);
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border-color: var(--border);
}

.btn-ghost:hover {
    background: var(--surface);
    color: var(--text);
}

.btn-icon,
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    color: var(--text-3);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

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

.btn-icon:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
    background: var(--surface);
    color: var(--text);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: default;
}

.btn-delete-project:hover,
.btn-group-delete:hover,
.btn-cat-delete:hover,
.icon-btn.danger:hover {
    background: var(--offline-soft) !important;
    color: var(--offline-text) !important;
}

.btn-open {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-2);
    box-shadow: var(--shadow-xs);
}

.btn-open:hover {
    color: var(--accent) !important;
    border-color: #c7c9fb;
    background: var(--accent-soft) !important;
}

.btn-back {
    display: none;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 12px;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 41, 0.35);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    animation: fade-in 0.15s ease;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: pop-in 0.18s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
}

@keyframes pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 4px;
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.2px;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    color: var(--text-3);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    background: var(--surface);
    color: var(--text);
}

.modal-form {
    padding: 16px 24px 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 550;
    color: var(--text);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    box-shadow: var(--shadow-xs);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group textarea {
    resize: vertical;
    min-height: 64px;
    line-height: 1.5;
}

.form-group input[type="color"] {
    height: 42px;
    padding: 4px;
    cursor: pointer;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.form-hint {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 6px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.category-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 8px 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.category-row .category-chip {
    margin: 0 auto 0 0;
}

.category-usage {
    font-size: 12px;
    color: var(--text-3);
    margin-right: 4px;
}

.hidden {
    display: none !important;
}

/* ---------- Terminal ---------- */
.terminal-modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 820px;
    max-width: calc(100vw - 32px);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: pop-in 0.18s ease;
}

.terminal-modal .modal-header {
    padding-bottom: 16px;
}

.terminal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.terminal-header-actions .btn-sm {
    height: 32px;
}

.terminal-output {
    background: #0d1117;
    color: #e6edf3;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.35;
    padding: 16px 18px;
    height: 480px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.terminal-footer {
    padding: 12px 20px;
    display: flex;
    align-items: center;
}

.terminal-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
}

.terminal-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.terminal-status.running { color: var(--warning-text); }
.terminal-status.running::before { animation: pulse 1s infinite; }
.terminal-status.done { color: var(--online-text); }
.terminal-status.error { color: var(--offline-text); }

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(800px 400px at 50% -10%, rgba(99, 102, 241, 0.12), transparent 70%),
        var(--bg);
}

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

.login-logo {
    justify-content: center;
    margin-bottom: 20px;
}

.login-title {
    text-align: center;
    font-size: 19px;
    font-weight: 650;
    margin-bottom: 24px;
}

.login-form .form-group {
    margin-bottom: 18px;
}

.login-submit {
    width: 100%;
}

.login-error {
    color: var(--offline-text);
    font-size: 13px;
    margin-bottom: 12px;
    text-align: center;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d0d5dd;
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.terminal-output::-webkit-scrollbar-thumb {
    background: #30363d;
    background-clip: padding-box;
}

/* Сенсорные экраны: наведения нет, инструменты видны всегда */
@media (hover: none) {
    .card-tools,
    .group-tools {
        opacity: 1;
    }
}

@media (max-width: 1100px) {
    .status-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .app {
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        padding: 16px;
        min-height: 100dvh;
    }

    .sections-list {
        flex: none;
    }

    .section-item {
        padding: 12px 10px;
    }

    .main {
        min-height: 100dvh;
    }

    .main-header {
        flex-direction: column;
        gap: 12px;
        padding: 16px 16px 0;
    }

    .main-header h1 {
        font-size: 21px;
    }

    .monitor-panel {
        padding: 16px 16px 0;
        overflow: visible;
    }

    .projects-list {
        overflow: visible;
    }

    .stat-tile {
        padding: 12px;
    }

    .stat-value {
        font-size: 20px;
    }

    .search-box {
        flex: 1 1 100%;
        max-width: none;
    }

    .toolbar-actions {
        width: 100%;
        margin-left: 0;
    }

    .toolbar-actions .btn {
        flex: 1;
        padding: 0 8px;
    }

    .projects-grid {
        grid-template-columns: 1fr;
    }

    /* в одну колонку квадрат слишком высокий — высота по содержимому */
    .project-card {
        aspect-ratio: auto;
        min-height: 0;
    }

    .project-comment {
        max-height: 140px;
    }

    .card-footer .btn-run,
    .card-footer .btn-open {
        height: 42px;
    }

    .card-footer .btn-open {
        width: 42px;
    }

    .terminal-output {
        height: 360px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal,
    .terminal-modal {
        max-width: none;
        width: 100%;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 92dvh;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions .btn {
        width: 100%;
        height: 44px;
    }

    .app.section-open .btn-back {
        display: inline-block;
    }

    .app.section-open .sidebar {
        display: none;
    }

    .app:not(.section-open) .main {
        display: none;
    }

    .empty-state {
        padding: 32px 16px;
    }
}

/* ---------- Ссылки «Бот» / «Дашборд» ---------- */
.card-links {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.link-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #e0e3ff;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.link-btn .i {
    width: 14px;
    height: 14px;
}

.link-btn:hover {
    background: #e2e5ff;
    border-color: #c7c9fb;
}

/* ---------- Перетаскивание ---------- */
.project-card[draggable="true"] {
    cursor: grab;
}

.project-card button,
.project-card a {
    cursor: pointer;
}

.drag-handle {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%) rotate(90deg);
    display: grid;
    place-items: center;
    width: 18px;
    color: var(--text-3);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.project-card:hover .drag-handle {
    opacity: 0.7;
}

.project-card.dragging {
    opacity: 0.35;
    transform: scale(0.97);
    box-shadow: none;
    border-style: dashed;
    border-color: var(--accent);
}

.projects-list.is-dragging .project-card:not(.dragging):hover {
    transform: none;
}

.projects-list.is-dragging .projects-grid {
    min-height: 90px;
    border-radius: var(--radius-lg);
    transition: background 0.15s ease, outline-color 0.15s ease;
    outline: 1.5px dashed transparent;
    outline-offset: 6px;
}

.project-group.drop-target .projects-grid {
    background: rgba(79, 70, 229, 0.04);
    outline-color: #c7c9fb;
}

.project-group.drop-target .group-name {
    color: var(--accent);
}

/* свёрнутая группа во время перетаскивания принимает карточку на заголовок */
.projects-list.is-dragging .project-group.collapsed .group-header {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 4px 10px;
}

.projects-list.is-dragging .project-group.collapsed.drop-target .group-header {
    border-color: var(--accent);
    background: var(--accent-soft);
}
