/* ============================================================
Палитра: светло-голубой / красный / чёрный
============================================================ */
:root {
--blue-50:  #e8f4fc;
--blue-100: #d0e9f9;
--blue-200: #a5d6f2;
--blue-300: #7bc4ec;
--blue-500: #29a3e0;
--blue-600: #0288d1;
--blue-800: #01579b;

--red:      #e53935;
--red-dark: #b71c1c;

--ink:      #111;
--ink-soft: #333;
--ink-mute: #666;

--bg:       #f6fafd;
--white:    #fff;

--radius:   8px;
--shadow:   0 2px 8px rgba(2, 136, 209, .12);
}

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

html {
/* Всегда резервируем место под вертикальный скроллбар */
overflow-y: scroll;
scrollbar-gutter: stable;
}

body {
font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
background: var(--bg);
color: var(--ink);
-webkit-text-size-adjust: 100%;   /* iOS не раздувает шрифт */
}

a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-dark); text-decoration: underline; }

/* ---------- Icons ---------- */
.ico {
width: 1em; height: 1em;
display: inline-block;
vertical-align: -.125em;
fill: currentColor;
}
.ico-22   { width: 22px; height: 22px; }
.ico-logo { width: 36px; height: 36px; display: block; }

#wrapper {
max-width: 1100px;
margin: 0 auto;
padding: 0 16px 24px;
}

/* ---------- HEADER ---------- */
#header {
display: flex;
align-items: center;
gap: 16px;
padding: 18px 0 14px;
border-bottom: 3px solid var(--blue-600);
}
#main-logo h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: .5px; }
#main-logo .logo {
display: inline-flex; align-items: center; gap: 10px;
color: var(--ink);
}
#main-logo .logo:hover { color: var(--ink); text-decoration: none; }
#description {
margin-left: auto;
color: var(--blue-800);
font-weight: 600; letter-spacing: .3px;
}

/* ---------- COMMAND BAR ---------- */
#commandbar {
background: linear-gradient(180deg, var(--blue-100), var(--blue-50));
border: 1px solid var(--blue-200);
border-radius: var(--radius);
box-shadow: var(--shadow);
margin: 14px 0 22px;
overflow: hidden;
display: flex;
justify-content: space-between;
align-items: center;
padding: 2px 6px 2px 2px;
}

#commandbar ul {
display: flex; flex-wrap: wrap;
list-style: none; margin: 0; padding: 6px; gap: 4px;
flex: 1;
}

#commandbar a {
display: inline-flex; align-items: center; gap: 6px;
padding: 6px 12px;
border-radius: 6px;
color: var(--ink);
font-weight: 600; font-size: 12px;
text-transform: uppercase; letter-spacing: .5px;
transition: background .15s, color .15s;
}
#commandbar a:hover {
background: var(--blue-600); color: #fff; text-decoration: none;
}

/* Поиск в командной строке */
.commandbar-search { flex-shrink: 0; }
.search-container { position: relative; display: flex; align-items: center; }

.commandbar-search input {
width: 220px;
padding: 7px 32px 7px 12px;
border: 1px solid var(--blue-300);
border-radius: 6px;
font-size: 13px;
outline: none;
background: var(--white);
color: var(--ink);
transition: border-color .15s, box-shadow .15s;
}
.commandbar-search input:focus {
border-color: var(--blue-600);
box-shadow: 0 0 0 2px rgba(2, 136, 209, 0.2);
}

.search-clear-btn {
position: absolute;
right: 6px; top: 50%;
transform: translateY(-50%);
background: none; border: none;
color: var(--ink-mute);
cursor: pointer; padding: 4px;
display: none;
align-items: center; justify-content: center;
border-radius: 50%;
transition: color 0.15s, background 0.15s;
}
.search-clear-btn:hover { color: var(--red); background: rgba(0,0,0,0.05); }
.search-clear-btn svg { width: 14px; height: 14px; display: block; }

/* ---------- LOCATION ---------- */
#files h2 {
margin: 0 0 12px;
font-size: 15px; font-weight: 600;
color: var(--ink-mute);
}
#files h2 #folder { color: var(--blue-800); font-weight: 700; }
#folder a { word-break: break-word; }

