/* Additions of the new app that the legacy stylesheets do not have. Built from existing tokens only. */

/* Diagnostics feed is on (ADR-0013): the owner's header chip and the state chip on «عیب‌یابی». Terracotta, the
   second accent, so it reads as "attention, by choice" next to the green. Dark mode comes from the tokens. */
.chip-terra { background: var(--terra-tint); color: var(--terra-text); }
.chip-terra::before { background: var(--terra); }
a.chip-terra { text-decoration: none; }

/* Dashboard layout v2 (ADR-0014): outside edit mode each item sits at its saved cell on an 8-column grid from
   1200 px. Vue sets --x, --y, --w and --h through the CSSOM (CSP allows it; there is no style attribute in the
   markup). Narrower windows keep the v1 flow in reading order. Tiles are app icons: 1 cell shows the icon and
   title, a 2x2 tile is drawn like the large «ثبت بیمار جدید» button and shows its line of text. */
.dash-v2 > .dash-cell[data-tile] > .qa-tile { justify-content: center; }
.dash-v2 > .dash-cell[data-tile]:not([data-size="2x2"]) .qa-text > span { display: none; }
/* Home screen (owner decision 2026-11-17, option «الف»): from 600 px the view and the editor show the same grid.
   Vue counts the columns from the grid's width (8 up to the room for nine 120 px columns, then one more per 120 px,
   at most 16; zooming out widens the grid, so there is more room instead of bigger cards) and places each card at
   its saved cell (--x, --y, --w, --h); empty cells stay empty. */
@media (min-width: 600px) {
  .dash-grid.dash-v2 { grid-template-columns: repeat(var(--cols, 8), minmax(0, 1fr)); grid-auto-rows: clamp(150px, 104px + 3.6vw, 176px); grid-auto-flow: row; }
  .dash-v2 > .dash-cell { grid-column: var(--x) / span var(--w); grid-row: var(--y) / span var(--h); min-height: 0; }
  /* Rows have a fixed height (the card's h decides its height, never its content), so the editor and the view are
     the same geometry; a card with more content than room scrolls inside itself. */
  .dash-v2 > .dash-cell > :is(.card, .qa-tile, .pl-locked) { flex: 1 1 auto; min-height: 0; overflow: auto; }
  /* Tiles and number cards never scroll (owner, 2026-11-16): they are drawn to fit; only list widgets scroll. */
  .dash-v2 > .dash-cell > :is(.qa-tile, .stat, .income-today) { overflow: hidden; }
  /* inside a scrolling card a focus ring sits inside the element, so the card edge never cuts it off */
  .dash-v2 > .dash-cell :focus-visible { outline-offset: -2px; }
}
/* 600 to 1199 px: the same 8 columns, narrower, so rows are lower too. */
@media (min-width: 600px) and (max-width: 1199px) {
  .dash-grid.dash-v2 { grid-auto-rows: 124px; }
}
/* Under 600 px: each widget and each 2x2 tile on its own row; other tiles one cell each, four to a row like a phone
   home screen. */
@media (max-width: 599px) {
  .dash-v2 > .dash-cell:not([data-tile]) { grid-column: 1 / -1; }
  .dash-v2 > .dash-cell[data-tile] { grid-column: span 1; grid-row: span 1; }
  .dash-v2 > .dash-cell[data-tile][data-size="2x2"] { grid-column: 1 / -1; }
  .dash-v2 > .dash-cell[data-tile]:not([data-size="2x2"]) > .qa-tile { padding: var(--sp-2); gap: var(--sp-2); align-items: center; text-align: center; min-height: 0; }
  .dash-v2 > .dash-cell[data-tile]:not([data-size="2x2"]) .qa-text b { font-size: var(--fs-xs); }
}

/* Home-screen editor (owner decision 2026-11-17, option «الف», lib/gridEditor.ts): the same rows and columns as the
   view. Empty cells show as soft wells (.g-slot) with two spare rows to drop into; a card is dragged from anywhere
   on it; a dashed spot (.g-ghost, terracotta when there is no room) shows where it will land while the cards it
   covers slide aside. A tapped card (.is-sel) gets a handle in the middle of each edge, like a phone widget. */
.dash-v2.is-editing > .dash-cell { position: relative; cursor: grab; touch-action: none; }
/* While editing, a card's own links, lists and fields rest (like a phone in edit mode): a press anywhere on the card
   picks it up; only the editor's tools (head, grip, ×, handles) answer. */
