/* ============================================
   Rate Bridge Cloud - Dark Violet Theme
   ============================================ */

:root {
  --bg: #0f0a1e;
  --surface: #1a1235;
  --primary: #6d28d9;
  --primary-hover: #7c3aed;
  --primary-light: #8b5cf6;
  --secondary: #4c1d95;
  --text: #e2e0ff;
  --text-muted: #9f9cb8;
  --text-dim: #6b6588;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #eab308;
  --info-blue: #3b82f6;
  --border: rgba(109, 40, 217, 0.2);
  --border-solid: #2d2252;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Loading / Init ---- */
#init-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 1.1rem;
  color: var(--text-muted);
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-solid);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ---- Login View ---- */
#login-view {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--primary-light);
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.login-error {
  color: var(--error);
  font-size: 0.85rem;
  margin-bottom: 12px;
  min-height: 20px;
}

/* ---- Forms ---- */
.form-group {
  margin-bottom: 20px;
}

.form-group > label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover), #8b5cf6);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-solid);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(109, 40, 217, 0.1);
  border-color: var(--primary);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

/* ---- Dashboard ---- */
#dashboard-view {
  display: none;
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.3rem;
  color: var(--primary-light);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right .user-email {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title-row .card-title {
  margin-bottom: 0;
}

/* ---- Connection Status ---- */
.connection-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.connection-item {
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.connection-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--error);
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

.connection-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.connection-status {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-left: auto;
}

.connection-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
  padding-left: 18px;
}

/* ---- Calendar ---- */
.calendar-widget {
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.calendar-month {
  font-weight: 600;
  font-size: 0.95rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}

.cal-day-header {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  padding: 4px 0;
  text-transform: uppercase;
}

.cal-day {
  padding: 8px 4px;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.cal-day:hover:not(.past):not(.empty) {
  background: rgba(109, 40, 217, 0.3);
}

.cal-day.today {
  border: 1px solid var(--primary);
  color: var(--primary-light);
}

.cal-day.selected {
  background: var(--primary);
  color: #fff;
}

.cal-day.in-range {
  background: rgba(109, 40, 217, 0.25);
  color: var(--primary-light);
}

.cal-day.past {
  color: var(--text-dim);
  opacity: 0.4;
  cursor: default;
}

.cal-day.empty {
  cursor: default;
}

.nights-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.nights-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.nights-select {
  width: auto;
  min-width: 120px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.nights-select:focus {
  border-color: var(--primary);
}

.selected-dates {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--primary-light);
  font-weight: 500;
}

/* ---- Day of Week Toggles ---- */
.day-toggles {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.day-toggle {
  width: 40px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-solid);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}

.day-toggle.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.day-toggle:hover:not(.active) {
  border-color: var(--primary);
  color: var(--text);
}

.day-quick-buttons {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

/* ---- Hotels Checkbox Grid ---- */
.hotel-select-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.checkbox-label:hover {
  background: rgba(109, 40, 217, 0.08);
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  margin-top: 1px;
  flex-shrink: 0;
}

/* ---- Radio Buttons ---- */
.radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.radio-label input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-solid);
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  flex-shrink: 0;
}

.radio-label input[type="radio"]:checked {
  border-color: var(--primary);
  background: var(--bg);
}

.radio-label input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.radio-label input[type="radio"]:hover {
  border-color: var(--primary);
}

.mode-sub {
  margin-top: 8px;
}

.mode-sub select,
.mode-sub input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.mode-sub select:focus,
.mode-sub input:focus {
  border-color: var(--primary);
}

/* ---- Toggle Switch ---- */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
  display: inline-block;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: 22px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* ---- Schedule Cards ---- */
.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schedule-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: border-color 0.2s;
}

.schedule-card.expanded {
  border-color: var(--primary);
}

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

.schedule-time {
  font-size: 1.05rem;
  font-weight: 600;
  min-width: 85px;
}

.schedule-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
  flex: 1;
  margin: 0 16px;
  line-height: 1.4;
}

.schedule-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Schedule edit panel */
.schedule-edit {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.schedule-card.expanded .schedule-edit {
  display: block;
}

.edit-row {
  margin-bottom: 14px;
}

.edit-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.edit-row select,
.edit-row input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.edit-row select:focus,
.edit-row input[type="number"]:focus {
  border-color: var(--primary);
}

.edit-radio-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.edit-radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
}

.edit-radio-label input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-solid);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.edit-radio-label input[type="radio"]:checked {
  border-color: var(--primary);
}

.edit-radio-label input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.schedule-save-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* ---- Run History Table ---- */
.runs-table-wrapper {
  overflow-x: auto;
}

.runs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.runs-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-solid);
  white-space: nowrap;
}

.runs-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.runs-table tbody tr.run-row {
  cursor: pointer;
  transition: background 0.15s;
}

.runs-table tbody tr.run-row:hover {
  background: rgba(109, 40, 217, 0.08);
}

.runs-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success, .badge-done {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
}

.badge-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--error);
}

.badge-running {
  background: rgba(234, 179, 8, 0.12);
  color: var(--warning);
}

.badge-scraping {
  background: rgba(59, 130, 246, 0.12);
  color: var(--info-blue);
}

.badge-pending {
  background: rgba(107, 101, 136, 0.2);
  color: var(--text-muted);
}

/* Run detail / log expansion */
.run-detail {
  display: none;
}

.run-detail td {
  padding: 0;
}

.run-detail.open {
  display: table-row;
}

.run-logs {
  padding: 12px 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin: 4px 12px 12px;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  line-height: 1.7;
}

.run-logs .log-line {
  display: flex;
  gap: 8px;
}

.run-logs .log-ts {
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.run-logs .log-msg { color: var(--text-muted); }
.run-logs .log-msg.info { color: var(--text-muted); }
.run-logs .log-msg.success { color: var(--success); }
.run-logs .log-msg.error { color: var(--error); }

/* ---- Copy Config Modal/Dropdown ---- */
.copy-config-select {
  margin-top: 8px;
  display: none;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-config-select.visible {
  display: flex;
}

.copy-config-select select {
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border-solid);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .connection-grid {
    grid-template-columns: 1fr;
  }

  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .schedule-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .schedule-summary {
    margin: 4px 0;
    order: 3;
    width: 100%;
  }

  .radio-group {
    flex-direction: column;
    gap: 10px;
  }

  .runs-table {
    font-size: 0.82rem;
  }

  .runs-table th,
  .runs-table td {
    padding: 8px;
  }

  .day-toggles {
    gap: 4px;
  }

  .day-toggle {
    width: 36px;
    height: 30px;
    font-size: 0.72rem;
  }
}
