/* B Nazanin is used when installed on the device or when its files are placed in public/fonts/.
   Latin text (model names) falls through to the next family. */
@font-face {
  font-family: "B Nazanin";
  src: local("B Nazanin"), local("BNazanin"), url("/fonts/BNazanin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "B Nazanin";
  src: local("B Nazanin Bold"), local("BNazaninBold"), url("/fonts/BNazanin-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --tile: #0E7C7B;
  --tile-deep: #0A5E5D;
  --tile-soft: #E1F0EF;
  --on-tile: #FFFFFF;
  --ink: #15242A;
  --muted: #5C6F75;
  --paper: #F3F6F5;
  --surface: #FFFFFF;
  --line: #DCE4E2;
  --saffron: #E0A526;
  --crimson: #B42318;
  --crimson-soft: #FBE9E7;
  --r-lg: 18px;
  --r-md: 12px;
  --tabbar: 64px;
  color-scheme: light dark;
  font-family: "B Nazanin", Vazirmatn, "Noto Naskh Arabic", Tahoma, sans-serif;
  font-size: 18px; /* Nazanin's x-height is small: 18px reads like 16px elsewhere */
  line-height: 1.75;
  background: var(--paper);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tile: #47B9B6;
    --tile-deep: #7FD3D0;
    --tile-soft: #173A3B;
    --on-tile: #0D1B1E;
    --ink: #E4EDEB;
    --muted: #93A7AC;
    --paper: #0D1719;
    --surface: #152427;
    --line: #253A3E;
    --crimson: #F28B82;
    --crimson-soft: #3A1E1D;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; }
[hidden] { display: none !important; }
img, svg { display: block; }
a { color: var(--tile-deep); }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: 6px; }
h1, h2 { line-height: 1.3; font-weight: 700; margin: 0; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
input, button { font: inherit; color: inherit; }

/* header + tabs: tabs sit in the header on wide screens, at the bottom (thumb reach) on phones */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 1rem; padding-top: max(.55rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.25rem; color: var(--ink); text-decoration: none; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: .25rem; }
.tabs a { display: flex; align-items: center; gap: .35rem; padding: .3rem .8rem; border-radius: 999px; color: var(--muted); text-decoration: none; }
.tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--tile-deep); background: var(--tile-soft); font-weight: 700; }

@media (max-width: 719px) {
  .tabs {
    position: fixed; inset: auto 0 0 0; z-index: 5;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding: 0 .5rem env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around;
  }
  .tabs a { flex-direction: column; gap: 0; font-size: .8rem; padding: .35rem 1rem; background: none !important; }
  .tabs svg { width: 24px; height: 24px; }
  body:has(.tabs:not([hidden])) main { padding-bottom: calc(var(--tabbar) + 2rem + env(safe-area-inset-bottom)); }
}

main { max-width: 44rem; margin: 0 auto; padding: 1rem 1rem 3rem; }

/* building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem; }
.field { display: grid; gap: .25rem; font-size: .9rem; color: var(--muted); }
.field input, .row input {
  width: 100%; min-height: 48px; padding: .5rem .85rem;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper);
  color: var(--ink); font-size: 1rem;
}
.field input:focus, .row input:focus { outline: none; border-color: var(--tile); box-shadow: 0 0 0 3px var(--tile-soft); }
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }

button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .55; cursor: progress; }
.primary {
  min-height: 48px; padding: .4rem 1.4rem; border-radius: var(--r-md);
  background: var(--tile); color: var(--on-tile); font-weight: 700; font-size: 1.05rem;
}
.primary:hover { background: var(--tile-deep); }
.ghost { min-height: 40px; padding: .2rem 1rem; border-radius: var(--r-md); color: var(--tile-deep); box-shadow: inset 0 0 0 1px var(--line); font-weight: 700; }
.ghost:hover { background: var(--tile-soft); }
.link { color: var(--tile-deep); padding: .25rem .5rem; font-size: .9rem; }
.danger { color: var(--crimson); }
.row { display: flex; gap: .6rem; align-items: center; }
.error { color: var(--crimson); margin: 0; min-height: 1.6em; font-size: .95rem; }

/* segmented control + chips (real radios/checkboxes underneath, so keyboard and screen readers just work) */
.segmented { display: flex; padding: 4px; gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; }
.segmented label { flex: 1; }
.segmented input, .chip input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: .3rem .9rem; border-radius: 999px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segmented input:focus-visible + span, .chip input:focus-visible + span { outline: 3px solid var(--saffron); }
.segmented.small span { padding: .15rem .8rem; font-size: .95rem; }
.chip span { display: inline-block; padding: .25rem .95rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); cursor: pointer; background: var(--surface); }
.chip input:checked + span { background: var(--tile); border-color: var(--tile); color: var(--on-tile); font-weight: 700; }

/* auth */
.auth { display: grid; gap: 1.5rem; padding-top: 1.5rem; }
.hero h1 { font-size: 2.2rem; }
.hero p { color: var(--muted); margin: .6rem 0 0; max-width: 30em; }
#auth-form { display: grid; gap: 1rem; max-width: 26rem; width: 100%; }
.pass { position: relative; display: block; }
.pass .link { position: absolute; inset-inline-end: .4rem; inset-block: 0; }
.pass input { padding-inline-end: 4.5rem; }
@media (min-width: 720px) { .auth { grid-template-columns: 1fr 26rem; align-items: center; padding-top: 4rem; } }

