:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #7c7c82;
  --accent: #0071e3;
  --danger: #d0342c;
  --border: #e3e3e8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101014;
    --card: #1b1b21;
    --text: #f2f2f5;
    --muted: #9a9aa3;
    --accent: #2997ff;
    --danger: #ff6259;
    --border: #2c2c34;
  }
}
:root[data-theme="dark"] {
  --bg: #101014;
  --card: #1b1b21;
  --text: #f2f2f5;
  --muted: #9a9aa3;
  --accent: #2997ff;
  --danger: #ff6259;
  --border: #2c2c34;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 1.4rem; margin: 0; }
.muted { color: var(--muted); }
.small-text { font-size: 0.82rem; }
.center { text-align: center; }
.error { color: var(--danger); }

button, .btn {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  display: inline-block;
}
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
button.danger { color: var(--danger); }
button.link {
  background: none;
  color: var(--accent);
  padding: 0;
  text-decoration: underline;
}

.center-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: min(360px, 90vw);
  text-align: center;
}
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

#main-view { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; }
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.header-title h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
#header-sub { margin: 4px 0 0; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.header-actions button { font-size: 0.85rem; }
button.pill {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 18px;
}
button.plain {
  background: transparent;
  color: var(--text);
  font-weight: 600;
  padding: 9px 4px;
}
.theme-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun { display: none; }
.dark .theme-toggle .icon-moon { display: none; }
.dark .theme-toggle .icon-sun { display: block; }

#drop-zone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  margin-bottom: 24px;
  transition: border-color 0.15s, background 0.15s;
}
#drop-zone.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

#upload-status { margin-top: 16px; text-align: left; }
.upload-info { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.up-title { font-weight: 600; }
.progress {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 6px;
}
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.app-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.app-icon {
  width: 56px;
  height: 56px;
  border-radius: 13px;
  background: var(--border);
  object-fit: cover;
  flex-shrink: 0;
}
.app-icon.small { width: 40px; height: 40px; border-radius: 9px; }
.icon-wrap { position: relative; flex-shrink: 0; line-height: 0; }
.icon-refresh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}
.icon-wrap:hover .icon-refresh,
.icon-wrap.busy .icon-refresh { opacity: 1; }
.icon-refresh svg { width: 22px; height: 22px; }
.icon-wrap.busy .icon-refresh svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.app-info { flex: 1; min-width: 0; }
.app-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-bundle {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--bg);
  white-space: nowrap;
}
.app-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.confirm {
  width: auto;
  padding: 0 10px;
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  #main-view { padding: 16px 10px 40px; }
  .app-card { padding: 12px; gap: 10px; }
  .app-icon { width: 48px; height: 48px; border-radius: 11px; }
  .icon-refresh { border-radius: 11px; }
  #drop-zone { padding: 20px 12px; }
}
