/* The page's visual language, defined once and used by the side panel,
   the memory view, the home page and Files. Loaded after tokens.css
   (the tokens, the base controls: button, select, .segmented, .switch,
   .check, kbd, .caps) and before each page's own stylesheet, which only
   places these and adds what is its own.

   The patterns:
   - Section (.sec > .sec-title + .card): one setting or one list, its
     title above its card at --fs-lg/600, sections --sec-gap apart.
   - Card (.card): a raised surface on the panel (--card, a hairline,
     --r-lg, --shadow-card). Inside it either rows or a body:
     .card-row, one line each, apart by hairlines: a .row-main (its
     .row-title and .row-sub) and the control at the right; a row that
     is a button or a link is a .row-btn (full width, an icon, the key
     or a chevron at the right); .card-body, stacked content with the
     card's padding (a segmented control, a toolbar, a hint).
   - Toolbar (.toolbar): controls in a row, wrapping; `.toolbar.fill`
     stretches its buttons to share the row.
   - Buttons (tokens.css): plain, .primary, .icon, .small, .link;
     disabled ones sink into their surface.
   - Segmented (.segmented, tokens.css): one choice of a few; the chosen
     segment a raised thumb. `.fill` across its column.
   - Switch (.switch, tokens.css): one on/off setting in a row.
   - Input (.input, and .find): a text or search field.
   - Badge (.badge): a small pill for a count, a model or a state;
     `.accent` for a live one, `.outline` for a quiet tag.
   - Tabs (.tabs): underlined tabs, the count of a tab in a badge.
   - List rows (.node, .list tr, .levels li, .dtree-row, .dlist tr,
     .home-calc): --row tall, --hover under the pointer, --accent-soft
     when selected, the focus ring inside.
   - Empty state (.empty): a short heading and a sentence, muted.
   - Dialog, menu, toast and note: below. */

/* ---------------------------------------------------------- the patterns */

.sec { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sec-title {
  margin: 0;
  padding: 0 2px;
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: var(--lh-tight);
  color: var(--ink);
}
.sec-title .badge { margin-left: var(--s2); vertical-align: 2px; }

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: calc(var(--tap) + 2 * var(--s2));
  padding: var(--s2) var(--card-pad);
}
.card-row + .card-row, .card-body + .card-row, .card-row + .card-body { border-top: 1px solid var(--rule-soft); }
.row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title { font-weight: 600; line-height: var(--lh-tight); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: var(--fs-sm); line-height: var(--lh-tight); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub.wrap { white-space: normal; }
.card-body { display: flex; flex-direction: column; gap: var(--s2); padding: var(--card-pad); }
.card-hint { margin: 0; font-size: var(--fs-sm); line-height: var(--lh); color: var(--muted); }
/* A row that acts: no frame of its own, the card's width, its icon
   quiet, what is at its right (a key, a chevron) pushed there. */
button.row-btn, a.row-btn {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-start;
  gap: var(--s3);
  min-height: calc(var(--tap) + var(--s2));
  padding: 0 var(--card-pad);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--t-fast);
}
.row-btn + .row-btn { border-top: 1px solid var(--rule-soft); }
button.row-btn:hover:not(:disabled, [aria-disabled="true"]), a.row-btn:hover { background: var(--hover); border-color: var(--rule-soft); }
button.row-btn:active:not(:disabled, [aria-disabled="true"]), a.row-btn:active { background: var(--track); }
.row-btn > .ic { color: var(--muted); }
.row-btn > kbd, .row-btn > .row-end { margin-left: auto; }
.row-btn > .row-end { color: var(--muted); }
.row-btn:focus-visible { outline-offset: -3px; }
:root button.row-btn:is(:disabled, [aria-disabled="true"]) { border-width: 0; border-top-width: 0; }
:root .row-btn + button.row-btn:is(:disabled, [aria-disabled="true"]) { border-top: 1px solid var(--rule-soft); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
.toolbar.fill > button:not(.icon), .toolbar.fill > a.button { flex: 1 1 auto; min-width: 0; }
.toolbar > button { white-space: nowrap; }

.input, .find {
  font: inherit;
  color: var(--ink);
  background: var(--control);
  border: 1px solid var(--control-border);
  border-radius: var(--r-md);
  min-height: var(--tap);
  padding: 0 var(--s3);
  min-width: 0;
  box-shadow: var(--shadow-ctl);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:hover, .find:hover { border-color: var(--control-border-hover); }
.input:focus-visible, .find:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent); }
.input::placeholder, .find::placeholder { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  background: var(--track);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}
.badge:empty { display: none; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.outline { background: none; border: 1px solid var(--rule); font-weight: 400; }
.badge.caps { letter-spacing: var(--track-caps); text-transform: uppercase; }

.tabs { display: flex; flex: none; gap: var(--s1); min-width: 0; }
.tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  background: none;
  box-shadow: none;
  min-height: calc(var(--tap) + 4px);
  padding: 2px var(--s2) 0;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: var(--fs-base);
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--t-fast), background-color var(--t-fast);
}
.tabs button:first-child { margin-left: calc(-1 * var(--s2)); }
.tabs button:hover:not(:disabled) { color: var(--ink); background: var(--hover); border-color: transparent; border-bottom-color: transparent; }
.tabs button[aria-selected=true] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.tabs button[aria-selected=true]:hover { border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline-offset: -2px; border-radius: var(--r-sm); }
.tabs .badge { margin-left: 5px; padding: 0 6px; }
.tabs button[aria-selected=true] .badge { background: var(--accent-soft); color: var(--accent-text); }