/* ---------- TABLE ---------- */
#files table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
background: var(--white);
border: 1px solid var(--blue-200);
border-radius: var(--radius);
overflow: hidden;
box-shadow: var(--shadow);
}

#files thead th:first-child { border-top-left-radius: var(--radius); }
#files thead th:last-child { border-top-right-radius: var(--radius); }
#files tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
#files tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
#files tbody tr:first-child td { border-top: none; }

#files thead th {
background: var(--blue-600); color: #fff;
text-align: left;
font-weight: 700; font-size: 11px;
text-transform: uppercase; letter-spacing: .6px;
padding: 10px 14px;
border-bottom: 2px solid var(--blue-800);
}
#files thead th.icon { width: 44px; }
#files thead th.date { width: 160px; }
#files thead th.size { width: 100px; text-align: right; }

#files thead th.sortable { cursor: pointer; user-select: none; transition: background .15s; }
#files thead th.sortable:hover { background: var(--blue-800); }
#files thead th span { font-size: 10px; opacity: 0.6; margin-left: 4px; display: inline-block; }

#files tbody td {
padding: 9px 14px;
border-top: 1px solid var(--blue-100);
vertical-align: middle;
}
#files tbody tr:nth-child(even) { background: var(--blue-50); }
#files tbody tr:hover { background: var(--blue-100); }
#files tbody tr.is-dir { cursor: pointer; }

#files tbody td.icon { width: 44px; text-align: center; }
#files tbody td.name a { color: var(--ink); font-weight: 600; word-break: break-word; }
#files tbody td.name a:hover { color: var(--red); }
#files tbody td.date { color: var(--ink-mute); font-size: 13px; white-space: nowrap; }
#files tbody td.size { color: var(--ink-mute); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
#files tbody td.empty { text-align: center; color: var(--ink-mute); font-style: italic; padding: 24px; }

.ic-folder { color: var(--blue-500); }
.ic-ext-file { color: var(--ink-soft); }
td.icon svg { display: block; margin: 0 auto; }

/* ---------- PAGINATION ---------- */
.pagination {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 0;
font-size: 14px;
color: var(--ink-mute);
flex-wrap: wrap;
gap: 15px;
}
.page-info { white-space: nowrap; }
.page-controls { display: flex; gap: 8px; margin-left: auto; }

.pagination .page-btn {
display: inline-flex !important;
align-items: center; justify-content: center;
width: 24px !important; height: 24px !important;
padding: 0 !important;
border-radius: 6px;
background: var(--blue-600);
border: 1px solid var(--blue-800);
color: #fff !important;
text-decoration: none !important;
transition: background 0.15s, transform 0.1s;
box-shadow: 0 2px 4px rgba(2, 136, 209, 0.3);
}
.pagination .page-btn:hover:not(.disabled) { background: var(--blue-800); }
.pagination .page-btn:active:not(.disabled) { transform: scale(0.95); }
.pagination .page-btn.disabled { background: var(--blue-200); border-color: var(--blue-300); opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.pagination .page-btn svg { width: 20px !important; height: 20px !important; fill: currentColor; display: block; }

/* ---------- PREVIEW MODAL ---------- */
#preview-modal {
display: none;
position: fixed; inset: 0;
background: rgba(0,0,0,0.5);
z-index: 1000;
align-items: center; justify-content: center;
overscroll-behavior: contain;
}

.preview-box {
background: #fff;
width: 90%; max-width: 1000px; max-height: 90vh;
border-radius: 8px;
display: flex; flex-direction: column;
overflow: hidden;
box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.preview-head {
padding: 10px 15px;
background: var(--blue-100);
display: flex; justify-content: space-between; align-items: center;
border-bottom: 1px solid var(--blue-300);
}
#preview-title { color: var(--blue-800); font-weight: 600; }

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

/* Кнопки в шапке превью */
#preview-download {
display: none; /* JS меняет на inline-flex */
align-items: center;
justify-content: center;
background: var(--blue-600);
color: #fff !important;
text-decoration: none !important;
padding: 6px 12px;
border-radius: 4px;
font-weight: bold;
font-size: 13px;
box-sizing: border-box;
}
#preview-download:hover { background: var(--blue-800); }

