/* Grove — Variant A "Workspace": a persistent app shell.
   White canvas, one surface color, dark-green primary, light neutrals.
   All decisions are design hypotheses, not proven preferences. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f7f7f7;
  --surface-raised: #ffffff;
  --border: #dddddd;
  --border-soft: #ebebeb;
  --text: #222222;
  --text-body: #3f3f3f;
  --text-muted: #6a6a6a;
  --accent: #14532d;
  --accent-hover: #0f3f23;
  --accent-fg: #ffffff;
  --accent-disabled: #cfe3d6;
  --accent-soft: #e8f3ec;
  --accent-soft-border: #cfe3d6;
  --accent-text: #14532d;
  --danger: #c13515;
  --danger-soft: #fdecea;
  --warn-bg: #fff8e6;
  --warn-border: #e5c07b;
  --warn-text: #7a5310;
  --code-bg: #f7f7f7;

  /* Shared micro-scale tokens. Every control below is built from these. */
  --focus-ring: #14532d;
  --focus-w: 2px;
  --focus-offset: 2px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 7px;            /* one radius for controls, dialogs, menus, popovers */
  --border-w: 1px;
  --control-h: 32px;        /* 44px under (pointer: coarse) below */
  --control-w: 32px;        /* icon-only controls are square */
  --control-pad-x: 12px;
  --control-font: 13px;
  --control-weight: 500;
  --icon-control: 16px;     /* only the brand mark uses --icon-brand */
  --icon-brand: 20px;
  --hover-bg: #f7f7f7;
  --active-bg: #d8ebde;     /* open preview: stronger green, clearly darker than selected */
  --active-bar: #14532d;    /* 2px inset left bar, >=3:1 against the active tint */
  --selected-bg: #f2f4f2;   /* checkbox selection: near-white neutral grey-green */
  --disabled-opacity: 0.45;
  --page-pad: 1.1rem;       /* shared horizontal page gutter */
  --menu-pad: 0.35rem;
  --surface-pad: 1rem;
  --sidebar-w: 252px;
  --sidebar-rail: 60px;
  --details-w: 380px;
  --row-h: 44px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg);
  color: var(--text-body);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font-family: inherit; }
/* One focus-ring definition for every focusable element. Rows draw it inset
   because their edges touch the table borders; colour and width are shared. */
:where(a, button, summary, input, select, [tabindex]):focus-visible {
  outline: var(--focus-w) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
/* One control/content icon size; the brand mark is the only larger variant. */
.icon, .icon-sm, .icon-xs { width: var(--icon-control); height: var(--icon-control); flex-shrink: 0; }
.icon-dir { color: #a06a00; }
.icon-file { color: var(--text-muted); }

/* ---------- Buttons ---------- */
/* All buttons share height, padding, radius, border, font and disabled/hover
   states. Hierarchy comes from colour/weight, not from size drift. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  height: var(--control-h); padding: 0 var(--control-pad-x);
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  background: var(--surface-raised); color: var(--text);
  font-size: var(--control-font); font-weight: var(--control-weight); line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--hover-bg); text-decoration: none; }
.btn:disabled,
[data-slot="menu-item"][data-disabled], [data-slot="menu-item"][disabled],
.action-menu-item[aria-disabled="true"] {
  opacity: var(--disabled-opacity); cursor: not-allowed;
}
.btn:disabled:hover { background: var(--surface-raised); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-fg); }
.btn-primary:disabled { opacity: var(--disabled-opacity); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 0 var(--control-pad-x); font-size: var(--control-font); }
.btn-icon { width: var(--control-w); min-width: var(--control-w); height: var(--control-h); padding: 0; }
.btn-block { width: 100%; }
.btn-active { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-text); }
/* Icons inside controls use one size; content icons keep their own sizes. */
.btn .icon-sm, .btn .icon-xs { width: var(--icon-control); height: var(--icon-control); }

/* ---------- Fields / alerts / auth (unchanged behavior) ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 0.35rem; }
.field .hint, .hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }
input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%; height: var(--control-h); padding: 0 var(--control-pad-x);
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: var(--control-font);
}
input[type="file"], .file-input { font-size: 0.8rem; color: var(--text-muted); max-width: 100%; cursor: pointer; }
input[type="file"]::file-selector-button {
  font-family: inherit; font-size: 0.78rem; font-weight: 600; color: var(--text);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 5px;
  padding: 0.35rem 0.6rem; margin-right: 0.55rem; cursor: pointer;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.alert { padding: 0.55rem 1.15rem; font-size: 0.86rem; border-bottom: 1px solid var(--border); }
.form-error { margin: 0.5rem 0; padding: 0.5rem 0.65rem; border-radius: 6px; background: var(--danger-soft); color: var(--danger); font-size: 0.9rem; }
.alert-error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert-warning { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.alert-info { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-text); }
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 440px; background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow);
}
.auth-header { display: flex; align-items: center; gap: 0.65rem; margin-bottom: 0.6rem; }
.auth-title { margin: 0; font-size: 1.35rem; }
.auth-subtitle { margin: 0 0 1.4rem 0; font-size: 0.88rem; color: var(--text-muted); }
.auth-card .alert-error { border: 1px solid var(--danger); border-radius: 6px; margin-bottom: 1rem; padding: 0.6rem 0.75rem; }

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}
body.sidebar-collapsed .app-shell { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr) 0; }

/* ---------- Left sidebar ---------- */
.ws-sidebar {
  grid-column: 1; grid-row: 1;
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--bg); border-right: 1px solid var(--border);
}
.ws-sidebar-top {
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
  height: var(--topbar-h); flex: 0 0 auto; padding: 0 0.7rem 0 1rem;
  border-bottom: 1px solid var(--border-soft);
}
.ws-brand { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1rem; color: var(--text); min-width: 0; }
.ws-brand:hover { text-decoration: none; }
.ws-brand .icon { color: var(--accent-text); width: 20px; height: 20px; }
.ws-brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-collapse, .drawer-close { color: var(--text-muted); }
.drawer-close { display: none; }
.ws-sidebar-actions { flex: 0 0 auto; padding: 0.8rem 0.9rem 0.6rem; }
.ws-new { justify-content: flex-start; gap: 0.55rem; font-weight: 600; }
.ws-new-label { overflow: hidden; text-overflow: ellipsis; }
.ws-tree-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.7rem 0.3rem 1rem; flex: 0 0 auto;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted);
}
#tree-refresh { min-width: var(--control-w); min-height: var(--control-h); }
.ws-tree { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 0 0.45rem 0.6rem; }
.tree-list, .tree-children { list-style: none; margin: 0; padding: 0; }
.tree-children { margin-left: 0.25rem; padding-left: 0.45rem; border-left: 1px solid var(--border-soft); }
/* Cap visual indent at three levels so deep paths keep readable names.
   Full paths remain available via each link's title tooltip. */
