/* Legacy-view skin.
   The data screens (منابع داده، بازبینی، وظایف، دانش، مدیریت) are the SAME
   modules the classic panel runs — zero logic forked. This sheet restyles
   their class vocabulary into the Mind design system so they feel native
   inside a glass window. */

.page { padding: 0; max-width: none; }
/* Title block and its page action sit as one composed row (wrapping on
   phones) — never a heading with a stray button glued beneath it. */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: var(--s4) var(--s5);
  margin-block-end: var(--s6);
}
.page-head h1 { margin: 0 0 6px; font-size: var(--text-xl); font-weight: 700; }
.page-head p { margin: 0; color: var(--ink-2); font-size: var(--text-sm); line-height: 1.7; }
.page-head > div { flex: 1 1 260px; min-width: 0; }
.page-head > .btn { flex: none; margin-block-start: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

.small { font-size: var(--text-sm); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: .92em; font-variant-numeric: tabular-nums; }
.num { text-align: end; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* cards inside windows are quiet panels, not glass-on-glass */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: none;
  margin-block-end: var(--s5);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-block-end: 1px solid var(--hairline);
  font-weight: 650; font-size: var(--text-md);
}
.card-head h2 { margin: 0; font-size: var(--text-md); }
.card-body { padding: var(--s5); }
.card-body.tight { padding: 0; }

.win .empty, .bubble .empty {
  text-align: center; padding: var(--s10) var(--s5); color: var(--ink-2);
}
.win .empty h3, .bubble .empty h3 { margin: 0 0 var(--s1); color: var(--ink); font-size: var(--text-lg); }
.win .empty p, .bubble .empty p { margin: 0; font-size: var(--text-sm); }

.stat { padding: var(--s4) var(--s5); }
.stat-value { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-xs); color: var(--ink-3); }

.btn {
  appearance: none; font: inherit;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 9px var(--s4);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring),
              box-shadow var(--dur-fast), background var(--dur-fast);
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--gem-grad); border: 0; color: #241a04; font-weight: 700; }
.btn-primary:hover:not(:disabled) { background: var(--gem-grad); box-shadow: var(--glow); }
/* BUTTON LAW (user): a button ALWAYS shows a background — plain text that
   only reveals itself on hover is indistinguishable from a label, and touch
   devices have no hover at all. "Ghost" now means quiet, not invisible. */
.btn-ghost { background: var(--surface-2); border-color: var(--hairline); color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); background: var(--surface-3); }
.btn-danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad); color: #fff; }
.btn-sm { padding: 5px var(--s3); font-size: var(--text-xs); border-radius: var(--r-sm); }

.field { margin-block-end: var(--s4); }
.field label { display: block; font-size: var(--text-xs); font-weight: 650; color: var(--ink-2); margin-block-end: 6px; }
.win input, .win textarea, .win select,
.bubble input, .bubble textarea, .bubble select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px var(--s4);
}
.win :is(input, textarea, select):focus,
.bubble :is(input, textarea, select):focus {
  outline: none;
  border-color: var(--hairline-strong);
}
.win :is(input, textarea)::placeholder,
.bubble :is(input, textarea)::placeholder { color: var(--ink-3); }
/* pre-WRAP, never pre: knowledge files are prose-ish md/yaml — a hard `pre`
   forced horizontal + vertical scrolling to read one long line. Wrapped,
   the eye only ever travels down. */
