:root {
    --bg: #0d1220;
    --bg-2: #131b2e;
    --card: #1a2338;
    --card-2: #212c46;
    --border: #2a3654;
    --text: #eaf0fb;
    --text-dim: #93a3c4;
    --accent: #f39c12;
    --accent-soft: #3a2c12;
    --green: #37b26b;
    --red: #e05a5a;
    --radius: 16px;
    --radius-sm: 10px;
    --grad-accent: linear-gradient(135deg, #ffb43f 0%, #f0870f 100%);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.screen { min-height: 100vh; }

#screen-auth { display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 70% -10%, rgba(243,156,18,0.14), transparent 60%), var(--bg); padding: 20px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow); padding: 40px; width: 100%; max-width: 400px; animation: rise .4s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-badge { font-size: 54px; line-height: 1; }
.auth-logo h1 { font-size: 24px; margin-top: 12px; }
.auth-sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.form-error { color: var(--red); font-size: 13px; margin-top: 14px; text-align: center; }
.form-hint { color: var(--text-dim); font-size: 12px; margin-bottom: 14px; }
.form-section-label { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin: 16px 0 8px; }

label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], textarea {
    display: block; width: 100%; margin-top: 6px; padding: 11px 13px; border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); font: inherit; font-weight: 400; background: #0f1626; color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(243,156,18,.15); }
textarea { resize: vertical; min-height: 64px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 11px 18px; border: none; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; color: inherit; transition: transform .15s var(--ease), filter .15s, background .15s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--grad-accent); color: #1a1200; box-shadow: 0 4px 16px rgba(243,156,18,.3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #283350; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 13px; font-size: 12px; }

.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-2); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; white-space: nowrap; }
#media-search { flex: 1; max-width: 340px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.storage-pill { font-size: 12px; font-weight: 700; color: var(--text-dim); background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; white-space: nowrap; }
.upload-pending { color: var(--accent); font-weight: 700; font-size: 12px; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 5px 12px 5px 6px; font: inherit; font-weight: 600; cursor: pointer; }
.chip-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; background: var(--accent-soft); color: var(--accent); font-weight: 800; flex: none; }
.avatar-fallback { background: var(--accent-soft); color: var(--accent); }

.main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.empty { color: var(--text-dim); text-align: center; padding: 60px 20px; }