.dash-v2.is-editing > .dash-cell > :is(.card, .qa-tile, .pl-locked, .income-today) { pointer-events: none; }
.dash-v2.is-editing > .dash-cell :is(.pl-w-head, .pl-qa-tools, .g-handle) { pointer-events: auto; }
/* Every editor piece sits at its own cell (Vue sets --x, --y, --w, --h through the CSSOM). */
:is(.dash-v2, .fl-grid) > :is(.g-slot, .g-ghost, .fl-cell) { grid-column: var(--x) / span var(--w); grid-row: var(--y) / span var(--h); }
.g-slot { border-radius: var(--radius); background: var(--surface-2); opacity: .85; pointer-events: none; }
.g-ghost { z-index: 1; border-radius: var(--radius-lg); border: 2px dashed var(--accent); background: var(--accent-tint); pointer-events: none; }
.g-ghost.is-bad { border-color: var(--terra); background: var(--terra-tint); }
.dash-v2.is-editing > .dash-cell.is-lifted-g { z-index: 6; cursor: grabbing; opacity: .92; box-shadow: var(--shadow); border-radius: var(--radius-lg); }
.dash-v2.is-editing > .dash-cell.is-sel { z-index: 4; }
.dash-v2.is-editing > .dash-cell.is-sel > :is(.card, .qa-tile, .pl-locked) { box-shadow: 0 0 0 2px var(--accent-line); }
.g-handle {
  position: absolute; z-index: 5; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent); touch-action: none;
}
.g-handle::after { content: ""; position: absolute; inset: -11px; } /* 44 px to grab */
.g-top { inset-block-start: -11px; inset-inline-start: calc(50% - 11px); cursor: ns-resize; }
.g-bottom { inset-block-end: -11px; inset-inline-start: calc(50% - 11px); cursor: ns-resize; }
.g-start { inset-inline-start: -11px; inset-block-start: calc(50% - 11px); cursor: ew-resize; }
.g-end { inset-inline-end: -11px; inset-block-start: calc(50% - 11px); cursor: ew-resize; }
/* The editor's tools lie over the card instead of adding height, so each card is as tall as in the view and the
   rows match (Reviewer batch 8): the widget head floats over the card's top, the tile keeps its view padding. */
.dash-v2.is-editing > .dash-cell > .pl-w-head { position: absolute; inset-block-start: 6px; inset-inline: 6px; z-index: 3; margin: 0; box-shadow: var(--shadow-xs); }
.dash-v2.is-editing > .dash-cell[data-tile] > .qa-tile { padding-block-start: var(--sp-5); }
.dash-v2.is-editing .pl-grip { touch-action: none; }
.pl-add-v2 { margin-block-start: var(--sp-5); }

/* «فرم‌های چاپی» widget (ADR-0014 step 4): one day field, then one link per print form. */
.pf-list { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: grid; gap: var(--sp-1); }
.pf-list a { display: flex; align-items: center; gap: var(--sp-2); min-height: 44px; padding-inline: var(--sp-2); border-radius: var(--radius); color: var(--text); }
.pf-list a:hover { background: var(--raised); text-decoration: none; }
.pf-list .icon { width: 18px; height: 18px; flex: none; color: var(--accent-text); }
.dash-cell[data-widget="print_forms"] .card-body { overflow: auto; }

/* Upload of up to 20 files (SPEC 14.5.1-14.5.2): one preview card per file before upload, one per row under
   600 px, two from 600 px, four from 1200 px. The preview is a canvas drawn in the browser (contain, >= 240 px). */