.editor { font-family: var(--mono); font-size: 13px; min-height: 360px;
          white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; tab-size: 2;
          /* md/yaml are LTR documents — inheriting the page's RTL bidi
             reordered every line («Company Context #») and centred ragged
             text. Code always reads left-to-right. */
          direction: ltr; text-align: left; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 10px; border-radius: var(--r-full);
  font-size: var(--text-xs); font-weight: 650;
  background: var(--surface-3); color: var(--ink-2);
  border: 1px solid var(--hairline);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.info, .pill.running { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.running::before {
  content: ""; width: 7px; height: 7px; border-radius: var(--r-full);
  background: var(--accent); animation: pulse 1.1s ease-in-out infinite;
}

.table-scroll { overflow: auto; max-height: 440px; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: start; font-size: var(--text-xs); font-weight: 650;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink-3);
  background: var(--surface-solid);
  padding: var(--s3) var(--s4);
  border-block-end: 1px solid var(--hairline-strong);
  white-space: nowrap;
}
tbody td {
  padding: var(--s3) var(--s4);
  border-block-end: 1px solid var(--hairline);
  vertical-align: top; font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-block-end: none; }
tbody tr:hover, tr.has-menu:hover { background: var(--surface-2); }

.progress { height: 5px; border-radius: var(--r-full); overflow: hidden; background: var(--surface-3); }
.progress i { display: block; height: 100%; border-radius: var(--r-full); background: var(--gem-grad); transition: width .4s var(--ease-out); }

.notice {
  padding: var(--s4) var(--s5); border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-inline-start: 3px solid var(--hairline-strong);
  font-size: var(--text-sm); margin-block: var(--s2);
}
.notice.warn { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.notice.info { border-inline-start-color: var(--accent); background: var(--accent-soft); }

.steps { display: flex; flex-direction: column; gap: 5px; margin-block: var(--s2); }
.step { display: flex; align-items: baseline; gap: 8px; font-size: var(--text-sm); color: var(--ink-2); }
.step-dot { flex: none; width: 7px; height: 7px; border-radius: var(--r-full); background: var(--ink-3); }
.step.ok .step-dot, .step-dot.ok { background: var(--ok); }
.step.fail .step-dot, .step-dot.fail { background: var(--bad); }
.step.running .step-dot, .step-dot.running { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }

.chart { display: grid; gap: var(--s1); margin-block: var(--s2); }
/* The bar track needs a REAL minimum: bare 1fr contributes zero intrinsic
   width, so inside a fit-content bubble (and at phone widths, where the
   label column's growth limit swallowed the free space first) every bar
   rendered at 0px — labels and numbers with no bars. */
.chart-row { display: grid; grid-template-columns: minmax(70px, 35%) minmax(120px, 1fr) auto; gap: var(--s2); align-items: center; font-size: var(--text-sm); }
.chart-bar { height: 16px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.chart-bar i { display: block; height: 100%; background: var(--gem-grad); border-radius: 5px; }

.artifacts { display: flex; flex-direction: column; gap: var(--s2); margin-block-start: var(--s3); }
.artifact {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--hairline);
  font-size: var(--text-sm); color: var(--ink);
  cursor: pointer; font-weight: 570;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.artifact:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

details.diag { margin-block-start: var(--s2); }
details.diag > summary { cursor: pointer; font-size: var(--text-xs); color: var(--ink-2); user-select: none; }
details.diag pre {
  background: var(--surface-2); padding: var(--s3); border-radius: var(--r-sm);
  overflow: auto; font-size: 12px; margin: var(--s2) 0 0; max-height: 300px;
  border: 1px solid var(--hairline);
  white-space: pre-wrap; overflow-wrap: anywhere;   /* one axis: down */
}

/* markdown-lite (ui.js renderMarkdownLite) */
.md { display: flex; flex-direction: column; gap: var(--s2); }
.md-p { margin: 0; }
.md-h { font-weight: 700; font-size: var(--text-md); margin-block-start: var(--s1); }
.md-list { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 4px; }
.md-code {
  font-family: var(--mono); font-size: .9em;
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: 5px; padding: 1px 6px;
}
.md-link { font-weight: 650; }

/* context menu + toasts (ui.js appends these to <body>) */
.ctx-menu {
  position: fixed; z-index: 1000;
  min-width: 200px; padding: var(--s1);
  background: var(--material-thick);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; gap: 1px;
  overflow-y: auto; overscroll-behavior: contain;
  animation: menu-pop var(--dur-fast) var(--ease-spring) both;
}
@keyframes menu-pop { from { opacity: 0; transform: scale(.94); } }
.ctx-item {
  appearance: none; background: none; border: 0; border-radius: var(--r-sm);
  padding: var(--s2) var(--s3); font: inherit; font-size: var(--text-sm); color: var(--ink);
  text-align: start; cursor: pointer; white-space: nowrap;
}
.ctx-item:hover:not([disabled]) { background: var(--surface-2); }
.ctx-item[disabled] { color: var(--ink-3); cursor: default; }
.ctx-item.danger { color: var(--bad); }
.ctx-item.danger:hover:not([disabled]) { background: var(--bad-soft); }
.ctx-sep { height: 1px; background: var(--hairline); margin: var(--s1) var(--s1); }

.toast-host {
  position: fixed; inset-block-end: calc(var(--s5) + env(safe-area-inset-bottom));
  inset-inline-start: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--s2); z-index: 1200;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--material-thick);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-inline-start: 3px solid var(--hairline-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--s3) var(--s4); font-size: var(--text-sm);
  animation: bubble-in var(--dur-med) var(--ease-out) both;
}
.toast.error { border-inline-start-color: var(--bad); }
.toast.ok { border-inline-start-color: var(--ok); }

/* question form (reused pattern from convo) */
.q-form { display: flex; flex-direction: column; gap: var(--s3); }
.q-title { font-weight: 700; font-size: var(--text-sm); }
.q-item { display: flex; flex-direction: column; gap: var(--s1); }
.q-text { font-weight: 600; font-size: var(--text-sm); }
.q-option { border-style: dashed; }
.q-option.selected {
  background: var(--accent-soft); border-style: solid;
  border-color: var(--accent); color: var(--accent);
}
.thinking { display: inline-flex; align-items: center; gap: var(--s2); color: var(--ink-2); font-size: var(--text-sm); }
.thinking .dots { display: inline-flex; gap: 4px; }
.thinking .dots i { width: 6px; height: 6px; border-radius: var(--r-full); background: var(--accent); animation: bounce 1.2s ease-in-out infinite; }
.thinking .dots i:nth-child(2) { animation-delay: .15s; }
.thinking .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 30% { transform: translateY(-4px); opacity: .5; } }
.thinking .elapsed { color: var(--ink-3); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }


