/* Case file: the Shinichi Analysis of a case. Form in "Open a case", view in the case file drawer, table in Track record */

/* ----- the form */
.cf { display: grid; gap: var(--space-sm); margin: var(--space-3xs) 0 var(--space-md); padding: var(--space-sm) var(--space-md); border-radius: var(--radius-panel); border: 1px dashed color-mix(in srgb, var(--case-blue) 45%, var(--line)); background: color-mix(in srgb, var(--case-blue) 5%, transparent); }
.cf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-3xs) var(--space-sm); }
.cf-head h3 { font-size: var(--text-md); color: var(--case-blue); }
.cf-head .muted { font-size: var(--text-sm); font-style: italic; }
.cf-form { display: grid; gap: var(--space-sm); border-radius: var(--radius-panel); }
.cf-form.drop { box-shadow: 0 0 0 2px var(--sheet), 0 0 0 4px var(--case-blue); } /* a file is held over the form */
.cf-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-sm); }
.cf-form input[type="url"] { width: 100%; font-family: var(--font-body); }

/* rich text editor (headline, bold, highlight, lists) */
.rt-box { border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--sheet); transition: border-color .15s ease, box-shadow .15s ease; }
.rt-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.rt-bar { position: sticky; top: -18px; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3xs); padding: var(--space-2xs) var(--space-xs); border-bottom: 1px solid var(--line); border-radius: var(--radius-control) var(--radius-control) 0 0; background: color-mix(in srgb, var(--case-blue) 5%, var(--sheet)); }
.rt-btn { width: 32px; height: 30px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--muted); font: 700 var(--text-sm) var(--font-body); cursor: pointer; }
.rt-btn:hover { background: color-mix(in srgb, var(--case-blue) 10%, transparent); color: var(--fg); }
.rt-btn[aria-pressed="true"] { background: color-mix(in srgb, var(--case-blue) 16%, transparent); color: var(--case-blue); }
.rt-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rt-btn .ic { width: 17px; height: 17px; }
.rt-h { font: 700 var(--text-md) var(--font-body); }
.rt-sep { width: 1px; height: 18px; margin: 0 var(--space-2xs); background: var(--line); }
.rt-area { position: relative; min-height: 110px; padding: var(--space-sm) var(--space-sm); outline: none; cursor: text; color: var(--fg); font: 400 var(--text-md)/1.55 var(--font-body); overflow-wrap: anywhere; }
#m-log .rt-area { min-height: 76px; }
.rt-area.rt-empty::before { content: attr(data-placeholder); position: absolute; inset: 10px 12px auto; color: var(--muted); opacity: .8; pointer-events: none; }

/* the same look while writing and when reading */
.rt-area p, .rt-view p { margin: 0 0 .4em; }
.rt-area h3, .rt-view h3 { margin: .8em 0 .3em; font: 700 var(--text-md)/1.3 var(--font-body); color: var(--fg); letter-spacing: 0; text-transform: none; }
.rt-area ul, .rt-area ol, .rt-view ul, .rt-view ol { margin: .2em 0 .55em; padding-inline-start: 1.5em; }
.rt-area li, .rt-view li { margin: .2em 0; padding-inline-start: .2em; }
.rt-area li::marker, .rt-view li::marker { color: var(--case-blue); font-weight: 700; }
.rt-area b, .rt-area strong, .rt-view strong { font-weight: 700; color: var(--fg); }
.rt-area mark, .rt-view mark { padding: 0 .18em; border-radius: var(--radius-tag); color: inherit; background: color-mix(in srgb, var(--brass) 40%, transparent); }
.rt-area > :first-child, .rt-view > :first-child { margin-top: 0; }
.rt-view > :last-child { margin-bottom: 0; }
.rt-view { line-height: 1.6; overflow-wrap: anywhere; }
.rt-gap { height: .45em; }
.cf-form div.f { display: grid; gap: var(--space-2xs); font-size: var(--text-xs); color: var(--muted); }
.cf-hint { font-size: var(--text-xs); font-style: italic; }
.cf-msg { margin: 0; font-size: var(--text-sm); }
.cf-msg:empty { display: none; }
.cf-msg.bad { color: var(--bad); }