.tree-node[data-depth="3"] > .tree-children,
.tree-node[data-depth="4"] > .tree-children,
.tree-node[data-depth="5"] > .tree-children,
.tree-node[data-depth="6"] > .tree-children,
.tree-node[data-depth="7"] > .tree-children,
.tree-node[data-depth="8"] > .tree-children,
.tree-node[data-depth="9"] > .tree-children {
  margin-left: 0; padding-left: 0.35rem; border-left: 0;
}
.tree-node { min-width: 0; }
.tree-row { display: flex; align-items: center; min-width: 0; border-radius: 6px; }
.tree-row:hover { background: var(--hover-bg); }
.tree-node.is-current > .tree-row { background: var(--accent-soft); }
.tree-node.is-active-preview > .tree-row {
  background: var(--active-bg); box-shadow: inset 2px 0 0 var(--active-bar);
}
.tree-twisty {
  flex: 0 0 var(--control-w); width: var(--control-w); height: var(--control-h);
  display: inline-flex; align-items: center; justify-content: center;
  border: var(--border-w) solid transparent; background: transparent;
  color: var(--text-muted); cursor: pointer; border-radius: var(--radius);
  font-size: var(--control-font);
}
.tree-twisty:hover { background: var(--hover-bg); color: var(--text); }
.tree-twisty svg { transition: transform 0.15s ease; }
.tree-node.is-expanded > .tree-row > .tree-twisty svg { transform: rotate(90deg); }
.tree-twisty[data-empty] { visibility: hidden; }
.tree-link {
  display: flex; align-items: center; gap: 0.45rem; flex: 1 1 auto; min-width: 0;
  padding: 0.32rem 0.4rem 0.32rem 0; color: var(--text-body); font-size: 0.85rem; border-radius: 5px;
}
.tree-link:hover { color: var(--text); text-decoration: none; }
.tree-node.is-current > .tree-row > .tree-link { color: var(--accent-text); font-weight: 600; }
.tree-folder-icon { color: #a06a00; }
.tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tree-loading, .tree-error { padding: 0.3rem 0.4rem 0.3rem 1.4rem; font-size: 0.78rem; color: var(--text-muted); }
.tree-error { color: var(--danger); }
.ws-storage {
  flex: 0 0 auto; margin: 0.4rem 0.9rem 0.9rem; padding: 0.75rem 0.8rem;
  border-top: 1px solid var(--border-soft); background: var(--surface-alt); border-radius: 8px;
}
.ws-storage-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; font-weight: 600; color: var(--text); margin-bottom: 0.45rem; }
.ws-storage-pct { color: var(--accent-text); font-variant-numeric: tabular-nums; }
.meter { height: 7px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s ease; }
meter.meter { display: block; width: 100%; appearance: none; -webkit-appearance: none; }
meter.meter::-webkit-meter-bar { background: var(--bg); border: none; border-radius: 999px; height: 7px; }
meter.meter::-webkit-meter-optimum-value { background: var(--accent); border-radius: 999px; height: 100%; }
meter.meter::-webkit-meter-suboptimum-value { background: var(--accent); border-radius: 999px; height: 100%; }
meter.meter::-moz-meter-bar { background: var(--accent); border-radius: 999px; }
.ws-storage-caption { margin-top: 0.4rem; font-size: 0.74rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Collapsed icon rail */
body.sidebar-collapsed .ws-brand-name,
body.sidebar-collapsed .ws-new-label,
body.sidebar-collapsed .ws-tree-head,
body.sidebar-collapsed .ws-tree,
body.sidebar-collapsed .ws-storage { display: none; }
/* The rail keeps an explicit expand control: nothing may be hover-only. */
body.sidebar-collapsed .ws-sidebar-top {
  flex-direction: column; height: auto; padding: 0.5rem 0 0.35rem; gap: 0.25rem;
  justify-content: center; border-bottom: 0;
}
body.sidebar-collapsed .sidebar-collapse { display: inline-flex; min-width: 40px; min-height: 32px; }
body.sidebar-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
body.sidebar-collapsed .ws-sidebar-actions { padding: 0.4rem 0.5rem; }
body.sidebar-collapsed .ws-new { justify-content: center; }

/* ---------- Top bar ---------- */
.ws-main { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.app-topbar {
  display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto;
  height: var(--topbar-h); padding: 0 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg); z-index: 30;
}
.sidebar-toggle { color: var(--text-muted); }
#search-expand, #search-collapse, .mobile-crumbs { display: none; }
.search-form { position: relative; flex: 1 1 auto; min-width: 0; max-width: 720px; margin: 0 auto; }
.search-box {
  display: flex; align-items: center; gap: 0.5rem; min-width: 0; height: var(--control-h);
  padding: 0 0.35rem 0 var(--control-pad-x);
  background: var(--surface-alt); border: var(--border-w) solid var(--border); border-radius: 999px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.search-box:focus-within { border-color: var(--accent); background: var(--bg); }
.search-icon { color: var(--text-muted); }
.search-box input[type="search"] {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent; outline: none;
  padding: 0; box-shadow: none; font-size: var(--control-font); color: var(--text);
}
/* Our own clear button is the only one; suppress the browser's duplicate. */
.search-box input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-kbd {
  border: 1px solid var(--border); border-radius: 4px; padding: 0 0.35rem;
  font-size: 0.72rem; color: var(--text-muted); background: var(--bg); line-height: 1.4;
}
.search-box:focus-within .search-kbd { display: none; }
.search-clear {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-w); height: var(--control-h);
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text-muted);
  font-size: var(--control-font); line-height: 1; cursor: pointer;
}
.search-clear:hover { background: var(--hover-bg); color: var(--text); }
.search-spinner {
  width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent-text);
  border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.details-toggle[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-text); }