/* Nothing touches: every block sibling inside a window or bubble gets air.
   (Collapsing margins make this a floor — it never doubles existing gaps.) */
.win-body .page > * + *,
.win-body .page-head > * + *,
.win-body .card-body > * + *,
.bubble .inner > * + * { margin-block-start: var(--s4); }
.win-body .row { row-gap: var(--s2); }
.win-body .page-head + * { margin-block-start: var(--s5); }

/* ── THE CARD-TABLE LAW (phones, every orientation) ────────────────────────
   No table may scroll horizontally on a phone — each ROW becomes a readable
   CARD, each cell one labeled line (label = its column header, stamped as
   data-th by ui.js). The same gate as the messenger anatomy in shell.css. */
@media (max-width: 720px), (pointer: coarse) and (max-height: 500px) {
  .table-scroll { overflow: visible; max-height: none; }
  table, tbody { display: block; width: 100%; }
  thead { display: none; }              /* headers live inside each card */
  /* A row-card reads like a CARD, not an exploded spreadsheet: the first
     cell is the card's title on its own full line, and every other cell is
     a compact «label value» pair — pairs sit NEXT to each other and wrap
     naturally, labels glued to their values. Never space-between (it
     stretched every line into a sparse label……value mess). */
  /* Breathing rules: a card-list nested inside a panel is INSET from it
     (flush card-in-card borders read as a mistake), the title line gets
     real air before the pairs, and the last card doesn't drag a stray
     margin against the panel edge. */
  .card-body.tight { padding: var(--s4); }
  /* Rhythm hierarchy (the spacing law): within a pair 7px < between wrapped
     lines 12px < between pair columns 24px < between cards 16px+inset —
     every level visibly distinct, nothing clamped. */
  tbody tr {
    display: flex; flex-wrap: wrap; align-items: baseline;
    row-gap: 12px; column-gap: var(--s6);
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    background: var(--surface-2);
    padding: var(--s5);
    margin-block-end: var(--s4);
  }
  tbody tr:last-child { margin-block-end: 0; }
  /* stacked lines inside the title cell (name / subtitle / meta) breathe */
  tbody tr > td:first-child > * + * { margin-block-start: 6px; }
  tbody tr:hover { background: var(--surface-2); }  /* no row-hover on cards */
  tbody td {
    display: inline-flex; align-items: baseline; gap: 7px;
    padding: 0;
    border-block-end: 0;
    min-width: 0; max-width: 100%;
    text-align: start;
  }
  /* the label sits immediately beside its value — one breath, one pair */
  tbody td[data-th]::before {
    content: attr(data-th);
    flex: none;
    color: var(--ink-3);
    font-size: var(--text-xs); font-weight: 650;
  }
  /* the first cell IS the card title: full row, no label — the question /
     file / source speaks for itself */
  tbody tr > td:first-child {
    flex: 1 0 100%;
    display: block;
    font-weight: 570;
    overflow-wrap: anywhere;
  }
  tbody tr > td:first-child::before { display: none; }
  /* badges and buttons keep their intrinsic shape — a compressed pill
     wrapping one character per line is a design felony */
  tbody td .pill, tbody td .btn, tbody td .row { flex: none; white-space: nowrap; }
  /* unlabeled trailing cells (actions) drift to the row's end */
  tbody td:not([data-th]):not(:first-child) { margin-inline-start: auto; }
  /* an empty cell would render as a dangling label — drop the whole line */
  tbody td:empty { display: none; }
}

/* ── Accordion (knowledge files — the in-place open law) ──────────────────
   A file opens directly under its own title; the fold animates via the
   0fr→1fr grid trick (no max-height hacks, no jumps). */
