@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg: #f4f8fb;
  --text: #0f172a;
  --muted-text: #64748b;
  --surface: #ffffff;
  --surface-border: #d7e2ea;
  --surface-soft: #eef4f7;
  --primary: #4ecdc4;
  --primary-deep: #1a8a82;
  --slate-strong: #0f172a;
  --danger: #dc2626;
  --status-ok: #0f766e;
  --status-error: #b91c1c;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --grid-line: rgba(148, 163, 184, 0.08);
  --body-glow-a: #d7f5f2;
  --body-glow-b: #dff4ff;
  --body-fill-a: #f7fafc;
  --body-fill-b: #eff4f8;
}

.theme-dark {
  --bg: #020617;
  --text: #e2e8f0;
  --muted-text: #94a3b8;
  --surface: #0f172a;
  --surface-border: #334155;
  --surface-soft: #111c30;
  --primary: #4ecdc4;
  --primary-deep: #1a8a82;
  --slate-strong: #0f172a;
  --danger: #ef4444;
  --status-ok: #7dd3fc;
  --status-error: #fca5a5;
  --input-bg: #0b1324;
  --input-border: #334155;
  --grid-line: rgba(148, 163, 184, 0.1);
  --body-glow-a: #11233a;
  --body-glow-b: #143043;
  --body-fill-a: #020617;
  --body-fill-b: #0b1220;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 10%, var(--body-glow-a) 0%, transparent 42%),
    radial-gradient(circle at 86% 6%, var(--body-glow-b) 0%, transparent 38%),
    linear-gradient(160deg, var(--body-fill-a) 0%, var(--body-fill-b) 100%);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black 38%, transparent 92%);
  z-index: -1;
}

h1,
h2,
h3,
.timer,
.timer-badge {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
  animation: rise-in 0.45s ease both;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1,
h2 {
  margin-top: 0;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.5rem;
}

.tab-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--slate-strong), #1e293b);
  color: #e2e8f0;
  border-color: #1e293b;
  box-shadow: inset 0 0 0 1px rgba(78, 205, 196, 0.35);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.admin-page .grid {
  align-items: start;
}

.admin-page .card h2 {
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 1.05rem;
  color: #1e293b;
}

.theme-dark .admin-page .card h2 {
  color: #dbeafe;
}

.header-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.header-actions .btn-danger,
.header-actions .theme-toggle {
  width: auto;
  min-width: 120px;
}

label {
  display: block;
  margin-bottom: 0.4rem;
}

input,
textarea,
button,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  padding: 0.7rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--input-bg);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.2);
}

button {
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #38b2ab);
  color: #062e2b;
  font-weight: 700;
}

