/* ------------------------------------------------------------------
 * styles.css — Telegram-native look, RTL, mobile first, light + dark
 * ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  /* Telegram theme variables with safe fallbacks for browser preview */
  --bg:         var(--tg-theme-bg-color, #ffffff);
  --text:       var(--tg-theme-text-color, #111418);
  --hint:       var(--tg-theme-hint-color, #6d7885);
  --link:       var(--tg-theme-link-color, #2481cc);
  --btn:        var(--tg-theme-button-color, #2481cc);
  --btn-text:   var(--tg-theme-button-text-color, #ffffff);
  --sec-bg:     var(--tg-theme-secondary-bg-color, #f1f2f5);

  --border:     rgba(0, 0, 0, 0.12);
  --border-strong: rgba(0, 0, 0, 0.24);
  --field-bg:   #ffffff;
  --danger:     #d93a34;
  --danger-bg:  rgba(217, 58, 52, 0.10);
  --success:    #2e9e5b;
  --success-bg: rgba(46, 158, 91, 0.12);
  --info-bg:    rgba(36, 129, 204, 0.12);

  --radius:     14px;
  --radius-sm:  10px;
  --gap:        14px;
  --touch:      44px;

  /* Safe areas: CSS env() plus values pushed by app.js from the Telegram SDK */
  --sa-top:    calc(env(safe-area-inset-top, 0px) + var(--tg-sa-top, 0px));
  --sa-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-sa-bottom, 0px));

  /* Height reserved at the bottom for the in-page nav (0 when hidden) */
  --nav-space: 0px;
}

[data-theme="dark"] {
  --border:        rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.30);
  --field-bg:      rgba(255, 255, 255, 0.06);
  --danger:        #ff6b64;
  --danger-bg:     rgba(255, 107, 100, 0.14);
  --success:       #5ed48c;
  --success-bg:    rgba(94, 212, 140, 0.14);
  --info-bg:       rgba(94, 173, 240, 0.14);
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is element-level, so any class rule that sets a
   display value beats it (.fallback-nav sets display:flex). Restate it with
   enough weight that the hidden attribute always wins. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               "Noto Naskh Arabic", "Cairo", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------------------------- header ---------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(var(--sa-top) + 12px) 16px 10px;
  border-bottom: 1px solid var(--border);
}

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

.app-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.user-chip {
  font-size: 13px;
  color: var(--hint);
  background: var(--sec-bg);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header-link {
  background: none;
  border: none;
  color: var(--link);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 12px 8px;
  min-height: 44px;
  white-space: nowrap;
}

.header-link:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.progress-wrap { margin-top: 10px; }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--sec-bg);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 16.6%;
  background: var(--btn);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-text {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--hint);
}

/* ----------------------------- main ----------------------------- */

.app-main {
  padding: 16px 16px calc(var(--sa-bottom) + var(--nav-space) + 32px);
}

.step-title {
  margin: 4px 0 2px;
  font-size: 22px;
  font-weight: 700;
}

.step-subtitle {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--hint);
}

/* ---------------------------- banners --------------------------- */

.banners:empty { display: none; }

.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.banner-info    { background: var(--info-bg); }
.banner-success { background: var(--success-bg); }
.banner-error   { background: var(--danger-bg); color: var(--danger); }

.banner p { margin: 0; flex: 1; }

.banner-action {
  background: none;
  border: none;
  color: var(--link);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}

/* ---------------------------- fields ---------------------------- */

.field { margin-bottom: 22px; }

.field-label,
.field legend {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  padding: 0;
}

.field-optional {
  font-weight: 400;
  font-size: 13px;
  color: var(--hint);
}

.field-hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--hint);
}

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

input[type="text"],
input[type="url"],
input[type="date"],
input[type="number"],
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
}

input::placeholder,
textarea::placeholder { color: var(--hint); opacity: 0.8; }

input:focus-visible,
textarea:focus-visible {
  border-color: var(--btn);
  box-shadow: 0 0 0 3px rgba(36, 129, 204, 0.25);
}

.field.has-error input,
.field.has-error textarea { border-color: var(--danger); }

.field-error {
  display: none;
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--danger);
  font-weight: 600;
}

.field.has-error .field-error { display: block; }

/* --------------------------- choices ---------------------------- */

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

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--sec-bg);
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chip input,
.card input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.chip.is-checked {
  background: var(--btn);
  border-color: var(--btn);
  color: var(--btn-text);
}

.chip:focus-within,
.card:focus-within {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* ---------------------------- cards ----------------------------- */

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 460px) {
  .cards { grid-template-columns: 1fr 1fr; }
}

.card {
  position: relative;
  display: block;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--sec-bg);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.card.is-checked {
  border-color: var(--btn);
  background: var(--info-bg);
}

.card-title { font-size: 16px; font-weight: 700; }
.card-desc  { font-size: 13px; color: var(--hint); margin-top: 3px; }

/* ---------------------------- review ---------------------------- */

.review-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

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

.review-head h3 { margin: 0; font-size: 16px; font-weight: 700; }

