/* =========================================================================
   یارا — Console
   Aesthetic: "Editorial Ledger". Ink on warm paper, hairline rules instead of
   shadows, a rust accent, and mono type for anything Latin. Sharp corners,
   ruled panels, no glass, no gradients, no glow.
   ========================================================================= */

/* ---------- Fonts (self-hosted; no external download) ----------
   Vazirmatn variable font, served from /static/fonts. Previously this loaded
   from Google Fonts, which fails on a server with no outbound internet and is
   blocked by the panel's Content-Security-Policy. One variable file covers all
   weights (400/500/700/900). Latin/mono falls back to system fonts. */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root,
:root[data-theme="light"] {
  --paper: #f2efe7;
  --paper-2: #e9e5da;
  --surface: #fbfaf6;
  --surface-2: #f4f1e9;
  --surface-sunk: #eae6db;

  --ink: #17150f;
  --ink-2: #4d483d;
  --ink-3: #837d6d;
  --ink-4: #a9a293;

  --rule: #d8d1c0;
  --rule-strong: #b8b0a0;

  --rust: #ab4318;
  --rust-soft: #f0e0d6;
  --pine: #1e4b45;
  --pine-soft: #dbe6e2;
  --gold: #9a6b12;
  --gold-soft: #f2e6c8;
  --crimson: #92211d;
  --crimson-soft: #f3dcd8;
  --plum: #633f60;
  --plum-soft: #ebdfea;

  --on-accent: #fbf8f2;
  --focus: #ab4318;

  --grain: rgba(23, 21, 15, 0.035);
  --shade: rgba(23, 21, 15, 0.06);
  --backdrop: rgba(23, 21, 15, 0.42);
}

:root[data-theme="dark"] {
  --paper: #100f0d;
  --paper-2: #16150f;
  --surface: #1a1814;
  --surface-2: #211e19;
  --surface-sunk: #14130f;

  --ink: #ece5d6;
  --ink-2: #b4ac9b;
  --ink-3: #8a8271;
  --ink-4: #635d51;

  --rule: #302c25;
  --rule-strong: #474137;

  --rust: #e0703f;
  --rust-soft: #33211a;
  --pine: #58ab9d;
  --pine-soft: #16292a;
  --gold: #cf9f3d;
  --gold-soft: #2c2517;
  --crimson: #d95f52;
  --crimson-soft: #331c1a;
  --plum: #b58bb0;
  --plum-soft: #291d29;

  --on-accent: #16130f;
  --focus: #e0703f;

  --grain: rgba(236, 229, 214, 0.03);
  --shade: rgba(0, 0, 0, 0.3);
  --backdrop: rgba(8, 7, 6, 0.68);
}

:root {
  --fa: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", ui-monospace, monospace;
  --r: 3px;
  --r-lg: 4px;
  --gap: 18px;
  --tap: 38px;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--fa);
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--paper);
  /* Ruled-paper grain: hairlines, not a gradient. */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 27px,
    var(--grain) 27px 28px
  );
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 900;
  letter-spacing: -0.015em;
  line-height: 1.35;
}

p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Anything Latin reads in mono, isolated LTR. */
.mono,
.lat,
code,
pre {
  font-family: var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}

.lat {
  font-size: 0.74em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.rule {
  height: 1px;
  background: var(--rule);
  margin: 16px 0;
}

.rule--double {
  height: 3px;
  background: none;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rust);
  display: flex;
  align-items: center;
  gap: 8px;
}

.kicker::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--rust);
  flex: none;
}

.hint {
  color: var(--ink-3);
  font-size: 0.83rem;
  line-height: 1.6;
}

.tiny {
  font-size: 0.75rem;
}

/* ---------- Shells ---------- */
.shell--center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}

.auth {
  width: min(1000px, 100%);
}

.auth__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brandMark,
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--rust);
  color: var(--on-accent);
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
  padding-bottom: 4px;
  border-radius: var(--r);
}

.brandTitle {
  font-size: 1.6rem;
}

.brand h1 {
  font-size: 1.25rem;
}

.brandSubtitle,
.brand p {
  margin: 0;
  color: var(--ink-3);
  font-size: 0.82rem;
}

.auth__card {
  padding: 0;
}

