@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e6eb;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --warn-bg: #fff4e0;
  --warn-text: #8a5a00;
  --st-pending: #8a5a00;
  --st-pending-bg: #fff4e0;
  --st-in_progress: #0b57b0;
  --st-in_progress-bg: #e3f0ff;
  --st-done: #0b6e75;
  --st-done-bg: #dcf4f6;
  --st-success: #0a6b3a;
  --st-success-bg: #def7ea;
  --st-failed: #a02323;
  --st-failed-bg: #fde8e8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2029;
    --text: #e8ecf1;
    --muted: #9aa6b5;
    --border: #2a323d;
    --primary: #4c8dff;
    --warn-bg: #3a2c10;
    --warn-text: #f2c26b;
    --st-pending: #f2c26b;
    --st-pending-bg: #3a2c10;
    --st-in_progress: #8fc0ff;
    --st-in_progress-bg: #13294a;
    --st-done: #7fd8df;
    --st-done-bg: #0f3236;
    --st-success: #7be0a8;
    --st-success-bg: #10301f;
    --st-failed: #ff9c9c;
    --st-failed-bg: #3a1717;
  }
}

* { box-sizing: border-box; }

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

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 18px; margin: 0; }
.user { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user form { margin: 0; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

.search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 14px 0;
  overflow-x: auto;
  padding-bottom: 2px;
}
.tab {
  flex: none;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.tab.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.tab .count { opacity: .8; font-size: 13px; }

.hint, .empty { color: var(--muted); text-align: center; padding: 8px 0; }

.rows { display: flex; flex-direction: column; gap: 10px; }

.deal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.deal .main { display: grid; gap: 4px; }
.deal .who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mobile, .plate { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.car { color: var(--muted); }
.meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 22px;
  background: var(--border);
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.role { background: var(--st-in_progress-bg); color: var(--st-in_progress); }
.st-pending { background: var(--st-pending-bg); color: var(--st-pending); }
.st-in_progress { background: var(--st-in_progress-bg); color: var(--st-in_progress); }
.st-done { background: var(--st-done-bg); color: var(--st-done); }
.st-success { background: var(--st-success-bg); color: var(--st-success); }
.st-failed { background: var(--st-failed-bg); color: var(--st-failed); }

[x-cloak] { display: none !important; }

details.tools { margin-top: 8px; }
details.tools dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 8px 0 0; font-size: 13px; }
details.tools dt { color: var(--muted); }
details.tools dd { margin: 0; word-break: break-word; }

.more { text-align: center; margin-top: 4px; }

.btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.linkbtn { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}
.login h1 { font-size: 18px; margin: 0 0 16px; }
.login form { display: grid; gap: 8px; }
.login input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.login .btn { margin-top: 8px; }
.error { background: var(--st-failed-bg); color: var(--st-failed); padding: 8px 12px; border-radius: 10px; margin: 0 0 12px; }

@media (max-width: 520px) {
  main { padding: 12px; }
  .top h1 { font-size: 16px; }
}

/* ---- Phase 2: deal detail ---- */
.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }
.deal-link { color: var(--primary); text-decoration: none; margin-inline-start: auto; font-size: 13px; }
.back { color: var(--text); text-decoration: none; }
.deal.full { padding: 16px; }
.deal.full .detail { margin-top: 12px; }

.detail { display: grid; gap: 14px; margin-top: 10px; }
.tool h3 { font-size: 14px; margin: 0 0 6px; }
.tool form { display: grid; gap: 8px; }
.tool form.inline { grid-template-columns: max-content 1fr max-content; align-items: center; }
.tool form.inline input[x-show] { min-width: 0; }
.detail select, .detail input[type="text"], .detail textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  width: 100%;
}
.detail textarea { resize: vertical; }
.detail .btn { justify-self: start; }

.flash { background: var(--st-success-bg); color: var(--st-success); padding: 6px 12px; border-radius: 10px; margin: 0; }
.detail .error { margin: 0; }

.note { border-inline-start: 3px solid var(--border); padding: 2px 10px; margin: 8px 0; }
.note p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.note small, .history time { color: var(--muted); font-size: 12px; }