.denied-banner { background: rgba(224, 90, 90, .12); border: 1px solid var(--red); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.denied-banner button { border: none; background: transparent; color: var(--text-dim); cursor: pointer; font-size: 13px; padding: 2px 7px; border-radius: 999px; }
.denied-banner button:hover { background: var(--red); color: #fff; }

.request-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 10px; background: var(--card-2); }
.request-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.request-date { color: var(--text-dim); font-size: 12px; }
.request-msg { margin-top: 8px; padding: 8px 12px; background: #0f1626; border-radius: var(--radius-sm); font-size: 13px; }
.request-note { margin-top: 8px; }
.request-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

.admin-head { display: flex; justify-content: space-between; align-items: center; }
.admin-head h3 { margin: 0; }
.storage-bar-wrap { display: flex; align-items: center; gap: 12px; margin: 14px 0; flex-wrap: wrap; }
.storage-bar { flex: 1; min-width: 160px; height: 12px; background: #0f1626; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.storage-bar-fill { height: 100%; background: var(--grad-accent); border-radius: 999px; transition: width .4s var(--ease); }
.storage-bar-fill.warn { background: var(--red); }
#storage-detail { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.admin-settings { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.admin-settings label { flex: 1; min-width: 150px; margin-bottom: 0; }
.uploader-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.uploader-row:last-child { border-bottom: none; }
.uploader-row .sub { color: var(--text-dim); font-size: 12px; }

.media-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.folder-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.folder-chip {
    font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
    background: var(--card); color: var(--text-dim); border: 1px solid var(--border);
    border-radius: 999px; padding: 7px 13px; transition: color .15s, border-color .15s, background .15s;
}
.folder-chip:hover { color: var(--text); border-color: var(--accent); }
.folder-chip.active { background: var(--grad-accent); color: #1a1200; border-color: transparent; }
.folder-chip-count { opacity: .75; font-weight: 600; margin-left: 2px; }
.folder-chip-manage { border-style: dashed; }
.media-toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#media-sort { margin: 0; width: auto; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: #0f1626; color: var(--text); font: inherit; font-size: 12px; font-weight: 600; }

.new-badge { position: absolute; top: 8px; left: 8px; background: var(--grad-accent); color: #1a1200; font-size: 10px; font-weight: 800; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.fav-star { position: absolute; top: 6px; right: 6px; background: rgba(4,8,16,.55); border: none; border-radius: 999px; font-size: 15px; line-height: 1; padding: 6px 7px; cursor: pointer; color: #fff; opacity: .85; transition: transform .12s, opacity .12s; }
.fav-star:hover { opacity: 1; transform: scale(1.12); }
.fav-star.on { opacity: 1; }
.select-check {
    position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 999px;
    border: 2px solid #fff; background: rgba(4,8,16,.45);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 800; color: #1a1200;
}
.select-check.on { background: var(--accent); border-color: var(--accent); }
.media-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.media-folder-tag { color: var(--accent); font-weight: 700; }
#lb-fav.fav-on { color: var(--accent); border-color: var(--accent); }

.bulk-bar {
    position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
    background: var(--card-2); border: 1px solid var(--accent); border-radius: 16px;
    padding: 10px 16px; z-index: 60; box-shadow: var(--shadow); max-width: calc(100vw - 20px);
}
.bulk-bar span { font-size: 13px; font-weight: 700; white-space: nowrap; }
#bulk-folder { margin: 0; width: auto; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: #0f1626; color: var(--text); font: inherit; font-size: 12px; }

.folder-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.folder-row .folder-emoji { width: 58px; flex: none; margin: 0; text-align: center; }
.folder-row .folder-name { flex: 1; margin: 0; min-width: 110px; }
.folder-row .folder-parent { flex: none; width: auto; max-width: 150px; margin: 0; padding: 8px 9px; font-size: 12px; }
.folder-row-sub { margin-left: 20px; }
.folder-sub-arrow { color: var(--text-dim); font-weight: 700; flex: none; }
.folder-count { color: var(--text-dim); font-size: 11px; white-space: nowrap; flex: none; }
.folder-add-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.folder-add-row input:first-child { width: 58px; flex: none; margin: 0; text-align: center; }
.folder-add-row input { margin: 0; }
.folder-add-row select { flex: none; width: auto; max-width: 160px; margin: 0; padding: 8px 9px; font-size: 12px; }

.folder-card { border-style: solid; border-color: #3a4a74; background: linear-gradient(180deg, #212c46 0%, #1a2338 100%); position: relative; }
.folder-card::before { content: ''; position: absolute; top: -1px; left: 14px; width: 52px; height: 8px; background: #3a4a74; border-radius: 6px 6px 0 0; }
.folder-card:hover { border-color: var(--accent); }
.folder-thumb { background: #16203a; }
.folder-collage { position: absolute; inset: 0; display: grid; gap: 2px; opacity: .85; }
.folder-collage.c1 { grid-template-columns: 1fr; }
.folder-collage.c2 { grid-template-columns: 1fr 1fr; }
.folder-collage.c3, .folder-collage.c4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.folder-collage.c3 img:first-child { grid-row: span 2; }
.folder-collage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.folder-big-emoji { position: relative; font-size: 52px; line-height: 1; text-shadow: 0 4px 18px rgba(0,0,0,.55); }
.folder-big-emoji.corner { position: absolute; right: 8px; bottom: 8px; font-size: 30px; }
.folder-card.drop-hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
body.media-dragging .folder-card { outline: 1.5px dashed var(--accent); outline-offset: 2px; }

.media-card.dragging { opacity: .45; }
body.media-dragging .folder-chip { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
body.media-dragging .folder-chip-manage, body.media-dragging .folder-chip.active { outline: none; }
.folder-chip.drop-hover { background: var(--grad-accent); color: #1a1200; border-color: transparent; transform: scale(1.08); }
.folder-chip-sub { border-style: dotted; }

.slideshow { position: fixed; inset: 0; z-index: 900; background: #000; display: flex; flex-direction: column; }
.slideshow-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.slideshow-stage img, .slideshow-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.ss-embed { width: 100%; height: 100%; border: none; background: #000; }
.slideshow-caption { text-align: center; color: #fff; font-size: 15px; font-weight: 600; padding: 8px 16px; text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.slideshow-bar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(10,14,24,.85); flex-wrap: wrap; }
.slideshow-pos { color: var(--text-dim); font-size: 12px; font-weight: 700; }
#ss-interval { margin: 0; width: auto; padding: 7px 9px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: #0f1626; color: var(--text); font: inherit; font-size: 12px; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.media-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform .18s var(--ease), border-color .18s, box-shadow .18s; }
.media-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); }
.media-thumb { position: relative; aspect-ratio: 16/10; background: #0f1626; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .fallback-ico { font-size: 40px; opacity: .6; }
.media-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 40px; color: #fff; background: rgba(4, 8, 16, .35); text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.media-dur { position: absolute; right: 8px; bottom: 8px; background: rgba(4,8,16,.75); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.media-info { padding: 11px 13px; }
.media-title { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-meta { color: var(--text-dim); font-size: 11px; margin-top: 3px; }

.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(4, 8, 16, .92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox-inner { width: 100%; max-width: 1100px; max-height: 96vh; display: flex; flex-direction: column; gap: 10px; }
.lightbox-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.lightbox-title { font-weight: 800; font-size: 16px; }
.lightbox-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.lightbox-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lightbox-body { display: flex; align-items: center; justify-content: center; min-height: 0; }
.lightbox-body img { max-width: 100%; max-height: 78vh; border-radius: 12px; object-fit: contain; }
.lightbox-body video { max-width: 100%; max-height: 78vh; border-radius: 12px; background: #000; outline: none; }

.drop-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--text-dim); transition: border-color .15s, background .15s; }
.drop-zone.drag { border-color: var(--accent); background: rgba(243,156,18,.06); }
.drop-zone p { margin-bottom: 10px; line-height: 1.6; }
.drop-hint { font-size: 12px; margin-top: 10px; }
.up-item { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.up-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { flex: 1; height: 9px; background: #0f1626; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.up-bar-fill { height: 100%; background: var(--grad-accent); width: 0; transition: width .2s; }
.up-status { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.up-status.ok { color: var(--green); }
.up-status.err { color: var(--red); }

.modal-overlay { position: fixed; inset: 0; background: rgba(4, 8, 16, .65); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 250; padding: 20px; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); width: 100%; max-width: 480px; max-height: 90vh; display: none; flex-direction: column; overflow: hidden; animation: rise .2s var(--ease); }
.modal.open { display: flex; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header.danger { background: rgba(224, 90, 90, .12); }
.modal-header h3 { font-size: 15px; }
.modal-close { border: none; background: transparent; color: var(--text-dim); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }

.account-avatar-wrap { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.account-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; flex: none; }
.avatar-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-upload-btn { cursor: pointer; }
.account-info { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 14px; margin-bottom: 14px; }
.account-info > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.account-info > div:last-child { border-bottom: none; }
.account-info span:first-child { color: var(--text-dim); }

#toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--card-2); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 10px 20px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); animation: rise .25s var(--ease); max-width: 90vw; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
    #media-search { max-width: none; width: 100%; order: 3; }
    #chip-name { display: none; }
    .storage-pill { display: none; }
    .main { padding: 16px 10px 50px; }
    .media-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
    .modal-overlay { padding: 8px; align-items: flex-start; }
    .modal { max-width: 100%; max-height: 95vh; }
    input, select, textarea { font-size: 16px !important; }
    .btn { min-height: 40px; }
    .lightbox { padding: 6px; }
    .lightbox-head { flex-direction: column; align-items: flex-start; }
    .lightbox-actions { flex-wrap: wrap; }
    .admin-settings { flex-direction: column; align-items: stretch; }
    .request-head { flex-direction: column; align-items: flex-start; gap: 4px; }
    .media-toolbar { flex-direction: column; align-items: stretch; }
    .media-toolbar-right { justify-content: space-between; }
    .bulk-bar { bottom: 10px; }
}

.account-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
select { display: block; width: 100%; margin-top: 6px; padding: 11px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-weight: 400; background: #0f1626; color: var(--text); cursor: pointer; }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(243,156,18,.15); }
select option { background: #0f1626; color: var(--text); }
.auth-hint { text-align: center; margin-top: 12px; }
.account-pw-note { margin-top: 12px; text-align: center; }

.lb-embed { width: min(1000px, 92vw); aspect-ratio: 16/9; border: none; border-radius: 12px; background: #000; }
.lb-linkbox { text-align: center; padding: 40px 20px; }
.lb-linkurl { color: var(--text-dim); font-size: 13px; word-break: break-all; margin-bottom: 18px; max-width: 600px; }

.request-file-info { color: var(--text-dim); font-size: 13px; margin: 8px 0 4px; }
.req-status { font-size: 13px; font-weight: 700; margin-right: auto; }
.req-status.pending { color: var(--accent); }
.req-status.ok { color: var(--green); }
.req-status.err { color: var(--red); }
.slot-queue { margin-top: 4px; }
.request-msg a { color: var(--accent); word-break: break-all; }

.storage-full-banner { background: #c0392b; color: #fff; text-align: center; padding: 10px 16px; font-size: 13px; font-weight: 700; position: sticky; top: 0; z-index: 400; }

.request-quota { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.request-quota-lbl { font-size: 12px; color: var(--text-dim); }
.request-quota .quota-amount { width: 92px; margin: 0; display: inline-block; }
.request-quota .quota-unit { margin: 0; }
