:root {
  --bg: #e9ecf2;
  --surface: #ffffff;
  --ink: #1f2a44;
  --muted: #66708a;
  --line: #d5dae4;
  --accent: #2f4fd8;
  --accent-ink: #ffffff;
  --soon: #c2410c;
  --danger: #b42318;
  --code-font: "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --ui-font: Vazirmatn, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --surface: #1a202b;
    --ink: #e8ecf4;
    --muted: #8d96ab;
    --line: #2b3342;
    --accent: #8ea2ff;
    --accent-ink: #10141c;
    --soon: #fb923c;
    --danger: #f97066;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--ui-font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* دکمه‌ها و ورودی‌ها */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer; margin-top: 18px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit;
}
textarea { resize: vertical; font-family: var(--code-font); letter-spacing: .04em; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.err { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 0; }
.hint { color: var(--muted); margin: 0; }
.small { font-size: 13px; }

/* صفحهٔ قفل */
.lock { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.lock-box { width: min(340px, 100%); text-align: center; display: grid; justify-items: center; gap: 10px; }
.logo { border-radius: 18px; }
.lock h1 { font-size: 26px; }
#lockForm { width: 100%; display: grid; gap: 10px; margin-top: 8px; }
#lockForm input { text-align: center; font-size: 20px; letter-spacing: .3em; background: var(--surface); }

/* برنامه */
.app { max-width: 560px; margin: 0 auto; padding: 0 16px 120px; }
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; background: var(--bg);
}
.bar h1 { font-size: 22px; }
.bar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; stroke: currentColor; }
.warn { background: color-mix(in srgb, var(--soon) 14%, transparent); color: var(--ink); padding: 10px 14px; border-radius: 10px; font-size: 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.card {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.card-main {
  flex: 1; min-width: 0; text-align: start;
  display: grid; gap: 2px; padding: 4px 6px; margin: -4px -6px;
  border: 0; border-radius: 10px; background: none; color: inherit; font: inherit; cursor: pointer;
}
.card-main:active { background: var(--surface); }
.meta { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.issuer { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code {
  font-family: var(--code-font); font-variant-numeric: tabular-nums;
  font-size: clamp(34px, 11vw, 44px); font-weight: 600; letter-spacing: .06em;
  color: var(--accent); line-height: 1.15; text-align: right; justify-self: start;
  transition: color .2s;
}
.next { font-family: var(--code-font); font-size: 13px; color: var(--muted); justify-self: start; visibility: hidden; }
.next::before { content: "بعدی: "; font-family: var(--ui-font); }
.card.soon .code { color: var(--soon); }
.card.soon .next { visibility: visible; }
.card.copied .code { color: var(--ink); }

.side { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.timer { position: relative; width: 40px; height: 40px; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; transform: rotate(-90deg) scaleY(-1); }
.ring circle { fill: none; stroke-width: 3.2; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s linear; }
.card.soon .ring-fg { stroke: var(--soon); }
.secs { font-size: 13px; font-weight: 700; }
.del {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; opacity: .7;
}
.del:hover { color: var(--danger); opacity: 1; }
.del svg { width: 16px; height: 16px; stroke: currentColor; }

.empty { text-align: center; padding: 64px 0; color: var(--muted); display: grid; gap: 12px; justify-items: center; }
.empty p { margin: 0; }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab svg { width: 26px; height: 26px; stroke: currentColor; }

/* دیالوگ */
dialog {
  width: min(460px, calc(100% - 24px)); max-height: calc(100% - 24px);
  border: 0; border-radius: 16px; padding: 20px;
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(10 14 22 / .55); }
dialog form, .menu { display: grid; gap: 14px; }
dialog h2 { font-size: 20px; }
dialog h3 { font-size: 16px; margin-bottom: 6px; }
.menu section, #pinForm { display: grid; gap: 8px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details[open] summary { margin-bottom: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; inset-inline: 0; margin: auto; width: max-content; max-width: calc(100% - 32px);
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.fatal { padding: 32px; text-align: center; color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .ring-fg, .toast, .code { transition: none; }
}
