/* The panel's whole appearance. Hand written, no build step, no npm.
   Phone first: everything below is the phone layout, and the two media
   queries at the end are the only places a bigger screen is considered. */

@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Regular.ttf") format("truetype");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Medium.ttf") format("truetype");
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Bold.ttf") format("truetype");
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e2e5ea;
  --text: #16191d;
  --muted: #6a7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --danger: #e11d2f;
  --danger-soft: #fdeaec;
  --ok: #12a150;
  --ok-soft: #e6f7ed;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 16px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 8px 24px rgba(16, 20, 28, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1e232b;
    --line: #2a313b;
    --text: #e8eaee;
    --muted: #9aa3b0;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --accent-soft: #1b2438;
    --danger: #ff6b76;
    --danger-soft: #2a0d11;
    --ok: #4ade80;
    --ok-soft: #072014;
    --warn: #fbbf24;
    --warn-soft: #2a2008;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

/* Every icon is an inline SVG with no size of its own, so one default is set
   here. Without it an icon inside a flexible box grows to fill the box: the
   history page had a chevron the size of a card, which no automatic check
   noticed and a glance at a screenshot did. */
svg { width: 20px; height: 20px; flex: 0 0 auto; }

/* --- the frame ---------------------------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  min-height: 56px; padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top h1 {
  margin: 0; font-size: 18px; font-weight: 700; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top .who {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px; white-space: nowrap;
}
.top .back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin-inline-start: -8px;
  border-radius: 12px; color: var(--text);
}
.top .back:active { background: var(--surface-2); }

main {
  max-width: 820px; margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

/* One element. On a phone it is fixed to the bottom where a thumb already is;
   on a wide screen the same list becomes a row under the header. It is never
   two lists, so the two can never disagree. */
nav.bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
nav.bar a {
  flex: 1 1 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; padding: 6px 2px;
  color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.2;
}
nav.bar a svg { width: 24px; height: 24px; display: block; }
nav.bar a.on { color: var(--accent); }
nav.bar a.on svg { stroke-width: 2.2; }

/* --- pieces ------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card > h2 {
  margin: 0 0 12px; font-size: 16px; font-weight: 700; line-height: 1.5;
}
.card > h2 .count { color: var(--muted); font-weight: 500; font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.7; }
.center { text-align: center; }
.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  direction: ltr; unicode-bidi: isolate; letter-spacing: .3px;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px; min-height: 84px; padding: 10px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px;
  text-align: center;
}
.stat b { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12px; line-height: 1.4; }
.stat.good b { color: var(--ok); }
.stat.bad b { color: var(--danger); }

.rows { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px;
  color: var(--text);
}
.row .grow { flex: 1 1 auto; min-width: 0; }
.row .grow b { display: block; font-weight: 700; line-height: 1.5; }
.row .grow span {
  display: block; color: var(--muted); font-size: 13px; line-height: 1.6;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .chev { color: var(--muted); flex: 0 0 auto; display: flex; }

/* Several small facts on one line. They are separate elements rather than one
   sentence with dots in it: a neutral character between a Persian word and a
   Persian digit is reordered by the bidi algorithm and ends up on the wrong
   side of the number. Seen in a screenshot, not in the markup. */
.row .grow span.parts {
  display: flex; flex-wrap: wrap; gap: 2px 14px;
  white-space: normal; overflow: visible;
}
.row .grow span.parts > span { display: inline; }

.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 26px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1;
  background: var(--accent-soft); color: var(--accent);
  white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.plain { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }

.notice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: 14px; margin-bottom: 16px;
  font-size: 14px; line-height: 1.7;
}
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

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

label.field { display: block; margin-bottom: 14px; }
label.field > span.name {
  display: block; margin-bottom: 6px;
  font-size: 14px; font-weight: 500; line-height: 1.6;
}
label.field > span.hint {
  display: block; margin-top: 6px;
  color: var(--muted); font-size: 13px; line-height: 1.7;
}

input[type="text"], input[type="password"], input[type="number"],
input[type="search"], input[type="tel"], textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  /* 16px is not a preference. Anything smaller and iOS Safari zooms the whole
     page the instant the field is tapped. */
  font-family: inherit; font-size: 16px; line-height: 1.7;
}
textarea { min-height: 160px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
  border-color: transparent;
}
/* The file field itself is invisible and covers the box below it, so a tap
   anywhere on the box opens the picker. 16px because it is still a field and
   iOS zooms the page for anything smaller. */