#preview-close {
display: inline-flex;
align-items: center;
justify-content: center;
background: var(--red); color: #fff;
border: none; padding: 6px 12px; border-radius: 4px;
cursor: pointer; font-weight: bold;
font-size: 13px;
box-sizing: border-box;
}
#preview-close:hover { background: var(--red-dark); }

.preview-body {
padding: 15px;
overflow: auto;
flex: 1;
background: #f9f9f9;
overscroll-behavior: contain;
}
#preview-content {
margin: 0; white-space: pre-wrap; word-wrap: break-word;
font-family: monospace; font-size: 13px; color: #333;
}

/* Обертка для картинки: центрирование и шахматный фон */
#preview-image-wrap {
width: 100%;
height: 100%;
min-height: 60vh;
display: none;
align-items: center;
justify-content: center;
padding: 10px;
box-sizing: border-box;
background-color: #fff;
background-image: 
linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
background-size: 20px 20px;
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
border-radius: 4px;
}
#preview-image {
max-width: 100%;
max-height: 65vh;
object-fit: contain;
display: none;
background: transparent;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
border-radius: 2px;
}

/* ---------- FOOTER ---------- */
#footer {
margin-top: 32px;
padding: 22px 24px;
background: linear-gradient(180deg, var(--blue-100) 0%, transparent 100%);
border-radius: var(--radius);
display: flex; align-items: center;
gap: 24px; flex-wrap: wrap;
}
#footer-logo a { color: var(--blue-600); display: block; }
#footer-logo .ico-logo { width: 48px; height: 48px; }
#footer-info { line-height: 1.7; font-size: 13px; color: var(--ink-soft); }
#footer-info strong { color: var(--ink); }
#footer-info a { color: var(--blue-800); text-decoration: underline; }
#footer-info a:hover { color: var(--red); }

