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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22262f;
  --border: #2a2e3a;
  --text: #e4e6eb;
  --text-muted: #8b8fa3;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --danger: #e5484d;
  --danger-hover: #f07178;
  --success: #30a46c;
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

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

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}
.header-nav { display: flex; gap: 12px; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* Login */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 16px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.login-box h1 {
  font-size: 1.25rem;
  margin-bottom: 24px;
  text-align: center;
}
.login-box input {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 16px;
}
.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}
.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 12px;
  display: none;
}

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 24px;
}
.upload-area:hover, .upload-area.dragover {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.05);
}
.upload-area p { color: var(--text-muted); margin-top: 8px; font-size: 0.9rem; }
.upload-area .upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-area input[type="file"] { display: none; }

/* Upload queue */
.upload-queue { display: flex; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.upload-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.upload-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.upload-item-name {
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 8px;
}
.upload-item-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.upload-item-status.complete { color: var(--success); }
.upload-item-status.failed { color: var(--danger); }
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}
.progress-bar-fill.complete { background: var(--success); }

/* Cleanup */
.cleanup-btn {
  margin-top: 16px;
}
.cleanup-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  min-height: 1.2em;
}

/* Keep alive notice */
.notice {
  background: rgba(79, 140, 255, 0.1);
  border: 1px solid rgba(79, 140, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 20px;
}

/* Session list */
.sessions-list { display: flex; flex-direction: column; gap: 12px; }
.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.session-card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}
.session-thumb {
  width: 100px;
  height: 68px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}
.session-info { flex: 1; min-width: 0; }
.session-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

/* Session detail */
.session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.session-title-group { flex: 1; min-width: 0; }
.session-title {
  font-size: 1.2rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.session-title-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.session-actions { display: flex; gap: 8px; flex-shrink: 0; }

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.video-thumb-wrapper {
  position: relative;
  aspect-ratio: 16/9;
  background: var(--border);
}
.video-thumb-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.video-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 3px;
}
.video-info { padding: 10px; }
.video-name {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.video-actions { display: flex; gap: 6px; }

/* Editable name */
.editable-name {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.editable-name:hover { border-color: var(--border); }
.edit-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font-size: inherit;
  font-family: inherit;
  font-weight: inherit;
  padding: 2px 4px;
  width: 100%;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state p { margin-top: 8px; font-size: 0.9rem; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--text); }

/* Responsive */
@media (max-width: 600px) {
  .session-card { flex-direction: column; gap: 10px; }
  .session-thumb { width: 100%; height: 160px; }
  .video-grid { grid-template-columns: 1fr; }
  .session-header { flex-direction: column; }
  .upload-area { padding: 28px 16px; }
}

/* Version label */
.version-label {
  position: fixed;
  bottom: 6px;
  right: 10px;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.4;
  pointer-events: none;
}

/* Deliveries */
.deliveries-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}
.deliveries-list { display: flex; flex-direction: column; gap: 12px; }
.delivery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.delivery-card:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}
.delivery-thumb-wrapper {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--border);
}
.delivery-thumb-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.delivery-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
}
.delivery-thumb-placeholder.large {
  width: 200px;
  height: 200px;
  font-size: 2rem;
}
.delivery-info { flex: 1; min-width: 0; }
.delivery-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.delivery-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-bottom: 2px;
}
.delivery-platform {
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 500;
}
.delivery-post-link {
  font-size: 0.8rem;
  margin-top: 4px;
  display: inline-block;
}

/* Delivery form */
.delivery-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
}
.delivery-form label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: -6px;
}
.form-heading {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.form-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}
.form-input:focus { outline: none; border-color: var(--accent); }
textarea.form-input { resize: vertical; }
select.form-input { appearance: auto; }
.time-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.time-input-row span {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.time-input {
  width: 70px;
}
.file-pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-pick-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-pick-btn { cursor: pointer; }

/* Delivery detail */
.delivery-detail {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.delivery-detail-thumb {
  flex-shrink: 0;
}
.delivery-detail-thumb img {
  width: 200px;
  border-radius: var(--radius);
  object-fit: cover;
}
.delivery-detail-fields {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.delivery-detail-fields label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: -6px;
}
.delivery-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.delivery-detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Session deliveries section */
.session-deliveries-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.section-heading {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Time summary */
.time-summary {
  background: rgba(48, 164, 108, 0.1);
  border: 1px solid rgba(48, 164, 108, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.time-summary strong {
  color: var(--success);
}
.time-summary-entry {
  color: var(--text);
}

/* Confirm dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 380px;
  width: 100%;
}
.modal-box p { margin-bottom: 20px; font-size: 0.9rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