/* image strip: thumbnails + the "Add" tile */
.cf-imgs { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.cf-th, .cf-add { position: relative; width: 96px; height: 64px; border-radius: var(--radius-control); overflow: hidden; border: 1px solid var(--line); background: var(--sheet); }
.cf-th img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cf-th.wait { background: linear-gradient(90deg, var(--sheet), color-mix(in srgb, var(--case-blue) 14%, var(--sheet)), var(--sheet)) 0 0 / 200% 100%; animation: cfWait 1.1s linear infinite; }
@keyframes cfWait { to { background-position: -200% 0; } }
.cf-th.missing::after, .cv-th.missing::after { content: "?"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.cf-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: color-mix(in srgb, var(--ink-deep) 72%, transparent); color: var(--on-dark); font-size: var(--text-md); line-height: 1; cursor: pointer; }
.cf-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cf-add { display: grid; place-items: center; align-content: center; gap: var(--space-3xs); cursor: pointer; border-style: dashed; color: var(--case-blue); font-size: var(--text-xs); font-weight: 600; }
.cf-add:hover { border-color: var(--case-blue); }
.cf-add:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.cf-add input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.cf-add .ic { width: 18px; height: 18px; }

/* ----- break-even: the exact amount */
.be-row { display: grid; grid-template-columns: minmax(0, 220px) auto; justify-content: start; align-items: end; gap: var(--space-xs) var(--space-sm); margin-top: var(--space-sm); padding: var(--space-sm); border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--sheet); }
.be-row input { width: 100%; }
.be-hint { grid-column: 1 / -1; margin: 0; font-size: var(--text-sm); }
.be-hint.bad { color: var(--bad); }
@media (max-width: 420px) { .be-row { grid-template-columns: minmax(0, 1fr); } }

/* ----- case log: the "Case file" button */
.log-item:has([data-case]) { grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
.log-item .btn.has-file { color: var(--case-blue); border-color: color-mix(in srgb, var(--case-blue) 40%, var(--line)); }
@media (max-width: 520px) {
  .log-item:has([data-case]) { grid-template-columns: auto minmax(0, 1fr) auto auto; grid-auto-flow: row dense; }
}

/* ----- the case file drawer */
#d-case { width: min(700px, 100%); }
.cv-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-sm); }
.cv-head .btn .ic { width: 16px; height: 16px; }
.cv-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-sm); }
.cv-top .num { font: 700 var(--text-lg) var(--font-mono); }
.cv-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--space-sm); }
.cv-chart { display: grid; align-content: start; justify-items: start; text-align: start; gap: var(--space-xs); padding: var(--space-sm) var(--space-sm); border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--sheet); color: var(--fg); text-decoration: none; }
a.cv-chart:hover { border-color: var(--accent); }
.cv-chart.empty { border-style: dashed; }
.cv-chart b { font-family: var(--font-body); font-size: var(--text-md); }
.cv-chart img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius-tag); border: 1px solid var(--line); }
.cv-link { color: var(--case-blue); font-size: var(--text-sm); overflow-wrap: anywhere; }
.cv-sec { display: grid; gap: var(--space-2xs); }
.cv-sec h3 { margin: 0; font: 600 var(--text-sm) var(--font-body); color: var(--case-blue); }
.cv-sec p { margin: 0; }
.cv-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
/* written parts as note cards: the reason in blue, the lesson in brass */
.cv-note { display: grid; gap: var(--space-xs); padding: var(--space-md); border: 1px solid color-mix(in srgb, var(--case-blue) 30%, var(--line)); border-radius: var(--radius-panel); background: var(--sheet); }
.cv-note > h3 { display: flex; align-items: center; gap: var(--space-xs); margin: 0; font: 600 var(--text-sm) var(--font-body); color: var(--case-blue); }
.cv-note > h3 .ic { width: 16px; height: 16px; }
.cv-note.lesson { border-color: color-mix(in srgb, var(--brass) 55%, var(--line)); background: color-mix(in srgb, var(--brass) 9%, var(--sheet)); }
.cv-note.lesson > h3 { color: color-mix(in srgb, var(--brass) 65%, var(--fg)); }
.cv-none { margin: 0; font-style: italic; }
/* save / cancel stay in sight while editing a long case file */
.cv-actions { position: sticky; bottom: -22px; z-index: 2; display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: 0 -20px calc(var(--space-lg) * -1); padding: var(--space-sm) 20px; background: var(--panel); border-top: 1px solid var(--line); }
.cv-imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-xs); }
.cv-th { position: relative; aspect-ratio: 16 / 10; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-control); background: var(--sheet); cursor: zoom-in; }
.cv-th img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cv-th:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* full-size image */
.lightbox { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-lg); background: color-mix(in srgb, var(--ink-deep) 90%, transparent); cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 48px); object-fit: contain; border-radius: var(--radius-tag); box-shadow: 0 20px 50px color-mix(in srgb, var(--ink-deep) 50%, transparent); }
.lightbox .icon-btn { position: absolute; top: 14px; right: 14px; }