.empty { margin: 0; padding: var(--s5) var(--gutter); max-width: 48ch; color: var(--muted); line-height: 1.5; }
.empty h3 { margin: 0 0 var(--s2); font-size: 15px; font-weight: 600; line-height: var(--lh-tight); color: var(--ink); }
.empty p { margin: 0; }
.empty p + p { margin-top: var(--s2); }
.empty.error { color: var(--error); }

/* A dialog's backdrop and its entrance, for every dialog of the page. */
dialog::backdrop { background: rgba(20, 20, 19, 0.42); background: var(--backdrop); }
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: dialog-in var(--t) var(--ease); }
  dialog[open]::backdrop { animation: fade-in var(--t) var(--ease); }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
  @keyframes fade-in { from { opacity: 0; } }
}

/* The question before an action that cannot be undone (confirm.js). */
dialog.confirm {
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: var(--r-xl);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-3);
}
.confirm-box { padding: var(--s4) var(--gutter) var(--s3); }
.confirm-box h2 { margin: 0 0 var(--s2); font-size: var(--fs-lg); font-weight: 600; line-height: var(--lh-tight); overflow-wrap: anywhere; }
.confirm-box p { margin: 0 0 var(--s4); font-size: var(--fs-base); line-height: var(--lh); color: var(--ink); overflow-wrap: anywhere; }
.confirm-box p.confirm-note { margin-bottom: var(--s2); font-size: var(--fs-md); }
.confirm-list { margin: 0 0 var(--s4); padding-left: 1.4em; max-height: 9.5em; overflow-y: auto; font: var(--fs-md)/var(--lh) var(--mono); overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: var(--s2); }
button.confirm-danger { background: var(--error); border-color: var(--error); color: var(--error-ink); font-weight: 600; }
button.confirm-danger:hover:not(:disabled, [aria-disabled="true"]) { background: color-mix(in srgb, var(--error) 88%, var(--ink)); border-color: transparent; color: var(--error-ink); }
/* A narrow screen: a sheet at the bottom, the buttons the width of it. */
@media (max-width: 560px) {
  dialog.confirm {
    box-sizing: border-box;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-width: 1px 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .confirm-box { padding-bottom: calc(var(--s3) + var(--safe-b)); }
  .confirm-actions > button { flex: 1; }
}

/* "Connect your AI app" (web/ai-dialog.js): the confirmation's look,
   wider, with the address, the connected apps and the setting. */
dialog.ai {
  width: min(520px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--gutter));
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: var(--r-xl);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-3);
}
.ai-box { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4) var(--gutter) var(--s3); }
.ai-box h2 { margin: 0; font-size: var(--fs-lg); font-weight: 600; line-height: var(--lh-tight); }
.ai-box h3 { margin: var(--s2) 0 0; font-size: var(--fs-base); font-weight: 600; }
.ai-box p { margin: 0; font-size: var(--fs-base); line-height: var(--lh); overflow-wrap: anywhere; }
.ai-address-row { display: flex; gap: var(--s2); }
.ai-address-row[hidden] { display: none; }
.ai-address { flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: var(--fs-md); }
.ai-code { font-weight: 600; }
.ai-status { color: var(--muted); }
.ai-status.error { color: var(--error); }
.ai-note { color: var(--muted); font-size: var(--fs-md); }
.ai-apps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--s1); }
.ai-apps:empty { display: none; }
.ai-apps li { display: flex; align-items: center; gap: var(--s2); justify-content: space-between; }
.ai-app { min-width: 0; overflow-wrap: anywhere; }
.ai-app small, .ai-keep small { color: var(--muted); }
.ai-keep small { display: block; }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.ai-gap { flex: 1 1 auto; }
@media (max-width: 560px) {
  dialog.ai {
    box-sizing: border-box;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-width: 1px 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
  .ai-box { padding-bottom: calc(var(--s3) + var(--safe-b)); }
}
/* tab-mcp's own confirmation before store_variable and purge_variable
   (vendor/tab-mcp-client: styled through these properties only). */
:root {
  --tab-mcp-font: var(--fs-base)/var(--lh) var(--font);
  --tab-mcp-color: var(--ink);
  --tab-mcp-background: var(--panel);
  --tab-mcp-border: 1px solid var(--rule);
  --tab-mcp-radius: var(--r-xl);
  --tab-mcp-padding: var(--s4) var(--gutter) var(--s3);
  --tab-mcp-mono: var(--mono);
  --tab-mcp-title-size: var(--fs-lg);
}

/* Why a control that is off does nothing (web/shared/components/note.js). */
.note {
  position: fixed;
  z-index: 30;
  margin: 0;
  max-width: min(320px, calc(100vw - 16px));
  padding: var(--s2) var(--s3);
  font-size: var(--fs-sm);
  line-height: var(--lh-tight);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  /* A tap on what is under it still lands there (and closes it). */
  pointer-events: none;
}
/* What came of an action (web/shared/components/toast.js): over the stage,
   centred at its top, placed by its script; above the phone's bars and
   sheets. An outcome lets a tap through to what is under it; an error's
   text can be selected and copied, and its × (or Escape) closes it. */
.toast {
  position: fixed;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: max-content;
  transform: translateX(-50%);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-sm);
  line-height: var(--lh-tight);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  pointer-events: none;
}
.toast p { margin: 0; }
.toast.error { border-color: var(--error); color: var(--error); pointer-events: auto; user-select: text; padding-block: var(--s1); padding-right: var(--s1); }
.toast button.toast-close { flex: none; width: 28px; height: 28px; min-height: 0; color: var(--ink); }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in var(--t) var(--ease); }
  @keyframes toast-in { from { opacity: 0; } }
}
/* A menu (shared/components/menu.js): under its button or at the pointer, one
   column of items with a key on the right; Purge last, after a rule, in
   the error colour. */
