/* KSC-Lapse Client Portal */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0d0d0d;
  --card: #1a1a1a;
  --surface: #262626;
  --accent: #0ea5e9;
  --accent-dark: #0284c7;
  --accent-glow: rgba(14,165,233,0.15);
  --text-primary: #e8e8e8;
  --text-secondary: #999999;
  --text-muted: #666666;
  --border: #2a2a2a;
  --border-focus: #0ea5e9;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --card-radius: 8px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.65);
  --transition: 0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Auth overlay ─────────────────────────────────────── */

#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.auth-logo {
  display: flex;
  justify-content: center;
}

.auth-logo img {
  height: 48px;
  object-fit: contain;
}

.auth-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-primary);
}

.auth-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ── Form elements ────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

input[type="password"],
input[type="text"],
input[type="date"],
input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  color-scheme: dark;
}

input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--card-radius);
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #333333; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
}

.btn-full { width: 100%; }

.error-msg {
  color: var(--danger);
  font-size: 0.8125rem;
  text-align: center;
}

/* ── Site header ──────────────────────────────────────── */

#site-header {
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: relative;
}

.header-logo a {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.header-logo img {
  height: 36px;
  object-fit: contain;
}

.header-project-name {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 280px);
  pointer-events: none;
}


/* ── Main layout ──────────────────────────────────────── */

#main-content {
  flex: 1;
  display: none;
  flex-direction: column;
}

#main-content.visible { display: flex; }

/* ── Frame section ────────────────────────────────────── */

#frame-section {
  background: #000;
  width: 100%;
}

#frame-img-wrap {
  position: relative;
  width: 100%;
  height: calc(min(75vh, 75vw) - 100px);
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame-img {
  display: none;
  max-width: 100%;
  max-height: 100%;
  cursor: zoom-in;
  position: relative;
  z-index: 2;
}

.frame-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.875rem;
  background: #000;
  z-index: 1;
}

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: #555;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.frame-overlay {
  position: absolute;
  bottom: 12px;
  left: 16px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.8125rem;
  padding: 4px 10px;
  border-radius: 4px;
  display: none;
  pointer-events: none;
  z-index: 3;
}

.frame-overlay.visible { display: block; }

/* Fullscreen button — top-right */
.fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: rgba(255,255,255,0.8);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background var(--transition), opacity var(--transition);
  z-index: 3;
  opacity: 0;
}

#frame-img-wrap:hover .fullscreen-btn { opacity: 1; }
.fullscreen-btn:hover { background: rgba(0,0,0,0.88); color: #fff; }

/* Frame download button — bottom-right, hover to show */
.frame-download-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.65);
  color: rgba(255,255,255,0.9);
  border: none;
  border-radius: 20px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  z-index: 3;
}

#frame-img-wrap:hover .frame-download-btn { opacity: 1; }
.frame-download-btn:hover { background: rgba(14,165,233,0.85); color: #fff; }

/* Always show on touch */
@media (hover: none) {
  .frame-download-btn,
  .fullscreen-btn { opacity: 1; }
}

/* ── Scrubber section ─────────────────────────────────── */

#scrubber-section {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
}

.scrubber-inner {
  max-width: 1600px;
  margin: 0 auto;
}

.scrubber-meta {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.scrubber-track-wrap {
  position: relative;
  padding: 12px 0;
}

.scrubber-milestones {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 12px;
  pointer-events: none;
}

.milestone-marker {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: all;
  cursor: pointer;
}

.milestone-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--card);
  box-shadow: var(--shadow-sm);
}

.milestone-label {
  position: absolute;
  top: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
  z-index: 10;
}

.milestone-marker:hover .milestone-label { opacity: 1; }

#scrubber-input {
  width: 100%;
  margin-top: 4px;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

.scrubber-dates {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.scrubber-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.scrubber-controls .frame-datetime {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 220px;
  text-align: center;
}

/* Share button in scrubber */
.share-btn-wrap {
  position: relative;
  display: inline-flex;
}

.share-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.share-tooltip.visible { opacity: 1; }

/* ── Content below scrubber ───────────────────────────── */

#portal-body {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
}

@media (max-width: 900px) {
  #portal-body { grid-template-columns: 1fr; }
}

/* ── Milestones sidebar ───────────────────────────────── */

.milestones-sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-header .toggle-icon {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.milestones-sidebar.collapsed .sidebar-header .toggle-icon { transform: rotate(-90deg); }
.milestones-sidebar.collapsed .sidebar-body { display: none; }

.sidebar-body {
  max-height: 400px;
  overflow-y: auto;
}

.milestone-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.milestone-item:last-child { border-bottom: none; }
.milestone-item:hover { background: var(--surface); }

.milestone-item-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
}

.milestone-item-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Download section ─────────────────────────────────── */

.project-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.download-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}

.download-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.download-count-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  min-height: 1.2em;
}

.download-count-label.zero { color: var(--text-muted); }

.date-range-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.date-range-row .form-group { flex: 1; }

.embed-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
  display: none;
}

.embed-section.visible { display: block; }

.embed-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.embed-code-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 10px;
  display: none;
}

.embed-code-box.visible { display: block; }

/* ── Lightbox ─────────────────────────────────────────── */

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.96);
  z-index: 900;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

#lightbox.open { display: flex; }

#lightbox-img {
  max-width: 95vw;
  max-height: 82vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 18px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  color: rgba(255,255,255,0.8);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.lightbox-close:hover { background: rgba(255,255,255,0.15); color: #fff; }

.lightbox-caption {
  margin-top: 12px;
  color: rgba(255,255,255,0.5);
  font-size: 0.8125rem;
  text-align: center;
  pointer-events: none;
}

.lightbox-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
}

.lightbox-download-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
}

.lightbox-download-btn:hover { background: var(--accent-dark); }
.lightbox-download-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Loading states ───────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0;
  transition: width 0.3s ease;
  z-index: 9999;
}

/* ── Toast notifications ──────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { background: var(--success); color: #fff; border-color: transparent; }
.toast.error { background: var(--danger); color: #fff; border-color: transparent; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Download progress ────────────────────────────────── */

.download-progress {
  margin-top: 12px;
  display: none;
}

.download-progress.visible { display: block; }

.download-progress-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.5;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0%;
}

.download-complete-msg {
  font-size: 0.8125rem;
  color: var(--success);
  margin-top: 8px;
  display: none;
  font-weight: 500;
}

.download-complete-msg.visible { display: block; }

/* ── Site footer ──────────────────────────────────────── */

#site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  background: var(--card);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.footer-logo-link img {
  height: 32px;
  object-fit: contain;
}

.footer-divider {
  color: var(--border);
}

#site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}
#site-footer a:hover { color: var(--text-primary); }

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 640px) {
  .auth-card { padding: 28px 20px; }
  #portal-body { padding: 16px; }
  .date-range-row { flex-direction: column; }
  #scrubber-section { padding: 14px 16px; }

  .header-inner { padding: 0 16px; }

  .scrubber-controls .frame-datetime { min-width: 0; font-size: 0.875rem; }

  .lightbox-actions { flex-direction: column; align-items: center; }
}

@media (max-width: 480px) {
  .scrubber-controls { gap: 8px; }
  .header-project-name { display: none; }
}
