:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0f766e;
  --accent-2: #0e9f6e;
  --border: #d1d5db;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(1200px 600px at 0% -10%, #e5f6f2 0%, rgba(229, 246, 242, 0) 60%),
    radial-gradient(900px 420px at 100% 0%, #eef4ff 0%, rgba(238, 244, 255, 0) 58%),
    linear-gradient(180deg, #edf2f9 0%, var(--bg) 100%);
  color: var(--text);
  overflow-x: hidden;
  width: 100%;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
}

header h1 {
  margin-bottom: 0.25rem;
}

header p {
  margin-top: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.05);
}

.ribbon-card {
  background: linear-gradient(135deg, #f8fcfb 0%, #f5f9ff 100%);
  border: 1px solid #d5e4ea;
  border-radius: 12px;
  height: 76px;
  overflow: hidden;
  position: relative;
}

.ribbon-title {
  position: absolute;
  left: 0.85rem;
  top: 0.6rem;
  z-index: 2;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1f2937;
}

.ribbon-wave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.ribbon-wave path {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.6;
}

.ribbon-wave path:nth-child(1) {
  stroke: rgba(15, 118, 110, 0.5);
}

.ribbon-wave path:nth-child(2) {
  stroke: rgba(37, 99, 235, 0.44);
}

.ribbon-wave path:nth-child(3) {
  stroke: rgba(14, 159, 110, 0.34);
}

h2 {
  margin-top: 0;
}

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

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.95rem;
  min-width: 0;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

optgroup {
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  padding-top: 0.5rem;
}

optgroup option {
  font-weight: normal;
  color: var(--text);
  background: var(--surface);
}

.actions,
.timer-row {
  margin-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
}

button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

#syncBtn {
  background: var(--accent-2);
}

.video-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.video-link.disabled {
  color: var(--muted);
  pointer-events: none;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.time {
  font-size: 1.4rem;
  font-weight: 700;
}

.label,
.muted {
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: 0.75rem;
}

.history-footer-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.deployment-info {
  padding: 1rem;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.03) 0%, rgba(14, 159, 110, 0.03) 100%);
}

.deploy-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  font-family: monospace;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.badge-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-label {
  color: var(--muted, #666);
  font-weight: 600;
}

#commit-badge {
  color: #0369a1;
  text-decoration: none;
  padding: 1px 5px;
  background: #e0f2fe;
  border-radius: 3px;
}

#commit-badge:hover { background: #bae6fd; }

.badge-status {
  padding: 1px 5px;
  border-radius: 3px;
}

.status-success { color: #166534; background: #dcfce7; }
.status-failed  { color: #991b1b; background: #fee2e2; }
.status-running { color: #854d0e; background: #fef9c3; }
.status-unknown { color: #374151; background: #f3f4f6; }

.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: #fcfdfd;
}

.history-item h3 {
  margin: 0 0 0.45rem;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.45rem;
}

.delete-history-btn {
  background: #b91c1c;
}

ul {
  margin: 0;
  padding-left: 1.15rem;
}

.remove-btn {
  background: #b91c1c;
}

/* Pull to Refresh Styles */
.pull-to-refresh {
  position: fixed;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease-out;
  z-index: 100;
}

.pull-to-refresh.visible {
  transform: translateY(60px);
}

.pull-to-refresh-spinner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  font-size: 0.9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Video Library Styles */
.video-input-group {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.video-input-group label {
  flex: 1;
  margin-bottom: 0;
}

.video-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.video-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  position: relative;
}

.video-thumbnail {
  width: 100%;
  height: 180px;
  object-fit: cover;
  cursor: pointer;
}

.video-info {
  padding: 0.75rem;
}

.video-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
  line-height: 1.3;
}

.video-description {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-url {
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

.video-delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(185, 28, 28, 0.9);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.video-item:hover .video-delete-btn {
  opacity: 1;
}

.video-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.video-modal.active {
  display: flex;
}

.video-modal-content {
  background: black;
  border-radius: 8px;
  overflow: hidden;
  max-width: 90%;
  max-height: 90%;
  position: relative;
}

.video-modal iframe {
  width: 560px;
  height: 315px;
  border: none;
  display: block;
}

.video-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: white;
  border: none;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 720px) {
  .container {
    padding: 0.5rem;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .card {
    padding: 0.5rem;
  }

  .history-footer-actions {
    justify-content: center;
  }

  .deploy-badges {
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
  }

  #exportCsvBtn {
    order: 1;
  }

  /* Fix table width on mobile */
  table {
    min-width: 0;
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.35rem;
  }

  /* Adjust grid for mobile */
  .grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  /* Adjust buttons for mobile */
  .actions, .timer-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .timer-actions {
    display: flex;
    gap: 0.5rem;
  }

  .timer-actions button {
    flex: 1;
  }

  /* Adjust ribbon card for mobile */
  .ribbon-card {
    height: 60px;
  }

  .ribbon-title {
    font-size: 0.85rem;
    top: 0.4rem;
    left: 0.5rem;
  }
}

/* Extra small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
  .container {
    padding: 0.4rem;
  }

  .card {
    padding: 0.4rem;
  }

  table {
    font-size: 0.75rem;
  }

  th, td {
    padding: 0.25rem;
  }

  .ribbon-title {
    font-size: 0.75rem;
  }

  h2 {
    font-size: 1.1rem;
  }

  button {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Video library mobile styles */
  .video-input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .video-library-grid {
    grid-template-columns: 1fr;
  }

  .video-modal iframe {
    width: 100%;
    height: 200px;
  }
}