.prev {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 10px; margin: 4px 0;
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); text-decoration: none;
}
.prev time { color: var(--muted); font-size: 12px; margin-inline-start: auto; }
.history { margin: 0; padding-inline-start: 18px; font-size: 13px; }

details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.raw dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 8px 0 0; font-size: 13px; }
details.raw dt { color: var(--muted); }
details.raw dd { margin: 0; word-break: break-word; }

.banner {
  display: block; width: 100%;
  margin: -6px 0 12px; padding: 8px 12px;
  border: 1px solid var(--st-in_progress); border-radius: 10px;
  background: var(--st-in_progress-bg); color: var(--st-in_progress);
  font: inherit; cursor: pointer;
}

@media (max-width: 520px) {
  .tool form.inline { grid-template-columns: 1fr; }
}

/* ---- Phase 3: navigation, admin, modules ---- */
.mainnav { display: flex; gap: 14px; align-items: center; }
.mainnav a { color: var(--text); text-decoration: none; font-weight: 600; }
.mainnav a:hover { color: var(--primary); }

.subnav { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subnav a {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); text-decoration: none; background: var(--surface);
}
.subnav a.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card h4 { margin: 8px 0 0; font-size: 14px; }

.formgrid { display: grid; gap: 10px; }
.formgrid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.formgrid label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.formgrid input[type="text"], .formgrid input[type="password"], .formgrid input[type="number"], .formgrid select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; width: 100%;
}
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

.urow { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.uinfo .meta { margin-top: 4px; flex-wrap: wrap; }

.mhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mhead h3 { margin: 0; }
.field small { display: block; margin-top: 2px; }
.err { color: var(--st-failed); }

.audit .arow {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.audit .arow:last-child { border-bottom: 0; }
.audit time { color: var(--muted); }
.audit .auser { font-weight: 600; }
.audit code { background: var(--bg); padding: 0 6px; border-radius: 6px; }
.metajson { color: var(--muted); word-break: break-all; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.deal-link-inline { color: var(--primary); }
.badge.dup, .badge.warn { background: var(--warn-bg); color: var(--warn-text); }

.top { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 420px) {
  .top { padding: 8px 12px; }
  .user { gap: 6px; font-size: 13px; }
  .mainnav { gap: 10px; }
}

/* ---- Phase 4/5: module panels (sms, inquiry) ---- */
.smsform, .inqpending form { display: grid; gap: 8px; }
.smsform select, .smsform textarea, .inqpending select, .inqpending textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; width: 100%;
}
.smslog, .inqpanel > .inqrow:first-of-type { margin-top: 8px; }
.smsrow, .inqrow { border-top: 1px solid var(--border); padding: 8px 0; }
.smsrow .meta, .inqrow .meta { flex-wrap: wrap; }
.smstext { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; }

.inqpending { border: 1px solid var(--st-in_progress); background: var(--st-in_progress-bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; display: grid; gap: 8px; }
.inqpending p { margin: 0; }
.inqreq { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 0; font-size: 13px; }
.inqreq dt { color: var(--muted); }
.inqreq dd { margin: 0; }

.sms-queued, .inq-pending { background: var(--st-pending-bg); color: var(--st-pending); }
.sms-sent { background: var(--st-in_progress-bg); color: var(--st-in_progress); }
.sms-delivered, .inq-done, .inq-outcome-clear { background: var(--st-success-bg); color: var(--st-success); }
.sms-failed, .inq-failed, .inq-outcome-issue { background: var(--st-failed-bg); color: var(--st-failed); }
.sms-cancelled, .inq-cancelled, .inq-outcome-unknown { background: var(--border); color: var(--muted); }
.mainnav { flex-wrap: wrap; row-gap: 4px; }

/* ---- fuel-quota lead info ---- */
.quota { font-weight: 600; }
.natcode, .plate { font-variant-numeric: tabular-nums; }
.warnline { color: var(--warn-text); background: var(--warn-bg); border-radius: 8px; padding: 2px 10px; font-size: 13px; }

/* ---- one open lead at a time, clearly set apart from the closed ones ---- */
.deal { transition: border-color .15s, box-shadow .15s, opacity .15s, background-color .15s; }

details.tools > summary {
  list-style: none;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--primary);
  font-size: 14px; font-weight: 600; cursor: pointer; user-select: none;
}
details.tools > summary::-webkit-details-marker { display: none; }
details.tools > summary::before { content: "▸"; font-size: 12px; transition: transform .15s; }
details.tools > summary:hover { border-color: var(--primary); }
details.tools .lbl-open { display: none; }
details.tools[open] .lbl-open { display: inline; }
details.tools[open] .lbl-closed { display: none; }
details.tools[open] > summary::before { transform: rotate(90deg); }

/* The opened lead: accent border, lifted card, tinted tool panel that bleeds to the card edges. */
.deal:has(details.tools[open]) {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent), 0 8px 24px rgba(16, 24, 40, .12);
  background: var(--surface);
}
.deal:has(details.tools[open]) > .main {
  padding-bottom: 8px;
}
details.tools[open] {
  margin: 8px -14px -12px;
  padding: 10px 14px 14px;
  background: color-mix(in srgb, var(--primary) 6%, var(--bg));
  border-top: 2px solid var(--primary);
  border-radius: 0 0 11px 11px;
}
details.tools[open] > summary { background: var(--surface); border-color: var(--primary); }
details.tools[open] .tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
details.tools[open] .detail { margin-top: 12px; gap: 10px; }

/* While one lead is open the others recede (hover brings them back). */
#rows:has(details.tools[open]) > .deal:not(:has(details.tools[open])) { opacity: .6; }
#rows:has(details.tools[open]) > .deal:not(:has(details.tools[open])):hover,
#rows:has(details.tools[open]) > .deal:not(:has(details.tools[open])):focus-within { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .deal, details.tools > summary::before { transition: none; }
}