.review-edit {
  background: none;
  border: none;
  color: var(--link);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 8px;
  min-height: 44px;
}

.review-row { padding: 8px 0; border-top: 1px solid var(--border); }
.review-row:first-of-type { border-top: 0; }
.review-q { font-size: 13px; color: var(--hint); }
.review-a { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.review-empty { font-size: 14px; color: var(--hint); }

/* -------------------------- requests ---------------------------- */

.request-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

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

.request-ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 700;
  direction: ltr;
}

.request-name { font-size: 16px; font-weight: 600; }
.request-meta { font-size: 13px; color: var(--hint); margin-top: 4px; }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-new       { background: var(--info-bg);    color: var(--link); }
.badge-reviewing { background: rgba(224, 160, 40, 0.18); color: #d69017; }
.badge-contacted { background: var(--success-bg); color: var(--success); }
.badge-archived  { background: var(--sec-bg);     color: var(--hint); }

[data-theme="dark"] .badge-reviewing { color: #f2b544; }

.requests-empty {
  text-align: center;
  color: var(--hint);
  padding: 32px 12px;
  font-size: 15px;
}

.requests-loading { text-align: center; color: var(--hint); padding: 24px; }

.btn-block { width: 100%; margin-top: 16px; }

/* ------------------------- shared bits -------------------------- */

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

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

.section-head .step-title { margin-bottom: 2px; }

/* 44px hit area around a 20px glyph — the icon looks small, the target isn't */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--link);
  cursor: pointer;
}

.icon-btn:active { background: var(--sec-bg); }
.icon-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.is-busy svg { animation: spin 0.9s linear infinite; }

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

/* --------------------------- skeleton --------------------------- */

.skeleton {
  border-radius: var(--radius);
  background: var(--sec-bg);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(127, 127, 127, 0.12), transparent);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer { to { transform: translateX(100%); } }

.skeleton-card { height: 92px; margin-bottom: 10px; }
.skeleton-tile { height: 74px; }

@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}

/* ---------------------------- admin ----------------------------- */

/* Dense scale: the dashboard packs more per screen than the form does. */
.admin { --admin-gap: 8px; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--admin-gap);
  margin-bottom: 18px;
}

.stat-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-label { font-size: 13px; color: var(--hint); margin-top: 2px; }

.admin-section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 22px 0 10px;
}

/* Bar chart, plain SVG — no charting library in a Mini App */
.chart-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
}

.chart-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.chart-card svg { width: 100%; height: 88px; display: block; overflow: visible; }
.chart-bar { fill: var(--btn); }
.chart-baseline { stroke: var(--border); stroke-width: 1; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--hint);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.admin-search { margin-bottom: 10px; }

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 6px;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar { display: none; }

.filter-chip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--sec-bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.filter-chip[aria-pressed="true"] {
  background: var(--btn);
  border-color: var(--btn);
  color: var(--btn-text);
}

.filter-chip:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.filter-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
  margin-inline-start: 6px;
}

/* A whole row is the tap target, so it needs press feedback */
.admin-row {
  display: block;
  width: 100%;
  text-align: start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: var(--admin-gap);
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.admin-row:active { background: var(--sec-bg); }
.admin-row:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ------------------------ admin detail -------------------------- */

.detail-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.detail-block h3 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }

.status-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-note {
  font-size: 13px;
  color: var(--hint);
  margin: 10px 0 0;
}

/* --------------------------- empty ------------------------------ */

.empty-state {
  text-align: center;
  padding: 36px 16px;
}

.empty-state svg {
  width: 44px;
  height: 44px;
  color: var(--hint);
  opacity: 0.55;
  margin-bottom: 12px;
}

.empty-title { font-size: 16px; font-weight: 600; margin: 0 0 6px; }
.empty-text  { font-size: 14px; color: var(--hint); margin: 0 0 16px; }

/* --------------------------- success ---------------------------- */

.success { text-align: center; padding: 24px 8px 8px; }

.success-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
}

.success-icon svg { width: 34px; height: 34px; }

.success-title { margin: 0 0 12px; font-size: 22px; }
.success-text  { margin: 12px 0 4px; font-size: 15px; color: var(--hint); }

.reference {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  background: var(--sec-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 6px 0 10px;
  user-select: all;
}

.btn-copy { margin-bottom: 8px; }

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

/* --------------------------- buttons ---------------------------- */

.btn {
  min-height: var(--touch);
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.btn-primary   { background: var(--btn); color: var(--btn-text); }
.btn-secondary { background: var(--sec-bg); color: var(--text); border-color: var(--border); }
.btn-ghost     { background: none; color: var(--link); }

/* ------------------------- fallback nav ------------------------- */

.fallback-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  padding: 10px 16px calc(10px + var(--sa-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  max-width: 720px;
  margin: 0 auto;
}

.fallback-nav .btn { flex: 1; }
.fallback-nav .btn-primary { flex: 2; }

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

/* ------------------------ grouped choices ----------------------- */

.choice-group + .choice-group { margin-top: 16px; }

.choice-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 8px;
}

.choice-group-count {
  background: var(--btn);
  color: var(--btn-text);
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
