/* Mini App design system.
 *
 * Built on Telegram's own theme variables so the app inherits the user's
 * chosen colour scheme instead of fighting it: the page sits on
 * --tg-theme-secondary-bg-color and every card on --tg-theme-bg-color, which
 * is the grouped-list arrangement native Telegram screens use. Each variable
 * carries a light fallback, and the @media block below supplies dark values
 * for hosts that expose no theme at all (a plain browser, or Bale before its
 * variables are confirmed).
 */

:root {
  color-scheme: light dark;

  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-alt: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --fg: var(--tg-theme-text-color, #14161a);
  --fg-muted: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #707579));
  --hint: var(--tg-theme-hint-color, #8b8f95);
  --accent: var(--tg-theme-button-color, #2f83e8);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f83e8);
  --danger: var(--tg-theme-destructive-text-color, #e0503f);
  --success: #1eaa63;
  --warning: #d99310;

  --border: rgba(128, 132, 140, 0.18);
  --border-strong: rgba(128, 132, 140, 0.34);
  --shadow: 0 1px 2px rgba(16, 20, 28, 0.06), 0 8px 24px rgba(16, 20, 28, 0.05);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-pill: 999px;

  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #14171c);
    --surface: var(--tg-theme-bg-color, #1d2026);
    --surface-alt: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1d2026));
    --fg: var(--tg-theme-text-color, #f2f3f5);
    --fg-muted: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #9aa0a8));
    --hint: var(--tg-theme-hint-color, #868d95);
    --border: rgba(160, 168, 180, 0.16);
    --border-strong: rgba(160, 168, 180, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

/* The layout sets explicit `display` on several elements that are toggled via
   the `hidden` attribute (the app bar, its back link, the tab bar); without
   this that display would win and `hidden` would do nothing. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  direction: rtl;
  font-family: "Vazirmatn", "Segoe UI", "IRANSans", "SF Pro Text",
               system-ui, -apple-system, Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Persian text needs a touch more line height and slightly looser tracking
   than the Latin defaults these system fonts ship with. */
h1, h2, h3, p, li, label, button, input, select, a { line-height: 1.6; }

/* ---- app frame ------------------------------------------------------------ */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.appbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appbar .back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
  font-size: 16px;
  flex: none;
}

#app {
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
  max-width: 560px;
  margin: 0 auto;
}

#status { color: var(--hint); }

/* ---- bottom tab bar -------------------------------------------------------
   Seven destinations never fit across a phone as a top row - the previous
   layout scrolled sideways and simply looked broken. A fixed bottom bar of
   five icons is the pattern mini-apps are expected to use, and the overflow
   destinations live behind "بیشتر". */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  gap: 2px;
  padding: 6px 6px calc(env(safe-area-inset-bottom, 0px) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: var(--r-sm);
  text-decoration: none;
  color: var(--hint);
  font-size: 11px;
  font-weight: 600;
  transition: color .15s ease, background .15s ease;
}

.tabbar a .ico {
  font-size: 19px;
  line-height: 1;
  filter: grayscale(1);
  opacity: .75;
  transition: filter .15s ease, opacity .15s ease, transform .15s ease;
}

.tabbar a.active { color: var(--accent); }
.tabbar a.active .ico { filter: none; opacity: 1; transform: translateY(-1px); }
.tabbar a:active { background: var(--bg); }

/* ---- typography ------------------------------------------------------------ */

.page-title {
  margin: 4px 0 14px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.section-title {
  margin: 22px 4px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--hint);
  text-transform: none;
}

.muted { color: var(--fg-muted); }
.hint { font-size: 12.5px; color: var(--hint); margin: 8px 2px 0; }

/* ---- cards & rows ---------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.card.flush { padding: 4px 16px; }

.card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.card .row:last-child { border-bottom: none; }
.card .row > span:last-child { text-align: left; word-break: break-word; }

.label { color: var(--hint); font-size: 13.5px; flex: none; }

/* ---- hero / identity ------------------------------------------------------- */

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.avatar {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: var(--r-pill);
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 700;
  color: var(--accent-fg);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent) 92%, #fff 8%),
    color-mix(in srgb, var(--accent) 70%, #000 12%));
}

.hero-text { min-width: 0; flex: 1; }
.hero-name { font-size: 17px; font-weight: 700; }
.hero-sub { font-size: 13px; color: var(--hint); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}

.chip.ok { background: color-mix(in srgb, var(--success) 14%, transparent);
           color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); }
.chip.off { background: color-mix(in srgb, var(--hint) 14%, transparent);
            color: var(--fg-muted); border-color: var(--border-strong); }
.chip.warn { background: color-mix(in srgb, var(--warning) 16%, transparent);
             color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.chip.danger { background: color-mix(in srgb, var(--danger) 14%, transparent);
               color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }

/* ---- tile grid (home hub) --------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform .12s ease, border-color .12s ease;
}

.tile:active { transform: scale(.985); border-color: var(--border-strong); }
.tile .ico { font-size: 24px; line-height: 1; }
.tile .t { font-weight: 700; font-size: 15px; }
.tile .s { font-size: 12px; color: var(--hint); }

/* ---- list rows -------------------------------------------------------------- */

.list { margin-top: 12px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
  transition: transform .12s ease, border-color .12s ease;
}

.list-item:active { transform: scale(.99); border-color: var(--border-strong); }

.list-item .li-body { flex: 1; min-width: 0; }
/* Both are spans so the whole row can stay a single <a>; they still need to
   stack rather than run together on one line. */
.list-item .li-title,
.list-item .li-sub { display: block; }
.list-item .li-title { font-weight: 650; font-size: 15px; }
.list-item .li-sub { font-size: 12.5px; color: var(--hint); margin-top: 2px; }
.list-item .li-chev { color: var(--hint); font-size: 15px; flex: none; }
.list-item.inactive .li-title { color: var(--fg-muted); }

.dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--success);
}
.dot.off { background: var(--hint); }

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

.btn,
form.card button,
form.stack button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}

.btn:active, form.card button:active, form.stack button:active { transform: scale(.985); opacity: .92; }
.btn[disabled], form.card button[disabled], form.stack button[disabled] { opacity: .5; pointer-events: none; }

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

.btn.danger, form.card button.danger, form.stack button.danger { background: var(--danger); color: #fff; }

.btn.small { width: auto; margin-top: 0; padding: 8px 14px; font-size: 13px; }

/* ---- forms -------------------------------------------------------------------- */

form.card label,
form.stack label,
.card label,
.field {
  display: block;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
}

form.card label:first-of-type,
form.stack > label:first-of-type { margin-top: 4px; }

form.card input,
form.card select,
form.card textarea,
form.stack input,
form.stack select,
form.stack textarea,
.card input,
.card select,
.card textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  transition: border-color .15s ease, box-shadow .15s ease;
}

form.card input:focus,
form.card select:focus,
form.card textarea:focus,
form.stack input:focus,
form.stack select:focus,
form.stack textarea:focus,
.card input:focus,
.card select:focus,
.card textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

form.card textarea,
form.stack textarea,
.card textarea { min-height: 96px; resize: vertical; line-height: 1.7; }

form.card fieldset {
  margin-top: 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 6px 12px 10px;
}

form.card legend { font-size: 12.5px; color: var(--hint); padding: 0 6px; font-weight: 600; }

form.card .choice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--fg);
  margin: 0;
  padding: 7px 0;
}

