:root {
  --primary: #2c5f4f;
  --primary-hover: #3a7861;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #f9f9f9;
  --text: #1d2b26;
  --muted: #6b7770;
  --danger: #c0392b;
  --danger-hover: #a93226;
  --ok: #2c5f4f;
  --border: #e0e0e0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand img { height: 75px; width: auto; display: block; }

.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.01em;
}
.tagline { color: var(--muted); margin: 0; font-size: 0.85rem; }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

.card, .recorder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

input[type="text"], input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 4px;
  font-size: 0.95rem;
  flex: 1 1 200px;
  min-width: 160px;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(44, 95, 79, 0.15);
}

button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
button.ghost { background: transparent; }

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  color: var(--muted);
  margin-left: auto;
}

.status {
  margin: 0.85rem 0 0;
  color: var(--muted);
  min-height: 1.2em;
  font-size: 0.9rem;
}
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

.progress {
  margin-top: 0.75rem;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
}
.progress[hidden] { display: none; }
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 5px 0 0 5px;
  transition: width 0.15s ease;
}

.retry-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.85rem; }
.retry-row[hidden] { display: none; }

#preview {
  width: 100%;
  margin-top: 1rem;
  border-radius: 6px;
  background: #000;
  max-height: 300px;
  object-fit: contain;
}

#player {
  width: 100%;
  max-width: 100%;
  margin-top: 1rem;
  border-radius: 6px;
  background: #000;
  max-height: 70vh;
  object-fit: contain;
}

.gallery { margin-top: 2rem; }
.gallery h2 { font-size: 1.2rem; color: var(--primary); }
.empty { color: var(--muted); }

.gallery-search {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.gallery-search input[type="search"] { flex: 1 1 200px; }
.gallery-search input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  font-size: 0.9rem;
}
.gallery-search button { flex: 0 0 auto; }

/* ~4 columns on a wide desktop; collapses down gracefully on narrow screens. */
#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}

.rec-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-size: 0.85rem;
}
.rec-card video { width: 100%; display: block; background: #000; max-height: 160px; object-fit: contain; }
.rec-body { padding: 0.75rem; }

.rec-title-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0 0 0.25rem; }
.rec-title {
  font-weight: 600;
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
  border-radius: 3px;
  padding: 0.05rem 0.2rem;
  margin-left: -0.2rem;
}
.rec-title:hover { background: var(--surface-2); }
.rec-title.editing {
  background: var(--surface-2);
  outline: 1px solid var(--primary);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  cursor: text;
}
.rec-title-row .edit-title-btn { padding: 0.15rem 0.4rem; font-size: 0.72rem; }
.rec-meta { color: var(--muted); font-size: 0.78rem; margin: 0 0 0.6rem; }

.share-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.share-row input { flex: 1 1 240px; }
.share-link {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  font-size: 0.82rem;
  color: var(--primary);
  flex: 1 1 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.locked { color: var(--danger); border-color: var(--danger); }
.badge.open { color: var(--primary); border-color: var(--primary); }

.rec-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.rec-actions button { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
small.hint { color: var(--muted); display: block; margin-top: 0.4rem; }

/* ---------- share modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; color: var(--primary); }
.modal-close {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.15rem 0.4rem;
}
.modal-close:hover { color: var(--text); }

/* ---------- player / annotations ---------- */
/* The guest watch page uses the full viewport width (the owner gallery stays
   at the default 880px). */
.watch-page main { max-width: 1400px; }
.watch-page .player-wrap video { max-height: 80vh; object-fit: contain; }

/* Two-column: player on the left, notes panel on the right. */
.player-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.25rem;
  align-items: start;
}
.player-main { min-width: 0; }
.notes-panel {
  border-left: 1px solid var(--border);
  padding-left: 1.25rem;
  min-width: 0;
}
.notes-panel h4 { margin: 0 0 0.6rem; color: var(--primary); font-size: 0.95rem; }
.notes-panel .note-list { max-height: 60vh; overflow-y: auto; }
@media (max-width: 680px) {
  .player-layout { grid-template-columns: 1fr; }
  .notes-panel { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 1rem; }
}

.player-wrap { position: relative; line-height: 0; }
.player-wrap video { display: block; width: 100%; border-radius: 6px; background: #000; }
.ann-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.ann-overlay.drawing { pointer-events: auto; cursor: crosshair; }
.ann-box { fill: rgba(44, 95, 79, 0.12); stroke: #ffcc00; stroke-width: 3; }
.ann-pen { fill: none; stroke: #ffcc00; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ann-text {
  fill: #ffcc00;
  font: 700 5px -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.7);
  stroke-width: 1.2px;
}

.note-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.4rem; }
.note-item {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border-left: 3px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.note-item.active {
  background: rgba(255, 204, 0, 0.16);
  border-left-color: #ffcc00;
}
.note-item.active .note-ts { background: #ffcc00; border-color: #ffcc00; color: #1d2b26; }
.note-ts {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--primary);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.note-del { margin-left: auto; background: transparent; border: none; color: var(--muted); cursor: pointer; }
.note-del:hover { color: var(--danger); }

/* editor toolbar */
.editor-tools { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin: 0.75rem 0; }
.editor-tools .tool.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.editor-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.editor-section h4 { margin: 0 0 0.5rem; color: var(--primary); font-size: 0.95rem; }
.trim-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.trim-row .timecode { font-variant-numeric: tabular-nums; color: var(--muted); }
.add-note-row { display: flex; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; align-items: center; }
.add-note-row input { flex: 1 1 120px; min-width: 0; }
.add-note-row .timecode { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.8rem; }
.notes-panel .add-note-row button { flex: 0 0 auto; padding: 0.4rem 0.7rem; }
.toggle-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.75rem; font-size: 0.9rem; }
