/* ─── Matchbox Corporate-Modern Theme ─────────────────────────────────────── */

:root {
  --primary: #DC2626;
  --primary-hover: #B91C1C;
  --primary-light: rgba(220, 38, 38, 0.08);
  --bg: #F8FAFC;
  --card-bg: #FFFFFF;
  --text: #1e293b;
  --text-secondary: #334155;
  --text-muted: #64748B;
  --green: #22C55E;
  --green-light: #DCFCE7;
  --destructive: #DC2626;
  --separator: #E2E8F0;
  --border: #D1D5DB;
  --highlight-bg: #F1F5F9;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */

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

[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Oxygen-Sans', Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ─── App Layout ─────────────────────────────────────────────────────────── */

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 0 0 32px;
}

/* ─── Navigation Bar ─────────────────────────────────────────────────────── */

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 10;
  border-bottom: 1px solid var(--separator);
  box-shadow: var(--shadow-sm);
}

.nav-left {
  width: 44px;
}

.nav-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.nav-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
  box-shadow: var(--shadow-sm);
}

.nav-btn:hover { background: var(--primary-hover); }
.nav-btn:active { background: var(--primary-hover); }

/* ─── Job List ───────────────────────────────────────────────────────────── */

.ios-list {
  margin: 16px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* ─── Job Row ────────────────────────────────────────────────────────────── */

.job-row {
  position: relative;
  overflow: hidden;
}

.job-row + .job-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20px;
  right: 20px;
  height: 1px;
  background: var(--separator);
  z-index: 2;
}

.job-content {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  gap: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  position: relative;
  z-index: 1;
  background: var(--card-bg);
}

.job-content:hover {
  background: var(--highlight-bg);
}

.job-content:active {
  background: var(--highlight-bg);
}

.job-info {
  flex: 1;
  min-width: 0;
}

.job-schedule {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.5px;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.job-row.disabled .job-schedule,
.job-row.disabled .job-name,
.job-row.disabled .job-meta {
  opacity: 0.4;
}

.job-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.job-meta .schedule-badge {
  font-family: 'SF Mono', 'Menlo', 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  background: var(--highlight-bg);
  border: 1px solid var(--separator);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

/* ─── Swipe to Delete ────────────────────────────────────────────────────── */

.job-delete-bg {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background: var(--destructive);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  z-index: 0;
}

/* ─── Toggle Switch ──────────────────────────────────────────────────────── */

.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

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

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 15.5px;
  cursor: pointer;
  transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle .slider::after {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
}

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

.toggle input:checked + .slider::after {
  transform: translateX(20px);
}

/* ─── Sheet (Bottom Sheet Modal) ─────────────────────────────────────────── */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 100;
  animation: fadeIn 0.2s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  background: var(--card-bg);
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom, 16px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 10px auto 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--separator);
}

.sheet-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* X close button */
.sheet-btn-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.sheet-btn-close:hover { background: var(--highlight-bg); }
.sheet-btn-close:active { background: var(--highlight-bg); }

/* Save button */
.sheet-btn-save {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
  box-shadow: var(--shadow-sm);
}

.sheet-btn-save:hover { background: var(--primary-hover); }
.sheet-btn-save:active { background: var(--primary-hover); }
.sheet-btn-save:disabled { opacity: 0.4; cursor: default; }

/* ─── Form Sections ──────────────────────────────────────────────────────── */

.ios-section {
  margin: 0 20px 16px;
}

.ios-section-header {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 4px 8px;
}

.ios-field-group {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ios-field-group input[type="text"],
.ios-field-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.65;
  outline: none;
  resize: none;
}

.ios-field-group input::placeholder,
.ios-field-group textarea::placeholder {
  color: var(--text-muted);
}

.ios-field-group:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ─── Settings Rows ──────────────────────────────────────────────────────── */