/* ---- previous deals: inline dropdowns (no navigation) ---- */
details.prev { border: 1px solid var(--border); border-radius: 10px; margin: 6px 0; background: var(--surface); }
details.prev > summary {
  list-style: none; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 10px; cursor: pointer; border-radius: 10px;
}
details.prev > summary::-webkit-details-marker { display: none; }
details.prev > summary::before { content: "▸"; font-size: 11px; color: var(--muted); transition: transform .15s; }
details.prev[open] > summary::before { transform: rotate(90deg); }
details.prev > summary:hover { background: var(--bg); }
details.prev .prevtitle { font-weight: 600; }
details.prev > summary time { margin-inline-start: auto; color: var(--muted); font-size: 12px; }
details.prev[open] { border-color: var(--muted); }
.prevslot { padding: 4px 12px 12px; border-top: 1px dashed var(--border); }
.prevsum h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.prevsum .kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 8px 0 0; font-size: 13px; }
.prevsum .kv dt { color: var(--muted); }
.prevsum .kv dd { margin: 0; }
.gotodeal { display: inline-block; margin-top: 10px; text-decoration: none; }

/* ---- sticky bar of the opened lead (name, number, close) ---- */
.stickywrap { position: sticky; top: 0; height: 0; z-index: 20; }
.stickybar {
  position: absolute; top: 0; inset-inline: -14px;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 6px 16px rgba(16, 24, 40, .16);
  visibility: hidden; opacity: 0; transform: translateY(-6px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.deal.sticky-on .stickybar { visibility: visible; opacity: 1; transform: none; }
.sb-title { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-close {
  margin-inline-start: auto; flex: none;
  padding: 4px 14px; border: 1px solid var(--primary); border-radius: 999px;
  background: var(--primary); color: var(--primary-text); font: inherit; font-size: 13px; cursor: pointer;
}
@media (prefers-reduced-motion: reduce) { .stickybar { transition: none; } }

/* ---- ready-made notes ---- */
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.presets-label { color: var(--muted); font-size: 12px; }
.presets-more { display: contents; }
.presets-more[hidden] { display: none; }
.chip {
  padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover, .chip:focus-visible { border-color: var(--primary); color: var(--primary); }
.presets-toggle { border-style: dashed; color: var(--primary); }
.presetcard.behind { border-style: dashed; }
.btn.arrow { padding: 6px 12px; min-width: 40px; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ---- lead types: a quiet accent stripe and a small chip per card ---- */
.lt-blue   { --lt: #2f6fdb; }
.lt-violet { --lt: #7c5cd6; }
.lt-gray   { --lt: #8a94a6; }
@media (prefers-color-scheme: dark) {
  .lt-blue   { --lt: #6ea0ff; }
  .lt-violet { --lt: #a98cff; }
  .lt-gray   { --lt: #9aa6b5; }
}
.deal { border-inline-start: 3px solid var(--lt, var(--border)); }
.deal.full { border-inline-start-width: 3px; }
.typechip {
  display: inline-block; padding: 0 9px; border-radius: 999px;
  font-size: 11px; line-height: 20px; font-weight: 600;
  color: var(--lt, var(--muted));
  background: color-mix(in srgb, var(--lt, var(--muted)) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--lt, var(--muted)) 35%, transparent);
}
.deal .typechip { margin-inline-start: auto; }
.deal:has(details.tools[open]) { border-inline-start-color: var(--lt, var(--primary)); }

.typefilter { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0; }
.tchip {
  padding: 3px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.tchip.active { color: var(--text); border-color: var(--text); font-weight: 600; }
.tchip:hover { color: var(--text); }
.badge.typebadge { background: var(--bg); color: var(--muted); }
.varhelp p { margin: 4px 0; }

/* ---- activity log in plain language ---- */
.catfilter { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.catfilter .tchip { text-decoration: none; }
h3.auditday { margin: 18px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.audit .arow { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.audit .arow:last-child { border-bottom: 0; }
.audit .acat {
  flex: none; margin-top: 2px; min-width: 62px; text-align: center;
  padding: 0 8px; border-radius: 999px; font-size: 11px; line-height: 20px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
}
.audit .cat-lead .acat     { color: #2f6fdb; border-color: color-mix(in srgb, #2f6fdb 35%, transparent); background: color-mix(in srgb, #2f6fdb 10%, transparent); }
.audit .cat-sms .acat      { color: #1e8e4e; border-color: color-mix(in srgb, #1e8e4e 35%, transparent); background: color-mix(in srgb, #1e8e4e 10%, transparent); }
.audit .cat-inquiry .acat  { color: #7c5cd6; border-color: color-mix(in srgb, #7c5cd6 35%, transparent); background: color-mix(in srgb, #7c5cd6 10%, transparent); }
.audit .cat-access .acat   { color: #667085; }
.audit .cat-settings .acat { color: #b7791f; border-color: color-mix(in srgb, #b7791f 35%, transparent); background: color-mix(in srgb, #b7791f 10%, transparent); }
.audit .abody { flex: 1; min-width: 0; }
.audit .atext { margin: 0; line-height: 1.7; }
.audit .aactor { font-weight: 700; }
.audit .arole { color: var(--muted); font-size: 12px; }
.audit .asubject { margin: 2px 0 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.audit .asubject a { color: var(--primary); text-decoration: none; }
.audit .atime { flex: none; text-align: end; color: var(--muted); font-size: 12px; white-space: nowrap; }
.audit .atime small { display: block; font-size: 11px; opacity: .8; }
@media (max-width: 520px) {
  .audit .arow { flex-wrap: wrap; }
  .audit .acat { min-width: 0; }
  .audit .atime { margin-inline-start: auto; }
}

/* ---- reports ---- */
.report .rhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.report h2 { margin: 0 0 6px; font-size: 18px; }
.rangechips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.report .tchip { text-decoration: none; }
.report .typefilter { margin: 4px 0 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; display: grid; gap: 2px; }
.stat-n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat-l { color: var(--muted); font-size: 13px; }
.delta { font-size: 12px; }
.delta.up { color: var(--st-success); }
.delta.down { color: var(--st-failed); }
.delta.flat { color: var(--muted); }

.chartbox { margin: 14px 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.chartbox figcaption { font-weight: 600; margin-bottom: 4px; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg.chart .seg { fill: var(--lt, var(--primary)); }
svg.chart .hit { fill: transparent; }
svg.chart .bar:hover .seg { opacity: .8; }
svg.chart .bar:hover .hit { fill: color-mix(in srgb, var(--primary) 8%, transparent); }
.legend { list-style: none; display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0 0; padding: 0; font-size: 13px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--lt); margin-inline-end: 6px; }
.datatable { margin-top: 10px; }
.datatable summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.datatable table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.datatable th, .datatable td { text-align: start; padding: 4px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }

.shares { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.share { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; font-size: 14px; }
.share small { color: var(--muted); }
svg.sharebar { grid-column: 1 / -1; width: 100%; height: 6px; }
svg.sharebar .track { fill: var(--border); }
svg.sharebar .fill { fill: currentColor; color: var(--muted); }
svg.sharebar .fill.st-pending { color: var(--st-pending); }
svg.sharebar .fill.st-in_progress { color: var(--st-in_progress); }
svg.sharebar .fill.st-done { color: var(--st-done); }
svg.sharebar .fill.st-success { color: var(--st-success); }
svg.sharebar .fill.st-failed { color: var(--st-failed); }
svg.sharebar .fill[class*="lt-"] { color: var(--lt); }

/* stored fuel quotas of a plate (inquiry module) */
.inqquotas { margin-top: .8rem; }
.inqquotas h4 { margin: 0 0 .35rem; font-size: .9rem; }
.inqtable { width: 100%; border-collapse: collapse; font-size: .85rem; }
.inqtable th, .inqtable td { padding: .25rem .5rem; border-bottom: 1px solid var(--border); text-align: right; }
.inqtable th { font-weight: 600; color: var(--muted); }

/* inquiry request: month picker next to the button */
.inqactions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inqmonth { display: inline-flex; align-items: center; gap: 6px; }
.inqmonth select { min-width: 7.5rem; }
.inqmore { margin-top: 6px; }

/* ---- compact lead detail: status line, tool buttons and their sections ---- */
.statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.statusform { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.statusform label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.detail .statusform .statussel { width: auto; min-width: 7.5rem; padding: 3px 8px; font-size: 13px; font-weight: 600; border-radius: 8px; }
.detail .statusform .reasonrow input[type="text"] { width: 15rem; max-width: 100%; padding: 4px 8px; font-size: 13px; border-radius: 8px; }
.statusform .reasonrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.statusform .reasonrow[hidden] { display: none; }
.failreason { margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbtn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600;
}
.toolbtn:hover { border-color: var(--muted); }
.toolbtn.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tb-count {
  min-width: 1.4em; padding: 0 6px; border-radius: 999px; text-align: center;
  background: var(--border); color: var(--text); font-size: 12px; font-weight: 700; line-height: 1.6;
}
.toolbtn.on .tb-count { background: var(--bg); color: var(--text); }
.tb-hint { font-size: 12px; font-weight: 600; color: var(--muted); }
.toolbtn.on .tb-hint { color: inherit; opacity: .8; }
/* tools that need attention are coloured even while closed */
.toolbtn.lv-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-text); }
.toolbtn.lv-warn .tb-hint { color: var(--warn-text); }
.toolbtn.lv-warn.on { background: var(--warn-text); color: var(--warn-bg); }
.toolbtn.lv-bad { background: var(--st-failed-bg); color: var(--st-failed); border-color: var(--st-failed); }
.toolbtn.lv-bad .tb-hint { color: var(--st-failed); }
.toolbtn.lv-bad.on { background: var(--st-failed); color: var(--st-failed-bg); }

/* the working tools (top) are larger; the informational ones (bottom) are quieter */
.toolbar-main .toolbtn { padding: 6px 16px; font-size: 14px; }
.toolbar-info { margin-top: 4px; padding-top: 8px; border-top: 1px dashed var(--border); }
.toolbar-info .toolbtn { padding: 3px 10px; font-size: 12px; font-weight: 500; color: var(--muted); }
.toolbar-info .toolbtn.on { color: var(--bg); }
.toolbar-info .toolbtn.lv-warn { color: var(--warn-text); }
.toolbar-info .toolbtn.lv-bad { color: var(--st-failed); }
.toolbar-info .toolbtn.lv-warn.on { color: var(--warn-bg); }
.toolbar-info .toolbtn.lv-bad.on { color: var(--st-failed-bg); }
.rawdl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 0; font-size: 13px; }
.rawdl dt { color: var(--muted); }
.rawdl dd { margin: 0; word-break: break-word; }
.toolpanels { display: grid; }
.toolpanels:empty { display: none; }
.toolpanel { border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.toolpanel[hidden] { display: none; }
.toolpanel.lv-warn { border-color: var(--warn-text); }
.toolpanel.lv-bad { border-color: var(--st-failed); }

/* a contact with no earlier deals */
.badge.new { background: #e3f6ec; color: #11633d; font-weight: 700; }
@media (prefers-color-scheme: dark) { .badge.new { background: #123a28; color: #7fe0ac; } }

/* ---- smaller action buttons inside the tool sections; the note button is apart from what is above it ---- */
.toolpanel .btn { padding: 4px 14px; font-size: 13px; border-radius: 8px; }
.toolpanel .btn.noteadd { margin-top: 10px; }
.toolpanel form > .presets { margin-bottom: 2px; }
.toolpanel form > .btn:last-child { margin-top: 8px; }
.toolpanel form > .btn.noteadd:last-child { margin-top: 10px; }

/* ---- click to copy ---- */
.copyable { cursor: pointer; border-radius: 4px; }
.copyable:hover { background: var(--border); }
.copyable:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.copyable[data-copied]::after {
  content: "کپی شد"; margin-inline-start: 6px; padding: 0 6px; border-radius: 999px;
  background: var(--st-success-bg); color: var(--st-success); font-size: 11px; font-weight: 700;
}
.copyable[data-copied="fail"]::after { content: "کپی نشد"; background: var(--st-failed-bg); color: var(--st-failed); }
.copy-scratch { position: fixed; top: 0; inset-inline-start: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* the month an inquiry in the history belongs to */
.badge.period { background: var(--st-in_progress-bg); color: var(--st-in_progress); font-weight: 700; }

/* one-click quota message in the inquiry panel */
.quicksms { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.quickres .flash, .quickres .error { display: inline-block; padding: 3px 10px; font-size: 13px; }

/* ---- compact lead card: national code in the first line, small tools button on the last line ---- */
.topitem { font-size: 12px; color: var(--muted); white-space: nowrap; }
.topitem bdi { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.deal .main { gap: 2px; }
/* the tools button lives in the meta row, first (at the start, before the status); the details'
   own summary stays only as the markup behind it */
details.tools > summary { display: none; }
details.tools { margin-top: 0; }
details.tools[open] { margin-top: 8px; }
.toolsbtn {
  padding: 1px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--primary); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; line-height: 1.7;
}
.toolsbtn::before { content: "▸"; margin-inline-end: 5px; font-size: 10px; display: inline-block; transition: transform .15s; }
.toolsbtn:hover { border-color: var(--primary); }
.toolsbtn.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.toolsbtn.on::before { transform: rotate(90deg); }

/* ---- dropdowns: one consistent look for every <select>, and nicer opened sections ---- */
.detail select, .toolpanel select {
  appearance: none; -webkit-appearance: none;
  height: 32px; padding: 0 12px 0 30px; border-radius: 8px;
  font-size: 13px; line-height: 30px; cursor: pointer;
  background-color: var(--bg);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: 15px 50%, 10px 50%; background-size: 5px 5px; background-repeat: no-repeat;
  transition: border-color .12s, box-shadow .12s;
}
.detail select:hover, .toolpanel select:hover { border-color: var(--muted); }
.detail select:focus-visible, .toolpanel select:focus-visible {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
.detail select option, .toolpanel select option { background: var(--surface); color: var(--text); }
/* the month picker is as high as the buttons beside it and a little narrower */
.inqmonth select { min-width: 5.8rem; width: auto; }
.inqmonth { gap: 6px; font-size: 13px; color: var(--muted); }
/* the status select takes the colour of the status it shows */
.detail .statusform .statussel { padding: 0 12px 0 30px; min-width: 8.5rem; }
.statussel.st-in_progress { background-color: var(--st-in_progress-bg); color: var(--st-in_progress); border-color: var(--st-in_progress); }
.statussel.st-done        { background-color: var(--st-done-bg);        color: var(--st-done);        border-color: var(--st-done); }
.statussel.st-pending     { background-color: var(--st-pending-bg);     color: var(--st-pending);     border-color: var(--st-pending); }
.statussel.st-success     { background-color: var(--st-success-bg);     color: var(--st-success);     border-color: var(--st-success); }
.statussel.st-failed      { background-color: var(--st-failed-bg);      color: var(--st-failed);      border-color: var(--st-failed); }

/* opened sections slide in, and an opened previous deal is clearly the active one */
@keyframes toolin { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.toolpanel:not([hidden]) { animation: toolin .14s ease-out; }
details.prev { transition: border-color .15s, box-shadow .15s; }
details.prev > summary { padding: 7px 10px; border-radius: 10px; cursor: pointer; }
details.prev[open] {
  border-color: var(--primary);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 14%, transparent);
}
details.prev[open] > summary { background: color-mix(in srgb, var(--primary) 7%, var(--surface)); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
details.prev[open] > summary::before { color: var(--primary); }
details.prev[open] .prevslot { animation: toolin .14s ease-out; background: color-mix(in srgb, var(--primary) 3%, var(--surface)); border-radius: 0 0 10px 10px; }
@media (prefers-reduced-motion: reduce) { .toolpanel:not([hidden]), details.prev[open] .prevslot { animation: none; } }

/* ---- custom dropdown over the lead detail's selects (the native option list cannot be styled) ---- */
.dd { position: relative; display: inline-block; vertical-align: middle; }
.dd-native { display: none !important; }
.dd-btn {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 5.8rem; height: 32px; padding: 0 12px 0 30px; border: 1px solid var(--border); border-radius: 8px;
  background-color: var(--bg); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-align: start;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: 15px 50%, 10px 50%; background-size: 5px 5px; background-repeat: no-repeat;
  transition: border-color .12s, box-shadow .12s;
}
.dd-btn:hover { border-color: var(--muted); }
.dd-btn:focus-visible, .dd.open > .dd-btn {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}
.dd.open > .dd-btn { background-image: linear-gradient(45deg, var(--primary) 50%, transparent 50%), linear-gradient(135deg, transparent 50%, var(--primary) 50%); }
.dd-btn:disabled { opacity: .55; cursor: not-allowed; }
.dd-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn.statussel { min-width: 8.5rem; font-weight: 600; }

.dd-list {
  position: absolute; z-index: 40; inset-inline-start: 0; top: calc(100% + 4px);
  min-width: 100%; width: max-content; max-width: 22rem; max-height: 15rem; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .18), 0 2px 6px rgba(16, 24, 40, .08);
  animation: toolin .12s ease-out;
}
.dd-list[hidden] { display: none; }
.dd.up > .dd-list { top: auto; bottom: calc(100% + 4px); }
.dd-list li {
  padding: 6px 10px 6px 28px; border-radius: 7px; font-size: 13px; cursor: pointer;
  white-space: nowrap; position: relative;
}
.dd-list li.act { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.dd-list li.sel { font-weight: 700; color: var(--primary); }
.dd-list li.sel::after { content: "✓"; position: absolute; inset-inline-end: auto; left: 9px; top: 50%; transform: translateY(-50%); font-size: 12px; }
.dd-list li[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .dd-list { animation: none; } }

/* the whole card header is clickable: it opens the lead's tools */
.deal:not(.full) > .main { cursor: pointer; }
.deal:not(.full):hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.deal .main a, .deal .main button, .deal .main .copyable { cursor: pointer; }
.deal .main .who strong, .deal .main .who .mobile, .deal .main .car, .deal .main .topitem { cursor: pointer; }