.menu {
  position: fixed;
  z-index: 20;
  min-width: 208px;
  overflow: auto;
  padding: var(--s1);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}
@media (prefers-reduced-motion: no-preference) {
  .menu { animation: menu-in var(--t-fast) var(--ease); }
  @keyframes menu-in { from { opacity: 0; } }
}
.menu [role=menuitem] {
  display: flex;
  width: 100%;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  padding: 0 var(--s3) 0 var(--s2);
  /* Transparent: an off item's light one takes its place, nothing moves. */
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  box-shadow: none;
  justify-content: flex-start;
  text-align: left;
  font-size: var(--fs-md);
  color: var(--ink);
  white-space: nowrap;
}
/* An off item keeps its off look under the pointer and the focus; the
   focus ring still marks it. */
.menu [role=menuitem]:is(:hover, :focus-visible):not([aria-disabled=true]) { background: var(--hover); border-color: transparent; }
.menu [role=menuitem]:focus-visible { outline-offset: -2px; }
.menu [role=menuitem] .ic { width: 16px; height: 16px; color: var(--muted); }
.menu [role=menuitem] kbd { margin-left: auto; color: var(--muted); }
.menu [role=menuitem].danger:not([aria-disabled=true]), .menu [role=menuitem].danger:not([aria-disabled=true]) .ic { color: var(--error); }
.menu [role=separator] { height: 1px; margin: var(--s1) var(--s2); background: var(--rule-soft); }
.menu-note { margin: 0; padding: 2px var(--s2) var(--s1); font-size: var(--fs-xs); color: var(--muted); white-space: normal; max-width: 30ch; }