.user-menu-trigger { gap: 0.4rem; }
.user-menu-name { font-weight: var(--control-weight); max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Popup menus ---------- */
.menu-anchor { position: relative; display: inline-block; }
.menu-anchor > summary { list-style: none; cursor: pointer; user-select: none; }
.menu-anchor > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; top: calc(100% + 6px); min-width: 190px; max-width: min(320px, calc(100vw - 1.5rem));
  background: var(--surface-raised); border: var(--border-w) solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--menu-pad); z-index: 60;
}
.menu-panel:not(.search-results) { display: flex; flex-direction: column; gap: 0.1rem; }
/* UI SDK components are themed through the same tokens; their behaviour is
   left entirely to the SDK. */
[data-slot="menu-content"] {
  background: var(--surface-raised); border: var(--border-w) solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--menu-pad); min-width: 180px; z-index: 120;
}
[data-slot="menu-item"] { cursor: pointer; }
[data-slot="menu-item"][data-highlighted] { background: var(--hover-bg); }
[data-slot="menu-item"][data-disabled], [data-slot="menu-item"][disabled] { opacity: 0.45; cursor: default; }
[data-slot="menu-separator"] { height: 1px; background: var(--border); margin: 0.25rem 0; }
#user-menu .menu-panel, #new-menu .menu-panel { right: 0; }
#sort-menu .menu-panel, .crumb-menu { left: 0; right: auto; min-width: 170px; }
.user-menu-username { padding: 0.45rem 0.6rem; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); word-break: break-all; }
.action-menu-item {
  display: flex; align-items: center; gap: 0.55rem; width: 100%;
  min-height: var(--control-h); padding: 0 var(--control-pad-x);
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text);
  font-size: var(--control-font); font-weight: var(--control-weight);
  text-align: left; text-decoration: none; cursor: pointer;
}
.action-menu-item > span:first-child:not(:only-child) { flex: 1 1 auto; }
.action-menu-item:hover { background: var(--hover-bg); text-decoration: none; }
.action-menu-item[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.action-menu-active { background: var(--accent-soft); color: var(--accent-text); }
.action-menu-danger { color: var(--danger); }
.action-menu-danger:hover { background: var(--danger-soft); }
.search-results { left: 0; right: 0; max-width: none; max-height: 60vh; overflow-y: auto; padding: 0.3rem; }
.search-result {
  display: flex; align-items: center; gap: 0.55rem; width: 100%;
  min-height: var(--control-h); padding: 0 var(--control-pad-x);
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text);
  text-align: left; cursor: pointer; font-size: var(--control-font);
}
.search-result:hover, .search-result.is-active { background: var(--hover-bg); text-decoration: none; }
.search-result-main { display: flex; flex-direction: column; min-width: 0; }
.search-result-name, .search-result-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-name { font-weight: 600; }
.search-result-path { font-size: 0.74rem; color: var(--text-muted); }
.search-status { padding: 0.7rem 0.6rem; font-size: 0.82rem; color: var(--text-muted); }
.search-result-group {
  padding: 0.4rem 0.6rem 0.2rem; font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted);
}

