: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); }


/* Panel Ustawienia administratora */
.settings-modal-box { max-width: 900px; width: 96%; }
.settings-modal-header { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:15px; }
.settings-section { border:1px solid var(--border-color); border-radius:10px; padding:18px; margin-top:15px; background:var(--bg-color); }
.settings-section-title { font-size:17px; font-weight:700; margin-bottom:5px; }
.settings-section-description { color:#777; font-size:13px; line-height:1.45; margin-bottom:15px; }
.settings-subtitle { font-size:13px; font-weight:700; margin:12px 0 7px 0; }
.settings-subtitle-row { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.settings-pin-row { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.settings-pin-input { width:150px; max-width:100%; box-sizing:border-box; padding:9px 11px; border:1px solid var(--border-color); border-radius:6px; background:var(--card-bg); color:var(--text-color); font-size:15px; font-family:monospace; letter-spacing:4px; }
.settings-small-btn { padding:6px 9px; font-size:11px; margin:0; }
.settings-remove-btn { background:#dc3545; margin:0; }
.settings-actions-row { display:flex; flex-wrap:wrap; gap:8px; margin-top:14px; }
.settings-actions-row .btn { margin:0; }
.settings-status { padding:10px 12px; border-radius:7px; background:rgba(40,167,69,0.12); border:1px solid rgba(40,167,69,0.35); color:var(--text-color); font-size:13px; margin-bottom:12px; }
.settings-status-error { background:rgba(220,53,69,0.12); border-color:rgba(220,53,69,0.4); }
.settings-folder-summary { font-size:13px; margin-bottom:8px; }
.settings-folder-tree { max-height:390px; overflow:auto; border:1px solid var(--border-color); border-radius:8px; background:var(--card-bg); padding:8px; }
.settings-tree-node { min-width:max-content; }
.settings-tree-row { display:flex; align-items:center; gap:7px; min-height:30px; padding:2px 4px; border-radius:5px; }
.settings-tree-row:hover { background:rgba(128,128,128,0.08); }
.settings-tree-toggle { width:24px; height:24px; flex:0 0 24px; padding:0; border:none; background:transparent; color:var(--text-color); cursor:pointer; }
.settings-tree-toggle:disabled { cursor:default; }
.settings-folder-checkbox { width:16px; height:16px; flex:0 0 auto; }
.settings-tree-name { white-space:nowrap; }
.settings-tree-children { margin-left:19px; padding-left:9px; border-left:1px solid var(--border-color); }
.settings-tree-loading, .settings-tree-empty, .settings-tree-error { padding:9px; font-size:13px; color:#777; }
.settings-tree-error { color:#dc3545; }

/* Przyklejona belka nawigacji podczas przewijania strony */
.sticky-site-header {
    position: sticky;
    top: 0;
    z-index: 3000;
    background: var(--bg-color);
    padding-top: 1px;
    margin-top: -1px;
}
.sticky-admin-bar-placeholder { height: 0; }
.path-header.sticky-admin-bar-active {
    position: fixed !important;
    z-index: 2990;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 15px 25px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    box-shadow: 0 6px 14px rgba(0,0,0,0.08);
}

@media (max-width: 700px) {
    body { padding: 10px; }
    .settings-modal-box { width:100%; }
    .settings-section { padding:12px; }
    .settings-pin-row { align-items:stretch; }
    .settings-pin-input { flex:1; width:auto; min-width:0; }
    .settings-folder-pin-input { flex:1 1 100%; width:100%; max-width:none; }
    .settings-folder-tree { max-height:45dvh; }
    .path-header.sticky-admin-bar-active { padding: 12px; }
    .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; }
}

/* Panel torrentów administratora */
.torrent-modal-box { max-width:1000px; width:96%; }
.torrent-modal-header { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:14px; }
.torrent-muted { color:#777; font-size:12px; line-height:1.4; }
.torrent-system-status { padding:10px 12px; border-radius:7px; border:1px solid rgba(40,167,69,0.35); background:rgba(40,167,69,0.10); margin-bottom:12px; font-size:13px; }
.torrent-system-warning { border-color:rgba(255,193,7,0.5); background:rgba(255,193,7,0.12); }
.torrent-system-error { border-color:rgba(220,53,69,0.45); background:rgba(220,53,69,0.12); }
.torrent-global-row { display:flex; align-items:stretch; gap:10px; flex-wrap:wrap; margin-bottom:15px; }
.torrent-global-stat { min-width:160px; flex:1; border:1px solid var(--border-color); border-radius:8px; padding:10px 12px; background:var(--bg-color); display:flex; flex-direction:column; gap:3px; }
.torrent-global-stat span { color:#777; font-size:12px; }
.torrent-global-stat strong { font-size:18px; }
.torrent-add-toggle { margin:0; min-width:150px; }
.torrent-add-panel { border:1px solid var(--border-color); border-radius:10px; padding:16px; background:var(--bg-color); margin-bottom:15px; }
.torrent-section-title { font-size:16px; font-weight:700; margin-bottom:12px; }
.torrent-label { display:block; font-size:13px; font-weight:600; margin:8px 0 5px; }
.torrent-input { width:100%; box-sizing:border-box; padding:10px 12px; border:1px solid var(--border-color); border-radius:7px; background:var(--card-bg); color:var(--text-color); }
.torrent-textarea { resize:vertical; min-height:70px; font-family:monospace; font-size:12px; overflow-wrap:anywhere; }
.torrent-or { text-align:center; color:#888; font-size:12px; padding:8px 0 2px; }
.torrent-full-width { width:100%; box-sizing:border-box; }
.torrent-destination-box { margin-top:14px; }
.torrent-dest-selected { margin:7px 0 10px; padding:10px 12px; border-radius:6px; border:1px solid var(--border-color); background:var(--card-bg); font-size:13px; font-weight:600; overflow-wrap:anywhere; }
.torrent-dest-tree { max-height:230px; margin-bottom:12px; }
.torrent-tree-select { border:0; background:transparent; color:var(--text-color); cursor:pointer; padding:5px 4px; text-align:left; font-size:14px; flex:1; }
.torrent-add-actions { display:flex; gap:8px; flex-wrap:wrap; margin-top:12px; }
.torrent-add-actions .btn { margin:0; }
.torrent-jobs-list { display:flex; flex-direction:column; gap:12px; }
.torrent-empty { padding:20px; text-align:center; color:#777; border:1px dashed var(--border-color); border-radius:8px; }
.torrent-card { border:1px solid var(--border-color); border-radius:10px; padding:14px; background:var(--bg-color); }
.torrent-card-top { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.torrent-card-name { font-weight:700; font-size:15px; min-width:0; overflow-wrap:anywhere; }
.torrent-state { flex:0 0 auto; font-size:11px; font-weight:700; padding:4px 8px; border-radius:12px; background:rgba(0,123,255,0.12); border:1px solid rgba(0,123,255,0.25); }
.torrent-state-warning { background:rgba(255,193,7,0.14); border-color:rgba(255,193,7,0.45); }
.torrent-state-error { background:rgba(220,53,69,0.14); border-color:rgba(220,53,69,0.45); }
.torrent-state-completed { background:rgba(40,167,69,0.14); border-color:rgba(40,167,69,0.4); }
.torrent-progress { height:12px; border-radius:8px; background:rgba(128,128,128,0.18); overflow:hidden; margin-top:11px; }
.torrent-progress > div { height:100%; background:#20c997; transition:width .35s ease; }
.torrent-progress-text { display:flex; justify-content:space-between; gap:10px; font-size:12px; margin-top:5px; color:#777; }
.torrent-stats-grid { display:grid; grid-template-columns:repeat(6, minmax(0,1fr)); gap:8px; margin-top:10px; font-size:12px; }
.torrent-stats-grid span { padding:7px 8px; border-radius:6px; background:var(--card-bg); border:1px solid var(--border-color); text-align:center; white-space:nowrap; }
.torrent-cloud-line { margin-top:9px; font-size:12px; color:#17a2b8; overflow-wrap:anywhere; }
.torrent-warning { margin-top:9px; padding:8px 10px; border-radius:6px; background:rgba(255,193,7,0.12); border:1px solid rgba(255,193,7,0.35); font-size:12px; }
.torrent-job-message { margin-top:8px; color:#777; font-size:12px; overflow-wrap:anywhere; }
.torrent-card-actions { display:flex; gap:7px; flex-wrap:wrap; margin-top:11px; }
.torrent-card-actions .btn { margin:0; }
.torrent-files-modal-box { max-width:900px; width:96%; }
.torrent-file-tools { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:10px; }
.torrent-file-tools .btn { margin:0; }
.torrent-files-list { max-height:58dvh; overflow:auto; border:1px solid var(--border-color); border-radius:8px; }
.torrent-file-row { display:flex; align-items:flex-start; gap:10px; padding:10px 12px; border-bottom:1px solid var(--border-color); cursor:pointer; }
.torrent-file-row:last-child { border-bottom:0; }
.torrent-file-row:hover { background:rgba(128,128,128,0.06); }
.torrent-file-checkbox { width:18px; height:18px; flex:0 0 auto; margin-top:2px; }
.torrent-file-main { min-width:0; display:flex; flex-direction:column; gap:3px; overflow-wrap:anywhere; }
.torrent-file-main strong { font-size:13px; font-weight:600; }
.torrent-file-main small { color:#777; }
.torrent-files-footer { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:12px; }
.torrent-selected-size { font-weight:600; font-size:13px; }
.torrent-delete-modal-box { max-width:520px; }
.torrent-delete-actions { display:flex; flex-direction:column; gap:8px; }
.torrent-delete-actions .btn { width:100%; margin:0; padding:11px; }

@media (max-width: 700px) {
    .torrent-modal-box, .torrent-files-modal-box { width:100%; padding:14px; }
    .torrent-modal-header { align-items:flex-start; }
    .torrent-global-row { display:grid; grid-template-columns:1fr 1fr; }
    .torrent-add-toggle { grid-column:1 / -1; width:100%; }
    .torrent-global-stat { min-width:0; }
    .torrent-stats-grid { grid-template-columns:repeat(2, minmax(0,1fr)); }
    .torrent-progress-text { flex-direction:column; gap:2px; }
    .torrent-card-top { flex-direction:column; gap:7px; }
    .torrent-state { align-self:flex-start; }
    .torrent-card-actions .btn { flex:1 1 calc(50% - 7px); }
    .torrent-add-actions { flex-direction:column; }
    .torrent-add-actions .btn { width:100%; }
    .torrent-files-footer { flex-direction:column; align-items:stretch; }
    .torrent-files-footer .btn { width:100%; margin:0; }
    .torrent-dest-tree { max-height:32dvh; }
}

@media (max-width: 420px) {
    .torrent-global-row { grid-template-columns:1fr; }
    .torrent-add-toggle { grid-column:auto; }
    .torrent-stats-grid { grid-template-columns:1fr 1fr; gap:5px; }
    .torrent-stats-grid span { white-space:normal; }
    .torrent-card-actions .btn { flex:1 1 100%; }
}