/* A device's directories (shared/components/device-tree.js): one row a
   directory, indented by its depth, the shown one marked. */
.dtree { display: block; padding: var(--s1) 0; overflow: auto; }
.dtree-row {
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-height: var(--row);
  padding: 0 var(--s2) 0 calc(var(--s2) + var(--depth, 0) * 16px);
  border-radius: var(--r-sm);
  cursor: default;
  white-space: nowrap;
  font-size: var(--fs-md);
}
.dtree-row:hover { background: var(--hover); }
.dtree-row[aria-selected=true] { background: var(--accent-soft); font-weight: 600; }
.dtree-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dtree-toggle { display: inline-flex; width: 16px; justify-content: center; color: var(--muted); cursor: pointer; }
.dtree-row .ic-sm { color: var(--muted); }
.dtree-name { font-family: var(--mono); }
.dtree-note { font-size: var(--fs-xs); }
.dtree-note.error { color: var(--error); }

/* A directory's variables (shared/components/device-list.js): a table,
   directories first, sortable columns, a "⋯" a row; a file dragged over
   it is outlined. */
.dlist { display: block; min-height: 0; position: relative; }
.dlist.drop { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: var(--r-md); background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.dlist-wrap { overflow-x: auto; }
.dlist table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.dlist th { text-align: left; font-weight: 600; padding: 0; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--paper); z-index: 1; }
.dlist th.col-size, .dlist th.col-checksum, .dlist th.col-modified { text-align: right; }
.dlist-sort {
  width: 100%;
  min-height: var(--row);
  justify-content: inherit;
  padding: 0 var(--s2);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--muted);
}
.dlist th.col-size .dlist-sort, .dlist th.col-checksum .dlist-sort, .dlist th.col-modified .dlist-sort { justify-content: flex-end; }
.dlist th.col-name .dlist-sort, .dlist th.col-kind .dlist-sort { justify-content: flex-start; }
.dlist-sort:hover:not(:disabled) { background: var(--hover); border-color: transparent; }
.dlist td { padding: 0 var(--s2); height: var(--row); border-bottom: 1px solid var(--rule-soft); white-space: nowrap; }
.dlist td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: var(--fs-sm); }
.dlist td.col-name { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dlist td.col-name .ic-sm { color: var(--muted); margin-right: var(--s2); }
.dlist-name { font-family: var(--mono); }
.dlist-kind-inline { display: none; margin-left: var(--s2); font-size: var(--fs-xs); }
.dlist td.col-more { width: 1px; padding: 0 var(--s1); }
.dlist td.col-more button.icon { width: 28px; height: 28px; }
.dlist tbody tr { cursor: default; }
.dlist tbody tr:hover { background: var(--hover); }
.dlist tbody tr[aria-selected=true] { background: var(--accent-soft); }
.dlist tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Folders' names semi-bold, the parent folder's ".." among them. */
.dlist :is(tr.dir, tr.dlist-up) .dlist-name { font-weight: 600; }
/* A folder's icon is filled, a file's hollow: at 16 px the outlines alone
   look alike. Forced colours keep the fill, in a system colour. */
.ic.ic-dir { fill: var(--folder-fill); }
@media (forced-colors: active) {
  .ic.ic-dir { fill: CanvasText; }
}
/* A row being read or written: a thin bar under its name (setBusy). */
.dlist tr.busy td.col-name { position: relative; }
.dlist-busy { position: absolute; left: var(--s2); right: var(--s2); bottom: 3px; height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 22%, transparent); overflow: hidden; pointer-events: none; }
.dlist-busy > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s linear; }
.dlist-busy.unknown > span { width: 30%; animation: dlist-busy 1.4s ease-in-out infinite; }
@keyframes dlist-busy { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) {
  .dlist-busy > span { transition: none; }
  .dlist-busy.unknown > span { animation: none; width: 100%; opacity: 0.5; }
}
.dlist-state { margin: 0; padding: var(--s4) var(--s3); }
.dlist-state.error { color: var(--error); }
/* Narrow: the type under the name, the checksum left out. */
@media (max-width: 559px) {
  .dlist .col-kind, .dlist .col-checksum, .dlist .col-modified { display: none; }
  .dlist-kind-inline { display: inline; }
}
@media (pointer: coarse) {
  .dlist td.col-more button.icon { width: var(--tap); height: var(--tap); }
}