/* ---------- Context bar (path + arrange) ---------- */
#browser-content {
  flex: 1 1 auto; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
}
.context-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  flex: 0 0 auto; min-height: 50px; padding: 0.35rem 1.1rem;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.breadcrumbs { display: flex; align-items: center; flex-wrap: nowrap; gap: 0.15rem; min-width: 0; overflow-x: auto; font-size: 0.85rem; scrollbar-width: none; }
.breadcrumbs::-webkit-scrollbar { display: none; }
.crumb-home, .crumb-link {
  display: inline-flex; align-items: center; gap: 0.3rem; flex-shrink: 0;
  padding: 0.25rem 0.4rem; border-radius: 5px; color: var(--text-muted);
}
.crumb-home:hover, .crumb-link:hover { color: var(--text); background: var(--hover-bg); text-decoration: none; }
.crumb-active { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--text-muted); flex-shrink: 0; user-select: none; }
.crumb-more {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  min-width: var(--control-w); height: var(--control-h); padding: 0 var(--control-pad-x);
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  background: var(--surface-raised); color: var(--text-muted);
  font-size: var(--control-font); font-weight: var(--control-weight); line-height: 1; cursor: pointer;
}
.crumb-more:hover, .crumb-more[aria-expanded="true"] {
  background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-text);
}
.crumb-menu { top: calc(100% + 8px); left: 0; right: auto; max-height: 50vh; overflow: auto; }
.listing-tools { display: flex; align-items: center; gap: 0.35rem; margin-left: auto; flex-shrink: 0; }
.context-tools { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.select-mode-btn {
  gap: 0.35rem; color: var(--text-muted);
  border-left: 3px solid var(--border); padding-left: 0.7rem;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.select-mode-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-soft-border); color: var(--accent-text); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.segmented .btn { border: 0; border-radius: 0; }
.segmented .btn + .btn { border-left: 1px solid var(--border); }
.sort-trigger { color: var(--text-muted); }

/* ---------- Selection bar ---------- */
.selection-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  flex: 0 0 auto; min-height: 50px; padding: 0.4rem 1.1rem;
  background: var(--accent-soft); border-bottom: 1px solid var(--accent-soft-border);
}
.selection-count { font-size: 0.86rem; font-weight: 700; color: var(--accent-text); }
.selection-actions { display: flex; align-items: center; gap: 0.3rem; }
.selection-actions .btn:disabled { opacity: 0.4; }
.selection-divider { width: 1px; height: 22px; background: var(--accent-soft-border); margin: 0 0.2rem; }

