/* ── Zmienne / reset ───────────────────────────────────────────────────── */
:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242e;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --primary: #4f8cff;
    --primary-600: #3b78f0;
    --danger: #ef4d5a;
    --danger-600: #d83a47;
    --ok: #38c172;
    --radius: 12px;
    --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* Atrybut hidden musi wygrywać z regułami display: flex/grid poniżej. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
}

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

/* ── Przyciski ─────────────────────────────────────────────────────────── */
.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, border-color .15s, transform .05s;
    white-space: nowrap;
}
.btn:hover { background: #262b36; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-600); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
    background: transparent; border: 0; color: var(--muted);
    cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 30;
    background: rgba(15, 17, 21, .9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: 12px 18px;
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { font-size: 26px; }
.brand-title { font-weight: 650; font-size: 17px; }
.brand-sub { font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: nowrap; justify-content: flex-end; align-items: center; }

/* ── Menu „overflow" (rozwijane na wąskich ekranach) ──────────────────── */
.overflow { position: relative; display: flex; align-items: center; gap: 8px; }
.overflow-toggle { display: none; }
.overflow-group { display: flex; align-items: center; gap: 8px; }
@media (max-width: 720px) {
    .overflow-toggle { display: inline-flex; }
    .overflow-group {
        position: absolute; top: calc(100% + 6px); right: 0; z-index: 45;
        flex-direction: column; align-items: stretch; gap: 6px;
        min-width: 210px; padding: 8px;
        background: var(--surface); border: 1px solid var(--border);
        border-radius: 12px; box-shadow: var(--shadow);
        display: none;
    }
    .overflow.open .overflow-group { display: flex; }
    .overflow-group .btn { justify-content: flex-start; width: 100%; }
}

/* ── Container / crumbs ────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 18px; }
.crumbs {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    margin-bottom: 14px; font-size: 14px;
}
.crumbs a { color: var(--muted); text-decoration: none; cursor: pointer; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { color: var(--border); }
.crumbs .current { color: var(--text); font-weight: 600; }

/* ── Pasek zaznaczenia ─────────────────────────────────────────────────── */
.selbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 8px 12px; margin-bottom: 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius);
}
.selbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
#selCount { white-space: nowrap; font-size: 14px; }