/* ---------- ERROR PAGES ---------- */
.error-wrap {
text-align: center; padding: 60px 20px;
background: var(--white); border-radius: var(--radius);
box-shadow: var(--shadow); border: 1px solid var(--blue-200);
margin-top: 20px; margin-bottom: 40px;
}
.error-icon { width: 72px; height: 72px; color: var(--blue-300); margin-bottom: 16px; }
.error-code.404 + .error-icon { color: var(--red); }
.error-code.403 + .error-icon { color: var(--blue-600); }
.error-code.500 + .error-icon { color: #f59e0b; }
.error-code { font-size: 64px; font-weight: 800; line-height: 1; margin: 0 0 10px; color: var(--ink); letter-spacing: -2px; }
.error-title { font-size: 20px; font-weight: 700; color: var(--ink); margin: 0 0 12px; }
.error-desc { color: var(--ink-mute); font-size: 15px; margin: 0 0 28px; max-width: 400px; margin-left: auto; margin-right: auto; }
.error-btn { display: inline-block; padding: 10px 24px; background: var(--blue-600); color: #fff !important; border-radius: 6px; font-weight: 600; text-decoration: none !important; transition: background .15s; }
.error-btn:hover { background: var(--blue-800); }

/* ---------- UTILITIES (Scroll & Copy) ---------- */
html.no-scroll, body.no-scroll {
overflow: hidden !important;
height: 100% !important;
}
body.no-copy {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

/* ============================================================
MOBILE / TABLET  (≤ 720px)
============================================================ */
@media (max-width: 720px) {
/* HEADER */
#header { flex-wrap: wrap; gap: 8px 12px; padding: 12px 0 10px; border-bottom-width: 2px; }
#main-logo h1 { font-size: 17px; letter-spacing: .3px; }
#main-logo .logo { gap: 8px; }
#main-logo .ico-logo { width: 28px; height: 28px; }
#description { margin-left: 0; font-size: 12px; width: 100%; }

/* COMMAND BAR */
#commandbar { flex-direction: column; align-items: stretch; padding: 5px; margin: 10px 0 16px; }
#commandbar ul { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 5px; padding-bottom: 5px; }
#commandbar ul::-webkit-scrollbar { display: none; }
#commandbar li { flex-shrink: 0; }
#commandbar a { flex-shrink: 0; padding: 8px 12px; font-size: 11px; }

.commandbar-search { margin: 0 4px 4px 4px; }
.search-container { width: 100%; }
.commandbar-search input { width: 100%; box-sizing: border-box; padding: 10px 36px 10px 12px; }
.search-clear-btn { right: 10px; padding: 8px; }
.search-clear-btn svg { width: 16px; height: 16px; }

/* LOCATION */
#files h2 { font-size: 13px; margin-bottom: 10px; }
#folder { line-height: 1.7; }

/* TABLE -> CARDS */
#files thead { display: none; }
#files table, #files tbody { display: block; background: transparent; border: none; box-shadow: none; overflow: visible; }
#files tbody tr {
display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; grid-template-rows: auto auto;
column-gap: 10px; row-gap: 2px; align-items: start;
padding: 12px; margin-bottom: 8px;
background: var(--white); border: 1px solid var(--blue-200); border-radius: var(--radius); box-shadow: var(--shadow);
}
#files tbody tr:nth-child(even) { background: var(--white); }
#files tbody tr:hover { background: var(--white); }
#files tbody tr.is-dir:hover { background: var(--blue-50); }
#files tbody tr.is-dir:active { background: var(--blue-100); }
#files tbody td { border: none; padding: 0; background: transparent; display: block; }

#files tbody td.icon { grid-row: 1 / 3; grid-column: 1; width: 36px; align-self: center; text-align: center; }
#files tbody td.icon svg { width: 28px; height: 28px; }
#files tbody td.name { grid-row: 1; grid-column: 2; min-width: 0; }
#files tbody td.name a { display: block; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; word-break: break-word; }
#files tbody td.size { grid-row: 1; grid-column: 3; font-size: 12px; text-align: right; white-space: nowrap; align-self: start; padding-top: 2px; }
#files tbody td.date { grid-row: 2; grid-column: 2 / 4; font-size: 11px; color: var(--ink-mute); white-space: nowrap; }
#files tbody tr:has(td.empty) { display: block; padding: 24px; text-align: center; font-size: 13px; }
#files tbody td.empty { padding: 0; border: none; }

/* PAGINATION */
.pagination { flex-direction: column; align-items: stretch; gap: 10px; }
.page-controls { justify-content: space-between; margin-left: 0; }

/* MODAL */
.preview-box { width: 100%; max-width: none; height: 100vh; height: 100dvh; max-height: none; border-radius: 0; }
.preview-head { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }

/* Кнопки в модалке: делаем одинаковыми */
#preview-download, #preview-close {
padding: 10px 16px;
font-size: 14px;
min-height: 44px; /* Apple HIG */
}

.preview-body { padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
#preview-content { font-size: 12px; }

/* ERROR */
.error-wrap { padding: 40px 15px; }
.error-code { font-size: 48px; }
.error-icon { width: 56px; height: 56px; }
.error-title { font-size: 18px; }
.error-desc { font-size: 14px; }
.error-btn { display: block; width: 100%; padding: 12px; }

/* FOOTER */
#footer { padding: 16px; gap: 12px; margin-top: 20px; }
#footer-logo .ico-logo { width: 36px; height: 36px; }
#footer-info { font-size: 12px; }
}

/* ============================================================
МАЛЕНЬКИЕ ЭКРАНЫ (≤ 380px)
============================================================ */
@media (max-width: 380px) {
#wrapper { padding: 0 10px 16px; }
#main-logo h1 { font-size: 15px; }
#files tbody tr { padding: 10px; grid-template-columns: 32px minmax(0, 1fr) auto; column-gap: 8px; }
#files tbody td.icon, #files tbody td.icon svg { width: 26px; height: 26px; }
#files tbody td.name a { font-size: 12px; }
}

/* ============================================================
TOUCH-УСТРОЙСТВА И АНИМАЦИИ
============================================================ */
@media (hover: none) and (pointer: coarse) {
#commandbar a { min-height: 40px; padding: 10px 14px; }
#files tbody tr.is-dir { min-height: 56px; }
#preview-close, #preview-download { min-height: 44px; min-width: 88px; }
}

@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { transition: none !important; animation: none !important; }
}
/* Контейнер для PDF */
#preview-pdf-wrap {
flex: 1;
display: flex;
flex-direction: column;
}
#preview-pdf {
flex: 1;
min-height: 65vh;
}