.auth__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 26px 26px 18px;
}

.auth__welcome h2 {
  font-size: 1.75rem;
  margin: 10px 0 6px;
}

.auth__card > .rule--double {
  margin: 0;
}

.auth__form {
  padding: 24px 26px 28px;
}

.authPane {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 18px;
  background: var(--surface-2);
}

.auth__footer {
  margin-top: 18px;
  text-align: center;
}

.sectionHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sectionTitle {
  font-weight: 700;
  font-size: 1rem;
}

/* ---------- App layout ---------- */
.app {
  display: grid;
  grid-template-columns: 272px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-inline-end: 1px solid var(--rule);
  background: var(--surface);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__inner {
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  background: none;
  border: 0;
  border-inline-start: 3px solid transparent;
  border-radius: 0 var(--r) var(--r) 0;
  cursor: pointer;
  text-align: start;
  color: var(--ink-2);
  transition: background 0.12s, color 0.12s;
}

.nav button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav button.active {
  background: var(--rust-soft);
  color: var(--ink);
  border-inline-start-color: var(--rust);
  font-weight: 700;
}

.nav button.active .meta {
  color: var(--rust);
}

.nav__content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.meta {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.sidebar__footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main {
  padding: 26px 30px 60px;
  min-width: 0;
}

.main__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 22px;
  border-bottom: 3px double var(--rule-strong);
}

.main__headline {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-top: 6px;
}

/* ---------- Pills / chips / tags / badges ---------- */
.pill {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
}

.pill > span {
  font-size: 0.76rem;
  color: var(--ink-3);
}

.pill > strong {
  font-weight: 700;
  font-size: 0.9rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.chip--live {
  color: var(--pine);
  border-color: var(--pine);
  background: var(--pine-soft);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: blip 2.2s ease-in-out infinite;
}

@keyframes blip {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.28; }
}

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; }
}

.tag {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 2px;
  border: 1px solid currentColor;
  flex: none;
}

.tag--provider {
  color: var(--rust);
  background: var(--rust-soft);
}

.tag--tenant {
  color: var(--pine);
  background: var(--pine-soft);
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 2px;
  font-size: 0.76rem;
  font-weight: 500;
  border: 1px solid var(--rule-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}

.badge.success {
  color: var(--pine);
  border-color: var(--pine);
  background: var(--pine-soft);
}

.badge.danger {
  color: var(--crimson);
  border-color: var(--crimson);
  background: var(--crimson-soft);
}

.badge.warning {
  color: var(--gold);
  border-color: var(--gold);
  background: var(--gold-soft);
}

.badge.primary {
  color: var(--rust);
  border-color: var(--rust);
  background: var(--rust-soft);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 8px 16px;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Support both BEM (`btn--primary`) and legacy (`btn primary`) spellings. */
.btn--primary,
.btn.primary {
  background: var(--rust);
  border-color: var(--rust);
  color: var(--on-accent);
}

.btn--primary:hover,
.btn.primary:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn--secondary,
.btn.secondary {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--on-accent);
}

.btn--secondary:hover,
.btn.secondary:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn--danger,
.btn.danger {
  background: transparent;
  border-color: var(--crimson);
  color: var(--crimson);
}

.btn--danger:hover,
.btn.danger:hover {
  background: var(--crimson);
  color: var(--on-accent);
}

.btn--ghost,
.btn.ghost {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--ink-2);
}

.btn--ghost:hover,
.btn.ghost:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--surface-2);
}

.btn.icon {
  min-height: 30px;
  width: 30px;
  padding: 0;
  border-radius: 2px;
}

.btn--sm {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Theme toggle ---------- */
.themeToggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  min-height: var(--tap);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--ink-2);
}

.themeToggle--block {
  width: 100%;
  justify-content: space-between;
}

.themeToggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.themeToggle__track {
  position: relative;
  width: 38px;
  height: 18px;
  flex: none;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: var(--surface-sunk);
}

.themeToggle__thumb {
  position: absolute;
  top: 1px;
  inset-inline-start: 1px;
  width: 16px;
  height: 14px;
  background: var(--ink-3);
  transition: inset-inline-start 0.16s ease, background 0.16s;
}

