:root {
    --bg-color: #f4f6f9;
    --text-color: #333;
    --card-bg: #fff;
    --border-color: #e0e0e0;
    --th-bg: #f8f9fa;
    --link-color: #0056b3;
    --btn-gray: #6c757d;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --border-color: #333;
    --th-bg: #222;
    --link-color: #66b2ff;
    --btn-gray: #444;
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: var(--bg-color); color: var(--text-color); margin: 0; padding: 20px; transition: background 0.3s, color 0.3s; }
a { color: var(--link-color); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }

.top-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; max-width: 1100px; margin: 0 auto 20px auto; }
.top-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.logo { font-size: 24px; font-weight: bold; text-decoration: none; color: var(--text-color); }
.content-box { max-width: 1100px; margin: auto; background: var(--card-bg); padding: 25px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); border: 1px solid var(--border-color); box-sizing: border-box; overflow-x: auto; }

.search-container { max-width: 1100px; margin: 0 auto 20px auto; }
#searchInput { width: 100%; padding: 15px; font-size: 16px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--card-bg); color: var(--text-color); }
#searchInput:focus { outline: none; border-color: #007bff; }
.search-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--card-bg); border: 1px solid var(--border-color); border-top: none; border-radius: 0 0 8px 8px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); z-index: 1000; max-height: 400px; overflow-y: auto; }
.s-item { display: flex; align-items: center; padding: 12px 15px; border-bottom: 1px solid var(--border-color); color: var(--text-color); }
.s-item:hover { background: rgba(128,128,128,0.1); text-decoration: none; }

