:root {
  --bg: #f3f5f8; --card: #fff; --text: #1d2330; --muted: #6b7484; --line: #e3e7ee;
  --primary: #1f5fbf; --primary-weak: #e8f0fc; --danger: #c62828; --ok: #2e7d32;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --card: #1d2128; --text: #e6e9ef; --muted: #9aa3b2; --line: #2c323c;
          --primary: #5b95ec; --primary-weak: #23324a; --danger: #ef5350; --ok: #66bb6a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
button, .btn, input { font: inherit; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }

/* 로그인 */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); padding: 28px 22px; border-radius: 14px; width: 100%; max-width: 360px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 10px; }
.login-card .brand { font-size: 26px; font-weight: 700; color: var(--primary); }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 16px; }

/* 상단 */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; font-size: 18px; color: var(--primary); text-decoration: none; white-space: nowrap; }
.storage-info { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); cursor: pointer; }
.storage-info .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 3px; max-width: 320px; }
.storage-info .bar > i { display: block; height: 100%; background: var(--primary); }
.storage-info .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner { background: #fff3e0; color: #8a4b00; padding: 10px 16px; font-size: 14px; }
.tip { background: var(--primary-weak); color: var(--text); padding: 8px 10px 8px 16px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.tip span { flex: 1; }
.small { font-size: 12px; margin: 4px 0 0; }
#btnMenu { font-size: 22px; padding: 2px 10px; }
.up-row { color: var(--primary); }
.up-row .ic { font-size: 22px; }
.menu .who { padding: 10px 16px 6px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.admin-table button { border: 0; background: none; color: var(--danger); cursor: pointer; }
.form-row { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.form-row input[type=text], .form-row input[type=password] { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 16px; }
.hide-write .write-only { display: none !important; }
#addrTip a.btn { min-height: 32px; padding: 4px 12px; text-decoration: none; white-space: nowrap; }
/* 모바일: 큰 올리기 버튼 */
.fab { display: none; }
@media (max-width: 640px) {
  .fab { display: flex; position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 12;
    align-items: center; gap: 6px; height: 60px; padding: 0 22px 0 18px; border: 0; border-radius: 30px;
    background: var(--primary); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 6px 18px rgba(0,0,0,.28); cursor: pointer; }
  .fab span { font-size: 17px; font-weight: 600; }
  body.uploads-open .fab { bottom: calc(50vh + 24px); }
  #toolbarNormal label[for], #toolbarNormal .btn.primary.write-only { display: none; }
  .row { min-height: 64px; }
  .row .ic { width: 52px; height: 52px; }
  .row .name { font-size: 16px; }
  .up-row .name { font-weight: 600; }
}
.admin-kv { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 6px; }
.admin-kv td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-kv td:first-child { color: var(--muted); white-space: nowrap; width: 38%; }
.ok-text { color: var(--ok); } .bad-text { color: var(--danger); }
@media (prefers-color-scheme: dark) { .banner { background: #3a2a10; color: #ffcc80; } }

.crumbs { display: flex; flex-wrap: wrap; gap: 2px; padding: 10px 16px 4px; font-size: 15px; }
.crumbs a { color: var(--primary); text-decoration: none; padding: 2px 4px; border-radius: 4px; max-width: 60vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs span.sep { color: var(--muted); padding: 2px 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px; align-items: center; }
.toolbar .spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; user-select: none; min-height: 38px; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary { padding: 12px; border-radius: 8px; border: 0; cursor: pointer; font-size: 16px; }
.btn.danger { color: var(--danger); }
.ghost { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 8px; }
.sel-count { font-weight: 600; margin-right: 4px; }

/* 목록 */
.list { padding: 0 8px 120px; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px; margin: 2px 0; border-radius: var(--radius);
  background: var(--card); cursor: pointer; min-height: 56px; }
.row:hover { background: var(--primary-weak); }
.row.selected { background: var(--primary-weak); outline: 2px solid var(--primary); }
.row .ic { width: 44px; height: 44px; flex: none; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; background: var(--bg); overflow: hidden; }
.row .ic img { width: 100%; height: 100%; object-fit: cover; }
.row .meta { flex: 1; min-width: 0; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .more { flex: none; width: 40px; height: 40px; border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer; border-radius: 50%; }
.row .chk { flex: none; width: 22px; height: 22px; }

.list.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; padding: 0 12px 120px; }
.list.grid .row { flex-direction: column; align-items: stretch; padding: 0; gap: 0; min-height: 0; position: relative; }
.list.grid .row .ic { width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: var(--radius) var(--radius) 0 0; font-size: 40px; }
.list.grid .row .meta { padding: 4px 6px 6px; }
.list.grid .row .sub { display: none; }
.list.grid .row .name { font-size: 12px; }
.list.grid .row .more { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.35); color: #fff; width: 32px; height: 32px; font-size: 18px; }
.list.grid .row .chk { position: absolute; top: 6px; left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.drop-hint { position: fixed; inset: 0; background: rgba(31,95,191,.15); border: 3px dashed var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--primary); z-index: 20; pointer-events: none; }

/* 업로드 패널 */
.uploads { position: fixed; right: 12px; bottom: 12px; width: min(420px, calc(100vw - 24px)); max-height: 50vh;
  background: var(--card); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 15; display: flex; flex-direction: column; }
.uploads-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.up-list { overflow: auto; padding: 6px 14px 10px; }
.up-item { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.up-item .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-item .p { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 4px 0; }
.up-item .p > i { display: block; height: 100%; background: var(--primary); width: 0; }
.up-item .s { color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.up-item.done .p > i { background: var(--ok); }
.up-item.fail .s { color: var(--danger); }
.up-item button { border: 0; background: none; color: var(--danger); cursor: pointer; padding: 0; }

/* 뷰어 */
.viewer { position: fixed; inset: 0; background: #000; z-index: 30; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #fff; background: rgba(0,0,0,.6); }
.v-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.vbtn { color: #fff; background: rgba(255,255,255,.12); border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; }
.viewer-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.viewer-bottom { display: flex; gap: 8px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(0,0,0,.6); }
.viewer-bottom .vbtn { flex: 1; text-align: center; padding: 12px 0; font-size: 15px; }
.vbtn.danger { color: #ff8a80; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-body video { width: 100%; height: 100%; background: #000; }
.viewer-body audio { width: min(600px, 92vw); }
.viewer-body .loading { color: #aaa; }
.vnav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0;
  background: rgba(255,255,255,.12); color: #fff; font-size: 36px; cursor: pointer; border-radius: 8px; }
.vnav.left { left: 6px; } .vnav.right { right: 6px; }

/* 모달 / 메뉴 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--card); border-radius: 14px; width: 100%; max-width: 440px; max-height: 85vh; display: flex; flex-direction: column; padding: 18px; }
.modal-card h3 { margin: 0 0 10px; font-size: 17px; }
.modal-card input[type=text] { width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 16px; }
#mBody { overflow: auto; min-height: 0; }
#mBody p { white-space: pre-line; margin: 4px 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.picker-path { font-size: 13px; color: var(--muted); margin-bottom: 6px; word-break: break-all; }
.picker-item { padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.picker-item:hover { background: var(--primary-weak); }
.menu { position: fixed; z-index: 35; background: var(--card); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.25); min-width: 170px; overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; background: none; color: var(--text); cursor: pointer; font-size: 15px; }
.menu button:hover { background: var(--primary-weak); }
.menu button.danger { color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #323232; color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 50; max-width: 90vw; font-size: 14px; }

@media (max-width: 640px) {
  .desktop-only { display: none !important; }
  .topbar { padding: 8px 12px; }
  .toolbar { padding: 6px 10px; }
  .crumbs { padding: 8px 10px 2px; }
  .list { padding: 0 4px 120px; }
  .vnav { width: 40px; height: 60px; }
}