:root[data-theme="dark"] .themeToggle__thumb {
  inset-inline-start: 19px;
  background: var(--rust);
}

.themeToggle__label {
  font-size: 0.8rem;
}

/* ---------- Cards / topbar / grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  margin-bottom: var(--gap);
}

.card > h3 {
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 16px;
}

.card > h3::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: none;
  background: var(--rust);
}

.card > h3 + .sub {
  margin-top: -8px;
  margin-bottom: 16px;
  color: var(--ink-3);
  font-size: 0.83rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: var(--gap);
  flex-wrap: wrap;
}

.topbar h2 {
  font-size: 1.28rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.grid > .card {
  grid-column: span 12;
  margin-bottom: 0;
}

/* ---------- Stats ---------- */
.stat {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  width: 3px;
  height: 100%;
  background: var(--rust);
}

.stat .label {
  font-size: 0.78rem;
  color: var(--ink-3);
}

.stat .value {
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.stat .chip {
  align-self: flex-start;
  margin-top: 2px;
}

.stat--pine::before { background: var(--pine); }
.stat--gold::before { background: var(--gold); }
.stat--plum::before { background: var(--plum); }
.stat--crimson::before { background: var(--crimson); }

/* ---------- Forms ---------- */
.form {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

.field {
  grid-column: span 6;
  min-width: 0;
}

.field.half {
  grid-column: span 3;
}

.field.third {
  grid-column: span 2;
}

.form > .row--2 {
  grid-column: span 6;
}

.row--2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

label {
  display: block;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 7px;
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface-sunk);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  transition: border-color 0.12s, background 0.12s;
}

input.mono,
textarea.mono {
  font-family: var(--mono);
  direction: ltr;
  text-align: left;
}

textarea {
  min-height: 92px;
  line-height: 1.7;
  resize: vertical;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--ink-3);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--rust);
  background: var(--surface);
}

input:disabled,
input[readonly] {
  color: var(--ink-3);
  background: var(--surface-2);
  cursor: default;
}

input::placeholder,
textarea::placeholder {
  color: var(--ink-4);
}

input[type="checkbox"] {
  width: 17px;
  height: 17px;
  min-height: 0;
  accent-color: var(--rust);
  cursor: pointer;
}

.checkRow {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.checkRow > label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  cursor: pointer;
  font-weight: 400;
  color: var(--ink);
}

/* Backwards-compatible alias used by the JS templates. */
.input {
  width: 100%;
}

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.table th {
  text-align: start;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 2px solid var(--rule-strong);
  white-space: nowrap;
}

.table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.tableWrap {
  overflow-x: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

/* ---------- Segmented control (filters) ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface-sunk);
}

.seg button {
  border: 0;
  background: none;
  padding: 7px 16px;
  min-height: 34px;
  cursor: pointer;
  color: var(--ink-3);
  font-size: 0.83rem;
  border-inline-end: 1px solid var(--rule);
  transition: background 0.12s, color 0.12s;
}

.seg button:last-child {
  border-inline-end: 0;
}

.seg button:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.seg button.active {
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
}

.seg .segCount {
  font-family: var(--mono);
  font-size: 0.72rem;
  opacity: 0.72;
  margin-inline-start: 6px;
}

.filterBar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filterBar__label {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Time-range picker ---------- */
.trp {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 14px;
}

.trp__ranges {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.trp__empty {
  color: var(--ink-3);
  font-size: 0.83rem;
  padding: 10px 2px;
}

.trp__row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
}

.trp__sep {
  color: var(--ink-3);
  font-size: 0.82rem;
}

.trp__row select {
  min-height: 32px;
  width: auto;
  min-width: 92px;
  padding: 4px 8px;
  font-size: 0.85rem;
}

.trp__span {
  margin-inline-start: auto;
  font-size: 0.78rem;
  color: var(--ink-3);
}

.trp__row.invalid {
  border-color: var(--crimson);
  background: var(--crimson-soft);
}

.trp__foot {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Visual 24h band showing the selected ranges. */
.trp__band {
  position: relative;
  height: 26px;
  flex: 1 1 220px;
  min-width: 180px;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: var(--surface-sunk);
  overflow: hidden;
  direction: ltr;
}

.trp__bandFill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--rust);
  opacity: 0.85;
}

