/* ───────────────────────────────────────────────────────────
   Shared admin panel — themeable via CSS variables.
   Each design overrides the :root vars to match its front.
   RTL, Persian-first. No external dependencies.
   ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #f1ede6;
  --panel:     #ffffff;
  --panel-2:   #f7f4ef;
  --text:      #1f1b16;
  --muted:     #8c8377;
  --border:    rgba(31,27,22,0.12);
  --border-2:  rgba(31,27,22,0.06);
  --accent:    #b5642c;
  --accent-2:  #8f4d20;
  --on-accent: #ffffff;
  --danger:    #c0392b;
  --danger-bg: #fdecea;
  --ok:        #2e7d54;
  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 1px 2px rgba(0,0,0,.04), 0 8px 30px rgba(0,0,0,.06);
  --font-ui:      "Vazirmatn", system-ui, sans-serif;
  --font-display: "Vazirmatn", system-ui, sans-serif;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
::selection { background: var(--accent); color: var(--on-accent); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .62rem 1.15rem; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: var(--font-ui); font-size: .88rem; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, filter .15s ease, background .15s, border-color .15s, color .15s;
  white-space: nowrap; line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { border-color: var(--muted); color: var(--text); }
.btn-soft  { background: var(--panel-2); color: var(--text); border-color: var(--border-2); }
.btn-soft:hover { border-color: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(.97); }
.btn-sm { padding: .4rem .75rem; font-size: .78rem; }
.btn-full { width: 100%; }
.btn-icon { padding: .42rem .55rem; }

/* ── Login ── */
#loginView {
  min-height: 100vh; display: none; align-items: center; justify-content: center; padding: 1.5rem;
}
#loginView.show { display: flex; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.25rem; width: 360px; max-width: 100%; box-shadow: var(--shadow);
}
.login-brand {
  font-family: var(--font-display); font-size: 1.55rem; font-weight: 800;
  color: var(--accent); margin-bottom: .25rem;
}
.login-sub { font-size: .85rem; color: var(--muted); margin-bottom: 1.75rem; }
.login-err {
  display: none; background: var(--danger-bg); color: var(--danger);
  font-size: .82rem; padding: .55rem .75rem; border-radius: var(--radius-sm); margin-bottom: .9rem;
}
.login-back { display: block; text-align: center; margin-top: 1.1rem; font-size: .8rem; color: var(--muted); text-decoration: none; }
.login-back:hover { color: var(--accent); }
.login-hint { margin-top: 1rem; text-align: center; font-size: .72rem; color: var(--muted); }

/* ── Form fields ── */
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }
.field > label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .4rem; color: var(--text); }
/* Bare <input> (no type attribute) is rendered as text by the browser but is
   NOT matched by input[type=text]; target it explicitly so every text-like
   field inherits the Persian UI font instead of the browser default serif. */
.input, input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; padding: .62rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font-ui); font-size: .9rem; color: var(--text); background: var(--panel);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
textarea { resize: vertical; min-height: 78px; line-height: 1.7; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 560px){ .grid-2 { grid-template-columns: 1fr; } }

/* ── Shell ── */
#appView { display: none; min-height: 100vh; }
#appView.show { display: block; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.25rem;
}
.topbar-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.topbar-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.topbar-actions a { color: var(--muted); font-size: .85rem; text-decoration: none; }
.topbar-actions a:hover { color: var(--accent); }

.tabs {
  position: sticky; top: 57px; z-index: 40;
  display: flex; gap: .15rem; background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0 1.25rem; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none; background: none; cursor: pointer; white-space: nowrap;
  font-family: var(--font-ui); font-size: .88rem; color: var(--muted);
  padding: .85rem .9rem; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.panel { display: none; }
.panel.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.panel-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; }
.panel-note { font-size: .82rem; color: var(--muted); margin-top: .15rem; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.1rem; }
.card-title { font-weight: 700; font-size: 1rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }

/* ── Table ── */
.table-scroll { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 560px; }
th { text-align: right; font-weight: 600; color: var(--muted); background: var(--panel-2); padding: .7rem .85rem; font-size: .8rem; white-space: nowrap; }
td { padding: .7rem .85rem; border-top: 1px solid var(--border-2); vertical-align: middle; }
tbody tr:hover { background: var(--panel-2); }
.t-name { font-weight: 600; }
.t-actions { display: flex; gap: .35rem; justify-content: flex-end; }
.muted { color: var(--muted); }
.center { text-align: center; }