.upload-form > .upload-note { grid-column: 1 / -1; margin: 0; }
.up-list { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); margin: 0; padding: 0; list-style: none; }
@media (min-width: 600px) { .up-list { grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); } }
@media (min-width: 1200px) { .up-list { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }
.up-card { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.up-card.up-failed, .up-card.up-refused { border-color: var(--crit-fg); }
.up-card.up-done { border-color: var(--accent-line); }
.up-media { display: grid; place-items: center; min-block-size: 240px; background: var(--surface-2); }
.up-canvas { display: block; inline-size: 100%; block-size: 240px; object-fit: contain; }
.up-body { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); }
.up-head { display: flex; align-items: center; gap: var(--sp-2); }
.up-name { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
.up-x { min-inline-size: 44px; min-block-size: 44px; justify-content: center; padding: 0; }
.up-size { font: 500 var(--fs-xs)/1.4 var(--font-mono); color: var(--text-3); }
.up-retry { min-block-size: 44px; align-self: flex-start; }
.up-state { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin: 0; }

/* Document folders (SPEC 14.5.4): the folder bar wraps (no horizontal scroll), the open folder's tools, the chip
   under a dragged card, a picked card, the selection bar (sticky; above the bottom tab bar under 900 px) and the
   label that follows the pointer while dragging (its place comes from --gx/--gy, set through the CSSOM). */
.folder-bar { display: flex; flex-direction: column; gap: var(--sp-3); padding: 14px var(--pad); border-bottom: 1px solid var(--border-subtle); }
.folder-chips { margin: 0; padding: 0; list-style: none; }
.folder-chips .chip-filter { display: inline-flex; align-items: center; gap: 6px; }
.folder-chips .chip-filter .icon { width: 15px; height: 15px; }
.folder-bar .folder-name { display: inline-block; max-inline-size: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.folder-chips .chip-filter.is-drop { background: var(--terra-tint); border-color: var(--terra); color: var(--terra-text); outline: 2px dashed var(--terra); outline-offset: 2px; }
.folder-new { border-style: dashed; }
/* Windows-style folders (owner, 2026-11-16): a folder is a card in the gallery, before the loose files, drawn like a
   file card with a large folder icon; inside a folder the bar shows the path «اسناد › <folder>». */
.folder-tile { padding: 0; font: inherit; color: inherit; text-align: start; cursor: pointer; }
.folder-tile:hover { border-color: var(--accent-line); }
.folder-tile:hover .doc-media-file { background: var(--accent-tint); color: var(--accent-text); }
.folder-tile .doc-type .icon { color: var(--terra); }
.folder-tile .doc-type b { letter-spacing: normal; text-transform: none; }
.folder-tile .doc-name { display: block; max-inline-size: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-tile.is-drop { border-color: var(--terra); background: var(--terra-tint); outline: 2px dashed var(--terra); outline-offset: 2px; }
.folder-path { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.folder-path .folder-sep { color: var(--text-3); }
.folder-path .btn.is-drop { background: var(--terra-tint); border-color: var(--terra); color: var(--terra-text); outline: 2px dashed var(--terra); outline-offset: 2px; }
.folder-form, .folder-open { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.folder-form .input { inline-size: min(100%, 22em); }
.folder-form .field-error { flex-basis: 100%; margin: 0; }
.doc-tile { position: relative; }
.doc-tile.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-line); }
.doc-pick { position: absolute; inset-block-start: var(--sp-2); inset-inline-start: var(--sp-2); z-index: 2; padding: 6px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.doc-sub .icon { width: 13px; height: 13px; vertical-align: -2px; }
.select-bar {
  position: sticky; inset-block-end: var(--sp-3); z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  margin: 0 var(--pad) var(--pad); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--accent-line); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow);
}
.select-bar > span { flex: 1; font-weight: 600; }
@media (max-width: 900px) { .select-bar { inset-block-end: calc(80px + env(safe-area-inset-bottom)); } }
.doc-ghost {
  /* physical left on purpose: the pointer's clientX/clientY are physical in both directions */
  position: fixed; inset-block-start: 0; left: 0; z-index: 100; pointer-events: none;
  transform: translate(calc(var(--gx, 0px) + 12px), calc(var(--gy, 0px) + 12px));
  padding: 6px 12px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: var(--shadow);
}
body.is-dragging-doc, body.is-dragging-doc * { cursor: grabbing; user-select: none; }

/* A native <dialog> as an app card (document edit). */
.app-dialog { inline-size: min(560px, calc(100% - 32px)); max-block-size: calc(100% - 32px); padding: 0; border: 0; background: transparent; color: var(--text); }
.app-dialog::backdrop { background: rgba(10, 16, 13, .45); }
.app-dialog > .card { margin: 0; box-shadow: var(--shadow); }

/* «ارسال تکی»: the finished message as it will be sent, drawn like a message bubble. */
.sms-preview { margin: var(--sp-2) 0 0; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-lg); background: var(--accent-tint); color: var(--text); white-space: pre-wrap; line-height: 1.8; max-inline-size: 42em; }

/* Patient form cards with cells (owner decision 2026-11-17): from 900 px each box sits at its cell on the card's
   4-column grid (--x, --y, --w, --h set by Vue through the CSSOM); narrower screens keep one column in reading order. */
@media (min-width: 901px) {
  .form-grid.form-cells { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; }
  .form-grid.form-cells > .field { grid-column: var(--x) / span var(--w); grid-row: var(--y) / span var(--h); }
}

/* Patient form layout editor (owner decision 2026-11-17): each card's boxes on a 4-column home-screen grid, the
   same wells, drop spot, lifted look and edge handles as the dashboard editor (.g-*). Narrow screens get one box per
   row (the cells still mean the desktop form; moving a box there uses its card list). */
.fl-grid { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: 104px; gap: var(--sp-3); padding: var(--sp-4); }
.fl-cell { position: relative; display: flex; min-width: 0; cursor: grab; touch-action: none; }
.fl-cell.is-lifted-g { z-index: 6; cursor: grabbing; opacity: .92; }
.fl-cell.is-lifted-g > .fl-box { box-shadow: var(--shadow); }
.fl-cell.is-sel { z-index: 4; }
.fl-cell.is-sel > .fl-box { box-shadow: 0 0 0 2px var(--accent-line); }
.fl-box { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.fl-head { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.fl-head b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.fl-tools .select-sm { max-width: 100%; min-width: 0; flex: 1 1 90px; }
@media (max-width: 900px) {
  .fl-grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  .fl-grid > .g-slot, .fl-grid > .g-ghost, .fl-cell .g-handle { display: none; }
  .fl-cell { grid-column: 1 / -1 !important; grid-row: auto !important; cursor: auto; }
}

/* Physiotherapy (SPEC §15.6, mockup docs/design/physio/, owner approved 2026-11-18). Each session is a 40 px circle
   with a 44 px tap area; Vue sets --cols (two rows up to 12 sessions, three above). Ticked: accent fill with a check
   and a small number badge; next: dashed accent outline on the tint. The widget draws 11 px dots in the same rows. */
.ps-boxes { --cols: 5; display: grid; grid-template-columns: repeat(var(--cols), 40px); gap: var(--sp-2); justify-content: start; }
.ps-box {
  position: relative; display: grid; place-items: center; inline-size: 40px; block-size: 40px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-full); background: var(--surface);
  color: var(--text-3); font: 500 var(--fs-sm) var(--font-body); font-variant-numeric: tabular-nums;
  cursor: default; padding: 0;
}
.ps-box.is-done { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.ps-box.is-next { border-style: dashed; border-color: var(--accent-line); color: var(--accent-text); background: var(--accent-tint); }
button.ps-box { cursor: pointer; }
button.ps-box::after { content: ""; position: absolute; inset: -2px; }
button.ps-box:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) {
  button.ps-box.is-next:hover { border-style: solid; border-color: var(--accent); }
  button.ps-box.is-last:hover { background: var(--accent-hover); }
}
.ps-box .icon { inline-size: 18px; block-size: 18px; }
.ps-box .ps-n { position: absolute; inset-block-start: -3px; inset-inline-start: -3px; display: grid; place-items: center; min-inline-size: 16px; block-size: 16px; padding-inline: 3px; border-radius: var(--radius-full); background: var(--surface); color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent-line); font-size: 10px; line-height: 1; opacity: .85; }
.ps-count { font-weight: 600; color: var(--text); white-space: nowrap; }
.ps-cell { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); }
.ps-table td { vertical-align: middle; }
.ps-table .ps-boxes { padding-block: var(--sp-2); }
.ps-last { color: var(--text-2); white-space: nowrap; }
.ps-last.is-old { color: var(--terra-text); }
.ps-body { display: grid; gap: var(--sp-4); }
.ps-history summary { cursor: pointer; color: var(--text-2); font-size: var(--fs-sm); min-block-size: 44px; display: flex; align-items: center; }
.ps-history ul { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }
.ps-history li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--fs-sm); }
.ps-count-edit { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.ps-count-edit .input { inline-size: 72px; text-align: center; }
.ps-foot { display: flex; justify-content: flex-end; }
a.card.stat { color: var(--text); text-decoration: none; }
.ps-widget ul { list-style: none; margin: 0; padding: 0 var(--pad) var(--sp-4); display: grid; }
.ps-widget li { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding-block: var(--sp-3); border-block-end: 1px solid var(--border-subtle); font-size: var(--fs-sm); }
.ps-widget li:last-child { border-block-end: 0; }
.ps-dots { grid-template-columns: repeat(var(--cols), 11px); gap: 3px; }
.ps-dots .ps-box { inline-size: 11px; block-size: 11px; border-width: 1px; font-size: 0; }
/* Phones: six or more per row shrink the circles to fit the cell. */
@media (max-width: 600px) {
  .ps-boxes:not(.ps-dots) { inline-size: 100%; grid-template-columns: repeat(var(--cols), minmax(0, 40px)); gap: 6px; }
  .ps-boxes:not(.ps-dots) .ps-box { inline-size: 100%; block-size: auto; aspect-ratio: 1; }
}