.trp__bandTicks {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
}

.trp__bandTick {
  flex: 1;
  border-inline-end: 1px solid var(--rule);
}

.trp__bandTick:last-child {
  border-inline-end: 0;
}

.trp__scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--ink-4);
  margin-top: 3px;
  direction: ltr;
}

.trp__presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chipBtn {
  border: 1px dashed var(--rule-strong);
  background: none;
  color: var(--ink-3);
  border-radius: 2px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  min-height: 28px;
}

.chipBtn:hover {
  border-style: solid;
  border-color: var(--rust);
  color: var(--rust);
}

/* ---------- Weekday windows editor ---------- */
.wdw {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wdw__day {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
}

.wdw__dayHead {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid transparent;
}

.wdw__day.open .wdw__dayHead {
  border-bottom-color: var(--rule);
}

.wdw__dayName {
  font-weight: 700;
  font-size: 0.92rem;
}

.wdw__daySummary {
  margin-inline-start: auto;
  font-size: 0.8rem;
  color: var(--ink-3);
}

.wdw__day.closed .wdw__dayName {
  color: var(--ink-4);
  text-decoration: line-through;
}

.wdw__body {
  padding: 12px 14px;
}

.wdw__day:not(.open) .wdw__body {
  display: none;
}

/* ---------- Jalali calendar ---------- */
.jcal {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 14px;
  max-width: 360px;
}

.jcal--wide {
  max-width: none;
}

.jcal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.jcal__title {
  font-weight: 700;
  font-size: 0.98rem;
}

.jcal__nav {
  display: flex;
  gap: 6px;
}

.jcal__nav button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink-2);
  line-height: 1;
}

.jcal__nav button:hover {
  border-color: var(--rust);
  color: var(--rust);
}

.jcal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.jcal__dow {
  text-align: center;
  font-size: 0.68rem;
  color: var(--ink-4);
  padding-bottom: 6px;
  font-weight: 500;
}

.jcal__dow.off {
  color: var(--crimson);
}

.jcal__cell {
  aspect-ratio: 1;
  min-height: 34px;
  border: 1px solid transparent;
  background: none;
  border-radius: 2px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  position: relative;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.jcal__cell:hover:not(.empty) {
  border-color: var(--rust);
  color: var(--rust);
}

.jcal__cell.empty {
  cursor: default;
}

.jcal__cell.today {
  border-color: var(--rule-strong);
  font-weight: 700;
}

/* Explicitly selected holiday date. */
.jcal__cell.picked {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--on-accent);
  font-weight: 700;
}

/* Implied by a weekly off-day rule — shown, but not individually removable. */
.jcal__cell.weeklyoff {
  background: var(--crimson-soft);
  color: var(--crimson);
}

.jcal__cell.picked.weeklyoff {
  background: var(--crimson);
  color: var(--on-accent);
}

.jcal__cell .cnt {
  position: absolute;
  bottom: 2px;
  inset-inline-end: 3px;
  font-family: var(--mono);
  font-size: 0.55rem;
  color: var(--rust);
}

.jcal__legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--ink-3);
}

.jcal__legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.jcal__legend i {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}

/* Weekly off-day toggles */
.weekToggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.weekToggle {
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 2px;
  padding: 7px 12px;
  min-height: 34px;
  cursor: pointer;
  font-size: 0.83rem;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.weekToggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.weekToggle.on {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--on-accent);
  font-weight: 700;
}

/* Chosen-dates list */
.dateChips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.dateChip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--crimson);
  background: var(--crimson-soft);
  color: var(--crimson);
  border-radius: 2px;
  padding: 3px 6px 3px 10px;
  font-size: 0.79rem;
}

.dateChip button {
  border: 0;
  background: none;
  cursor: pointer;
  color: inherit;
  line-height: 1;
  padding: 2px 4px;
  font-size: 0.9rem;
  opacity: 0.75;
}

.dateChip button:hover {
  opacity: 1;
}

/* ---------- Charts ---------- */
.chartCard {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chartCard__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.chartCard__title {
  font-weight: 700;
  font-size: 0.92rem;
}

.chartCard__sub {
  font-size: 0.76rem;
  color: var(--ink-3);
}

.chartCard svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  margin-top: 12px;
}

