/* ─── Telegram Theme Integration ─────────────────────────────────────────── */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2678b6);
  --btn: var(--tg-theme-button-color, #2678b6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
  --subtitle: var(--tg-theme-subtitle-text-color, #71727a);
  --section-bg: var(--tg-theme-section-bg-color, var(--bg));
  --section-separator: var(--tg-theme-section-separator-color, #e0e0e0);
  --radius: 12px;
}

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

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

[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0 16px;
}

header h1 {
  font-size: 20px;
  font-weight: 600;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.btn-icon:active { opacity: 0.7; }

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--btn);
  color: var(--btn-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 8px;
}

.btn-primary:active { opacity: 0.7; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-secondary, .btn-danger {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

.btn-danger {
  background: var(--destructive);
  color: #fff;
}

.btn-secondary:active, .btn-danger:active { opacity: 0.7; }

/* ─── Job Cards ──────────────────────────────────────────────────────────── */

.job-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: opacity 0.2s;
}

.job-card.disabled {
  opacity: 0.55;
}

.job-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.job-card-header .job-name {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
}

.job-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 8px;
}

.job-card-meta .schedule {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.job-card-meta .silent-badge {
  font-size: 12px;
  opacity: 0.7;
}

.job-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.job-card-actions button {
  background: none;
  border: none;
  color: var(--link);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.job-card-actions button:active {
  background: var(--bg);
}

.job-card-actions button.delete-btn {
  color: var(--destructive);
}

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

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

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

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--hint);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.25s;
}

.toggle .slider::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
}

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

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

/* ─── Modal ──────────────────────────────────────────────────────────────── */

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

.modal {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

.modal-small {
  border-radius: 16px;
  margin: auto;
  width: 90%;
  max-width: 320px;
  text-align: center;
  padding: 24px;
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-header .btn-icon {
  background: var(--secondary-bg);
  color: var(--text);
  width: 30px;
  height: 30px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.modal-small p {
  font-size: 16px;
  margin-bottom: 4px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

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

#job-form label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--subtitle);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
  margin-top: 12px;
}

#job-form label:first-of-type {
  margin-top: 0;
}

#job-form input[type="text"],
#job-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--section-separator);
  border-radius: 8px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

#job-form input[type="text"]:focus,
#job-form textarea:focus {
  border-color: var(--btn);
}

.mono {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace !important;
}

/* ─── Cron Presets ────────────────────────────────────────────────────────── */

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.presets button {
  padding: 6px 10px;
  border: 1px solid var(--section-separator);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.presets button:active {
  background: var(--btn);
  color: var(--btn-text);
  border-color: var(--btn);
}

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

.cron-preview {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.cron-preview.valid {
  background: rgba(76, 175, 80, 0.1);
  color: #4caf50;
}

.cron-preview.invalid {
  background: rgba(229, 57, 53, 0.1);
  color: var(--destructive);
}

/* ─── Checkbox ───────────────────────────────────────────────────────────── */

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--btn);
}

.checkbox-row label {
  font-size: 14px;
  margin: 0 !important;
  text-transform: none !important;
}

/* ─── States ─────────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--hint);
}

.empty-state p:first-child {
  font-size: 16px;
}

.hint {
  font-size: 13px;
  color: var(--hint);
}

.loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--hint);
  font-size: 15px;
}
