:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1c2128;
  --muted: #5d6773;
  --border: #d8dee6;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #cf222e;
  --warn-bg: #fff8e1;
  --warn-text: #7a5300;
  --android: #2e7d32;
  --ios: #3c4043;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --surface: #181d24;
    --surface-2: #222833;
    --text: #e6e9ee;
    --muted: #9aa4b0;
    --border: #2f3743;
    --accent: #4c8dff;
    --danger: #ff6b6b;
    --warn-bg: #3a2f10;
    --warn-text: #ffd479;
    --android: #66bb6a;
    --ios: #c9ced6;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
p { margin: .4rem 0; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .88em; word-break: break-all; }
[hidden] { display: none !important; }

/* ---- ヘッダー ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: .92rem; white-space: nowrap;
}
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.main { max-width: 880px; margin: 0 auto; padding: 16px 16px 64px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- 部品 ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-align: center; white-space: nowrap; flex: none;
}
.btn.big { white-space: normal; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 52px; font-size: 1.05rem; width: 100%; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }

label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=search], input[type=email], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  border: 1px solid currentColor; white-space: nowrap;
}
.badge.android { color: var(--android); }
.badge.ios { color: var(--ios); }
.badge.role-admin { color: #8250df; }
.badge.role-uploader { color: var(--accent); }
.badge.role-viewer { color: var(--muted); }
.badge.latest { color: var(--accent); }
.badge.off { color: var(--danger); }

.warn {
  background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 8px 12px; font-size: .88rem;
}
.warn ul { margin: 0; padding-left: 1.2em; }
.error { color: var(--danger); white-space: pre-wrap; }

/* ---- アプリ一覧 ---- */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 160px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  border: 0; background: var(--surface); color: var(--muted); padding: 8px 12px; font: inherit; cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.app-list { display: grid; gap: 10px; }
.app-item {
  display: flex; gap: 12px; align-items: center; padding: 12px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.app-item:hover { border-color: var(--accent); }
.app-item .info { flex: 1; min-width: 0; }
.app-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-item .sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon {
  width: 56px; height: 56px; border-radius: 13px; flex: none; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); font-size: 1.4rem;
}
.icon.lg { width: 76px; height: 76px; border-radius: 17px; font-size: 1.8rem; }

/* ---- アプリ詳細 ---- */
.app-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.app-head .info { min-width: 0; }
.app-head h1 { margin: 0; overflow-wrap: anywhere; }
.qr-card { display: flex; gap: 16px; align-items: center; }
.qr-card img { width: 120px; height: 120px; background: #fff; border-radius: 8px; padding: 4px; flex: none; }
.build.latest { border-color: var(--accent); }
.build-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.build-head .ver { font-size: 1.15rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: .85rem; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: .9rem; margin: 8px 0; }

/* ---- アップロード ---- */
.drop {
  display: block; border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 16px;
  text-align: center; cursor: pointer; background: var(--surface);
}
.drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop input { display: none; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---- 表 ---- */
.list-row {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--border);
}
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 180px; }
.list-row select { width: auto; padding: 6px 8px; }

/* ---- ログイン ---- */
.auth-box { max-width: 420px; margin: 8vh auto 0; }
.auth-box .logo { width: 56px; height: 56px; display: block; margin: 0 auto 12px; }

/* ---- ダイアログ・通知 ---- */
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog .qr { display: block; width: 220px; height: 220px; margin: 12px auto; background: #fff; padding: 6px; border-radius: 8px; }
.link-box { display: flex; gap: 6px; }
.link-box input { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 100;
  max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, .25); font-size: .92rem;
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 560px) {
  .nav { width: 100%; margin-left: 0; justify-content: space-between; }
  .nav a { flex: 1; text-align: center; padding: 6px 4px; }
  .qr-card { display: none; }
}
