:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --soft: #eef2f6;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}

button:hover { background: var(--brand-strong); }
button.secondary, .row-actions button, .taxonomy button, .logout, #bulkDeleteBtn { background: var(--soft); color: var(--ink); }
button.danger { background: var(--danger); color: #fff; }

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.admin-body, .admin-app { min-height: 100vh; }

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 40px rgba(23, 32, 51, 0.08);
}

.login-box h1, .page-head h1, .panel-title h2, dialog h2 { margin: 0; }
.login-box form, dialog form, .settings-form { display: grid; gap: 16px; }
.form-msg { min-height: 22px; margin: 0; color: var(--danger); }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
  padding: 22px 16px;
  background: #101828;
  color: #fff;
}

.brand {
  display: grid;
  gap: 2px;
  padding: 0 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand strong { font-size: 22px; }
.brand span { color: #b9c2d0; font-size: 13px; }
.nav { display: grid; align-content: start; gap: 8px; }
.nav button, .logout { justify-content: start; width: 100%; background: transparent; color: #d0d5dd; text-align: left; }
.nav button.active { background: #ffffff; color: #101828; }
.logout { background: rgba(255,255,255,0.08); }

.content { min-width: 0; padding: 24px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head p, .panel-title span { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.page { display: none; gap: 16px; }
.page.active { display: grid; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
}

.filters, .taxonomy {
  display: grid;
  grid-template-columns: 2fr repeat(4, minmax(130px, 1fr)) auto;
  gap: 12px;
}

.filters.compact { grid-template-columns: minmax(220px, 420px) 160px; }
.taxonomy { margin-top: 12px; grid-template-columns: repeat(3, 1fr); }
.taxonomy form { display: flex; gap: 8px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
}

.stat strong { display: block; font-size: 28px; }
.stat span, .muted { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #fbfcfe;
}

.link-cell { display: flex; align-items: center; gap: 8px; }
.link-cell a { color: var(--brand-strong); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  background: var(--soft);
}

.badge.active { background: #dcfce7; color: var(--ok); }
.badge.disabled, .badge.missing { background: #fee2e2; color: var(--danger); }
.badge.expired { background: #fef3c7; color: var(--warn); }
.row-actions { display: flex; gap: 8px; }

.material-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.material-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.material-thumb {
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  background: #111827;
  color: #fff;
}

.material-thumb img, .material-thumb video { width: 100%; height: 100%; object-fit: cover; }
.material-info { display: grid; gap: 6px; padding: 12px; }
.material-info strong { word-break: break-word; }

.settings-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 24px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 150px;
  border: 2px dashed #a7b2c3;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  text-align: center;
}

.drop-zone.small { min-height: 118px; }
.drop-zone strong { color: var(--ink); }
.drop-zone.dragging { border-color: var(--brand); background: #ecfdf5; }
.drop-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.file-preview {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--muted);
  background: #fbfdff;
  font-size: 13px;
  word-break: break-word;
}

.queue { display: grid; gap: 8px; }

.queue-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.queue-item progress { grid-column: 1 / -1; width: 100%; height: 10px; accent-color: var(--brand); }

dialog {
  width: min(620px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
.dialog-actions { display: flex; justify-content: end; gap: 10px; }

.viewer {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  background: #0b1018;
  color: #fff;
}

.viewer h1 {
  margin: 0;
  font-size: clamp(20px, 6vw, 28px);
  line-height: 1.2;
  word-break: break-word;
}

.media-wrap { min-height: 0; display: grid; place-items: center; }
.media { width: 100%; max-height: calc(100vh - 160px); border-radius: 8px; background: #000; }
.media.image { height: auto; object-fit: contain; }

.download {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 6px;
  background: #fff;
  color: #0b1018;
  text-decoration: none;
  font-weight: 700;
}

.message { place-items: center; text-align: center; grid-template-rows: 1fr auto 1fr; }
.message p { margin: 0; color: #cbd5e1; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; grid-template-rows: auto auto; gap: 12px; }
  .nav { grid-template-columns: repeat(4, 1fr); }
  .logout { position: absolute; right: 12px; top: 14px; width: auto; }
  .content { padding: 16px; }
  .filters, .filters.compact, .taxonomy, .stats-grid, .settings-grid { grid-template-columns: 1fr; }
  .page-head, .panel-title { align-items: stretch; flex-direction: column; }
}