.chartEmpty {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--ink-4);
  font-size: 0.83rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 14px;
  font-size: 0.79rem;
  color: var(--ink-2);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

.legend b {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--ink-3);
  font-size: 0.75rem;
}

.donutCenter {
  font-family: var(--fa);
  font-weight: 900;
  fill: var(--ink);
}

.donutCenterSub {
  font-size: 9px;
  fill: var(--ink-3);
  font-weight: 400;
}

.axisLine {
  stroke: var(--rule);
  stroke-width: 1;
}

.axisText {
  fill: var(--ink-4);
  font-size: 9px;
  /* Persian numerals: the Latin mono face has no glyphs for them. */
  font-family: var(--fa);
}

.gridLine {
  stroke: var(--rule);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

/* Horizontal meter rows */
.meter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--rule);
}

.meter:last-child {
  border-bottom: 0;
}

.meter__name {
  flex: 0 0 34%;
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter__track {
  /* Rendered as a <span> in places — blockify so the height applies. */
  display: block;
  flex: 1;
  height: 10px;
  background: var(--surface-sunk);
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
}

.meter__fill {
  display: block;
  height: 100%;
  background: var(--rust);
}

.meter__val {
  flex: none;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-2);
  min-width: 44px;
  text-align: end;
}

/* ---------- Dropzone ---------- */
.drop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px;
  border: 2px dashed var(--rule-strong);
  border-radius: var(--r);
  background: var(--surface-2);
  transition: border-color 0.12s, background 0.12s;
}

.drop.hover {
  border-color: var(--rust);
  background: var(--rust-soft);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 18px;
  inset-inline-start: 50%;
  z-index: 90;
  pointer-events: none;
}

.msg {
  padding: 11px 20px;
  border-radius: var(--r);
  font-size: 0.87rem;
  font-weight: 500;
  border: 1px solid;
  box-shadow: 0 6px 20px var(--shade);
  animation: drop-in 0.18s ease-out;
  transform: translateX(50%);
}

[dir="ltr"] .msg {
  transform: translateX(-50%);
}

.msg.ok {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--on-accent);
}

.msg.err {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--on-accent);
}

@keyframes drop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--backdrop);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.modal {
  width: min(760px, 100%);
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: 0 24px 60px var(--shade);
}

.modal .head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal .head h3 {
  font-size: 1.12rem;
}

.modal > .rule {
  margin: 14px 0 18px;
}

.analysisPre {
  font-family: var(--fa);
  white-space: pre-wrap;
  line-height: 1.9;
  background: var(--surface-sunk);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 14px 16px;
  margin: 0;
  font-size: 0.88rem;
  direction: rtl;
}

/* Transcript turns */
.turn {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.turn__who {
  flex: none;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding-top: 9px;
  min-width: 46px;
}

.turn__text {
  flex: 1;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 9px 13px;
  background: var(--surface-2);
  font-size: 0.88rem;
}

.turn--bot .turn__text {
  border-inline-start: 3px solid var(--pine);
}

.turn--user .turn__text {
  border-inline-start: 3px solid var(--rust);
}

/* ---------- Knowledge base row buttons ---------- */
.kbDel,
.kbRe {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-inline-end: 0;
    border-bottom: 1px solid var(--rule);
  }

  .sidebar__inner {
    min-height: 0;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav button {
    width: auto;
    border-inline-start: 0;
    border-bottom: 3px solid transparent;
    border-radius: var(--r);
  }

  .nav button.active {
    border-inline-start: 0;
    border-bottom-color: var(--rust);
  }

  .sidebar__footer {
    margin-top: 8px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar__footer .rule {
    display: none;
  }

  .themeToggle--block {
    width: auto;
  }

  .main {
    padding: 20px 18px 48px;
  }
}

@media (max-width: 760px) {
  .field.half,
  .field.third {
    grid-column: span 6;
  }

  .row--2 {
    grid-template-columns: 1fr;
  }

  .auth__top {
    flex-direction: column;
  }

  .meter__name {
    flex-basis: 42%;
  }
}