/* ── Dropzone / grid ───────────────────────────────────────────────────── */
.dropzone { position: relative; min-height: 50vh; border-radius: var(--radius); }
.dropzone.dragover .drop-overlay { display: flex; }
.drop-overlay {
    display: none; position: fixed; inset: 0; z-index: 40;
    background: rgba(79, 140, 255, .12);
    backdrop-filter: blur(2px);
    align-items: center; justify-content: center;
    border: 3px dashed var(--primary); border-radius: 0;
    pointer-events: none;
}
.drop-overlay-inner {
    background: var(--surface); border: 1px solid var(--primary);
    padding: 18px 26px; border-radius: 14px; font-size: 18px; font-weight: 600;
    box-shadow: var(--shadow);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color .15s, transform .08s, box-shadow .15s;
}
.card:hover { border-color: #3a4150; box-shadow: var(--shadow); }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }

.card-thumb {
    aspect-ratio: 1 / 1; width: 100%;
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb .file-ico { font-size: 44px; }
.card-thumb .ext-badge {
    position: absolute; bottom: 8px; left: 8px;
    background: rgba(0,0,0,.6); color: #fff; font-size: 11px;
    padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em;
}

.card-folder .card-thumb { font-size: 54px; }

.card-info { padding: 8px 10px; }
.card-name {
    font-size: 13px; font-weight: 550;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card-caption {
    font-size: 11px; color: var(--muted); margin-top: 3px; font-style: italic;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Checkbox zaznaczenia */
.card-check {
    position: absolute; top: 8px; left: 8px; z-index: 3;
    width: 22px; height: 22px; border-radius: 6px;
    background: rgba(0,0,0,.45); border: 1.5px solid rgba(255,255,255,.7);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 14px; opacity: 0;
    transition: opacity .12s;
}
.card:hover .card-check, .card.selected .card-check { opacity: 1; }
.card.selected .card-check { background: var(--primary); border-color: var(--primary); }

/* Menu akcji na karcie */
.card-actions {
    position: absolute; top: 8px; right: 8px; z-index: 3;
    display: flex; gap: 4px; opacity: 0; transition: opacity .12s;
}
.card:hover .card-actions { opacity: 1; }
.card-actions button {
    width: 28px; height: 28px; border-radius: 7px;
    background: rgba(0,0,0,.5); border: 0; color: #fff; cursor: pointer; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
}
.card-actions button:hover { background: rgba(0,0,0,.75); }

/* ── Stan pusty ───────────────────────────────────────────────────────── */
.empty {
    text-align: center; padding: 70px 20px; color: var(--muted);
}
.empty-icon { font-size: 54px; margin-bottom: 8px; }
.empty p { margin: 4px 0; }

/* ── Panel uploadów ───────────────────────────────────────────────────── */
.uploads-panel {
    position: fixed; right: 18px; bottom: 18px; z-index: 50;
    width: 340px; max-width: calc(100vw - 36px);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.uploads-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px;
}
.uploads-list { max-height: 280px; overflow-y: auto; padding: 6px; }
.up-item { padding: 7px 8px; }
.up-item-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.up-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-status { color: var(--muted); flex-shrink: 0; }
.up-status.ok { color: var(--ok); }
.up-status.err { color: var(--danger); }
.up-bar { height: 5px; background: var(--surface-2); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.up-bar-fill { height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.up-bar-fill.ok { background: var(--ok); }
.up-bar-fill.err { background: var(--danger); }

/* ── Lightbox ─────────────────────────────────────────────────────────── */
.lightbox {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(8, 9, 12, .94);
    display: flex; align-items: center; justify-content: center;
}
.lb-figure {
    margin: 0; max-width: 92vw; max-height: 86vh;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.lb-figure img {
    max-width: 92vw; max-height: 78vh; object-fit: contain;
    border-radius: 8px; box-shadow: var(--shadow);
}
.lb-caption { display: flex; flex-direction: column; align-items: center; gap: 4px; width: min(560px, 90vw); }
.lb-caption input {
    width: 100%; text-align: center;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    padding: 8px 12px; border-radius: 9px; font-size: 14px;
}
.lb-meta { font-size: 12px; color: var(--muted); }
.lb-close {
    position: fixed; top: 16px; right: 18px; z-index: 61;
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    font-size: 18px; cursor: pointer;
}
.lb-close:hover { background: var(--surface-2); }
.lb-nav {
    position: fixed; top: 50%; transform: translateY(-50%); z-index: 61;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    font-size: 28px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.lb-nav:hover { background: var(--surface-2); }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-toolbar {
    position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 61;
    display: flex; gap: 8px;
}

/* ── Toasty ───────────────────────────────────────────────────────────── */
.toasts {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
    background: var(--surface); border: 1px solid var(--border);
    padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
    font-size: 14px; animation: toastIn .2s ease;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ── Przeciąganie elementów / cel upuszczenia ─────────────────────────── */
.card[draggable="true"] { -webkit-user-drag: element; }
.card.dragging { opacity: .4; }
.card.drop-target {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary) inset;
    background: rgba(79, 140, 255, .12);
}
.crumbs a.drop-target {
    background: var(--primary); color: #fff;
    border-radius: 6px; padding: 2px 8px;
}

/* ── Modal „Przenieś do folderu" ──────────────────────────────────────── */
.modal {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(8, 9, 12, .7);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; width: min(440px, 100%); max-height: 80vh;
    display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.modal-body { overflow-y: auto; padding: 8px; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); text-align: right; }
.move-item {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 14px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.move-item:hover { background: var(--surface-2); }
.move-empty { padding: 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── Login ────────────────────────────────────────────────────────────── */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
    width: 100%; max-width: 360px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 32px 28px; text-align: center; box-shadow: var(--shadow);
}
.login-icon { font-size: 38px; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-input {
    width: 100%; margin-top: 18px;
    background: var(--bg); border: 1px solid var(--border); color: var(--text);
    padding: 12px 14px; border-radius: 10px; font-size: 15px;
}
.login-input:focus { outline: none; border-color: var(--primary); }
.login-btn { width: 100%; margin-top: 12px; justify-content: center; }
.login-error {
    margin-top: 14px; background: rgba(239, 77, 90, .12);
    border: 1px solid var(--danger); color: #ffb3ba;
    padding: 9px; border-radius: 9px; font-size: 13px;
}

/* ── Responsywność ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
    .brand-sub { display: none; }
    .topbar-actions .btn span.lbl { display: none; }
}
