/* Telegram Mobile Blue styling for FairDraw Mini App, Public Proof Page & Shared Tokens */

:root {
  color-scheme: light dark;

  --brand-ocean: #035695;
  --brand-navy: #0a2f57;
  --brand-accent: #22c5d9;

  /* Light Telegram Mobile Blue palette */
  --bg-light: #edf4fc;
  --surface-light: #ffffff;
  --surface-alt-light: #e3effb;
  --text-light: #0b1f3a;
  --muted-light: #476589;
  --accent-light: #1e78c8;
  --accent-text-light: #ffffff;
  --border-light: rgba(30, 120, 200, 0.18);

  /* Dark Telegram Night Blue palette */
  --bg-dark: #0e1621;
  --surface-dark: #17212b;
  --surface-alt-dark: #1f2d3d;
  --text-dark: #edf5ff;
  --muted-dark: #849fb9;
  --accent-dark: #2aabee;
  --accent-text-dark: #061826;
  --border-dark: rgba(132, 159, 185, 0.22);

  /* Resolved tokens (FairDraw Telegram Mobile Blue always takes precedence over host gray) */
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-alt: var(--surface-alt-light);
  --text: var(--text-light);
  --muted: var(--muted-light);
  --accent: var(--accent-light);
  --accent-text: var(--accent-text-light);
  --border: var(--border-light);

  --success-bg: rgba(16, 185, 129, 0.14);
  --success-text: #059669;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --warn-text: #b45309;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --danger-text: #dc2626;
  --info-bg: rgba(42, 171, 238, 0.14);
  --info-text: #0369a1;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-alt: var(--surface-alt-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --accent: var(--accent-dark);
    --accent-text: var(--accent-text-dark);
    --border: var(--border-dark);
    --success-text: #34d399;
    --warn-text: #fbbf24;
    --danger-text: #f87171;
    --info-text: #5cc8ff;
  }
}

