:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #606770;
  --border: #dfe3e8;
  --primary: #0b6ef6;
  --primary-hover: #0958c9;
  --danger: #d93025;
  --danger-hover: #b3261e;
  --warn-bg: #fff4db;
  --warn-text: #7a4f01;
  --info-bg: #e8f1fe;
  --info-text: #0b4ea2;
  --err-bg: #fdecea;
  --err-text: #9f1b13;
  --ok-bg: #e6f4ea;
  --ok-text: #137333;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1b1f26;
    --text: #e6e8ec;
    --muted: #9aa2ad;
    --border: #2e3440;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warn-bg: #3b2d0a;
    --warn-text: #fcd34d;
    --info-bg: #172a45;
    --info-text: #93c5fd;
    --err-bg: #3b1414;
    --err-text: #fca5a5;
    --ok-bg: #123320;
    --ok-text: #86efac;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: 100%;
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 16px;
  font-size: 0.95rem;
}

.main-content {
  flex: 1;
  padding-top: 20px;
  padding-bottom: 36px;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 14px 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  word-break: normal;
}

.small {
  font-size: 0.85rem;
}

.hidden {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.app-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 0;
}

.app-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  margin-bottom: 12px;
}

.app-card-head:hover {
  text-decoration: none;
}

.app-title {
  margin: 0;
  font-size: 1.05rem;
}

.app-version {
  font-size: 0.9rem;
  color: var(--muted);
}

.app-card-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.app-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}

.app-icon-lg {
  width: 72px;
  height: 72px;
  border-radius: 16px;
}

.app-icon-sm {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.app-icon-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
}

.app-icon-sm.app-icon-fallback {
  font-size: 0.85rem;
}

.app-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
  filter: brightness(0.96);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-lg {
  padding: 12px 20px;
  font-size: 1rem;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.app-hero-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-hero-left > div {
  min-width: 0;
}

.app-hero-left h1 {
  margin: 0;
  font-size: 1.4rem;
}

.app-desc {
  margin: 8px 0 0;
}

.latest-release {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
}

.latest-qr {
  text-align: center;
}

.qr-img {
  width: 160px;
  height: 160px;
  background: #fff;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.qr-caption {
  margin: 6px 0 0;
  font-size: 0.8rem;
  max-width: 180px;
}

.meta-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 14px;
}

.meta-list li {
  margin-bottom: 4px;
}

.release-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
}

.badge-primary {
  background: var(--info-bg);
  color: var(--info-text);
  border-color: transparent;
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.alert-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.alert-info {
  background: var(--info-bg);
  color: var(--info-text);
}

.alert-error {
  background: var(--err-bg);
  color: var(--err-text);
}

.text-error {
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.text-right {
  text-align: right;
}

.row-hidden {
  opacity: 0.6;
}

.auth-box {
  max-width: 420px;
  margin: 32px auto;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.admin-header,
.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  margin-bottom: 0;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 4px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: var(--info-bg);
}

.upload-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

#upload-input:focus-visible + label {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.upload-file-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.progress-wrap progress {
  flex: 1;
  height: 14px;
}

.upload-results {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-results li {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
}

.upload-added {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.upload-exists {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.upload-error {
  background: var(--err-bg);
  color: var(--err-text);
}

.inline-notes-form {
  display: flex;
  gap: 6px;
  min-width: 180px;
}

.actions-cell {
  white-space: nowrap;
}

.actions-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.actions-row form {
  display: flex;
  margin: 0;
}

.actions-row .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.delete-app-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 720px) {
  .table-wrap {
    overflow-x: visible;
  }
  .builds-table,
  .builds-table tbody,
  .builds-table tr,
  .builds-table td {
    display: block;
    width: 100%;
  }
  .builds-table thead {
    display: none;
  }
  .builds-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: var(--bg);
  }
  .builds-table td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
    white-space: normal;
  }
  .builds-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }
  .builds-table td::before {
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
  }
  .inline-notes-form {
    min-width: 0;
    width: 100%;
  }
  .inline-notes-form input[type="text"] {
    flex: 1;
    min-width: 0;
  }
  .actions-row {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .latest-release {
    grid-template-columns: 1fr;
  }
  .latest-qr {
    justify-self: center;
  }
  .app-hero-left {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Dashboard app list: drop the long package column on phones (it is shown on the app page). */
@media (max-width: 640px) {
  .apps-table .col-pkg { display: none; }
}