/* ---------- List / grid ---------- */
.content-pane { flex: 1 0 auto; min-width: 0; width: 100%; }
.table-wrap, .grid-view, .empty-state { min-width: 0; }
table.file-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; table-layout: fixed; }
table.file-table col.col-select { width: 44px; }
table.file-table col.col-name { width: auto; }
table.file-table col.col-size { width: 110px; }
table.file-table col.col-modified { width: 190px; }
table.file-table th, table.file-table td { padding: 0 0.75rem; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: middle; }
table.file-table thead th { height: 38px; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
table.file-table tbody tr { height: var(--row-h); }
table.file-table tbody tr:hover, .grid-card:hover { background: var(--surface-alt); }
/* Selection is signalled by the checked native box plus a near-white neutral
   tint; the active preview is signalled by the inset bar and a bolder name. */
table.file-table tbody tr.is-selected, .grid-card.is-selected { background: var(--selected-bg); }
.entry-item.is-active-preview, .grid-card.is-active-preview {
  background: var(--active-bg);
  box-shadow: inset 2px 0 0 var(--active-bar);
}
.entry-item.is-active-preview.is-selected, .grid-card.is-active-preview.is-selected {
  background: var(--active-bg);
}
.entry-item.is-active-preview .entry-name-text,
.grid-card.is-active-preview .entry-name-text { font-weight: 600; }
.entry-item:focus-visible { outline: var(--focus-w) solid var(--focus-ring); outline-offset: calc(-1 * var(--focus-offset)); }
.th-sort-link { color: var(--text-muted); }
.th-sort-link:hover { color: var(--text); text-decoration: none; }
.col-select, .entry-check { text-align: center; }
.col-select input, .entry-checkbox { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
#browser-content:not(.select-mode) .col-select,
#browser-content:not(.select-mode) .entry-check { visibility: hidden; }
#browser-content:not(.select-mode) table.file-table col.col-select { width: 0; }
#browser-content:not(.select-mode) table.file-table th.col-select,
#browser-content:not(.select-mode) table.file-table td.col-select { width: 0; padding: 0; border: 0; overflow: hidden; }
.name-cell { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.name-cell-main { flex: 1 1 auto; min-width: 0; }
table.file-table td.col-size, table.file-table td.col-modified { color: var(--text-muted); white-space: nowrap; }
table.file-table td.col-name { max-width: 0; overflow: hidden; }
.entry-link { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--text); font-weight: 500; max-width: 100%; border-radius: 4px; min-width: 0; height: var(--row-h); }
.entry-link:hover { color: var(--accent-text); text-decoration: none; }
.entry-name-text { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-icon-wrap { position: relative; width: var(--control-w); height: var(--control-w); flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.entry-thumb { position: absolute; inset: 0; width: 32px; height: 32px; object-fit: cover; border-radius: var(--radius); background: var(--surface-alt); }
.entry-thumb[data-broken] { display: none; }
.grid-card-media { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: var(--radius); background: var(--surface-alt); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.grid-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.grid-thumb[data-broken] { display: none; }
.grid-fallback-icon { width: 40px; height: 40px; color: var(--text-muted); }
.entry-meta-mobile { display: none; }
/* Icon-only row action on fine pointers: no bordered button box. It stays in
   the tab order (opacity 0, never display:none) and appears on hover, focus or
   when the row is selected. Touch keeps it permanently visible. */
.entry-more {
  color: var(--text-muted); opacity: 0; flex: 0 0 auto;
  border: 0; background: transparent; border-radius: var(--radius);
  width: var(--control-w); height: var(--control-h); padding: 0;
  font-size: var(--control-font);
}
.entry-item:hover .entry-more, .entry-item:focus-within .entry-more,
.entry-item.is-selected .entry-more, .grid-card:hover .entry-more,
.grid-card:focus-within .entry-more, .grid-card.is-selected .entry-more { opacity: 1; }
.grid-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0.25rem 0.5rem; padding: 0.5rem 0.9rem; }
.grid-card { border-radius: 8px; padding: 0.5rem 0.6rem; min-width: 0; }
.grid-card-main { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.grid-card-body { display: flex; flex-direction: column; gap: 0.15rem; flex: 1 1 auto; min-width: 0; }
.grid-card-head { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.grid-card-meta { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-state { padding: 4rem 1.5rem; text-align: center; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.empty-state-icon { width: 48px; height: 48px; border-radius: 999px; background: var(--surface-alt); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; margin-bottom: 0.3rem; }
.empty-state-icon svg { width: 24px; height: 24px; }
.empty-state-title { margin: 0; font-size: 1.05rem; color: var(--text); }
.empty-state-hint { margin: 0; font-size: 0.86rem; max-width: 420px; }

/* ---------- Full-viewport file viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 80; display: flex; }
.viewer-scrim { position: absolute; inset: 0; background: #ffffff; }
.viewer[data-kind="image"] .viewer-scrim { background: #0b0d0f; }
.viewer-frame { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex: 0 0 auto; min-height: 56px; padding: 0 var(--page-pad);
  background: var(--bg); border-bottom: var(--border-w) solid var(--border);
}
.viewer[data-kind="image"] .viewer-bar { background: #111417; color: #fff; border-bottom-color: #2a2f34; }
.viewer-heading { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
#viewer-title { margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-position { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.viewer[data-kind="image"] .viewer-position { color: rgba(255,255,255,0.7); }
.viewer-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.viewer-icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-w); height: var(--control-h);
  border: var(--border-w) solid transparent; border-radius: var(--radius);
  background: transparent; color: inherit; cursor: pointer; text-decoration: none;
}
.viewer-icon-btn:hover, .viewer-icon-btn:focus-visible { background: var(--hover-bg); }
.viewer[data-kind="image"] .viewer-icon-btn:hover,
.viewer[data-kind="image"] .viewer-icon-btn:focus-visible { background: rgba(255,255,255,0.16); }
.viewer-icon-btn.is-danger { color: var(--danger); }
.viewer-icon-btn::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 6px); right: 0; z-index: 4;
  padding: 0.25rem 0.45rem; border-radius: var(--radius); background: var(--bg);
  border: var(--border-w) solid var(--border); color: var(--text);
  font-size: 0.74rem; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.viewer-icon-btn:hover::after, .viewer-icon-btn:focus-visible::after { opacity: 1; }
.viewer-stage {
  position: relative; flex: 1 1 auto; min-height: 0; overflow: auto;
  display: flex; align-items: center; justify-content: center; padding: 1rem 4rem;
}
.viewer-content { display: flex; align-items: center; justify-content: center; max-width: 100%; max-height: 100%; min-width: 0; }
.viewer-image-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; max-width: 100%; }
.viewer-image-wrap img { max-width: 100%; max-height: calc(100dvh - 180px); width: auto; height: auto; object-fit: contain; }
.viewer-image-wrap [data-preview-image-error] { color: #fff; text-align: center; }
.viewer-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  padding: 0.5rem 0.8rem; border-radius: var(--radius); background: var(--bg);
  border: var(--border-w) solid var(--border); color: var(--text-muted); font-size: 0.84rem;
}
.viewer-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: var(--border-w) solid var(--border); border-radius: 999px;
  background: var(--surface-raised); color: var(--text); cursor: pointer;
  box-shadow: var(--shadow);
}
.viewer-arrow-prev { left: 0.5rem; }
.viewer-arrow-next { right: 0.5rem; }
.viewer-stage.is-text .viewer-content { width: 100%; }
.viewer-text {
  width: min(960px, 100%); max-height: 100%; overflow: auto; padding: 1rem;
  background: var(--bg); border: var(--border-w) solid var(--border); border-radius: var(--radius);
}
.viewer-text .preview-code {
  counter-reset: grove-line; margin: 0; padding: 0.75rem 0.8rem; background: var(--code-bg);
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  font-size: 0.82rem; line-height: 1.55; overflow: auto; white-space: pre; tab-size: 4;
}
.viewer-text .preview-code .code-line { display: block; counter-increment: grove-line; }
.viewer-text .preview-code .code-line::before {
  content: counter(grove-line); display: inline-block; width: 2.6rem; padding-right: 0.7rem;
  margin-right: 0.7rem; text-align: right; color: var(--text-muted);
  border-right: var(--border-w) solid var(--border); user-select: none;
}
.viewer-unsupported { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; text-align: center; color: var(--text); }
.viewer-unsupported .icon-sm { width: 64px; height: 64px; color: var(--text-muted); }
.viewer-unsupported .muted { margin: 0; }
.viewer-info {
  position: absolute; top: 56px; right: 0; bottom: 0; z-index: 3;
  width: min(340px, 92vw); display: flex; flex-direction: column; min-height: 0;
  background: var(--bg); border-left: var(--border-w) solid var(--border); box-shadow: var(--shadow);
}
.viewer-info-head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  flex: 0 0 auto; padding: 0.6rem 1rem; border-bottom: var(--border-w) solid var(--border);
}
.viewer-info-head h3 { margin: 0; font-size: 0.95rem; }
.viewer-info-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--surface-pad); }
.viewer-info-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem;
  flex: 0 0 auto; padding: 0.6rem 1rem; border-top: var(--border-w) solid var(--border);
}

/* ---------- Dialogs ---------- */
.modal-dialog {
  width: min(460px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1rem); padding: 0;
  color: var(--text); background: var(--surface-alt); border: var(--border-w) solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
[data-slot="dialog-backdrop"] { background: rgba(1, 4, 9, 0.75); }
.modal-dialog form { margin: 0; display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: var(--surface-pad); border-bottom: var(--border-w) solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 1.05rem; }
.dialog-body {
  padding: var(--surface-pad); display: flex; flex-direction: column; gap: 0.35rem;
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
}
.dialog-body .field { margin-bottom: 0.6rem; }
.dialog-hint { margin: 0 0 0.6rem; font-size: var(--control-font); color: var(--text-muted); word-break: break-word; }
.dialog-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem;
  flex: 0 0 auto; flex-wrap: wrap; padding: var(--surface-pad);
  border-top: var(--border-w) solid var(--border); background: var(--surface-alt);
}
.meta-list { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.4rem 1rem; font-size: 0.84rem; margin: 0; }
.meta-list dt { color: var(--text-muted); font-weight: 600; }
.meta-list dd { margin: 0; word-break: break-all; }

/* ---------- Drop overlay, upload tray, toasts ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.86); border: 3px dashed var(--accent); pointer-events: none;
}
.drop-overlay-inner { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; color: var(--accent-text); }
.drop-overlay-inner svg { width: 56px; height: 56px; }
.drop-overlay-inner strong { font-size: 1.25rem; }
.drop-overlay-inner span { font-size: 0.9rem; color: var(--text-muted); }
.upload-queue {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 95; width: min(360px, calc(100vw - 2rem));
  background: var(--surface-raised); border: var(--border-w) solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.upload-queue-header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); }
.upload-queue-header h2 { margin: 0; font-size: 0.9rem; }
.upload-queue-head-actions { display: flex; gap: 0.15rem; }
.upload-queue-pill {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; width: 100%;
  min-height: var(--control-h); padding: 0 var(--control-pad-x);
  border: 0; background: var(--accent); color: var(--accent-fg);
  font-size: var(--control-font); font-weight: var(--control-weight); cursor: pointer;
}
.upload-pill-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-fg); opacity: 0.8; }
.upload-overall { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; }
.upload-overall .progress-bar { flex: 1 1 auto; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.progress-fill { width: 0%; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.15s ease; }
.upload-queue-list { list-style: none; margin: 0; padding: 0 0.8rem 0.8rem; max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.upload-item { padding: 0.55rem; background: var(--surface-alt); border: 1px solid var(--border-soft); border-radius: 7px; }
.upload-item-main { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.82rem; margin-bottom: 0.35rem; }
.upload-item-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-pct { flex-shrink: 0; }
.upload-item-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.35rem; }
.upload-item-status { font-size: 0.76rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-buttons { display: flex; gap: 0.3rem; flex-shrink: 0; }
.upload-cancel, .upload-retry { font-size: var(--control-font); padding: 0 var(--control-pad-x); height: var(--control-h); }
.upload-item.is-error .progress-fill { background: var(--danger); }
.upload-item.is-error .upload-item-status { color: var(--danger); }
.toast-region { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 110; display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; }
.toast {
  max-width: min(440px, calc(100vw - 2rem)); padding: 0.6rem 1rem; background: var(--surface-raised);
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 7px;
  box-shadow: var(--shadow); font-size: 0.84rem; color: var(--text); pointer-events: auto;
}
.toast.is-error { border-left-color: var(--danger); }

/* ---------- Responsive: tablet ---------- */
@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; --details-w: 340px; }
}

/* ---------- Responsive: phone (390x844) ---------- */
@media (max-width: 680px) {
  :root { --page-pad: 0.75rem; --topbar-h: 44px; }
  .app-shell, body.sidebar-collapsed .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .ws-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 90; width: min(86vw, 320px);
    transform: translateX(-101%); transition: transform 0.18s ease; box-shadow: var(--shadow);
  }
  body.drawer-open .ws-sidebar { transform: translateX(0); }
  .drawer-close { display: inline-flex; }
  .sidebar-collapse { display: none; }
  .ws-main { grid-column: 1; }
  /* One connected header block: flat navigation icons above a breadcrumb row
     whose tools are a single segmented group, not four floating boxes. */
  .app-topbar { gap: 0.25rem; padding: 0 var(--page-pad); border-bottom: 0; }
  .sidebar-toggle { display: inline-flex; }
  .search-form { max-width: none; }
  .search-box { padding-left: 0.6rem; }
  .search-kbd { display: none; }
  .user-menu-name { display: none; }
  .app-topbar .sidebar-toggle,
  .app-topbar .details-toggle,
  .app-topbar .user-menu-trigger {
    border: 0; background: transparent; padding: 0;
    width: 44px; min-width: 44px; height: 44px; color: var(--text-muted);
    border-radius: var(--radius);
  }
  .app-topbar .sidebar-toggle:hover,
  .app-topbar .details-toggle:hover,
  .app-topbar .user-menu-trigger:hover { background: var(--hover-bg); }
  .app-topbar .details-toggle[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); }
  input[type="text"], input[type="password"], input[type="search"], select,
  .search-box input[type="search"] { font-size: 16px; }
  .btn, .btn-sm, .btn-icon, .user-menu-trigger, .sort-trigger, .select-mode-btn,
  .search-clear, .tree-twisty, .crumb-more, .upload-cancel, .upload-retry,
  .ws-brand, .tree-link, .tree-row, #tree-refresh, .crumb-home, .crumb-link {
    min-height: 44px;
  }
  .btn-icon, .tree-twisty, .crumb-more, #tree-refresh { min-width: 44px; }
  /* Name and meta form one tight block inside a single 44px+ link target. */
  table.file-table tbody .entry-link {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center; column-gap: 0.5rem; row-gap: 0.1rem;
    height: auto; min-height: 44px; padding: 0.3rem 0;
  }
  /* One fixed 32px slot: icon and thumbnail share the same left edge and never
     overlap the name. */
  .entry-icon-wrap { width: 32px; height: 32px; flex: 0 0 32px; }
  .entry-icon-wrap > .icon { width: 32px; height: 32px; }
  table.file-table tbody .entry-link > .entry-icon-wrap { grid-column: 1; grid-row: 1 / 3; align-self: center; }
  table.file-table tbody .entry-name-text { grid-column: 2; grid-row: 1; }
  .entry-more { min-width: 44px; min-height: 44px; opacity: 1; }
  .action-menu-item { min-height: 44px; }
  /* Flat icon controls: 44px hit area, no card-per-button boxes. */
  #search-expand { display: inline-flex; }
  #search-collapse { display: none; }
  .app-topbar .topbar-icon-btn {
    position: relative; width: 44px; height: 44px; min-width: 44px;
    border: 0; background: transparent; padding: 0; border-radius: var(--radius);
  }
  .app-topbar .topbar-icon-btn:hover { background: var(--hover-bg); }
  .app-topbar .topbar-icon-btn > svg { position: relative; z-index: 1; }
  .search-form { display: none; }
  body.search-open .search-form {
    display: block; position: absolute; z-index: 50;
    left: var(--page-pad); right: var(--page-pad); top: calc(var(--topbar-h) + 2px);
    padding: 0.35rem; background: var(--bg); border: var(--border-w) solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
  }
  body.search-open #search-collapse { display: inline-flex; }
  /* Mobile breadcrumb: up chevron + parent hint + one ellipsized leaf. */
  .breadcrumbs { display: none; }
  .mobile-crumbs { display: flex; align-items: center; gap: 0.2rem; width: 100%; min-width: 0; height: 44px; }
  .mobile-crumb-btn { width: 44px; height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--text-muted); }
  .mobile-crumb-current { display: flex; align-items: center; gap: 0.3rem; min-width: 0; flex: 1 1 auto; padding: 0.3rem 0; border: 0; background: transparent; text-align: left; color: var(--text); }
  .mobile-crumb-parent { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }
  .mobile-crumb-leaf { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Breadcrumb and file tools share one row; the tools form one connected
     segmented group so they read as part of the navigation bar. */
  .context-bar {
    padding: 0 var(--page-pad); gap: 0.25rem; min-height: 44px;
    flex-direction: row; align-items: center;
    border-top: var(--border-w) solid var(--border-soft);
    border-bottom: var(--border-w) solid var(--border);
  }
  .breadcrumbs { width: 100%; flex: 0 0 auto; }
  .mobile-crumbs { width: auto; flex: 1 1 auto; min-width: 0; }
  .context-tools {
    gap: 0; flex: 0 0 auto; align-self: center;
    border: var(--border-w) solid var(--border); border-radius: var(--radius);
    overflow: hidden; background: var(--surface-raised);
  }
  .context-tools > * + * { border-left: var(--border-w) solid var(--border-soft); }
  .context-tools > .btn,
  .context-tools > details > summary,
  .context-tools .segmented { border: 0; border-radius: 0; background: transparent; }
  .context-tools > .btn,
  .context-tools > details > summary,
  .context-tools .segmented .btn {
    width: 44px; min-width: 44px; height: 44px; min-height: 44px;
  }
  .context-tools > details > summary { display: inline-flex; align-items: center; justify-content: center; }
  .select-mode-btn span { display: none; }
  .selection-bar { padding: 0.35rem var(--page-pad); }
  .selection-actions .btn-icon { min-width: var(--control-w); min-height: var(--control-h); }
  .menu-panel { right: 0; left: auto; }
  #sort-menu .menu-panel, .crumb-menu, #new-menu .menu-panel { left: 0; right: auto; }
  /* Two-column tiles on phones. Only grid selectors are touched here; the
     list view and the desktop grid keep their existing rules. */
  .grid-view { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; padding: 0.5rem var(--page-pad); }
  .grid-card {
    position: relative; min-width: 0; padding: 0.5rem 0.45rem;
    border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface-raised);
  }
  .grid-card-main { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
  .grid-card-body { min-width: 0; flex: 1 1 auto; }
  .grid-card-head { gap: 0.35rem; padding-right: 2.85rem; }
  .grid-card-head .entry-link { height: 44px; min-height: 44px; }
  .grid-card-meta { padding-left: 0; margin-top: 0.15rem; font-size: 0.72rem; }
  .grid-card .entry-more {
    position: absolute; top: 50%; right: 0.3rem; transform: translateY(-50%);
    min-width: 44px; min-height: 44px; opacity: 1;
  }
  #browser-content:not(.select-mode) .grid-card .entry-check { display: none; }
  #browser-content.select-mode .grid-card .entry-check {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px;
  }
  table.file-table colgroup, table.file-table thead { display: none; }
  table.file-table, table.file-table tbody { display: block; width: 100%; }
  table.file-table tbody tr { display: flex; align-items: center; gap: 0; padding: 0.25rem var(--page-pad); min-height: 56px; }
  #browser-content.select-mode table.file-table tbody tr { gap: 0.4rem; }
  table.file-table tbody td { border: 0; padding: 0; }
  table.file-table tbody td.col-name { flex: 1 1 auto; max-width: none; overflow: visible; }
  table.file-table tbody td.col-size, table.file-table tbody td.col-modified { display: none; }
  table.file-table tbody td.col-select { width: auto; padding: 0 0.2rem; visibility: visible !important; }
  #browser-content:not(.select-mode) table.file-table tbody td.col-select { visibility: hidden !important; width: 0; padding: 0; }
  .entry-meta-mobile {
    display: flex; grid-column: 2; grid-row: 2; align-items: center; gap: 0.35rem;
    min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-size: 0.76rem; color: var(--text-muted);
  }
  .viewer-bar { min-height: 52px; }
  .viewer-stage { padding: 0.5rem 3.25rem; }
  .viewer-image-wrap img { max-height: calc(100dvh - 150px); }
  .viewer-info {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 70dvh;
    border-left: 0; border-top: var(--border-w) solid var(--border);
    border-radius: 16px 16px 0 0;
  }
  .upload-queue { right: 0.5rem; bottom: 0.5rem; width: calc(100vw - 1rem); }
  .toast-region { bottom: 0.75rem; }
}

/* ---------- Coarse pointers: every tappable target >= 44px ---------- */
@media (pointer: coarse) {
  /* Every button, icon-only control, input and menu item picks these up from
     the tokens; link-style targets get an explicit minimum as well. */
  :root { --control-h: 44px; --control-w: 44px; }
  .btn { min-width: var(--control-w); }
  .ws-brand, .tree-link, .tree-row, .crumb-home, .crumb-link, .entry-link {
    min-height: var(--control-h);
  }
  .entry-more { opacity: 1; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- UX rethink 2026-11-17 ---------- */
.desktop-only { display: inline-flex; }
.mobile-location, .mobile-new-menu, .drawer-user-menu { display: none; }

.dest-browser {
  border: var(--border-w) solid var(--border); border-radius: var(--radius);
  padding: 0.5rem 0.6rem; margin-bottom: 0.8rem; background: var(--surface-alt);
}
.dest-browser-head {
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; min-width: 0;
}
.dest-browser-head strong {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dest-folders {
  list-style: none; margin: 0.5rem 0 0; padding: 0;
  max-height: 34vh; overflow-y: auto; border-top: var(--border-w) solid var(--border-soft);
}
.dest-folder-btn {
  display: flex; align-items: center; gap: 0.4rem; width: 100%;
  min-height: 40px; padding: 0.35rem 0.4rem; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.dest-folder-btn:hover, .dest-folder-btn:focus-visible { background: var(--hover-bg); }
.dest-folder-btn .dest-folder-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-empty { margin: 0.6rem 0 0.2rem; font-size: 0.85rem; color: var(--text-muted); }
.dest-summary { margin: 0.4rem 0 0; font-weight: 600; color: var(--accent-text); }
.field-hint { margin: 0.25rem 0 0; font-size: 0.8rem; color: var(--text-muted); }
.transfer-results {
  margin-top: 0.6rem; padding: 0.5rem 0.6rem; border-radius: var(--radius);
  background: var(--surface-alt); border: var(--border-w) solid var(--border-soft);
  font-size: 0.85rem; max-height: 30vh; overflow-y: auto;
}
.transfer-results ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.transfer-results li { margin: 0.1rem 0; }
.entry-item.drop-folder-target, .grid-card.drop-folder-target {
  outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft);
}
.entry-item.is-dragging, .grid-card.is-dragging { opacity: 0.55; }

@media (max-width: 680px) {
  /* One location-dominant top bar: current folder is the largest text, the
     chevron exposes every ancestor, and creation is visible without a drawer. */
  .desktop-only { display: none !important; }
  /* Account lives in the drawer on phones; the title needs this width more. */
  .app-topbar .user-menu { display: none !important; }
  .mobile-location {
    display: flex; align-items: center; gap: 0.2rem; position: relative;
    flex: 1 1 auto; min-width: 0;
  }
  .mobile-location-text {
    display: flex; flex-direction: column; justify-content: center;
    flex: 1 1 auto; min-width: 0; line-height: 1.15;
  }
  .mobile-location-parent {
    font-size: 0.72rem; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mobile-location-leaf {
    font-size: 1rem; font-weight: 700; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mobile-folder-nav {
    display: flex; align-items: center; gap: 0.25rem; flex: 1 1 auto; min-width: 0;
    min-height: 44px; padding: 0 0.25rem; border: 0; border-radius: var(--radius);
    background: transparent; color: var(--text); text-align: left;
  }
  .mobile-folder-nav:hover, .mobile-folder-nav[aria-expanded="true"] { background: var(--hover-bg); }
  .mobile-folder-chevron { flex: 0 0 16px; color: var(--text-muted); }
  .mobile-ancestor-menu {
    /* Viewport-anchored, not anchored inside the location button: the button
       starts ~108px in, so an absolute 280px panel ran off a 320px screen. */
    position: fixed; top: calc(var(--topbar-h) + 4px);
    left: var(--page-pad); right: var(--page-pad); width: auto; min-width: 0;
    max-height: 60vh; overflow-y: auto; z-index: 130;
  }
  .mobile-new-menu { display: inline-flex; }
  .mobile-new-menu .menu-panel { right: 0; left: auto; min-width: 200px; }
  .drawer-user-menu { display: block; padding: 0 0.75rem 0.6rem; }
  .drawer-user-trigger { width: 100%; justify-content: flex-start; gap: 0.5rem; }
  .drawer-user-menu .menu-panel { left: 0.75rem; right: auto; min-width: 200px; }

  /* The old mobile breadcrumb/up row is obsolete: location now lives in the
     top bar. Earlier (max-width:680px) rules set display:flex, so override with
     equal-or-higher specificity here. One up control only — no duplicate. */
  .app-topbar .mobile-crumbs, .mobile-crumbs { display: none !important; }

  /* Select keeps its label and its own pressed state at every width. */
  .select-mode-btn span { display: inline; }
  .select-mode-btn {
    min-width: 0; padding: 0 0.65rem; gap: 0.3rem;
    border-left: 1px solid var(--border); border-radius: var(--radius);
  }
  .select-mode-btn[aria-pressed="true"] {
    background: var(--accent-soft); border-color: var(--accent-soft-border);
    color: var(--accent-text); font-weight: 600;
  }
  #sel-all-mobile:not([hidden]) { display: inline-flex; }
  .selection-bar { flex-wrap: wrap; }
  .dest-folders { max-height: 40vh; }
}
