:root {
  --bg: #f0fdfa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --text: #134e4a;
  --text-muted: #5b7c78;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: #ccfbf1;
  --accent: #0e7490;
  --accent-hover: #155e75;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --border: #99f6e4;
  --border-subtle: #e2e8f0;
  --shadow: 0 10px 30px rgba(15, 118, 110, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --space: 8px;
  --font: "Vazirmatn", system-ui, -apple-system, sans-serif;
  --touch: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, #99f6e4 0%, transparent 50%),
    radial-gradient(900px 500px at -10% 100%, #a5f3fc 0%, transparent 45%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--primary);
}

.view {
  min-height: 100dvh;
}

/*
 * Author `display:` rules (e.g. .view-login { display: grid }) override the
 * UA stylesheet for [hidden], so the login view stays visible after auth.
 * Force-hide anything with the hidden attribute.
 */
[hidden] {
  display: none !important;
}

/* Login */
.view-login {
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.login-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 28px 22px;
}

.brand {
  text-align: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  margin-bottom: 12px;
}

.brand h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Form */
.form,
.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.7;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

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

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

.password-row input {
  flex: 1;
}

.btn-icon {
  width: var(--touch);
  height: var(--touch);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.btn-icon:hover,
.btn-icon:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
  outline: none;
}

.error {
  margin: 0;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn-block {
  width: 100%;
}

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

.btn-primary:hover:not(:disabled),
.btn-primary:focus-visible {
  background: var(--primary-hover);
  outline: none;
}

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

.btn-accent:hover:not(:disabled),
.btn-accent:focus-visible {
  background: var(--accent-hover);
  outline: none;
}

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

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: var(--primary-soft);
  color: var(--primary);
  outline: none;
}

.btn-sm {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* App shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  min-height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}

.topbar-brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.wallet-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  margin-inline-start: auto;
  margin-inline-end: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft, rgba(15, 118, 110, 0.12));
  border: 1px solid rgba(15, 118, 110, 0.25);
  line-height: 1.15;
  max-width: 46%;
}

.wallet-badge .wallet-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.wallet-badge strong {
  font-size: 0.8rem;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + var(--safe-bottom));
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
}

.tabs.tabs-4 {
  grid-template-columns: repeat(4, 1fr);
}

.tabs.tabs-5 {
  grid-template-columns: repeat(5, 1fr);
}

.tabs.tabs-6 {
  grid-template-columns: repeat(6, 1fr);
}

.tabs.tabs-7 {
  grid-template-columns: repeat(7, 1fr);
}

