/* ==========================================================================
   Lattice — embeddable spreadsheet
   The canvas renderer reads its colours from these custom properties, so
   theming the component is a matter of overriding them on .lat-root.
   ========================================================================== */

.lat-root {
  --lat-font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --lat-font-size: 13;

  --lat-bg: #ffffff;
  --lat-surface: #ffffff;
  --lat-chrome: #f7f8fa;
  --lat-chrome-2: #eef0f4;
  --lat-border: #d8dce3;
  --lat-gridline: #e3e6ea;
  --lat-header-bg: #f4f5f8;
  --lat-header-fg: #545c6b;
  --lat-header-active-bg: #dfe9fb;
  --lat-header-active-fg: #1550b3;
  --lat-header-border: #ccd2db;
  --lat-text: #14181f;
  --lat-text-muted: #626b7a;
  --lat-accent: #1a6dd8;
  --lat-accent-soft: #e8f0fd;
  --lat-selection-fill: rgba(26, 109, 216, 0.10);
  --lat-frozen-line: #98a2b3;
  --lat-error: #c81e1e;
  --lat-marching: #1a6dd8;
  --lat-shadow: 0 6px 24px rgba(15, 23, 42, 0.14), 0 1px 3px rgba(15, 23, 42, 0.10);

  color-scheme: light;
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 260px;
  overflow: hidden;
  background: var(--lat-surface);
  color: var(--lat-text);
  font-family: var(--lat-font);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  border: 1px solid var(--lat-border);
  border-radius: 8px;
}

.lat-root[data-theme="dark"],
.lat-root[data-theme="auto"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  .lat-root[data-theme="auto"] {
    color-scheme: dark;
    --lat-bg: #16181d;
    --lat-surface: #16181d;
    --lat-chrome: #1d2027;
    --lat-chrome-2: #24282f;
    --lat-border: #333944;
    --lat-gridline: #2b2f37;
    --lat-header-bg: #1f232a;
    --lat-header-fg: #a2acbb;
    --lat-header-active-bg: #23375c;
    --lat-header-active-fg: #93b8f5;
    --lat-header-border: #383e49;
    --lat-text: #e8ebf0;
    --lat-text-muted: #98a2b3;
    --lat-accent: #4a90ea;
    --lat-accent-soft: #1e3252;
    --lat-selection-fill: rgba(74, 144, 234, 0.16);
    --lat-frozen-line: #5b6474;
    --lat-error: #f26b6b;
    --lat-marching: #4a90ea;
    --lat-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

.lat-root[data-theme="dark"] {
  color-scheme: dark;
  --lat-bg: #16181d;
  --lat-surface: #16181d;
  --lat-chrome: #1d2027;
  --lat-chrome-2: #24282f;
  --lat-border: #333944;
  --lat-gridline: #2b2f37;
  --lat-header-bg: #1f232a;
  --lat-header-fg: #a2acbb;
  --lat-header-active-bg: #23375c;
  --lat-header-active-fg: #93b8f5;
  --lat-header-border: #383e49;
  --lat-text: #e8ebf0;
  --lat-text-muted: #98a2b3;
  --lat-accent: #4a90ea;
  --lat-accent-soft: #1e3252;
  --lat-selection-fill: rgba(74, 144, 234, 0.16);
  --lat-frozen-line: #5b6474;
  --lat-error: #f26b6b;
  --lat-marching: #4a90ea;
  --lat-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
}

.lat-root *,
.lat-root *::before,
.lat-root *::after { box-sizing: border-box; }

/* ------------------------------------------------------------- toolbar */

.lat-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 5px 8px;
  background: var(--lat-chrome);
  border-bottom: 1px solid var(--lat-border);
  flex: 0 0 auto;
}

.lat-tb-group { display: flex; align-items: center; gap: 1px; }
.lat-tb-sep {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--lat-border);
}

.lat-tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--lat-text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.lat-tb-btn svg { width: 17px; height: 17px; }
.lat-tb-btn:hover:not(:disabled) { background: var(--lat-chrome-2); }
.lat-tb-btn:active:not(:disabled) { background: var(--lat-border); }
.lat-tb-btn.is-active {
  background: var(--lat-accent-soft);
  border-color: color-mix(in srgb, var(--lat-accent) 35%, transparent);
  color: var(--lat-accent);
}
.lat-tb-btn:disabled { opacity: 0.38; cursor: default; }
.lat-tb-btn:focus-visible { outline: 2px solid var(--lat-accent); outline-offset: 1px; }