/* ----- Track record: case files table */
table.cases tbody tr { cursor: pointer; }
table.cases tbody tr:hover td { background: color-mix(in srgb, var(--case-blue) 6%, transparent); }
table.cases td { vertical-align: middle; }
.cf-note { font-size: var(--text-xs); max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-badges { display: flex; flex-wrap: wrap; gap: var(--space-2xs); }
.cf-b { padding: var(--space-3xs) var(--space-xs); border-radius: var(--radius-pill); border: 1px solid color-mix(in srgb, var(--case-blue) 35%, var(--line)); color: var(--case-blue); font-size: var(--text-xs); text-decoration: none; white-space: nowrap; }
a.cf-b:hover { background: color-mix(in srgb, var(--case-blue) 10%, transparent); }

/* ----- Arabic: links stay left-to-right, corner buttons move to the left */
:root[lang="ar"] .cf-form input[type="url"] { direction: ltr; text-align: left; }
:root[lang="ar"] .cv-link { direction: ltr; unicode-bidi: isolate; }
:root[lang="ar"] .cf-x { right: auto; left: 3px; }
:root[lang="ar"] .lightbox .icon-btn { right: auto; left: 14px; }
:root[lang="ar"] .cf-hint, :root[lang="ar"] .cf-head .muted, :root[lang="ar"] .cv-none { font-style: normal; }
:root[lang="ar"] .cv-note > h3 { letter-spacing: 0; }
:root[lang="ar"] .cv-text { text-align: start; }

/* ----- required parts of a new case */
.req { color: var(--bad); font-weight: 700; }
.req-note { margin-inline-start: auto; font-size: var(--text-xs); color: var(--muted); }
.req-msg { margin: 0 0 var(--space-sm); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-control); font-size: var(--text-sm); color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 35%, var(--line)); }
.req-msg:empty { display: none; }
#m-log input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.rt-box.invalid { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }

/* ----- phone: each case file is one block, its amount on the first line */
@media (max-width: 600px) {
  table.cases thead { display: none; }
  table.cases tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2xs) var(--space-sm); padding: var(--space-sm) 0; border-bottom: 1px solid var(--line); }
  table.cases td { display: block; padding: 0; border: 0; white-space: normal; background: transparent !important; position: static; box-shadow: none; }
  table.cases td:nth-child(1) { grid-area: 1 / 1; color: var(--muted); }
  table.cases td:nth-child(4) { grid-area: 1 / 2; text-align: end; }
  table.cases td:nth-child(2) { grid-area: 2 / 1 / 3 / 3; }
  table.cases td:nth-child(3) { grid-area: 3 / 1; }
  table.cases td:nth-child(6) { grid-area: 3 / 2; text-align: end; }
  table.cases td:nth-child(5) { grid-area: 4 / 1 / 5 / 3; }
  table.cases td[colspan] { grid-column: 1 / -1; }
}
/* a link that leaves the app: its icon, with a gap */
.cf-b, .cv-link { display: inline-flex; align-items: center; gap: var(--space-2xs); }
.ic.ext { width: 12px; height: 12px; }
