:root {
  --bg: #0b0f14;
  --surface: #161c24;
  --surface-2: #1f2731;
  --border: #2b3440;
  --accent: #4cc2ff;
  --accent-dim: #2b7fb0;
  --text: #f2f5f8;
  --muted: #9aa7b4;
  --danger: #e0555b;
  --ok: #3fa66b;
  --warn: #e0a955;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }
.brand span { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 4px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
}
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); }

.view { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head > div:first-child { flex: 1 1 280px; min-width: 0; }

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

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #05202e; font-weight: 600; }
.btn-primary:hover { background: #6fd0ff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 4px 8px; min-width: 32px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1 1 200px; }

.login-wrap { max-width: 380px; margin: 60px auto; }
.error { color: var(--danger); font-size: 14px; margin-top: 6px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
td.right, th.right { text-align: right; }
td.actions { white-space: nowrap; text-align: right; }
.row-link { cursor: pointer; }

.thumb {
  width: 72px;
  height: 44px;
  border-radius: 6px;
  background: var(--surface-2);
  object-fit: cover;
  display: block;
}
.thumb-video {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.thumb-wrap { position: relative; flex: none; display: block; width: 72px; height: 44px; }
.thumb-play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; pointer-events: none;
}
.thumb-play .icon { width: 22px; height: 22px; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.8)); }
.name-cell { display: flex; align-items: center; gap: 12px; }
.name-cell .name { font-weight: 500; }
/* The name cell is a <button> so it can open the preview: strip the button chrome. */
button.name-cell {
  background: none; border: 0; padding: 0; margin: 0;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
button.name-cell:hover .name { color: var(--accent); }

.icon { width: 1em; height: 1em; vertical-align: -0.15em; flex: none; }
.btn-icon .icon { width: 16px; height: 16px; display: block; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}
.badge-image { background: var(--ok); }
.badge-video { background: var(--danger); }
.badge-web { background: var(--warn); }
.thumb-web { display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--muted); border-radius: 6px; }
.thumb-web .icon { width: 22px; height: 22px; }
.badge-muted { background: var(--surface-2); color: var(--muted); }

.status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot-ok { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-bad { background: var(--danger); }

.meta-line { display: flex; flex-wrap: wrap; gap: 4px 0; font-size: 13px; color: var(--muted); }
.meta-line > * + *::before { content: "·"; margin: 0 8px; color: var(--border); }
.meta-line strong { color: var(--text); font-weight: 600; }

.drop-card { position: relative; }
.drop-card .drop-hint {
  display: none;
  position: absolute; inset: 0;
  align-items: center; justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(11, 15, 20, 0.85);
  color: var(--text); font-weight: 600;
  pointer-events: none;
}
.drop-card.over .drop-hint { display: flex; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.over { border-color: var(--accent); background: rgba(76, 194, 255, 0.06); color: var(--text); }
.dropzone strong { color: var(--text); }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.15s; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 10; padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 640px; max-height: 85vh;
  display: flex; flex-direction: column;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
/* Media preview: the dialog shrinks to the media, which app.js sizes to fit the window. */
.modal-preview { width: auto; max-width: none; }
.modal-preview .modal-body { padding: 0; overflow: hidden; background: #000; display: flex; align-items: center; justify-content: center; position: relative; }
.preview-count { white-space: nowrap; }
.preview-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11, 15, 20, 0.7); border: 1px solid var(--border); color: #fff;
  cursor: pointer;
}
.preview-nav.prev { left: 12px; }
.preview-nav.next { right: 12px; }
.preview-nav:hover:not(:disabled) { border-color: var(--accent); background: rgba(11, 15, 20, 0.9); }
.preview-nav:disabled { opacity: 0.3; cursor: default; }
.preview-nav .icon { width: 24px; height: 24px; }
.modal-preview .modal-foot { display: none; }
.preview-media { display: block; max-width: 100%; max-height: calc(85vh - 60px); }
/* Until the browser reports the video's size (or if it can't decode it), show it
   large and 16:9 instead of the 300×150 default. app.js overrides this inline. */
video.preview-media { width: min(90vw - 40px, 1400px); aspect-ratio: 16 / 9; }

.check-list { display: flex; flex-direction: column; gap: 4px; }
.check-list label {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer;
}
.check-list label:hover { background: var(--surface-2); }
.check-list input { width: 16px; height: 16px; }
.check-list .sub { color: var(--muted); font-size: 12px; margin-left: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.order-cell { display: flex; gap: 4px; }
.help { font-size: 13px; color: var(--muted); }

input[type="number"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
}
input[type="number"]:focus { outline: none; border-color: var(--accent); }
.duration-input::placeholder { color: var(--muted); }
h1 .badge { vertical-align: middle; font-size: 12px; }
.idx-m { display: none; }

/* ------------------------------------------------------------ mobile */
@media (max-width: 720px) {
  body { font-size: 14px; }
  h1 { font-size: 22px; }

  .topbar { flex-wrap: wrap; height: auto; gap: 8px 16px; padding: 10px 16px; }
  .topbar nav { order: 3; width: 100%; }
  .topbar nav a { flex: 1; text-align: center; }
  #user-name { display: none; }

  .view { padding: 20px 16px 48px; }
  .card { padding: 16px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .kv { grid-template-columns: 110px 1fr; }
  .modal-foot .btn { flex: 1; }
  video.preview-media { width: calc(100vw - 40px); }

  /* Tables marked .resp become a stack of cards: one card per row,
     each cell rendered as "Label ........ value" using its data-label. */
  /* List pages: the row cards replace the wrapping card. */
  .card:has(> table.resp) { background: none; border: none; padding: 0; }

  table.resp, table.resp tbody, table.resp tr, table.resp td { display: block; width: 100%; }
  table.resp thead { display: none; }
  table.resp tr {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
  }
  table.resp tr:last-child { margin-bottom: 0; }
  table.resp tr:hover td { background: transparent; }
  table.resp tr.row-link:active { border-color: var(--accent); }
  table.resp td {
    border: none;
    padding: 5px 0;
    text-align: right;
    overflow: hidden; /* contains the floated label */
    overflow-wrap: anywhere;
  }
  table.resp td[data-label]::before {
    content: attr(data-label);
    float: left;
    margin-right: 12px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 20px;
  }
  table.resp td:empty { display: none; }
  table.resp td.idx { display: none; }
  table.resp .idx-m { display: inline; margin-right: 6px; }
  table.resp td.card-title {
    text-align: left;
    padding: 0 0 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
  }
  table.resp td.card-title .name { font-size: 15px; }
  table.resp td.card-title button.name-cell { width: 100%; }
  table.resp td.actions {
    text-align: right;
    padding-top: 10px;
    margin-top: 6px;
    border-top: 1px solid var(--border);
  }
  table.resp td.actions .order-cell { justify-content: flex-end; }
  table.resp td .order-cell { display: inline-flex; }
}

/* ---------------------------------------------------------------- register page */
.register-wrap { max-width: 440px; margin: 32px auto; padding: 0 16px 40px; }
.register-wrap h1 { font-size: 24px; }
.device-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; margin-bottom: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
}
.device-chip .mono { color: var(--accent); }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  flex: 1; padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.btn-block { display: block; width: 100%; text-align: center; margin-top: 6px; padding: 11px 14px; }
label .help { font-weight: 400; color: var(--muted); font-size: 12px; }
@media (max-width: 480px) {
  .register-wrap { margin-top: 12px; }
  .register-wrap .card { padding: 16px; }
}