@media (max-width: 720px) {
  .tabs.tabs-7 {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 560px) {
  .tabs.tabs-4,
  .tabs.tabs-5,
  .tabs.tabs-6,
  .tabs.tabs-7 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 380px) {
  .tabs.tabs-5,
  .tabs.tabs-6,
  .tabs.tabs-7 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn-danger-text {
  color: var(--danger) !important;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-secondary-soft {
  min-height: 40px;
  border-radius: 10px;
  padding: 0 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
}

.btn-secondary-soft:hover,
.btn-secondary-soft:focus-visible {
  background: var(--primary-soft);
  outline: none;
}

.tab {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

.tab.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.panel[hidden] {
  display: none !important;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0;
  font-size: 1.1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.field-check {
  justify-content: space-between;
}

.field-check > span {
  margin-bottom: 4px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
}

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

.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  right: 4px;
  top: 4px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s ease;
}

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

.switch input:checked + .slider::before {
  transform: translateX(-20px);
}

.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

.empty {
  color: var(--text-muted);
  background: #f8fafc;
  border: 1px dashed var(--border-subtle);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 4px 10px;
  direction: ltr;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.subhead {
  margin: 8px 0 0;
  font-size: 0.95rem;
}

.article-preview {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
  background: #fafafa;
  overflow-x: auto;
}

.article-preview h2,
.article-preview h3 {
  color: var(--text);
  line-height: 1.4;
}

.article-preview p {
  margin: 0 0 12px;
}

.alt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alt-list li {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px;
}

.alt-list strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.alt-list span {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.note {
  margin: 0;
  white-space: pre-wrap;
  background: #f0fdfa;
  border-radius: 12px;
  padding: 12px;
  color: var(--text);
  font-size: 0.92rem;
}

.publish-result {
  border-radius: 12px;
  padding: 12px;
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.92rem;
}

.publish-result a {
  font-weight: 600;
  word-break: break-all;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 100;
  max-width: min(92vw, 420px);
  background: #134e4a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.is-error {
  background: #991b1b;
}

.hint-banner {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text);
  background: #ecfeff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.schedule-box {
  border-top: 1px dashed var(--border-subtle);
  padding-top: 12px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schedule-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.schedule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schedule-item {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: #f8fafc;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.schedule-item-prompt {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.schedule-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.status-pending {
  background: #fef3c7;
  color: #92400e;
}

.status-running {
  background: #dbeafe;
  color: #1e40af;
}

.status-done {
  background: var(--primary-soft);
  color: var(--primary);
}

.status-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== ویرایشگر (site editor) ===== */
.editor-images li {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-image-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: #fff;
  flex: 0 0 auto;
}

.editor-image-title {
  flex: 1 1 auto;
  min-width: 0;
}

.editor-image-src {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  direction: ltr;
  text-align: left;
  word-break: break-all;
}

.editor-status {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.editor-status.has {
  background: var(--primary-soft);
  color: var(--primary);
}

.editor-status.missing {
  background: #fef3c7;
  color: #92400e;
}

.editor-alt-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
}

.editor-alt-input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.editor-cost-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ===== AI operation status (sticky top bar) ===== */
.ai-status {
  position: sticky;
  top: calc(8px + var(--safe-top));
  z-index: 20;
  background: #0f766e;
  color: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.28);
}

.ai-status.is-error {
  background: #b91c1c;
  box-shadow: 0 10px 24px rgba(185, 28, 28, 0.28);
}

.ai-status-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-status-head strong {
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
}

.ai-status-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin-inline-start: auto;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.ai-status-close:hover,
.ai-status-close:focus-visible {
  background: rgba(255, 255, 255, 0.25);
  outline: none;
}

.billing-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--primary-soft, rgba(15, 118, 110, 0.1));
  border: 1px solid rgba(15, 118, 110, 0.2);
  font-size: 0.9rem;
}

.billing-summary .billing-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.billing-kind-spend {
  color: var(--danger, #b91c1c);
}

.billing-kind-credit {
  color: var(--primary, #0f766e);
}

.ai-status-detail {
  font-size: 0.85rem;
  margin-top: 8px;
  color: #d8f3ef;
}

.ai-status-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.ai-progress {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
  margin-top: 10px;
}

.ai-progress span {
  display: block;
  height: 100%;
  width: 40%;
  background: #fff;
  border-radius: 999px;
  animation: ai-slide 1.2s ease-in-out infinite;
}

@keyframes ai-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

.footer-copyright {
  opacity: 0.9;
}



.status-cancelled {
  background: #e2e8f0;
  color: #475569;
}

.btn-danger-soft {
  color: var(--danger);
  border: 1px solid #fecaca;
  background: #fff;
  min-height: 40px;
  border-radius: 10px;
  padding: 0 12px;
  font-weight: 600;
}

.btn-danger-soft:hover,
.btn-danger-soft:focus-visible {
  background: var(--danger-soft);
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* App footer / version */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  font-size: 0.78rem;
  color: var(--text-muted);
  opacity: 0.85;
}

.footer-version {
  font-variant-numeric: tabular-nums;
}

.app-footer .footer-version::before {
  content: "•";
  margin-inline-end: 8px;
  opacity: 0.5;
}