.theme-toggle {
  width: auto;
  border: 1px solid var(--surface-border);
  background: linear-gradient(135deg, var(--surface-soft), #dceaf0);
  color: var(--text);
  font-weight: 700;
  padding: 0.62rem 0.85rem;
  border-radius: 999px;
}

.theme-dark .theme-toggle {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  border-color: #334155;
  color: #e2e8f0;
}

.btn-alt {
  background: linear-gradient(135deg, var(--slate-strong), #1e293b);
  color: #e2e8f0;
  font-weight: 700;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, var(--danger));
  color: #fff;
  font-weight: 700;
}

.timer {
  font-size: clamp(2.5rem, 8vw, 7rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
}

.status {
  text-align: center;
  margin-top: 0.5rem;
  color: var(--muted-text);
}

.status.error {
  color: var(--status-error);
}

.cells-editor {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
}

.cell-card {
  border: 1px solid #d6e2ea;
  border-radius: 12px;
  padding: 0.55rem;
  background: linear-gradient(180deg, #f9fcff, #eef4f8);
  display: grid;
  gap: 0.45rem;
}

.theme-dark .cell-card {
  background: linear-gradient(180deg, #101b2e, #0f172a);
}

.cell-card-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.25);
}

.cell-card.dragging {
  opacity: 0.55;
}

.media-list {
  display: grid;
  gap: 0.5rem;
}

.media-item {
  border: 1px solid #d6e2ea;
  border-radius: 10px;
  padding: 0.5rem;
  background: #f7fbfd;
  display: grid;
  gap: 0.45rem;
}

.theme-dark .media-item {
  background: #101b2e;
}

.media-item .btn-alt,
.media-item .btn-primary {
  padding: 0.55rem;
}

.folder-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.folder-tab {
  width: auto;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  font-weight: 700;
}

.theme-dark .folder-tab {
  background: #0b1324;
  color: #cbd5e1;
}

.folder-tab.active {
  background: linear-gradient(135deg, var(--primary), #3dbeb5);
  color: #073a37;
  border-color: #36b6ad;
  box-shadow: 0 0 0 1px rgba(78, 205, 196, 0.4);
}

.display-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 1rem;
  padding: 1rem;
}

.display-shell .card {
  background: linear-gradient(160deg, rgba(15, 23, 42, 0.94), rgba(30, 41, 59, 0.92));
  border-color: rgba(148, 163, 184, 0.35);
  color: #f8fafc;
}

.display-shell .meta {
  color: #cbd5e1;
}

.video-wrap {
  position: relative;
  min-height: 70vh;
  padding: 0.4rem;
  overflow: hidden;
}

.preview-shell {
  position: relative;
  min-height: 500px;
  border-radius: 14px;
  border: 1px solid #d6e2ea;
  background: radial-gradient(circle at 14% 14%, #e9f7f6 0%, #eef4f8 52%);
  padding: 0.4rem;
  overflow: hidden;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.preview-toolbar {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
}

.theme-dark .preview-shell {
  border-color: #334155;
  background: radial-gradient(circle at 14% 14%, #122335 0%, #0b1220 52%);
}

.preview-shell .video-grid {
  min-height: 490px;
}

.video-grid {
  width: 100%;
  height: 100%;
  min-height: 68vh;
  display: grid;
  gap: 0.5rem;
}

.video-cell {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  background: #0b1220;
}

.preview-cell {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.preview-cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 30px rgba(15, 23, 42, 0.15);
}

.preview-cell-active {
  border-color: rgba(78, 205, 196, 0.95);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.2), 0 18px 34px rgba(15, 23, 42, 0.18);
}

.preview-empty-state {
  width: 100%;
  height: 100%;
  min-height: 180px;
  display: grid;
  place-items: center;
  color: rgba(226, 232, 240, 0.9);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.75), rgba(30, 41, 59, 0.4));
}

.video-cell video {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
}

.cell-label {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  background: rgba(15, 23, 42, 0.76);
  border: 1px solid rgba(78, 205, 196, 0.45);
  color: #f8fafc;
  border-radius: 8px;
  padding: 0.2rem 0.48rem;
  font-size: 0.88rem;
  font-weight: 700;
}

.preview-editable {
  cursor: text;
  min-width: 48px;
}

.preview-editable:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.28);
}

.preview-cell-meta {
  position: absolute;
  left: 0.6rem;
  bottom: 0.6rem;
  z-index: 1;
  color: rgba(226, 232, 240, 0.9);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: #000;
}

.timer-overlay {
  --timer-scale: 1;
  position: absolute;
  z-index: 2;
  padding: 0.85rem 1rem;
  border: 2px solid rgba(78, 205, 196, 0.72);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.86), rgba(30, 41, 59, 0.66));
  backdrop-filter: blur(6px);
  transform-origin: center;
  transform: scale(var(--timer-scale));
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.35);
}

.timer-badge {
  display: inline-block;
  margin: 0 auto 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timer-overlay .timer {
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 1;
}

.timer-overlay .status {
  font-weight: 600;
  color: inherit;
}

.logo-overlay {
  position: absolute;
  z-index: 3;
  max-width: 140px;
  max-height: 70px;
  object-fit: contain;
  padding: 0.3rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(78, 205, 196, 0.42);
}

.logo-handle {
  min-width: 140px;
  min-height: 70px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
}

.logo-handle.dragging {
  cursor: grabbing;
}

.logo-handle img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-placeholder {
  display: none;
  width: 100%;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #dbeafe;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.logo-handle.is-empty {
  border-style: dashed;
  background: rgba(15, 23, 42, 0.6);
}

.bottom-link {
  position: absolute;
  z-index: 3;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0.9rem;
  max-width: calc(100% - 2rem);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  color: #e2e8f0;
  text-decoration: none;
  border: 1px solid rgba(78, 205, 196, 0.42);
  background: rgba(15, 23, 42, 0.72);
  border-radius: 999px;
  padding: 0.36rem 0.75rem;
  font-size: 0.88rem;
  align-items: center;
  justify-content: center;
}

.bottom-link:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.28);
}

.pos-top-left {
  top: 1rem;
  left: 1rem;
}