.path-header { display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--border-color); }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 6px; text-decoration: none !important; font-size: 13px; color: #fff !important; border: none; cursor: pointer; transition: opacity 0.2s; white-space: nowrap; margin-right: 4px; margin-bottom: 4px; }
.btn:hover { opacity: 0.8; }
.btn-blue { background: #007bff; }
.btn-green { background: #28a745; }
.btn-orange { background: #fd7e14; }
.btn-gray { background: var(--btn-gray); }
.btn-dark { background: #343a40; }

.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid #ffbf47; outline-offset: 2px; }

.file-list { width: 100%; border-collapse: collapse; }
.file-list th, .file-list td { padding: 15px; border-bottom: 1px solid var(--border-color); text-align: left; }
.file-list th { background: var(--th-bg); font-weight: 600; }
.file-row:hover { background: rgba(128,128,128,0.05); }
.actions-cell { text-align: right; }
.badge { background: #17a2b8; color: #fff; padding: 3px 8px; border-radius: 12px; font-size: 12px; font-weight: bold; }

/* * UNIWERSALNE STYLE LINKÓW I IKON 
 * Naprawiają problem brzydkiego ucinania .jpg 
 */
.item-link { display: inline-flex; align-items: center; text-decoration: none; color: inherit; max-width: 100%; overflow-wrap: break-word; }
.item-name { overflow-wrap: break-word; word-break: break-word; line-height: 1.3; }
.item-icon { font-size: 24px; margin-right: 12px; min-width: 30px; text-align: center; }
.item-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; margin-right: 12px; flex-shrink: 0; border: 1px solid var(--border-color); background: #20242a; }
.video-thumb { width: 96px; height: 54px; aspect-ratio: 16 / 9; }

/* * WIDOK KAFELKÓW
 */
body.grid-mode .file-list, 
body.grid-mode .file-list tbody { display: flex; flex-wrap: wrap; gap: 20px; justify-content: flex-start; }
body.grid-mode .file-list thead { display: none; }
body.grid-mode .file-row { display: flex; flex-direction: column; width: 230px; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 10px; padding: 15px; text-align: center; justify-content: space-between; box-sizing: border-box; }
body.grid-mode .file-row td { display: block; width: 100%; border: none; padding: 5px 0; text-align: center; box-sizing: border-box; }
body.grid-mode .meta-data { color: #888; font-size: 12px; }

/* Transformacja ikon i miniatur w Kafelkach */
body.grid-mode .item-link { flex-direction: column; width: 100%; align-items: center; }
body.grid-mode .item-icon { font-size: 55px; margin-bottom: 12px; margin-right: 0; }
body.grid-mode .item-thumb { width: 100%; height: 160px; margin-bottom: 12px; margin-right: 0; border-radius: 6px; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border: none; }
body.grid-mode .video-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; }

/* Naprawa rozjechanych przycisków w Kafelkach */
body.grid-mode .actions-cell { display: flex; flex-wrap: wrap; justify-content: center; margin-top: 15px; gap: 6px; }
body.grid-mode .actions-cell .btn { margin: 0; padding: 8px 6px; font-size: 12px; flex: 1 1 45%; }

/* Strona PIN */
.pin-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; height: auto; background: #121212; margin: 0; padding: 20px; box-sizing: border-box; }
.pin-box { background: #1e1e1e; padding: 40px; border-radius: 12px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); border: 1px solid #333; box-sizing: border-box; width: 100%; max-width: 360px; }
.pin-box h2 { color: #fff; margin-top: 0; }
.pin-box input { padding: 15px; font-size: 30px; width: 180px; max-width: 100%; box-sizing: border-box; text-align: center; letter-spacing: 15px; margin-bottom: 25px; border-radius: 8px; border: 1px solid #444; background: #2a2a2a; color: #fff; font-family: monospace; outline: none; }
.pin-box input:focus { border-color: #007bff; }
.pin-box button { width: 100%; font-size: 18px; padding: 12px; }

.main-folders { display: flex; flex-wrap: wrap; gap: 20px; }
.folder-card { background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 10px; padding: 20px; width: 200px; box-sizing: border-box; text-align: center; text-decoration: none; color: var(--text-color); transition: transform 0.2s; }
.folder-card:hover { transform: translateY(-5px); background: rgba(128,128,128,0.1); }
.folder-icon { font-size: 60px; margin-bottom: 15px; }
.folder-name { font-weight: bold; font-size: 18px; }
.sort-select { padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--card-bg); color: var(--text-color); font-size: 13px; outline: none; cursor: pointer; transition: 0.2s; }
.modal-overlay { position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:10000; display:flex; justify-content:center; align-items:center; padding:10px; box-sizing:border-box; }
.modal-box { background:var(--card-bg); padding:25px; border-radius:10px; width:90%; max-width:400px; max-height:calc(100dvh - 20px); overflow-y:auto; box-sizing:border-box; color:var(--text-color); border:1px solid var(--border-color); box-shadow:0 10px 30px rgba(0,0,0,0.5); }

@media (max-width: 700px) {
    body { padding: 10px; }
    .top-bar { align-items: flex-start; }
    .logo { font-size: 20px; }
    .top-controls { width: 100%; }
    .top-controls form { margin-left: 0 !important; }
    .content-box { padding: 12px; }
    .path-header { align-items: flex-start; gap: 10px; }
    .sort-select { max-width: 100%; }
    /* Mobilny widok listy: wszystkie kolumny mieszczą się bez przewijania poziomego. */
    body:not(.grid-mode) .file-list,
    body:not(.grid-mode) .file-list tbody { display: block; width: 100%; min-width: 0; }
    body:not(.grid-mode) .file-list thead { display: none; }
    body:not(.grid-mode) .file-row {
        display: grid;
        grid-template-columns: 34px minmax(0, 1fr);
        grid-template-areas:
            "check item"
            ". size"
            ". downloads"
            ". actions";
        width: 100%;
        box-sizing: border-box;
        padding: 12px 0;
        border-bottom: 1px solid var(--border-color);
    }
    body:not(.grid-mode) .file-row td { border: none; padding: 4px 0; min-width: 0; box-sizing: border-box; }
    body:not(.grid-mode) .file-row td:nth-child(1) { grid-area: check; display: flex; justify-content: center; align-items: flex-start; padding-top: 9px; }
    body:not(.grid-mode) .file-row td:nth-child(2) { grid-area: item; }
    body:not(.grid-mode) .file-row td:nth-child(3) { grid-area: size; color: #888; font-size: 12px; }
    body:not(.grid-mode) .file-row td:nth-child(4) { grid-area: downloads; font-size: 12px; }
    body:not(.grid-mode) .file-row td:nth-child(5) { grid-area: actions; }
    body:not(.grid-mode) .file-row td:nth-child(3)::before { content: "Rozmiar: "; font-weight: 600; }
    body:not(.grid-mode) .file-row td:nth-child(4)::before { content: "Pobrania: "; color: #888; font-weight: 600; margin-right: 5px; }
    body:not(.grid-mode) .item-link { width: 100%; min-width: 0; align-items: center; }
    body:not(.grid-mode) .item-name { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
    body:not(.grid-mode) .actions-cell { display: flex; flex-wrap: wrap; gap: 6px; text-align: left; margin-top: 4px; }
    body:not(.grid-mode) .actions-cell .btn { margin: 0; }
    .content-box { overflow-x: hidden; }
    body.grid-mode .file-list,
    body.grid-mode .file-list tbody { min-width: 0; width: 100%; justify-content: center; }
    body.grid-mode .file-row { width: 100%; max-width: 230px; }
    .main-folders { justify-content: center; }
    .folder-card { width: 100%; max-width: 260px; }
    .modal-overlay { align-items: flex-start; overflow-y: auto; }
    .modal-box { width: 100%; margin: auto 0; }
}

@media (max-width: 420px) {
    .pin-box { padding: 25px 20px; }
    .pin-box input { width: 100%; font-size: 26px; letter-spacing: 12px; }
}
