:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1d1f23;
    --muted: #6b7280;
    --accent: #2563eb;
    --ok: #16a34a;
    --bad: #dc2626;
    --line: #00000014;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #16181d;
        --card: #22252c;
        --text: #e5e7eb;
        --muted: #9ca3af;
        --accent: #3b82f6;
        --line: #ffffff1a;
    }
}

:root[data-theme="dark"] {
    --bg: #16181d;
    --card: #22252c;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #3b82f6;
    --line: #ffffff1a;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
}

h1 {
    font-size: 20px;
    margin: 0;
}

h2 {
    font-size: 16px;
    margin: 0 0 12px;
}

/* Заголовок карточки в одну строку без отступов, чтобы кнопка «Закрыть» стояла ровно по центру строки.
   Длинное имя сервера обрезается с «…», а не переносится: иначе кнопка центрируется относительно двух строк. */
.terminal-head h2 {
    margin: 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.terminal-head button {
    flex-shrink: 0;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

/* Страница входа */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-card {
    width: min(360px, 100%);
    background: var(--card);
    border-radius: 10px;
    padding: 24px;
}

.login-card h1 {
    margin: 0 0 16px;
    font-size: 20px;
}

#login-form {
    display: grid;
    gap: 12px;
}

#login-form label {
    display: grid;
    gap: 4px;
    font-size: 14px;
}

#login-form input {
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

#login-form button {
    padding: 8px;
}

main {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px 32px;
    display: grid;
    /* minmax(0, 1fr): колонка не растягивается под длинный текст и не даёт прокрутку страницы */
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

.card {
    background: var(--card);
    border-radius: 10px;
    padding: 16px;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.server {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.server:first-child {
    border-top: none;
}

/* Длинное имя сервера переносится внутри строки, а не выталкивает страницу вбок */
.server > div {
    min-width: 0;
}

.server strong {
    overflow-wrap: anywhere;
}

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

button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

button:disabled {
    opacity: 0.4;
    cursor: default;
}

.badge {
    font-size: 12px;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: 99px;
}

.badge.on {
    background: var(--ok);
    color: #fff;
}

.badge.off {
    background: var(--line);
    color: var(--muted);
}

.error {
    color: var(--bad);
}

.small {
    font-size: 12px;
}

#message {
    min-height: 1.2em;
    margin: 12px 0 0;
    color: var(--muted);
}

.terminal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

button.ghost {
    background: var(--line);
    color: var(--text);
}

#output {
    height: 360px;
    overflow: auto;
    padding: 12px;
    border-radius: 8px;
    background: #0d0f12;
    color: #d1d5db;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
}

#output div {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Файловый менеджер */
#files-path {
    margin-bottom: 8px;
    font-size: 14px;
    word-break: break-all;
}

.crumb {
    color: var(--accent);
    cursor: pointer;
}

.muted {
    color: var(--muted);
}

/* Таблица файлов: колонки как в проводнике.
   На узком экране таблица прокручивается внутри карточки, а не всей страницы. */
.files-table {
    overflow-x: auto;
}

#files-list {
    min-width: 760px;
}

#files-list li.row {
    display: grid;
    grid-template-columns: minmax(160px, 2fr) 150px 110px 90px 200px;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border-top: 1px solid var(--line);
    font-size: 14px;
}

#files-list li.head {
    border-top: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

/* Кликабельна вся строка, а не только текст */
#files-list li.row.clickable {
    cursor: pointer;
}

#files-list li.row.clickable:hover {
    background: var(--line);
}

#files-list .cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#files-list li.row > .cell:first-child {
    white-space: normal;
    word-break: break-all;
}

#files-list li.row > .cell:nth-child(4) {
    text-align: right;
}

/* Колонка действий не обрезается, иначе кнопки перекроют размер файла */
#files-list li.row > .cell:last-child {
    overflow: visible;
}

#files-list .actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    white-space: nowrap;
}

.link-button.small {
    padding: 4px 10px;
    font-size: 13px;
}

.link-button {
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    text-decoration: none;
}

/* Кадр полноэкранного режима (monitor): такой же фон, как у вывода, но без переноса строк */
#screen {
    height: 360px;
    overflow: auto;
    padding: 12px;
    border-radius: 8px;
    background: #0d0f12;
    color: #d1d5db;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
}

#screen div {
    white-space: pre;
}

/* Цвета из консоли сервера (ANSI 30-37 и 90-97).
   Подобраны близко к стандартной палитре Windows-консоли, чтобы вывод выглядел как в самой консоли.
   Чёрный (30) сделан светло-серым, иначе он не видно на тёмном фоне. */
.c30 { color: #767676; }
.c31 { color: #e04b59; }
.c32 { color: #2fb320; }
.c33 { color: #d0a600; }
.c34 { color: #3b78ff; }
.c35 { color: #d05ccf; }
.c36 { color: #3a96dd; }
.c37 { color: #cccccc; }
.c90 { color: #767676; }
.c91 { color: #e74856; }
.c92 { color: #16c60c; }
.c93 { color: #f9f1a5; }
.c94 { color: #3b78ff; }
.c95 { color: #e879f9; }
.c96 { color: #61d6d6; }
.c97 { color: #f2f2f2; }

#command-form {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

#command-input {
    flex: 1;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 14px;
}
