:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #15181e;
  --muted: #646b78;
  --line: #e3e6eb;
  --hover: #eef1f5;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgb(15 17 21 / 0.14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e8eaee;
    --muted: #8d95a3;
    --line: #262b35;
    --hover: #1f242d;
    --accent: #3b82f6;
    --danger: #f87171;
    --shadow: 0 8px 30px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; }

button, .button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.ghost, .button.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
button.ghost:hover, .button.ghost:hover { background: var(--hover); }
button.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px var(--line); }
button.small { padding: 2px 8px; }
button:focus-visible, .button:focus-within, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top form { margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; }
.brand img { border-radius: 6px; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.tabs a:hover { background: var(--hover); }
.tabs a.on { color: var(--text); background: var(--hover); font-weight: 600; }
.usage { margin-left: auto; display: grid; gap: 3px; min-width: 140px; }
.usage .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.usage .bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.usage small { color: var(--muted); font-size: 12px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 16px; }
.crumbs a { padding: 4px 6px; border-radius: 6px; text-decoration: none; }
.crumbs a:hover { background: var(--hover); }
.crumbs a:last-child { font-weight: 600; }
.crumbs span { color: var(--muted); }
.hint { color: var(--muted); margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }

/* file and trash lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.list:empty { display: none; }
.list li { display: grid; grid-template-columns: 40px 1fr auto auto auto; align-items: center; gap: 12px; padding: 6px 12px; border-top: 1px solid var(--line); min-height: 52px; }
.list li:first-child { border-top: 0; }
.list li:hover { background: var(--hover); }
.list .icon { width: 40px; height: 40px; border-radius: 6px; display: grid; place-items: center; font-size: 22px; overflow: hidden; background: var(--hover); }
.list .icon img { width: 100%; height: 100%; object-fit: cover; }
.list .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; text-decoration: none; }
.list .name small { display: block; color: var(--muted); font-size: 12px; }
.list .meta { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.list .more { padding: 4px 10px; font-size: 18px; line-height: 1; }

/* context menu */
.menu { position: fixed; z-index: 30; list-style: none; margin: 0; padding: 6px; min-width: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.menu button { width: 100%; background: transparent; color: var(--text); justify-content: flex-start; }
.menu button:hover { background: var(--hover); }
.menu button.danger { box-shadow: none; color: var(--danger); }

/* photos */
.month h3 { font-size: 15px; margin: 20px 4px 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.grid button { position: relative; padding: 0; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: var(--hover); }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid .badge { position: absolute; right: 6px; bottom: 6px; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: rgb(0 0 0 / 0.6); color: #fff; }
.sentinel { height: 1px; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: grid; grid-template-rows: auto 1fr; color: #fff; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: rgb(0 0 0 / 0.6); }
.viewer-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .ghost { color: #fff; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25); }
.viewer-bar .ghost:hover { background: rgb(255 255 255 / 0.1); }
.stage { display: grid; place-items: center; min-height: 0; overflow: hidden; touch-action: pan-y; }
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.stage .loading { color: #aaa; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgb(255 255 255 / 0.12); color: #fff; font-size: 30px; width: 48px; height: 64px; justify-content: center; }
.viewer .prev { left: 12px; }
.viewer .next { right: 12px; }

/* drop target */
.drop { position: fixed; inset: 0; z-index: 15; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); pointer-events: none; }
.drop p { background: var(--panel); padding: 14px 20px; border-radius: 10px; box-shadow: var(--shadow); }

/* upload queue */
.queue { position: fixed; right: 16px; bottom: 16px; z-index: 10; width: min(380px, calc(100vw - 32px)); max-height: 50vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.queue header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.queue ul { list-style: none; margin: 0; padding: 4px 0; overflow: auto; }
.queue li { padding: 6px 12px; display: grid; gap: 4px; }
.queue li .row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.queue li .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue li .row span:last-child { color: var(--muted); white-space: nowrap; }
.queue progress { width: 100%; height: 4px; appearance: none; border: 0; border-radius: 2px; background: var(--line); }
.queue progress::-webkit-progress-bar { background: var(--line); border-radius: 2px; }
.queue progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }
.queue progress::-moz-progress-bar { background: var(--accent); }
.queue li.error span:last-child { color: var(--danger); }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog p:empty { display: none; }
dialog input, .login input { width: 100%; font: inherit; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; display: grid; gap: 8px; }
.toasts div { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(340px, 100%); display: grid; gap: 14px; justify-items: center; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.login h1 { margin: 0; font-size: 22px; }
.login img { border-radius: 12px; }
.login label { width: 100%; display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.login button { width: 100%; justify-content: center; }
.login .hint { margin: 0; text-align: center; font-size: 14px; }
.login label.check { display: flex; align-items: center; gap: 8px; }
.login label.check input { width: auto; }
.login .back { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); margin: 0; }

/* security */
.panel { max-width: 560px; margin: 0 auto 16px; padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: grid; gap: 12px; }
.panel h2 { margin: 0; font-size: 17px; }
.panel .hint { margin: 0; }
.panel .qr { width: 220px; height: 220px; border-radius: 8px; background: #fff; justify-self: center; }
.panel .secret { justify-self: center; font-size: 15px; letter-spacing: 1px; user-select: all; }
.panel .row { display: flex; gap: 8px; flex-wrap: wrap; }
.panel .row input { flex: 1; min-width: 120px; font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.panel .row #sec-code { font-size: 20px; letter-spacing: 4px; }
.devices li { grid-template-columns: 40px 1fr auto; }
.panel details { border-top: 1px solid var(--line); padding-top: 10px; }
.panel summary { cursor: pointer; font-weight: 600; }
.panel details ol { margin: 8px 0 0; padding-left: 20px; color: var(--muted); display: grid; gap: 6px; }
.panel .cmd { display: block; margin: 6px 0; padding: 8px 10px; background: var(--bg); border-radius: 6px; font-size: 13px; word-break: break-all; user-select: all; color: var(--text); }
.camera { margin: 0 4px 8px; font-size: 13px; }
.panel .empty.small { padding: 8px; }
.token { display: block; padding: 10px 12px; background: var(--bg); border-radius: 8px; font-size: 14px; word-break: break-all; user-select: all; }
.codes { list-style: none; margin: 0; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; background: var(--bg); border-radius: 8px; user-select: all; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 8px 12px; }
  .tabs { order: 3; width: 100%; }
  .tabs a { flex: 1; text-align: center; }
  .usage { min-width: 0; flex: 1; }
  .list li { grid-template-columns: 40px 1fr auto; }
  .list .meta.size, .list .meta.date { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 2px; }
  .viewer .nav { display: none; }
}