.ios-settings-group {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ios-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.ios-row + .ios-row {
  border-top: 1px solid var(--separator);
}

.ios-row-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.ios-row-value {
  font-size: 15px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.ios-row-value.accent {
  color: var(--primary);
}

.ios-row-chevron {
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.6;
}

.ios-row-clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ios-row-clickable:active {
  background: var(--highlight-bg);
}

/* Inline input inside settings row */
.ios-row input[type="text"] {
  text-align: right;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  flex: 1;
  min-width: 0;
  margin-left: 16px;
}

.ios-row input[type="text"]::placeholder {
  color: var(--text-muted);
}

/* ─── Frequency Tabs (Segmented Control) ─────────────────────────────────── */

.freq-tabs {
  display: flex;
  background: var(--highlight-bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 3px;
}

.freq-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

.freq-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ─── Interval Chips ─────────────────────────────────────────────────────── */

.interval-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.interval-chip {
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

.interval-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.interval-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ─── Wheel Picker (Time Picker) ─────────────────────────────────────────── */

.wheel-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.wheel-highlight {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  height: 40px;
  background: var(--primary-light);
  border: 1px solid rgba(220, 38, 38, 0.15);
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 0;
}

.wheel-column {
  height: 220px;
  width: 90px;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  z-index: 1;
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.2) 15%,
    rgba(0,0,0,0.6) 25%,
    black 35%,
    black 65%,
    rgba(0,0,0,0.6) 75%,
    rgba(0,0,0,0.2) 85%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0,0,0,0.2) 15%,
    rgba(0,0,0,0.6) 25%,
    black 35%,
    black 65%,
    rgba(0,0,0,0.6) 75%,
    rgba(0,0,0,0.2) 85%,
    transparent 100%
  );
}

.wheel-column::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.wheel-padding {
  height: 90px;
  flex-shrink: 0;
}

.wheel-separator {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  z-index: 1;
  padding: 0 2px;
  line-height: 1;
}

/* ─── Repeat Mode ────────────────────────────────────────────────────────── */

.repeat-group {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.repeat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.repeat-row + .repeat-row {
  border-top: 1px solid var(--separator);
}

.repeat-row:active {
  background: var(--highlight-bg);
}

.repeat-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  transition: all 0.2s;
}

.repeat-row.active .repeat-check {
  border: none;
  background: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22' fill='white'%3E%3Cpath d='M9.5 15l-4-4 1.4-1.4 2.6 2.6 5.6-5.6 1.4 1.4z'/%3E%3C/svg%3E");
  background-size: 22px 22px;
}

.repeat-row.active {
  color: var(--text);
}

/* ─── Day of Week Selector ───────────────────────────────────────────────── */

.dow-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.dow-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

.dow-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

/* ─── Day of Month Grid ──────────────────────────────────────────────────── */

.dom-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.dom-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dom-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.dom-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ─── Cron Preview ───────────────────────────────────────────────────────── */

.cron-preview {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: center;
  font-weight: 500;
}

.cron-preview.valid {
  background: var(--green-light);
  color: #166534;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.cron-preview.invalid {
  background: rgba(220, 38, 38, 0.08);
  color: var(--destructive);
  border: 1px solid rgba(220, 38, 38, 0.15);
}

.cron-preview.pending {
  background: var(--highlight-bg);
  color: var(--text-muted);
  border: 1px solid var(--separator);
}

/* ─── Alert Dialog ───────────────────────────────────────────────────────── */

.alert-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.15s ease;
  padding: 40px;
}

.alert-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 320px;
  overflow: hidden;
  animation: alertPop 0.2s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: var(--shadow-md);
}

.alert-content {
  padding: 24px 20px 20px;
  text-align: center;
}

.alert-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.alert-message {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.alert-actions {
  display: flex;
  border-top: 1px solid var(--separator);
}

.alert-btn {
  flex: 1;
  padding: 14px 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.alert-btn:hover {
  background: var(--highlight-bg);
}

.alert-btn:active {
  background: var(--highlight-bg);
}

.alert-btn + .alert-btn {
  border-left: 1px solid var(--separator);
}

.alert-btn-destructive {
  color: var(--destructive);
  font-weight: 600;
}

/* ─── Empty State ────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 80px 32px 48px;
  color: var(--text-muted);
}

.empty-icon {
  margin-bottom: 20px;
  color: var(--border);
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 15px;
  color: var(--text-muted);
}

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

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 16px;
  color: var(--text-muted);
  font-size: 15px;
}

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

/* ─── Animations ─────────────────────────────────────────────────────────── */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes alertPop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
