:root {
  color-scheme: dark;
  --bg: #0c0e0b;
  --panel: #15171394;
  --panel-solid: #15171a;
  --panel-2: #1c1f1a;
  --line: #2c322a;
  --line-soft: #20241f;
  --text: #f3f1e7;
  --muted: #8a8d80;
  --muted-2: #5b5e54;
  --amber: #f5b640;
  --green: #68c06f;
  --red: #ef6461;
  --blue: #70a8d8;
  --gray: #71766b;
  --ink: #0b0d0b;
  --ring: 0 0 0 1px rgba(245, 182, 64, 0.55), 0 0 0 4px rgba(245, 182, 64, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Helvetica Neue", ui-sans-serif, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  margin: 0 2px;
  min-width: 18px;
  padding: 1px 5px;
  text-align: center;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1f231d;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  height: 32px;
  padding: 0 12px;
  transition: border-color 80ms ease, background 80ms ease, color 80ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--amber);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

button.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--ink);
}

button.danger:not(:disabled) {
  background: var(--red);
  border-color: var(--red);
  color: #fff8f2;
}

button.ghost {
  background: transparent;
  height: 26px;
  padding: 0 8px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.app {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
}

/* ============================ Topbar ============================ */
.topbar {
  align-items: center;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(220px, auto) 1fr auto;
  padding: 0 16px;
}

.topbar-left {
  align-items: baseline;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.project-name {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-stats {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-self: center;
}

.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  white-space: nowrap;
}

.chip.chip-progress strong {
  color: var(--text);
}

.chip-dirty[data-state="dirty"] {
  background: rgba(245, 182, 64, 0.16);
  border-color: var(--amber);
  color: var(--amber);
}

.chip-dirty[data-state="zero"] {
  opacity: 0.6;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

/* tools dropdown */
.tools-menu {
  position: relative;
}

.tools-menu summary {
  background: #1f231d;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  height: 32px;
  list-style: none;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  font-size: 16px;
  user-select: none;
}

.tools-menu summary::-webkit-details-marker { display: none; }

.tools-menu[open] summary {
  border-color: var(--amber);
  color: var(--amber);
}

.tools-menu-body {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
}

.tools-menu-body button {
  background: transparent;
  border: 1px solid transparent;
  height: 30px;
  justify-content: flex-start;
  text-align: left;
  width: 100%;
}

.tools-menu-body button:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--line);
}

/* ============================ Main ============================ */
.main {
  display: grid;
  grid-template-columns: 320px 1fr 260px;
  min-height: 0;
  overflow: hidden;
}

/* ============================ Sidebar ============================ */
.sidebar {
  background: var(--panel-solid);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.stats-bar {
  display: flex;
  height: 4px;
  overflow: hidden;
  width: 100%;
}

.stats-bar span {
  display: block;
  height: 100%;
  transition: flex-basis 240ms ease;
  flex-basis: 0;
  flex-shrink: 0;
  flex-grow: 0;
}

.stats-bar span[data-rating="S"] { background: var(--amber); }
.stats-bar span[data-rating="A"] { background: var(--green); }
.stats-bar span[data-rating="B"] { background: var(--blue); }
.stats-bar span[data-rating="C"] { background: var(--gray); }
.stats-bar span[data-rating="D"] { background: #4a4f48; }
.stats-bar span[data-rating="unrated"] { background: #1f231d; flex-grow: 1; }

.filter-bar {
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 8px;
}

.filter-bar button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  height: 26px;
  padding: 0 8px;
}

.filter-bar button em {
  color: var(--muted-2);
  font-style: normal;
  font-weight: 600;
  margin-left: 4px;
}

.filter-bar button[aria-pressed="true"] {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

.filter-bar button[aria-pressed="true"] em {
  color: var(--amber);
}

.filter-bar button:hover:not([aria-pressed="true"]) {
  border-color: var(--line);
  color: var(--text);
}

.asset-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  outline: none;
  padding: 4px;
  scroll-behavior: smooth;
}

.empty-list {
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
}

.empty-list strong {
  color: var(--text);
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.asset-row {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 8px;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  height: 64px;
  margin: 2px 0;
  padding: 4px 8px 4px 4px;
  text-align: left;
  width: 100%;
}

.asset-row:hover {
  background: var(--panel-2);
}

.asset-row[aria-selected="true"] {
  background: rgba(245, 182, 64, 0.1);
  border-color: rgba(245, 182, 64, 0.55);
}

.asset-row[data-rating-class="D"] {
  filter: grayscale(1) opacity(0.55);
}

.asset-thumb {
  background: #0a0c09;
  border-radius: 4px;
  height: 56px;
  overflow: hidden;
  position: relative;
  width: 56px;
}

.asset-thumb img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.asset-thumb .thumb-fallback {
  align-items: center;
  color: var(--muted-2);
  display: flex;
  font-size: 10px;
  font-weight: 700;
  height: 100%;
  justify-content: center;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  width: 100%;
}

.asset-thumb .thumb-overlay {
  bottom: 2px;
  display: flex;
  gap: 2px;
  left: 2px;
  position: absolute;
}

.thumb-tag {
  background: rgba(0, 0, 0, 0.7);
  border-radius: 3px;
  color: var(--text);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 1px 4px;
  text-transform: uppercase;
}

.thumb-tag[data-tag="live"] {
  background: var(--amber);
  color: var(--ink);
}

.thumb-tag[data-tag="motion"] {
  background: var(--blue);
  color: var(--ink);
}

.thumb-tag[data-tag="video"] {
  background: rgba(0, 0, 0, 0.85);
}

.asset-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.asset-name {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-meta {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-row .rating-pill {
  align-items: center;
  border-radius: 4px;
  display: flex;
  font-size: 11px;
  font-weight: 800;
  height: 22px;
  justify-content: center;
  min-width: 22px;
  padding: 0 6px;
}

.rating-pill[data-rating=""] {
  color: var(--muted-2);
}

.rating-pill[data-rating="S"] { background: var(--amber); color: var(--ink); }
.rating-pill[data-rating="A"] { background: var(--green); color: var(--ink); }
.rating-pill[data-rating="B"] { background: var(--blue); color: var(--ink); }
.rating-pill[data-rating="C"] { background: var(--gray); color: var(--ink); }
.rating-pill[data-rating="D"] { background: #2c322a; color: var(--muted); }

.dirty-dot {
  background: var(--amber);
  border-radius: 50%;
  height: 6px;
  margin-left: 6px;
  width: 6px;
}

/* ============================ Stage ============================ */
.stage {
  background: var(--bg);
  display: grid;
  grid-template-rows: 1fr auto auto auto;
  min-height: 0;
  min-width: 0;
}

.preview-stage {
  align-items: center;
  background: #07080a;
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  position: relative;
}

.motion-play-btn {
  align-items: center;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  bottom: 28px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  gap: 6px;
  height: 34px;
  letter-spacing: 0.6px;
  padding: 0 14px;
  position: absolute;
  right: 28px;
  transition: background 100ms ease, border-color 100ms ease, transform 100ms ease;
  z-index: 4;
}

.motion-play-btn:hover {
  background: rgba(0, 0, 0, 0.85);
  border-color: var(--amber);
  transform: scale(1.04);
}

.motion-play-btn[data-tag="live"]:hover { color: var(--amber); }
.motion-play-btn[data-tag="motion"]:hover { color: var(--blue); border-color: var(--blue); }

.motion-play-icon {
  font-size: 9px;
  line-height: 1;
}

.motion-overlay-video {
  background: #000;
  bottom: 16px;
  cursor: pointer;
  height: calc(100% - 32px);
  left: 16px;
  object-fit: contain;
  outline: none;
  position: absolute;
  right: 16px;
  top: 16px;
  width: calc(100% - 32px);
  z-index: 3;
}

.preview-stage img,
.preview-stage video {
  max-height: 100%;
  max-width: 100%;
  outline: none;
}

.preview-stage img {
  object-fit: contain;
}

.preview-stage video {
  background: #000;
  height: 100%;
  width: 100%;
}

.empty-state,
.fail-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  max-width: 540px;
  padding: 28px 32px;
  text-align: center;
}

.empty-state strong,
.fail-state strong {
  color: var(--text);
  display: block;
  font-size: 16px;
  margin-bottom: 8px;
}

.fail-state {
  border-color: var(--red);
}

.stage-meta {
  align-items: center;
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 10px 18px;
}

.stage-meta .meta-text {
  min-width: 0;
}

.stage-meta h2 {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-meta p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating-badge {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted-2);
  display: flex;
  font-size: 16px;
  font-weight: 800;
  height: 36px;
  justify-content: center;
  min-width: 44px;
  padding: 0 10px;
}

.rating-badge[data-rating="S"] { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.rating-badge[data-rating="A"] { background: var(--green); border-color: var(--green); color: var(--ink); }
.rating-badge[data-rating="B"] { background: var(--blue); border-color: var(--blue); color: var(--ink); }
.rating-badge[data-rating="C"] { background: var(--gray); border-color: var(--gray); color: var(--ink); }
.rating-badge[data-rating="D"] { background: #2c322a; border-color: #3a3f37; color: var(--muted); }

.rating-bar {
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 18px 14px;
}

.rating-bar button {
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 800;
  gap: 2px;
  height: 56px;
  justify-content: center;
  letter-spacing: 0.5px;
  min-width: 84px;
  padding: 6px 0;
  position: relative;
}

.rating-bar button .key {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 600;
}

.rating-bar button[data-rating="S"]:hover,
.rating-bar button[data-rating="S"][data-active="true"] { border-color: var(--amber); color: var(--amber); }
.rating-bar button[data-rating="A"]:hover,
.rating-bar button[data-rating="A"][data-active="true"] { border-color: var(--green); color: var(--green); }
.rating-bar button[data-rating="B"]:hover,
.rating-bar button[data-rating="B"][data-active="true"] { border-color: var(--blue); color: var(--blue); }
.rating-bar button[data-rating="C"]:hover,
.rating-bar button[data-rating="C"][data-active="true"] { border-color: var(--gray); color: var(--gray); }
.rating-bar button[data-rating="D"]:hover,
.rating-bar button[data-rating="D"][data-active="true"] { border-color: #5e6359; color: var(--muted); }

.rating-bar button[data-active="true"] {
  background: rgba(245, 182, 64, 0.05);
  box-shadow: var(--ring);
}

.rating-bar button[data-active="true"][data-rating="S"] .key,
.rating-bar button[data-active="true"][data-rating="A"] .key,
.rating-bar button[data-active="true"][data-rating="B"] .key,
.rating-bar button[data-active="true"][data-rating="C"] .key,
.rating-bar button[data-active="true"][data-rating="D"] .key {
  color: inherit;
}

/* ============================ Log Drawer ============================ */
.log-drawer {
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  bottom: 0;
  box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  height: 200px;
  left: 0;
  position: fixed;
  right: 0;
  z-index: 50;
}

.log-drawer-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
}

.log-drawer-head h2 {
  font-size: 13px;
}

.log-drawer-actions {
  align-items: center;
  display: flex;
  gap: 4px;
}

.icon-btn {
  align-items: center;
  display: inline-flex;
  font-size: 18px;
  font-weight: 400;
  height: 26px;
  justify-content: center;
  line-height: 1;
  min-width: 26px;
  padding: 0;
  width: 26px;
}

.log-list {
  color: var(--muted);
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  list-style: none;
  margin: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px;
}

.log-list li {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 5px 0;
}

.log-time {
  color: var(--amber);
  margin-right: 8px;
}

/* ============================ Video Progress ============================ */
.video-progress {
  align-items: center;
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
  padding: 10px 18px 4px;
}

.progress-input {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  height: 16px;
  margin: 0;
  width: 100%;
}

.progress-input::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    var(--amber) 0%,
    var(--amber) var(--progress-pct, 0%),
    #2c322a var(--progress-pct, 0%),
    #2c322a 100%
  );
  border-radius: 3px;
  height: 6px;
}

.progress-input::-moz-range-track {
  background: #2c322a;
  border-radius: 3px;
  height: 6px;
}

.progress-input::-moz-range-progress {
  background: var(--amber);
  border-radius: 3px;
  height: 6px;
}

.progress-input::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  background: var(--amber);
  border: 2px solid var(--ink);
  border-radius: 50%;
  height: 14px;
  margin-top: -4px;
  width: 14px;
}

.progress-input::-moz-range-thumb {
  background: var(--amber);
  border: 2px solid var(--ink);
  border-radius: 50%;
  height: 14px;
  width: 14px;
}

.progress-info {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  justify-content: space-between;
}

.progress-rate {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--amber);
  font-weight: 700;
  padding: 1px 6px;
}

/* ============================ Detail Panel ============================ */
.detail-panel {
  background: var(--panel-solid);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.detail-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
}

.detail-head h2 {
  font-size: 13px;
}

.detail-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px;
}

.detail-empty {
  color: var(--muted);
  font-size: 12px;
  margin-top: 24px;
  text-align: center;
}

.detail-section {
  border-bottom: 1px solid var(--line-soft);
  padding: 6px 0 8px;
}

.detail-section:last-child {
  border-bottom: none;
}

.detail-section-title {
  color: var(--muted-2);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.detail-row {
  align-items: baseline;
  display: grid;
  gap: 8px;
  grid-template-columns: 64px 1fr;
  padding: 3px 0;
}

.detail-label {
  color: var(--muted);
  font-size: 11px;
}

.detail-value {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
}

.detail-value-strong {
  color: var(--amber);
  font-family: "Avenir Next", "Helvetica Neue", ui-sans-serif, sans-serif;
  font-size: 13px;
  font-weight: 700;
  word-break: break-all;
}

@media (max-width: 1280px) {
  .main {
    grid-template-columns: 320px 1fr;
  }
  .detail-panel {
    display: none;
  }
}

@media (max-width: 1080px) {
  .main {
    grid-template-columns: 280px 1fr;
  }
}