/* Progressive enhancement with light-dark() when supported (also handles [data-theme] overrides) */
@supports (color: light-dark(white, black)) {
  :root {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-alt: light-dark(var(--surface-alt-light), var(--surface-alt-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --muted: light-dark(var(--muted-light), var(--muted-dark));
    --accent: light-dark(var(--accent-light), var(--accent-dark));
    --accent-text: light-dark(var(--accent-text-light), var(--accent-text-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --success-text: light-dark(#059669, #34d399);
    --warn-text: light-dark(#b45309, #fbbf24);
    --danger-text: light-dark(#dc2626, #f87171);
    --info-text: light-dark(#0369a1, #5cc8ff);
  }
}

/* Explicit light/dark override shared across Mini App, /verify, and /dashboard */
html[data-theme="light"] {
  color-scheme: light;
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-alt: var(--surface-alt-light);
  --text: var(--text-light);
  --muted: var(--muted-light);
  --accent: var(--accent-light);
  --accent-text: var(--accent-text-light);
  --border: var(--border-light);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--bg-dark);
  --surface: var(--surface-dark);
  --surface-alt: var(--surface-alt-dark);
  --text: var(--text-dark);
  --muted: var(--muted-dark);
  --accent: var(--accent-dark);
  --accent-text: var(--accent-text-dark);
  --border: var(--border-dark);
}

/* Richer Telegram Mobile Blue outer margin exclusively for the Mini App (light mode) */
html.mini-app {
  --bg-light: #d8e9fa; /* deeper sky-blue outer frame so white cards pop cleanly */
}

/* Keep tab track, header pill, and cards crisp against the deeper Mini App outer canvas */
html.mini-app[data-theme="light"] .tabs {
  background: rgba(3, 86, 149, 0.1);
  border: 1px solid var(--border);
}

html.mini-app[data-theme="light"] .topbar .pill:not(.active):not(.warn):not(.info) {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border);
}

html.mini-app[data-theme="light"] .card {
  box-shadow: 0 2px 10px rgba(3, 86, 149, 0.06);
}

html {
  accent-color: var(--accent);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Vazirmatn", sans-serif;
  font-size: clamp(0.92rem, 0.89rem + 0.2vw, 1rem);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: url("/logo.jpg") center / cover no-repeat;
  box-shadow: 0 2px 8px rgba(3, 86, 149, 0.35);
  flex: none;
}

/* Keyboard focus visibility */
.btn:focus-visible,
.tab-btn:focus-visible,
.chip:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
summary:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Soft loading shimmer */
.muted:only-child {
  animation: fd-pulse 1.4s ease-in-out infinite;
}

@keyframes fd-pulse {
  50% {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  .muted:only-child {
    animation: none;
  }
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--muted);
}

.pill.active {
  background: var(--success-bg);
  color: var(--success-text);
}

.pill.drawn {
  background: var(--surface-alt);
  color: var(--text);
}

.pill.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.pill.info {
  background: var(--info-bg);
  color: var(--info-text);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-subtle {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.h1 {
  font-size: clamp(1.18rem, 1.1rem + 0.45vw, 1.42rem);
  font-weight: 700;
  line-height: 1.25;
}

.h2 {
  font-size: clamp(0.98rem, 0.94rem + 0.25vw, 1.12rem);
  font-weight: 700;
  line-height: 1.3;
}

.muted {
  color: var(--muted);
  font-size: clamp(0.84rem, 0.82rem + 0.14vw, 0.92rem);
  line-height: 1.45;
}

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

.stack-sm > * + * {
  margin-top: 10px;
}

.stack-md > * + * {
  margin-top: 14px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-alt);
  margin-bottom: 14px;
}

.tab-btn {
  min-height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.tab-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(3, 86, 149, 0.14);
}

.btn {
  width: 100%;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  font-size: 0.94rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.08s ease;
}

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

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

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

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

.btn-sm {
  width: auto;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: 10px;
}

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

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

.stat-box {
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.stat-val {
  font-weight: 700;
  font-size: 1rem;
}

.stat-lbl {
  color: var(--muted);
  font-size: 0.74rem;
}

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

.field label,
.field-label {
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 18px;
  block-size: 18px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--info-bg);
  color: var(--info-text);
  cursor: help;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.94rem;
  font-family: inherit;
}

.textarea {
  min-height: 76px;
  resize: vertical;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 34px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.chip.is-selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  word-break: break-all;
  background: var(--surface-alt);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.switch-row.fd-check {
  justify-content: flex-start;
  gap: 10px;
}

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

.check-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

/* Fallback checkbox styling for browsers without accent-color */
@supports not (accent-color: auto) {
  .fd-check {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  .fd-check input[type="checkbox"] {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
  }

  .fd-check span::before {
    content: "";
    display: inline-block;
    width: 1.05rem;
    height: 1.05rem;
    margin-inline-end: 0.45rem;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    vertical-align: middle;
  }

  .fd-check input[type="checkbox"]:checked + span::before {
    background: var(--accent);
    border-color: var(--accent);
  }
}

/* Accessible accordion styling per modern-web-guidance (marker right next to label) */
details.accordion-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::before {
  content: "";
  inline-size: 0.95em;
  block-size: 0.95em;
  flex-shrink: 0;
  background-color: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat center / contain;
  rotate: -90deg;
}

details > summary:dir(rtl)::before {
  rotate: 90deg;
}

details[open] > summary::before {
  rotate: 0deg;
}

details::details-content {
  interpolate-size: allow-keywords;
  overflow: clip;
  contain: layout;
}

details:not([open])::details-content {
  block-size: 0;
}

@media (prefers-reduced-motion: no-preference) {
  details > summary::before {
    transition: rotate 0.2s ease;
  }
  details::details-content {
    transition: block-size 0.24s ease-in-out, content-visibility 0.24s ease-in-out;
    transition-behavior: allow-discrete;
  }
}

.details-body {
  padding-top: 10px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-alt);
}

.scroll-box {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(16px);
  background: #0b1f3a;
  color: #edf5ff;
  border: 1px solid rgba(42, 171, 238, 0.55);
  box-shadow: 0 6px 20px rgba(3, 47, 87, 0.28);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 99;
  max-width: 90vw;
  text-align: center;
}

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

/* Validation, required indicators, soft warnings & pagination */
.req-star {
  color: var(--danger-text);
  font-weight: 700;
  margin-inline-start: 2px;
}

.is-invalid {
  border-color: var(--danger-text) !important;
  box-shadow: 0 0 0 2px var(--danger-bg);
}

.field-error {
  color: var(--danger-text);
  font-size: 0.78rem;
  font-weight: 600;
}

.soft-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.8rem;
  line-height: 1.4;
}

.auth-gate-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
}

.auth-gate-card {
  width: 100%;
  max-width: 520px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.banner-preview-img {
  width: 100%;
  max-height: 240px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}

.banner-preview-img[hidden] {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.field-hint {
  color: var(--muted);
  font-size: clamp(0.8rem, 0.78rem + 0.1vw, 0.86rem);
  line-height: 1.45;
}

.field-hint.is-error {
  color: var(--danger-text);
  font-weight: 600;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger-text);
}

.inline-action-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.pill.danger {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.info-hint-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: help;
}

.human-check-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.media-upload-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface-alt);
}

.media-upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.details-kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 6px;
}

.details-kv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: clamp(0.78rem, 0.76rem + 0.1vw, 0.84rem);
}

.details-kv-on {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-inline-start: auto;
  text-align: end;
  color: var(--success-text);
  font-weight: 700;
}

.details-kv-off {
  color: var(--muted);
  margin-inline-start: auto;
  text-align: end;
}

.pill.ultra {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.2), rgba(99, 102, 241, 0.22));
  color: #4f46e5;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

[data-theme="dark"] .pill.ultra {
  color: #a5b4fc;
  border-color: rgba(165, 180, 252, 0.35);
}

.pill.core {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

[data-theme="dark"] .pill.core {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}

/* AdsGram Task web component themed across light/dark shadow boundary via CSS custom properties */
adsgram-task.fd-adsgram-task:not(:defined) {
  display: none;
}

adsgram-task.fd-adsgram-task {
  --adsgram-task-font-size: 0.9rem;
  --adsgram-task-icon-size: 44px;
  --adsgram-task-icon-title-gap: 12px;
  --adsgram-task-icon-border-radius: 10px;
  --adsgram-task-button-width: 72px;
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  color: var(--text);
  font-family: inherit;
}

.fd-task-reward {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.fd-task-btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.fd-task-btn-claim {
  background: var(--accent);
  color: var(--accent-text);
}

.fd-task-btn-done {
  background: var(--success-bg);
  color: var(--success-text);
}