.filepick { position: relative; }
.filepick input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; font-size: 16px; cursor: pointer;
}
.filepick .face {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  min-height: 84px; padding: 12px 14px; text-align: center;
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: 12px;
}
.filepick .pick { font-size: 16px; font-weight: 700; color: var(--accent); }
.filepick .chosen {
  max-width: 100%; color: var(--muted); font-size: 13px; line-height: 1.6;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.field > span.name {
  display: block; margin-bottom: 6px;
  font-size: 14px; font-weight: 500; line-height: 1.6;
}
.field > span.hint {
  display: block; margin-top: 6px;
  color: var(--muted); font-size: 13px; line-height: 1.7;
}
div.field { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font-family: inherit; font-size: 16px; font-weight: 700; line-height: 1;
  cursor: pointer;
}
.btn.wide { width: 100%; }
.btn.quiet {
  background: var(--surface-2); color: var(--text); border-color: var(--line);
}
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:active { filter: brightness(.95); }
.btn[disabled] { opacity: .5; cursor: default; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions > form { flex: 1 1 160px; display: flex; }
.actions > form > .btn { width: 100%; }
.inline { display: flex; gap: 10px; align-items: flex-end; }
.inline > label.field { flex: 1 1 auto; margin-bottom: 0; }

/* --- sign in ------------------------------------------------------------ */

.gate {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.gate .card { width: 100%; max-width: 380px; margin: 0; padding: 24px; }
.gate h1 {
  margin: 0 0 4px; font-size: 20px; font-weight: 700; text-align: center;
}
.gate p.lead {
  margin: 0 0 20px; color: var(--muted); font-size: 14px; text-align: center;
  line-height: 1.8;
}
.code-input {
  text-align: center; letter-spacing: 10px; font-size: 26px; font-weight: 700;
  direction: ltr; min-height: 60px;
}

/* --- the gallery -------------------------------------------------------- */

.gallery { display: flex; flex-direction: column; gap: 16px; }
.shot {
  display: block; width: 100%; height: auto; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
}
/* Both states side by side at every width, including a phone: the point of the
   gallery is comparing the two, and a column of twenty-four full-width
   pictures is a page nobody scrolls to the end of. The full-size pair is one
   tap away on the template's own page. */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair figure { margin: 0; }
.pair figcaption {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.6;
}
/* The single template's own page: one picture at a time on a phone, because
   here the point is to see it properly, and two across on a wide screen where
   there is room for both. */
.pair-big { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .pair-big { grid-template-columns: 1fr 1fr; } }

.tile { padding: 12px; }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.tile .head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.tile .head b { font-size: 16px; font-weight: 700; line-height: 1.5; }

/* --- history ------------------------------------------------------------ */

details.raw { margin-top: 10px; }
details.raw > summary {
  display: flex; align-items: center; gap: 6px;
  min-height: 40px; color: var(--muted); font-size: 13px; cursor: pointer;
  list-style: none;
}
details.raw > summary::-webkit-details-marker { display: none; }
details.raw pre {
  margin: 8px 0 0; padding: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px;
  direction: ltr; text-align: left;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}

.pager { display: flex; gap: 10px; margin-top: 16px; }
.pager .btn { flex: 1 1 0; }

.entry { padding: 12px; }
.entry .line1 {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.entry .line1 b { font-size: 16px; font-weight: 700; }
.entry .line2 {
  display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px;
  color: var(--muted); font-size: 13px; line-height: 1.7;
}

/* --- a bigger screen ---------------------------------------------------- */

@media (min-width: 900px) {
  body { font-size: 16px; }
  main { padding: 24px 24px 48px; max-width: 900px; }
  nav.bar {
    position: static; border-top: 0; border-bottom: 1px solid var(--line);
    justify-content: center; gap: 4px; padding: 6px 16px;
  }
  nav.bar a {
    flex: 0 0 auto; flex-direction: row; gap: 8px;
    min-height: 44px; padding: 0 14px; border-radius: 12px; font-size: 14px;
  }
  nav.bar a.on { background: var(--accent-soft); }
  .pair { grid-template-columns: 1fr 1fr; gap: 14px; }
  .stats { gap: 14px; }
}

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

/* The sign-in code, shown large enough to compare with the one in Telegram
   without squinting. Left to right, because it is not Persian text. */
.code-show {
  font: 800 34px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: .18em;
  text-align: center;
  direction: ltr;
  padding: 18px 12px;
  margin: 18px 0;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--text);
}

/* Spacing that used to be written as style="..." on the element. The panel
   sends a content security policy without 'unsafe-inline', which blocks a
   style attribute exactly as it blocks a script written into the page - so
   every one of those was silently doing nothing. */
[data-flush="bottom"] { margin-bottom: 0; }
[data-flush="top"] { margin-top: 0; }
[data-gap="below"] { margin: 0 0 14px; }
[data-gap="above"] { margin-top: 10px; }
