:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-soft: #eff6ff; --danger: #dc2626; --danger-soft: #fef2f2;
  --ok: #16a34a; --ok-soft: #f0fdf4; --warn: #d97706; --warn-soft: #fffbeb;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 6px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; min-height: 36px;
}
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 3px 9px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 6px 8px; }
input[type=text], input[type=password], input[type=search], select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; min-height: 38px; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 360px; background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow);
}
.login h1 { display: flex; align-items: center; gap: 10px; margin: 0 0 20px; font-size: 22px; }
.login h1 img { width: 34px; height: 34px; }
.login .btn { width: 100%; justify-content: center; margin-top: 6px; }
.err { color: var(--danger); font-size: 14px; min-height: 1.5em; margin: 4px 0 0; }

/* ---------- layout */
header.top {
  position: sticky; top: 0; z-index: 10; background: #1f2937; color: #fff;
  display: flex; align-items: center; gap: 8px; padding: 0 16px; height: 54px;
  padding-top: env(safe-area-inset-top); height: calc(54px + env(safe-area-inset-top));
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-right: 12px; }
header.top .brand img { width: 26px; height: 26px; }
nav.tabs { display: flex; gap: 2px; flex: 1; }
nav.tabs button {
  background: none; border: 0; color: #cbd5e1; padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
nav.tabs button.active { background: rgba(255,255,255,.12); color: #fff; }
nav.tabs button:hover { color: #fff; }
.usermenu { position: relative; }
.usermenu > button { background: none; border: 0; color: #fff; cursor: pointer; padding: 8px; display: flex; gap: 6px; align-items: center; }
.menu {
  position: absolute; right: 0; top: 100%; background: var(--panel); color: var(--text); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18); min-width: 180px; padding: 6px; z-index: 20;
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--bg); }
main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }

.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel, .panel + h2 { margin-top: 18px; }
h2 { font-size: 17px; margin: 26px 0 10px; }
h2:first-child { margin-top: 0; }

/* ---------- file browser */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .search { width: 220px; max-width: 100%; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 16px; margin-bottom: 12px; }
.crumbs button { background: none; border: 0; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--accent); }
.crumbs button:hover { background: var(--accent-soft); }
.crumbs button.current { color: var(--text); font-weight: 600; cursor: default; background: none; }
.crumbs .sep { color: var(--muted); }

.files { width: 100%; border-collapse: collapse; }
.files th { text-align: left; font-weight: 500; font-size: 13px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.files td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.files tr:last-child td { border-bottom: 0; }
.files tbody tr:hover { background: #fafbfc; }
.files tr.selected { background: var(--accent-soft) !important; }
.files .check { width: 36px; }
.files .name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.files .name button { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; overflow-wrap: anywhere; }
.files .name button:hover { color: var(--accent); text-decoration: underline; }
.files .ico { width: 28px; height: 28px; flex: none; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.files .size, .files .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.files .acts { white-space: nowrap; text-align: right; }
.files .acts .btn { margin-left: 4px; }
.files .sub { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 50px 16px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.selbar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 15;
  background: #1f2937; color: #fff; border-radius: 12px; padding: 8px 10px 8px 16px; display: flex; gap: 8px; align-items: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100% - 24px); flex-wrap: wrap;
}
.selbar .btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
.selbar .btn.danger { color: #fca5a5; }

.dropzone {
  position: fixed; inset: 0; background: rgba(37,99,235,.12); border: 3px dashed var(--accent); z-index: 30;
  display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); pointer-events: none;
}

.uploads { position: fixed; right: 16px; bottom: 16px; width: 340px; max-width: calc(100% - 32px); z-index: 25; }
.uploads .panel { padding: 12px 14px; max-height: 50vh; overflow: auto; }
.uploads .row { font-size: 13px; margin-bottom: 8px; }
.uploads .row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }
.bar.done > div { background: var(--ok); }
.bar.fail > div { background: var(--danger); }

/* ---------- modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 440px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); max-height: calc(100vh - 32px); overflow: auto; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal p { margin: 0 0 14px; }
.modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal.preview { max-width: min(1000px, 100%); padding: 14px; }
.modal.preview .media { display: grid; place-items: center; background: #111; border-radius: 8px; min-height: 200px; }
.modal.preview img, .modal.preview video { max-width: 100%; max-height: 72vh; display: block; }
.modal.preview iframe { width: 100%; height: 72vh; border: 0; background: #fff; }
.modal.preview audio { width: 100%; margin: 30px 0; }
.modal.preview .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.modal.preview .head .t { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.folderpick { border: 1px solid var(--line); border-radius: 8px; max-height: 300px; overflow: auto; }
.folderpick button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.folderpick button:hover { background: var(--bg); }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 50; background: #1f2937; color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); }

/* ---------- admin */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.card { padding: 16px 18px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 500; }
.card .big { font-size: 26px; font-weight: 700; }
.card .sub { color: var(--muted); font-size: 13px; }
.meter { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 10px 0 6px; }
.meter > div { height: 100%; background: var(--accent); }
.meter.high > div { background: var(--warn); }
.meter.full > div { background: var(--danger); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.notes { margin: 10px 0 0; padding: 0; list-style: none; font-size: 14px; }
.notes li { padding: 4px 0 4px 18px; position: relative; }
.notes li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.notes li.warn::before { background: var(--warn); }
.notes li.bad::before { background: var(--danger); }
details.more { margin-top: 10px; font-size: 13px; }
details.more summary { cursor: pointer; color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid select { width: auto; min-height: 32px; padding: 4px 8px; }
.tablewrap { overflow-x: auto; }
.adduser { display: grid; grid-template-columns: 1fr 1fr 140px auto; gap: 8px; padding: 14px; border-top: 1px solid var(--line); align-items: end; }
.logfilter { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logfilter select { width: auto; }
.act { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--bg); white-space: nowrap; }
.act.login { background: var(--ok-soft); color: var(--ok); }
.act.fail { background: var(--danger-soft); color: var(--danger); }
.act.write { background: var(--accent-soft); color: var(--accent); }
.act.del { background: var(--warn-soft); color: var(--warn); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* ---------- help */
.help { padding: 20px 22px; }
.help h3 { margin: 0 0 8px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.help ol { padding-left: 22px; margin: 8px 0; }
.help li { margin: 5px 0; }
.help .note { background: var(--warn-soft); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.copyline { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.copyline code, pre.code {
  flex: 1; background: #0f172a; color: #e2e8f0; padding: 8px 12px; border-radius: 8px; font-family: ui-monospace, Consolas, monospace;
  font-size: 13px; overflow-x: auto; white-space: pre; display: block;
}
pre.code { margin: 6px 0; }

@media (max-width: 720px) {
  header.top { padding: 0 8px; padding-top: env(safe-area-inset-top); }
  header.top .brand span { display: none; }
  nav.tabs button { padding: 8px 9px; }
  .usermenu .uname { display: none; }
  .files .date, .files th.date { display: none; }
  .files td, .files th { padding: 8px; }
  .files .acts .btn.optional { display: none; }
  .toolbar .search { width: 100%; order: 10; }
  .adduser { grid-template-columns: 1fr; }
  main { padding: 12px 10px 90px; }
}