.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 600; padding: .2rem .55rem; border-radius: 100px; }
.pill-on  { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pill-off { background: var(--danger-bg); color: var(--danger); }
.pill-star { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.cat-emoji { font-size: 1.15rem; }

/* ── Switch ── */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .55rem 0; }
.switch-row + .switch-row { border-top: 1px solid var(--border-2); }
.switch-label { font-size: .86rem; font-weight: 500; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--border); border-radius: 100px; transition: background .18s; cursor: pointer; }
.switch .track::before { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; right: 3px; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(-18px); }
.sub-field { margin-top: .5rem; }
.option-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .85rem 1rem; background: var(--panel-2); }
.option-box .box-title { font-size: .82rem; font-weight: 700; color: var(--accent); margin-bottom: .4rem; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,12,9,.5); backdrop-filter: blur(2px); z-index: 100; align-items: center; justify-content: center; padding: 1.25rem; }
.modal-overlay.open { display: flex; animation: fade .2s ease; }
.modal { background: var(--panel); border-radius: var(--radius); width: 540px; max-width: 100%; max-height: 92vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-head { position: sticky; top: 0; background: var(--panel); padding: 1.25rem 1.4rem .9rem; border-bottom: 1px solid var(--border-2); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; }
.modal-x { background: none; border: none; font-size: 1.25rem; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 1.25rem 1.4rem; }
.modal-foot { position: sticky; bottom: 0; background: var(--panel); padding: .9rem 1.4rem 1.25rem; border-top: 1px solid var(--border-2); display: flex; gap: .6rem; justify-content: flex-start; }

/* ── QR ── */
.qr-result { margin-top: 1.25rem; text-align: center; }
.qr-result img { width: 230px; max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); padding: .5rem; background: #fff; }
.qr-url { font-size: .78rem; color: var(--muted); margin: .6rem 0; word-break: break-all; }

/* ── Toast ── */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(90px); background: var(--text); color: var(--bg); padding: .7rem 1.3rem; border-radius: 100px; font-size: .86rem; font-weight: 600; z-index: 200; transition: transform .3s cubic-bezier(.34,1.56,.64,1); pointer-events: none; white-space: nowrap; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.toast.show { transform: translateX(-50%) translateY(0); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: rot .7s linear infinite; vertical-align: middle; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ── Item image upload ── */
input[type=file] { font: inherit; color: var(--muted); width: 100%; padding: .4rem 0; cursor: pointer; }
input[type=file]::file-selector-button {
  font: inherit; cursor: pointer; margin-inline-end: .7rem;
  padding: .45rem .9rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text); transition: border-color .15s, color .15s;
}
input[type=file]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }
.img-preview { margin-top: .65rem; display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }
.img-preview img { display: block; max-width: 100%; max-height: 200px; border-radius: var(--radius-sm); border: 1px solid var(--border); object-fit: cover; }

/* ── Analytics dashboard ─────────────────────────────────── */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem 1.1rem; }
.stat-num { font-size: 1.7rem; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-lab { font-size: .76rem; color: var(--muted); margin-top: .35rem; }

.chart { margin-top: .4rem; }
.bars { display: flex; align-items: flex-end; gap: .35rem; height: 168px; overflow-x: auto; padding-top: .5rem; }
.bar-col { flex: 1 0 auto; min-width: 20px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-val { font-size: .6rem; color: var(--muted); height: 1rem; font-variant-numeric: tabular-nums; }
.bar-track { flex: 1; width: 62%; max-width: 28px; display: flex; align-items: flex-end; background: var(--border-2); border-radius: 5px 5px 0 0; }
.bar-fill { width: 100%; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 2px; transition: height .3s; }
.bar-lab { font-size: .6rem; color: var(--muted); margin-top: .35rem; white-space: nowrap; }

.top-list { display: flex; flex-direction: column; gap: .55rem; }
.top-row { display: flex; align-items: center; gap: .7rem; }
.top-rank { width: 1.4rem; color: var(--muted); font-size: .8rem; font-weight: 700; text-align: center; }
.top-name { flex: 0 0 38%; font-weight: 600; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-bar { flex: 1; height: 8px; background: var(--border-2); border-radius: 100px; overflow: hidden; }
.top-fill { height: 100%; background: var(--accent); border-radius: 100px; }
.top-num { width: 2.6rem; text-align: left; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Per-table QR grid ───────────────────────────────────── */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-top: 1rem; }
.qr-item { text-align: center; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .85rem; }
.qr-item img { width: 100%; max-width: 160px; height: auto; border-radius: 6px; }
.qr-lab { font-weight: 700; margin: .45rem 0; }

/* ── Translation editors (textarea inside option-box) ────── */
.tr-input { width: 100%; }
textarea.tr-input { min-height: 60px; }