.pos-top-right {
  top: 1rem;
  right: 1rem;
}

.pos-bottom-left {
  left: 1rem;
  bottom: 1rem;
}

.pos-bottom-right {
  right: 1rem;
  bottom: 1rem;
}

.pos-center {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(var(--timer-scale));
}

.meta {
  font-size: 0.95rem;
  color: var(--muted-text);
}

.segment-row {
  display: grid;
  grid-template-columns: 42px minmax(170px, 2fr) minmax(70px, 1fr) 72px repeat(4, 46px);
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.segment-row .segment-palette {
  grid-column: 1 / -1;
}

.segment-drag-handle {
  font-weight: 800;
  letter-spacing: 0.12em;
}

.segment-row.segment-dragging {
  opacity: 0.55;
}

.segment-row.segment-drop-target {
  outline: 2px dashed rgba(78, 205, 196, 0.55);
  outline-offset: 2px;
}

.segment-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin-top: 0.2rem;
}

.segment-swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  padding: 0;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.3);
}

.segment-swatch.active {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.28);
}

.theme-dark .segment-swatch.active {
  border-color: #e2e8f0;
}

.timer-presets-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

.timer-presets-actions,
.timer-editor-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.cell-card.drop-target {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.25);
}

.preview-cell.drop-target,
.logo-handle.drop-target {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.3);
}

.media-card {
  position: relative;
}

.media-controls-row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}
.media-search-input {
  min-width: 180px;
  max-width: 260px;
  flex: 1 1 180px;
}
.media-sort-select {
  min-width: 120px;
  max-width: 180px;
  flex: 0 0 120px;
}
.media-delete-btn {
  margin-left: 0.5rem;
  min-width: 80px;
}

.media-preview {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #0b1220;
  border: 1px solid rgba(148, 163, 184, 0.3);
  min-height: 140px;
}

.media-preview-video,
.media-preview-image {
  width: 100%;
  height: 170px;
  display: block;
  border: none;
  border-radius: 0;
  object-fit: cover;
  background: #020617;
}

.media-rename-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  gap: 0.45rem;
  align-items: center;
}

.media-ext-tag {
  width: auto;
  padding: 0.45rem 0.58rem;
  border-radius: 8px;
  border: 1px solid var(--input-border);
  background: var(--surface-soft);
  color: var(--muted-text);
  font-size: 0.8rem;
  font-weight: 700;
}

.media-pill {
  width: fit-content;
  max-width: 100%;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(78, 205, 196, 0.18);
  color: var(--text);
  border: 1px solid rgba(78, 205, 196, 0.35);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1rem;
  align-items: stretch;
}

.login-brand {
  display: grid;
  align-content: center;
  gap: 0.8rem;
  padding: 1.4rem;
  background: linear-gradient(150deg, var(--slate-strong), #1e293b);
  color: #e2e8f0;
}

.login-brand .meta {
  color: #94a3b8;
}

.brand-mark {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #37b4ac);
  color: #042928;
  box-shadow: 0 14px 28px rgba(2, 6, 23, 0.35);
}

.login-highlights {
  margin: 0.6rem 0 0;
  padding-left: 1.2rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.login-card {
  align-self: center;
  max-width: 460px;
  width: 100%;
  justify-self: end;
}

.login-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.3rem;
}

.login-head h2 {
  margin: 0;
}

.display-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.display-footer-row .theme-toggle {
  min-width: 120px;
}

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

  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-card {
    max-width: 100%;
    justify-self: stretch;
  }

  .segment-row {
    grid-template-columns: 36px 1fr 1fr 82px repeat(4, 40px);
  }

  .timer-presets-head,
  .timer-presets-actions,
  .timer-editor-actions {
    grid-template-columns: 1fr;
  }

  .media-rename-row {
    grid-template-columns: 1fr;
  }

  .media-preview-video,
  .media-preview-image {
    height: 150px;
  }

  .preview-shell {
    min-height: 380px;
  }

  .preview-toolbar {
    grid-template-columns: 1fr;
  }

  .preview-shell .video-grid {
    min-height: 360px;
  }
}

@media (max-width: 700px) {
  .page {
    padding: 0.8rem;
  }

  .display-shell {
    padding: 0.6rem;
  }

  .logo-overlay {
    max-width: 110px;
    max-height: 55px;
  }

  .segment-row {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .btn-danger,
  .header-actions .theme-toggle {
    width: 100%;
  }
}
