:root {
  --bg: #f5f6f8; --panel: #ffffff; --side: #f0f2f5; --text: #1f2430; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2f6fed; --accent-2: #e8f0ff; --danger: #c0392b; --ok: #1f8a4c; --hover: #f2f5fb; --sel: #dbe7ff;
  --shadow: 0 6px 24px rgba(20, 30, 60, .08);
}
:root[data-theme="dark"] {
  --bg: #12151c; --panel: #1a1f29; --side: #161a22; --text: #e6e9ef; --muted: #98a2b3; --line: #2a3140;
  --accent: #6ea0ff; --accent-2: #1f2c4a; --danger: #ff7b6b; --ok: #4ccd7a; --hover: #202634; --sel: #27395f;
  --shadow: 0 6px 24px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; }
[hidden] { display: none !important; }

/* ログイン */
#login { display: grid; place-items: center; height: 100%; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(440px, 92vw); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 12px; font-size: 20px; }
.login-card label { display: block; margin: 10px 0; }
.login-card input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-top: 4px; }

/* レイアウト */
#app { display: grid; grid-template-columns: 240px 1fr auto; height: 100%; }
#side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.brand { font-weight: 700; padding: 18px 16px 10px; font-size: 15px; }
.folders { list-style: none; margin: 0; padding: 4px 8px; overflow: auto; flex: 1; }
.folders a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folders a:hover { background: var(--hover); }
.folders a.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: grid; gap: 6px; font-size: 13px; }
.who { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

#main { display: flex; flex-direction: column; min-width: 0; position: relative; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.crumbs-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crumbs { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.crumbs .cur { font-weight: 600; }
.crumbs .sep { color: var(--muted); }
.tools { display: flex; align-items: center; gap: 6px; }
.tools input[type=search] { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 220px; }
.actions { display: flex; align-items: center; gap: 10px; padding: 10px 18px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.sm { padding: 4px 8px; font-size: 13px; }
.btn.on { background: var(--accent-2); border-color: var(--accent); color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

/* 一覧 */
.items { flex: 1; overflow: auto; padding: 0 18px 18px; }
.items .row { display: grid; grid-template-columns: 32px 1fr 110px 170px 48px; align-items: center; gap: 8px; padding: 8px 6px; border-radius: 8px; cursor: default; }
.items .row:not(.head):hover { background: var(--hover); }
.items .row.selected { background: var(--sel); }
.items .row.head { color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); border-radius: 0; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.items .row.head .sortable { cursor: pointer; user-select: none; }
.c-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.c-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-size, .c-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.c-act { text-align: right; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; flex: none; }
.ic-folder { color: #e0a828; }
.ic-table { color: var(--ok); }
.ic-pdf { color: var(--danger); }
.ic-archive { color: #8e6cd1; }
.ic-image { color: #1e9bd7; }
.ic-file { color: var(--muted); }
.empty { color: var(--muted); padding: 60px 0; text-align: center; }

/* グリッド */
.items.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-content: start; padding-top: 6px; }
.items.grid .row { display: grid; grid-template-columns: 1fr; grid-template-rows: auto auto auto; gap: 4px; padding: 14px 10px 10px; border: 1px solid var(--line); background: var(--panel); text-align: center; }
.items.grid .row .c-check { display: none; }
.items.grid .row .c-name { flex-direction: column; }
.items.grid .row .c-name .nm { white-space: normal; word-break: break-all; font-size: 13px; }
.items.grid .row .ic { width: 44px; height: 44px; }
.items.grid .row .c-date { display: none; }
.items.grid .row .c-act { text-align: center; }
.items.grid .empty { grid-column: 1 / -1; }

/* ドロップ */
.drop-hint { display: none; position: absolute; inset: 0; place-items: center; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent); color: var(--accent); font-size: 18px; pointer-events: none; }
#main.drag .drop-hint { display: grid; }

/* アップロードキュー */
.queue { width: 320px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.q-title { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.queue ul { list-style: none; margin: 0; padding: 8px 14px; overflow: auto; }
.queue li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.q-head .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); transition: width .2s; }
.q-done .bar div { background: var(--ok); }
.q-error .bar div { background: var(--danger); }
.queue .err { font-size: 12px; margin-top: 4px; }

/* トースト */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

/* 管理画面 */
#app.admin { display: block; height: auto; min-height: 100%; overflow: auto; }
.admin { max-width: 1200px; margin: 0 auto; padding: 24px; }
.admin td.nowrap, .admin th.nowrap { white-space: nowrap; }
.admin .row-actions { flex-direction: column; align-items: stretch; min-width: 140px; }
.admin .row-actions .btn { white-space: nowrap; text-align: left; }
.admin .card label { white-space: nowrap; }
.admin h1 { font-size: 20px; margin: 0 0 4px; }
.admin h2 { font-size: 16px; margin: 24px 0 8px; }
.admin table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.admin th, .admin td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin th { font-size: 12px; color: var(--muted); background: var(--bg); }
.admin .perm { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.admin .perm label { white-space: nowrap; }
.admin .perm .missing { color: var(--muted); }
.admin .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 10px; display: grid; gap: 8px; }
.admin .card input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.admin .row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.admin .badge { font-size: 11px; padding: 2px 6px; border-radius: 10px; background: var(--accent-2); color: var(--accent); }
.admin .badge.off { background: var(--line); color: var(--muted); }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  #side { border-right: 0; border-bottom: 1px solid var(--line); }
  .folders { display: flex; gap: 4px; overflow-x: auto; }
  .items .row { grid-template-columns: 28px 1fr 80px 40px; }
  .items .row .c-date { display: none; }
  .tools input[type=search] { width: 140px; }
  .queue { width: auto; border-left: 0; border-top: 1px solid var(--line); max-height: 40vh; }
}