.acc { display: flex; flex-direction: column; gap: var(--s3); }
.acc-label {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4);
  margin-block: var(--s2) var(--s4);
  font-weight: 650;
}
.acc-item {
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface-2);
  overflow: hidden;
}
.acc-item.open { border-color: var(--hairline-strong); }
.acc-head {
  display: flex; align-items: baseline; gap: var(--s4);
  width: 100%;
  padding: var(--s4) var(--s5);
  background: none; border: 0; font: inherit; color: var(--ink);
  cursor: pointer; text-align: start;
}
.acc-head:hover { background: var(--surface-3); }
.acc-title { flex: 1; min-width: 0; }
.acc-title .acc-name { color: var(--accent); font-weight: 600; }
.acc-title .small { margin-block-start: 5px; }
.acc-head .chev {
  color: var(--ink-3); font-size: 11px;
  transition: transform var(--dur-med) var(--ease-spring);
}
.acc-item.open .chev { transform: rotate(180deg); }
.acc-body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-med) var(--ease-out);
}
.acc-item.open .acc-body { grid-template-rows: 1fr; }
.acc-fold { overflow: hidden; min-height: 0; }
.acc-pad {
  padding: var(--s2) var(--s5) var(--s5);
  display: flex; flex-direction: column; gap: var(--s4);
}
.acc-pad .editor { min-height: 260px; }

/* ── Charts v2 (SVG, theme-aware, dual-axis) ───────────────────────────── */
.chart-card { margin-block: var(--s3); }
.chartv2 { width: 100%; }
.chartv2 { overflow-x: auto; overflow-y: hidden; }
.chart-svg { height: auto; display: block; overflow: visible; direction: ltr; }
.chart-svg:not(.chart-scroll) { width: 100%; max-width: 440px; margin-inline: auto; }
.chart-svg.chart-scroll { width: auto; }   /* honour the width attr → true size, host scrolls */
.chart-tick { fill: var(--ink-3); font-size: 11px; font-family: var(--mono); }
.chart-xlabel { fill: var(--ink-2); font-size: 11px; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4);
  margin-block-start: var(--s3); justify-content: center;
}
.chart-legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: var(--text-sm); color: var(--ink-2); }
.chart-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.chart-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  margin-block-start: var(--s3);
}
.chart-toolbar:only-child, .chart-toolbar:last-child { justify-content: flex-end; }
.chart-toolbar .small { margin-inline-end: auto; }

/* Long-task controls + "show your work" */
.thinking { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.k-cancel { margin-inline-start: auto; }
details.work { margin-block-start: var(--s4); }
details.work > summary {
  cursor: pointer; font-size: var(--text-sm); color: var(--ink-2);
  font-weight: 600; user-select: none;
}
details.work[open] > summary { margin-block-end: var(--s3); }
.work-body { display: flex; flex-direction: column; gap: var(--s3); }
.work-sql {
  background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--r-sm); padding: var(--s3);
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;
  direction: ltr; text-align: left; margin: 0;
}


/* Vertical bars (HTML/CSS) — fit-width, 3-line wrapping labels at true size,
   value on each bar plus a gridline axis. The bulletproof categorical chart. */
.vchart { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; }
.vaxis {
  grid-column: 1; grid-row: 1; height: 240px;
  display: flex; flex-direction: column; justify-content: space-between; padding-block: 1px;
}
.vtick { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3);
         white-space: nowrap; text-align: end; line-height: 1; }
.vplot {
  grid-column: 2; grid-row: 1; height: 240px; position: relative;
  display: flex; align-items: flex-end; gap: 10px;
  border-inline-start: 1px solid var(--chart-axis);
  border-bottom: 1px solid var(--chart-axis);
}
.vgrid { position: absolute; inset-inline: 0; height: 0; border-top: 1px solid var(--chart-grid); }
.vcol {
  flex: 1 1 0; min-width: 0; height: 100%; z-index: 1;
  display: flex; justify-content: center; align-items: flex-end; gap: 3px;
}
.vbar-slot {
  flex: 1 1 0; min-width: 0; max-width: 64px; height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
}
.vbar-val {
  font-family: var(--mono); font-size: 10px; color: var(--ink-2);
  margin-bottom: 3px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.vbar { width: 100%; border-radius: 5px 5px 0 0; min-height: 2px; }
.vlabels { grid-column: 2; grid-row: 2; display: flex; gap: 10px; margin-top: 7px; }
.vlabel {
  flex: 1 1 0; min-width: 0; text-align: center; font-size: 11px; color: var(--ink-2);
  line-height: 1.35; overflow-wrap: anywhere; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