/* search form */
.search { display: grid; gap: .9rem; }
.fields { display: grid; grid-template-columns: 1.3fr 1fr; gap: .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.chips .segmented { margin-inline-start: auto; }
@media (max-width: 30rem) {
  .fields { grid-template-columns: 1fr; }
  .chips .segmented { margin-inline-start: 0; width: 100%; }
}

/* results */
.best { margin-top: 1.25rem; position: relative; overflow: hidden; }
.best .label { color: var(--muted); font-size: .95rem; }
.best .amount { font-size: 2.4rem; font-weight: 700; line-height: 1.25; margin: .2rem 0 .7rem; }
.best .amount span { text-decoration: underline 5px var(--saffron); text-underline-offset: 10px; text-decoration-skip-ink: none; }
.best .amount small { font-size: 1rem; color: var(--muted); font-weight: 400; margin-inline-start: .3rem; }
.best .meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; }

.sites { display: flex; flex-wrap: wrap; gap: .35rem 1rem; list-style: none; margin: .9rem .2rem; padding: 0; color: var(--muted); font-size: .85rem; }
.sites li::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--tile); margin-inline-end: .35rem; vertical-align: .15em; }
.sites li.down::before { background: var(--crimson); }

.offers { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.offer { display: grid; grid-template-columns: 1fr auto; gap: .15rem .9rem; }
.offer .where { font-size: .85rem; color: var(--muted); }
.offer h3 { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.offer .price { grid-row: 1 / 3; grid-column: 2; text-align: left; white-space: nowrap; }
.offer .price b { display: block; font-size: 1.45rem; line-height: 1.3; }
.offer .price small { color: var(--muted); font-size: .8rem; }
.tags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.tag { font-size: .8rem; padding: 0 .55rem; border-radius: 6px; background: var(--tile-soft); color: var(--tile-deep); }
.tag.bad { background: var(--crimson-soft); color: var(--crimson); }
.tag.plain { background: none; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.offer .foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .5rem; padding-top: .55rem; border-top: 1px dashed var(--line); }
.offer .foot a { font-weight: 700; text-decoration: none; white-space: nowrap; }

.plans-x { grid-column: 1 / -1; list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .4rem; }
.plans-x li { background: var(--paper); border-radius: var(--r-md); padding: .45rem .75rem; font-size: .92rem; }
.plans-x .more { color: var(--crimson); }
.plans-x .same { color: var(--tile-deep); }
.plans-x .sub { color: var(--muted); font-size: .85rem; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty strong { display: block; color: var(--ink); font-size: 1.1rem; margin-bottom: .3rem; }

/* skeleton while sites answer */
.skeleton { display: grid; gap: .7rem; margin-top: 1.25rem; }
.skeleton .card { height: 7.5rem; background: linear-gradient(90deg, var(--surface) 30%, var(--paper) 50%, var(--surface) 70%) 0 0 / 300% 100%; animation: shimmer 1.3s linear infinite; }
.skeleton .card:first-child { height: 9rem; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* account */
.banner { padding: .7rem 1rem; border-radius: var(--r-md); margin-bottom: 1rem; background: var(--tile-soft); color: var(--tile-deep); }
.banner.bad { background: var(--crimson-soft); color: var(--crimson); }
.sub .days { font-size: 2.6rem; font-weight: 700; line-height: 1.2; }
.sub .days small { font-size: 1rem; color: var(--muted); font-weight: 400; margin-inline-start: .3rem; }
.sub p { margin: .2rem 0 0; color: var(--muted); }
.meter { height: 8px; border-radius: 8px; background: var(--paper); margin-top: .8rem; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--tile); border-radius: inherit; }
.plans { display: grid; gap: .6rem; }
.plan { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.plan b { font-size: 1.05rem; }
.plan p { margin: 0; color: var(--muted); font-size: .9rem; }
#logout { margin-top: 2rem; }

/* admin */
#admin-search { padding: .6rem; }
.users { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .6rem; }
.user { display: grid; gap: .5rem; }
.user .head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.user .phone { font-weight: 700; direction: ltr; font-size: 1.05rem; }
.pill { font-size: .8rem; padding: 0 .6rem; border-radius: 999px; background: var(--tile-soft); color: var(--tile-deep); }
.pill.off { background: var(--crimson-soft); color: var(--crimson); }
.user .when { color: var(--muted); font-size: .9rem; }
.user .acts { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.user .acts input { width: 5rem; min-height: 40px; padding: .2rem .5rem; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); text-align: center; }

.toast {
  position: fixed; inset-inline: 1rem; bottom: calc(var(--tabbar) + 1rem + env(safe-area-inset-bottom)); z-index: 9;
  max-width: 24rem; margin: 0 auto; padding: .6rem 1rem; border-radius: var(--r-md);
  background: var(--ink); color: var(--paper); text-align: center; box-shadow: 0 6px 24px rgb(0 0 0 / .2);
}
@media (min-width: 720px) { .toast { bottom: 1.5rem; } }

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