.lat-color-btn { flex-direction: column; gap: 1px; padding-bottom: 3px; }
.lat-color-bar {
  display: block;
  width: 16px;
  height: 3px;
  border-radius: 1px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.lat-tb-select {
  height: 28px;
  max-width: 132px;
  padding: 0 4px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.lat-tb-select:focus-visible { outline: 2px solid var(--lat-accent); outline-offset: -1px; }
.lat-size { max-width: 60px; }

/* --------------------------------------------------------- formula bar */

.lat-formulabar {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 4px 8px;
  background: var(--lat-surface);
  border-bottom: 1px solid var(--lat-border);
  flex: 0 0 auto;
}

.lat-namebox {
  width: 116px;
  padding: 3px 7px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font: inherit;
  font-size: 12px;
}

.lat-fx {
  width: 28px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text-muted);
  cursor: pointer;
}
.lat-fx svg { width: 15px; height: 15px; }
.lat-fx:hover { background: var(--lat-chrome-2); color: var(--lat-text); }

.lat-formula-input {
  flex: 1;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
  resize: none;
  overflow: hidden;
}
.lat-formulabar.is-expanded .lat-formula-input { min-height: 74px; overflow: auto; }
.lat-namebox:focus, .lat-formula-input:focus {
  outline: none;
  border-color: var(--lat-accent);
  box-shadow: 0 0 0 2px var(--lat-accent-soft);
}

.lat-fb-expand {
  width: 22px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text-muted);
  cursor: pointer;
  font-size: 11px;
}

/* ---------------------------------------------------------------- grid */

.lat-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--lat-bg);
}

.lat-canvas {
  position: absolute;
  inset: 0;
  display: block;
}

.lat-scroller {
  position: absolute;
  inset: 0;
  overflow: auto;
  outline: none;
  cursor: cell;
  overscroll-behavior: contain;
}
.lat-spacer { pointer-events: none; }

.lat-scroller::-webkit-scrollbar { width: 14px; height: 14px; }
.lat-scroller::-webkit-scrollbar-track { background: transparent; }
.lat-scroller::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--lat-text) 26%, transparent);
  border: 4px solid transparent;
  border-radius: 8px;
  background-clip: padding-box;
}
.lat-scroller::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--lat-text) 40%, transparent);
  background-clip: padding-box;
}
.lat-scroller::-webkit-scrollbar-corner { background: transparent; }

.lat-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}
.lat-overlay > * { pointer-events: auto; }

.lat-focus-catch {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  overflow: hidden;
  z-index: 0;
}

/* ------------------------------------------------------------- editor */

.lat-editor {
  position: absolute;
  z-index: 6;
  margin: 0;
  padding: 2px 3px;
  border: 2px solid var(--lat-accent);
  border-radius: 2px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font-family: var(--lat-font);
  font-size: 13px;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
  outline: none;
  box-shadow: var(--lat-shadow);
  white-space: pre;
}

.lat-fn-hint {
  position: absolute;
  z-index: 7;
  max-width: 460px;
  padding: 5px 9px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-chrome);
  color: var(--lat-text);
  font-size: 12px;
  box-shadow: var(--lat-shadow);
  pointer-events: none;
}
.lat-fn-hint b { color: var(--lat-accent); }
.lat-fn-desc { display: block; margin-top: 3px; color: var(--lat-text-muted); }

.lat-autocomplete {
  position: absolute;
  z-index: 8;
  min-width: 260px;
  max-height: 250px;
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--lat-border);
  border-radius: 7px;
  background: var(--lat-surface);
  box-shadow: var(--lat-shadow);
}
.lat-ac-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
}
.lat-ac-item.is-active { background: var(--lat-accent-soft); }
.lat-ac-name { font-weight: 600; color: var(--lat-accent); }
.lat-ac-sig {
  color: var(--lat-text-muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------- tabs */

.lat-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 8px;
  background: var(--lat-chrome);
  border-top: 1px solid var(--lat-border);
  overflow-x: auto;
  flex: 0 0 auto;
  scrollbar-width: thin;
}

.lat-tab-item {
  position: relative;
  padding: 5px 13px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--lat-text-muted);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.lat-tab-item:hover { background: var(--lat-chrome-2); }
.lat-tab-item.is-active {
  background: var(--lat-surface);
  border-color: var(--lat-border);
  color: var(--lat-text);
  font-weight: 600;
}
.lat-tab-item.has-color::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 2px;
  height: 2px;
  border-radius: 2px;
  background: var(--tab-color);
}
.lat-tab-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--lat-text-muted);
  cursor: pointer;
}
.lat-tab-add svg { width: 15px; height: 15px; }
.lat-tab-add:hover { background: var(--lat-chrome-2); color: var(--lat-text); }

