:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --warning: #f59e0b;
  --danger: #ef4444;
  --priority: #f59e0b;
}

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

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 3rem;
  width: 100%;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: #38bdf8;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(30, 41, 59, 0.9);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  flex-wrap: wrap;
  gap: 1rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-circle {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #10b981, #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.topbar-brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.badge-neutral {
  background: #1e293b;
  color: var(--text-muted);
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.35);
}

.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.container {
  max-width: 1400px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.grid-two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.qr-card {
  border-color: var(--warning);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), var(--bg-card));
}

.qr-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.qr-text {
  flex: 1;
  min-width: 280px;
}

.qr-text h2 {
  margin-bottom: 0.5rem;
}

.qr-text ol {
  margin: 0.75rem 0 0.75rem 1.25rem;
  color: #e2e8f0;
}

.qr-box {
  background: #ffffff;
  padding: 0.75rem;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 256px;
  min-height: 256px;
}

.qr-box img {
  display: block;
  width: 240px;
  height: 240px;
}

.qr-loading-box {
  width: 240px;
  height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  border: 1px dashed var(--border);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  width: 100%;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #cbd5e1;
}

.help-text {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.input-row {
  display: flex;
  gap: 0.5rem;
  min-width: 0;
  width: 100%;
}

.input-row input,
.input-row select {
  flex: 1;
  min-width: 0;
}

.group-filter-input {
  max-width: 190px;
  min-width: 0;
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

select {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.3rem 0;
}

.section-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.section-subhead h3,
.form-stack h3 {
  font-size: 0.96rem;
  font-weight: 600;
}

.cron-details-box {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.radio-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.radio-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.83rem;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.83rem;
  cursor: pointer;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
  flex-shrink: 0;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #334155;
  transition: 0.2s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

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

input:checked + .slider:before {
  transform: translateX(24px);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #06281e;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  color: #fff;
}

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

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-secondary:hover:not(:disabled) {
  background: #475569;
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

.btn-danger-outline:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-full {
  width: 100%;
}

/* Chat Manager */
.chat-controls {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.filter-pills {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.pill {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chats-list {
  max-height: 540px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-right: 0.25rem;
}

.chat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chat-item.tier-priority {
  border-left: 4px solid var(--priority);
}

.chat-item.tier-ignored {
  opacity: 0.6;
}

.chat-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.chat-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

.tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-weight: 600;
}

.tag-unread {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.tag-unknown {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

.tag-type {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
}

.tier-buttons {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.tier-btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
}

.tier-btn.active-priority {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--priority);
  color: #fbbf24;
  font-weight: 600;
}

.tier-btn.active-normal {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent);
  color: #60a5fa;
  font-weight: 600;
}

.tier-btn.active-ignored {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
  color: #f87171;
  font-weight: 600;
}

/* History & Logs */
.history-list {
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-digest {
  white-space: pre-wrap;
  font-size: 0.84rem;
  background: #0b1120;
  padding: 0.75rem;
  border-radius: 6px;
  border: 1px solid #1e293b;
  max-height: 220px;
  overflow-y: auto;
}

.logs-box {
  background: #090d16;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  height: 420px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.log-line {
  line-height: 1.4;
  word-break: break-word;
}

.log-info { color: #cbd5e1; }
.log-success { color: #34d399; }
.log-warn { color: #fbbf24; }
.log-error { color: #f87171; }

/* Progress Banner */
.progress-banner {
  background: rgba(59, 130, 246, 0.15);
  border-bottom: 1px solid rgba(59, 130, 246, 0.4);
  padding: 0.75rem 2rem;
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
}

.progress-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.25s ease;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #60a5fa;
  border-top-color: transparent;
  border-radius: 50%;
   display: inline-block;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #10b981;
  color: #042f2e;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

/* Auth & Modal Overlays */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 29, 0.88);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 999;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 0.82rem;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  margin-top: 0.25rem;
}

.hidden {
  display: none !important;
}

/* Guide & Modal Extensions */
.modal-card-lg {
  max-width: 680px;
  max-height: 88vh;
  padding: 1.75rem 2rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.guide-content {
  overflow-y: auto;
  padding-right: 0.5rem;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.guide-content::-webkit-scrollbar {
  width: 6px;
}

.guide-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.guide-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.guide-overview {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  font-size: 0.92rem;
  line-height: 1.55;
}

.guide-step {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem 1.25rem;
}

.guide-step-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.guide-step-num {
  background: var(--accent);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.guide-step-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
}

.guide-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #60a5fa;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
}

.guide-link-btn:hover {
  background: rgba(59, 130, 246, 0.28);
  border-color: #60a5fa;
  color: #93c5fd;
  text-decoration: none;
}

.guide-alert-box {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 1.25rem;
}

.guide-alert-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fbbf24;
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.guide-subcard {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.btn-guide-pill {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #60a5fa;
  padding: 0.25rem 0.65rem;
  font-size: 0.76rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-guide-pill:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: #60a5fa;
  color: #93c5fd;
}

/* =========================================================================
   Responsive Breakpoints & Mobile Adaptations
   ========================================================================= */

@media (max-width: 1024px) {
  .container {
    max-width: 100%;
    padding: 0 1.25rem;
  }

  .topbar {
    padding: 0.85rem 1.25rem;
  }
}

@media (max-width: 768px) {
  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .topbar {
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }

  .topbar-brand {
    gap: 0.65rem;
  }

  .topbar-brand h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    font-size: 0.72rem;
    line-height: 1.3;
  }

  .topbar-status {
    width: 100%;
    justify-content: flex-start;
    gap: 0.4rem;
  }

  .badge {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
  }

  #runNowBtn {
    width: 100%;
    order: 10;
    margin-top: 0.25rem;
    padding: 0.65rem 1rem;
  }

  .container {
    padding: 0 0.85rem;
    margin: 0.85rem auto;
    gap: 1rem;
  }

  .card {
    padding: 1rem;
    border-radius: 10px;
    gap: 0.85rem;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .card-header button {
    align-self: flex-start;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .form-row-3 {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

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

  .qr-content {
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    text-align: left;
  }

  .qr-text {
    min-width: 0;
    width: 100%;
  }

  .qr-box {
    margin: 0 auto;
    width: 100%;
    max-width: 256px;
    min-width: unset;
  }

  .qr-box img {
    max-width: 100%;
    height: auto;
  }

  .qr-loading-box {
    width: 100%;
    max-width: 240px;
  }

  .chat-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .chat-meta {
    width: 100%;
  }

  .chat-name {
    max-width: 100%;
  }

  .tier-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.35rem;
  }

  .tier-btn {
    text-align: center;
    padding: 0.45rem 0.25rem;
    font-size: 0.78rem;
  }

  .history-header {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .logs-box {
    height: 300px;
    font-size: 0.72rem;
    padding: 0.55rem;
  }

  /* Prevent iOS Safari from auto-zooming inputs on tap */
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="time"],
  select,
  textarea {
    font-size: 16px;
  }

  .modal-backdrop {
    padding: 0.75rem;
  }

  .modal-card,
  .modal-card-lg {
    padding: 1.25rem 1rem;
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
  }

  .modal-header h2 {
    font-size: 1.1rem;
  }
}

@media (max-width: 580px) {
  .input-row {
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .input-row input,
  .input-row select {
    width: 100%;
    flex: 1 1 100%;
  }

  .group-filter-input {
    max-width: 100% !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  .topbar-brand {
    gap: 0.5rem;
  }

  .logo-circle {
    width: 36px;
    height: 36px;
    font-size: 1.15rem;
  }

  .filter-pills {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.35rem;
    -webkit-overflow-scrolling: touch;
  }

  .pill {
    flex-shrink: 0;
  }

  .auth-page-card {
    padding: 1.5rem 1.15rem;
  }
}