form.card .choice input { width: auto; margin: 0; }

/* ---- feedback ------------------------------------------------------------------- */

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  margin-top: 12px;
  border: 1px solid;
}

.alert.error {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
  color: var(--danger);
}

.alert.warn {
  background: color-mix(in srgb, var(--warning) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--warning) 34%, transparent);
  color: var(--warning);
}

.alert.ok {
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
}

.error { color: var(--danger); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--hint);
}

.empty .ico { font-size: 40px; display: block; margin-bottom: 8px; opacity: .55; }
.empty .t { font-weight: 650; color: var(--fg-muted); }
.empty .s { font-size: 12.5px; margin-top: 4px; }

/* Loading placeholders instead of a bare "loading..." line. */
.skeleton {
  background: linear-gradient(90deg,
    var(--border) 25%, color-mix(in srgb, var(--border) 45%, transparent) 37%, var(--border) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--r-md);
  height: 68px;
  margin-bottom: 10px;
}

.skeleton.line { height: 14px; border-radius: var(--r-pill); margin-bottom: 8px; }
.skeleton.line.short { width: 45%; }

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .tile, .list-item, .btn, form.card button { transition: none; }
}

.act-result { font-size: 12.5px; margin: 10px 0 0; color: var(--fg-muted); }
.act-result.error { color: var(--danger); }
.act-result:empty { margin: 0; }

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

/* Sub-navigation inside the admin area: a scrollable pill row is fine here
   because it is one level down and never holds more than five entries. */
.segmented {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0 4px;
  margin-bottom: 4px;
}

.segmented::-webkit-scrollbar { display: none; }

.segmented a {
  flex: none;
  padding: 7px 14px;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.segmented a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.stat .k { font-size: 12px; color: var(--hint); margin-top: 2px; }

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.admin-actions .btn,
.admin-actions button,
.admin-actions select {
  flex: 1 1 auto;
  min-width: 104px;
  width: auto;
  margin-top: 0;
  padding: 9px 12px;
  font-size: 13px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-weight: 650;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}

.admin-actions button.secondary,
.admin-actions .btn.secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--border-strong);
}

.admin-actions button.danger,
.admin-actions .btn.danger { background: var(--danger); color: #fff; }

.admin-actions select {
  background: var(--bg);
  color: var(--fg);
  border-color: var(--border-strong);
}

/* ---- admin editors ------------------------------------------------------------- */
/* A <form class="stack"> lays its fields out directly on the page instead of
   inside one card - the catalog and consultation editors are long enough that a
   single scrolling card would just add a border around the whole screen. */
.stack { margin-top: 12px; }

.stack > label,
.stack > .card { margin-top: 14px; }

/* A row that shows data rather than navigating anywhere: same shape as a
   .list-item link, minus the affordances that would imply it is tappable. */
.list-item.static {
  cursor: default;
  transform: none;
}
.list-item.static:active { transform: none; border-color: var(--border); }

.card .li-title {
  display: block;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 2px;
}

/* Checkbox beside its own label, rather than above it like the text fields. */
label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}
label.inline input { width: auto; margin: 0; }

.question-row { margin-top: 12px; }
.question-row .row { border-bottom: none; padding-bottom: 0; }

/* An <a class="btn"> must sit on the same baseline as a real <button>. */
a.btn { text-align: center; text-decoration: none; }
a.btn.small { display: inline-block; width: auto; }

.list-item a.btn.small,
.list-item button.btn.small,
.list-item button.small { flex: none; width: auto; margin-top: 0; margin-right: 8px; }

/* The user-history report is preformatted Markdown from the bot; it must wrap
   rather than force the page to scroll sideways. */
pre.report {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
}