/* ------------------------------------------------------------- status */

.lat-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px 10px;
  background: var(--lat-chrome);
  border-top: 1px solid var(--lat-border);
  color: var(--lat-text-muted);
  font-size: 11.5px;
  flex: 0 0 auto;
}
.lat-status-spacer { flex: 1; }
.lat-stat { margin-left: 14px; font-variant-numeric: tabular-nums; }
.lat-stat em { font-style: normal; opacity: 0.72; }
.lat-status-zoom { display: flex; align-items: center; gap: 4px; }
.lat-status-zoom button {
  width: 20px;
  height: 18px;
  border: 1px solid var(--lat-border);
  border-radius: 4px;
  background: var(--lat-surface);
  color: var(--lat-text);
  cursor: pointer;
  line-height: 1;
}
.lat-zoom-value { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- menus */

.lat-menu {
  position: fixed;
  z-index: 9999;
  min-width: 210px;
  padding: 5px;
  border: 1px solid var(--lat-border);
  border-radius: 8px;
  background: var(--lat-surface, #fff);
  color: var(--lat-text, #14181f);
  font-family: var(--lat-font, system-ui, sans-serif);
  font-size: 13px;
  box-shadow: var(--lat-shadow, 0 6px 24px rgba(0, 0, 0, 0.16));
  max-height: 70vh;
  overflow: auto;
}
/* A submenu is a popup in its own right (see menu.js), so it keeps .lat-menu's
   fixed positioning rather than being laid out inside its parent. */
.lat-submenu { position: fixed; }

.lat-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.lat-menu-item:hover:not(.is-disabled),
.lat-menu-item.is-open { background: var(--lat-accent-soft); }
.lat-menu-item.is-disabled { opacity: 0.4; cursor: default; }
.lat-menu-check { width: 13px; color: var(--lat-accent); }
.lat-menu-label { flex: 1; }
.lat-menu-accel { color: var(--lat-text-muted); font-size: 11.5px; }
.lat-menu-arrow { color: var(--lat-text-muted); }
.lat-menu-sep { height: 1px; margin: 4px 6px; background: var(--lat-border); }

.lat-dropdown {
  position: fixed;
  z-index: 9999;
  padding: 8px;
  border: 1px solid var(--lat-border);
  border-radius: 8px;
  background: var(--lat-surface, #fff);
  color: var(--lat-text, #14181f);
  font-family: var(--lat-font, system-ui, sans-serif);
  font-size: 13px;
  box-shadow: var(--lat-shadow, 0 6px 24px rgba(0, 0, 0, 0.16));
}

.lat-colorpicker .lat-color-row { display: flex; gap: 3px; margin-bottom: 3px; }
.lat-swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  cursor: pointer;
}
.lat-swatch:hover { transform: scale(1.14); }
.lat-swatch.is-current { outline: 2px solid var(--lat-accent); outline-offset: 1px; }
.lat-color-none, .lat-color-custom {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  padding: 4px 6px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.lat-color-custom { margin: 6px 0 0; display: flex; align-items: center; gap: 6px; }
.lat-color-custom input { flex: 1; height: 22px; border: 0; background: none; }

.lat-border-menu .lat-border-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
}
.lat-border-grid button {
  padding: 5px 9px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.lat-border-grid button:hover { background: var(--lat-accent-soft); }
.lat-border-opts {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--lat-border);
  font-size: 12px;
}
.lat-border-opts label { display: flex; align-items: center; gap: 4px; }
.lat-border-opts select {
  border: 1px solid var(--lat-border);
  border-radius: 4px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
}

/* ------------------------------------------------------------- modals */

.lat-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(1.5px);
}

.lat-modal {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--lat-border);
  border-radius: 10px;
  background: var(--lat-surface);
  box-shadow: var(--lat-shadow);
  overflow: hidden;
}
.lat-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--lat-border);
}
.lat-modal-head h2 { margin: 0; font-size: 14px; font-weight: 650; }
.lat-modal-close {
  border: 0;
  background: none;
  color: var(--lat-text-muted);
  font-size: 14px;
  cursor: pointer;
}
.lat-modal-body { padding: 14px 16px; overflow: auto; }
.lat-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  padding: 11px 16px;
  border-top: 1px solid var(--lat-border);
  background: var(--lat-chrome);
}

.lat-btn {
  padding: 6px 13px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.lat-btn:hover { background: var(--lat-chrome-2); }
.lat-btn-primary {
  border-color: var(--lat-accent);
  background: var(--lat-accent);
  color: #fff;
}
.lat-btn-primary:hover { filter: brightness(1.07); background: var(--lat-accent); }

.lat-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 11px; }
.lat-field > label { color: var(--lat-text-muted); font-size: 11.5px; }
.lat-field input[type="text"],
.lat-field select {
  padding: 6px 8px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font: inherit;
  font-size: 12.5px;
}
.lat-field input:focus, .lat-field select:focus {
  outline: none;
  border-color: var(--lat-accent);
  box-shadow: 0 0 0 2px var(--lat-accent-soft);
}
.lat-sort-row { display: flex; gap: 10px; align-items: flex-end; }
.lat-sort-row .lat-field { flex: 1; }
.lat-check-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; font-size: 12.5px; }
.lat-check-row label { display: flex; align-items: center; gap: 5px; }
.lat-hint { color: var(--lat-text-muted); font-size: 11.5px; }
.lat-confirm { margin: 0; font-size: 13px; }

.lat-fmt-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  max-height: 230px;
  overflow: auto;
  margin-bottom: 12px;
}
.lat-fmt-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.lat-fmt-item em { color: var(--lat-text-muted); font-style: normal; font-variant-numeric: tabular-nums; }
.lat-fmt-item.is-active { border-color: var(--lat-accent); background: var(--lat-accent-soft); }

.lat-tabs-row { display: flex; gap: 3px; margin-bottom: 13px; }
.lat-tab {
  padding: 5px 11px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: var(--lat-text-muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.lat-tab.is-active {
  border-color: var(--lat-accent);
  background: var(--lat-accent-soft);
  color: var(--lat-accent);
  font-weight: 600;
}

.lat-cf-styles { display: flex; flex-wrap: wrap; gap: 10px; }
.lat-cf-styles label { display: flex; align-items: center; gap: 5px; font-size: 12.5px; }
.lat-cf-chip { padding: 3px 9px; border-radius: 4px; }
.lat-cf-scales { display: flex; flex-direction: column; gap: 5px; }
.lat-cf-scale {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.lat-cf-scale span { width: 76px; height: 15px; border-radius: 3px; }
.lat-cf-scale.is-active { border-color: var(--lat-accent); background: var(--lat-accent-soft); }

.lat-chart-types { display: flex; flex-wrap: wrap; gap: 5px; }
.lat-chart-type {
  padding: 6px 12px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.lat-chart-type.is-active { border-color: var(--lat-accent); background: var(--lat-accent-soft); color: var(--lat-accent); }

.lat-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-bottom: 12px; }
.lat-table th, .lat-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--lat-border);
  text-align: left;
}
.lat-table th { color: var(--lat-text-muted); font-weight: 500; font-size: 11.5px; }
.lat-link { border: 0; background: none; color: var(--lat-accent); font: inherit; font-size: 12px; cursor: pointer; }

.lat-fn-browser { display: flex; gap: 10px; height: 250px; }
.lat-fn-cats, .lat-fn-list {
  overflow: auto;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  padding: 4px;
}
.lat-fn-cats { width: 140px; flex: 0 0 auto; }
.lat-fn-list { flex: 1; }
.lat-fn-cat, .lat-fn-item {
  display: block;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.lat-fn-cat.is-active, .lat-fn-item.is-active { background: var(--lat-accent-soft); color: var(--lat-accent); font-weight: 600; }
.lat-fn-detail { margin-top: 11px; font-size: 12.5px; }
.lat-fn-detail code {
  display: block;
  padding: 6px 9px;
  border-radius: 5px;
  background: var(--lat-chrome-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.lat-fn-detail p { margin: 7px 0 0; color: var(--lat-text-muted); }

/* -------------------------------------------------------------- charts */

.lat-chart {
  position: absolute;
  z-index: 4;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--lat-border);
  border-radius: 8px;
  background: var(--lat-surface);
  box-shadow: var(--lat-shadow);
  overflow: hidden;
}
.lat-chart.is-selected { border-color: var(--lat-accent); box-shadow: 0 0 0 2px var(--lat-accent-soft), var(--lat-shadow); }
.lat-chart-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 6px;
  background: var(--lat-chrome);
  border-bottom: 1px solid var(--lat-border);
  cursor: move;
  flex: 0 0 auto;
}
.lat-chart-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lat-chart-btn {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--lat-text-muted);
  font-size: 11px;
  cursor: pointer;
}
.lat-chart-btn:hover { background: var(--lat-chrome-2); color: var(--lat-text); }
.lat-chart canvas { display: block; }
.lat-chart-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--lat-border) 50%);
}
.lat-chart-tip {
  position: absolute;
  z-index: 5;
  padding: 5px 9px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  box-shadow: var(--lat-shadow);
  font-size: 11.5px;
  pointer-events: none;
  white-space: nowrap;
}
.lat-tip-cat { color: var(--lat-text-muted); margin-bottom: 2px; }
.lat-tip-row { display: flex; gap: 10px; justify-content: space-between; }
.lat-tip-row b { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- toast */

.lat-toast {
  position: absolute;
  left: 50%;
  bottom: 54px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 8px 15px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--lat-text) 88%, transparent);
  color: var(--lat-surface);
  font-size: 12.5px;
  box-shadow: var(--lat-shadow);
  transition: opacity 0.4s ease;
}
.lat-toast.is-out { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .lat-swatch:hover { transform: none; }
  .lat-toast { transition: none; }
}

/* ---------------------------------------------------------------- cloud */

.lat-field input[type="password"],
.lat-field input[type="number"] {
  padding: 6px 8px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: var(--lat-text);
  font: inherit;
  font-size: 12.5px;
}

/* .lat-field sets display:flex, which outranks the UA's [hidden] rule. */
.lat-field[hidden] { display: none; }

.lat-cloud-intro { margin: 0 0 14px; line-height: 1.5; }
.lat-cloud-error { color: var(--lat-error); font-size: 12px; min-height: 1.2em; }

.lat-cloud-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.lat-cloud-up {
  flex: none;
  width: 26px;
  height: 26px;
  border: 1px solid var(--lat-border);
  border-radius: 6px;
  background: var(--lat-surface);
  color: var(--lat-text);
  cursor: pointer;
}
.lat-cloud-up:hover { background: var(--lat-chrome-2); }
.lat-cloud-crumbs {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  overflow: hidden;
  font-size: 12.5px;
  white-space: nowrap;
}
.lat-cloud-crumbs button {
  padding: 2px 5px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--lat-accent);
  font: inherit;
  cursor: pointer;
}
.lat-cloud-crumbs button:hover { background: var(--lat-accent-soft); }
.lat-cloud-crumbs .is-current { padding: 2px 5px; font-weight: 600; }
.lat-cloud-sep { color: var(--lat-text-muted); }
.lat-cloud-newfolder { flex: none; padding: 4px 10px; }

.lat-cloud-list {
  height: 300px;
  overflow: auto;
  border: 1px solid var(--lat-border);
  border-radius: 8px;
  background: var(--lat-bg);
}
.lat-cloud-list:focus-visible { outline: 2px solid var(--lat-accent); outline-offset: 1px; }

.lat-cloud-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--lat-gridline);
  cursor: pointer;
  user-select: none;
}
.lat-cloud-row:last-child { border-bottom: 0; }
.lat-cloud-row:hover { background: var(--lat-chrome); }
.lat-cloud-row.is-selected { background: var(--lat-accent-soft); }
.lat-cloud-icon { display: flex; flex: none; color: var(--lat-text-muted); }
.lat-cloud-row.is-dir .lat-cloud-icon { color: var(--lat-accent); }
.lat-cloud-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lat-cloud-badge {
  flex: none;
  color: var(--lat-text-muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lat-cloud-when,
.lat-cloud-size {
  flex: none;
  color: var(--lat-text-muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.lat-cloud-when { width: 96px; text-align: right; }
.lat-cloud-size { width: 62px; text-align: right; }

.lat-cloud-actions { flex: none; display: flex; gap: 4px; visibility: hidden; }
.lat-cloud-row:hover .lat-cloud-actions,
.lat-cloud-row.is-selected .lat-cloud-actions { visibility: visible; }
.lat-cloud-actions button {
  padding: 2px 7px;
  border: 1px solid var(--lat-border);
  border-radius: 5px;
  background: var(--lat-surface);
  color: var(--lat-text-muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.lat-cloud-actions button:hover { color: var(--lat-text); background: var(--lat-chrome-2); }

.lat-cloud-empty {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--lat-text-muted);
  font-size: 12.5px;
}

.lat-cloud-namefield { position: relative; margin: 11px 0 0; }
.lat-cloud-namefield input { padding-right: 92px; }
.lat-cloud-ext {
  position: absolute;
  right: 9px;
  bottom: 7px;
  color: var(--lat-text-muted);
  font-size: 11.5px;
  pointer-events: none;
}

.lat-cloud-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
}
