/* The tools panel (ui/js/tools.js): two tab panes, stacked when docked at
   the right or in its own window, side by side when docked at the bottom;
   the Notes tab (ui/js/notes.js) and the Find tab (ui/js/find.js). Uses
   only the app's :root tokens; every class of its own is prefixed with
   tools-, notes- or find-. */

/* ------------------------------------------------------------------------ */
/* Where the panel sits */

.workspace > .panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

/* Docked at the bottom: the grid gets the whole width, the panel a height. */
.workspace.tools-bottom {
  flex-direction: column;
}

/* The grid scrolls inside what is left above the panel. */
.workspace.tools-bottom > .main {
  flex: 1 1 0;
  min-height: 0;
}

.workspace.tools-bottom > .panel {
  width: auto;
  height: 300px;
  border-left: 0;
  border-top: 1px solid var(--border);
}

.workspace.tools-bottom > .panel-resizer {
  width: auto;
  height: 7px;
  margin: -3px 0 -4px;
  cursor: row-resize;
}

.workspace.tools-bottom > .panel-resizer:hover::after,
.workspace.tools-bottom > .panel-resizer:focus-visible::after,
body.panel-resizing-y .workspace.tools-bottom > .panel-resizer::after {
  content: "";
  position: absolute;
  top: 2px;
  bottom: auto;
  left: 0;
  right: 0;
  width: auto;
  height: 3px;
  background: var(--accent);
}

body.panel-resizing-y {
  cursor: row-resize;
  user-select: none;
  -webkit-user-select: none;
}

/* The tools window: the panel is the whole page. */
body.tools-window > .panel {
  display: flex;
  flex-direction: column;
  width: auto;
  height: 100vh;
  padding: 0;
  border: 0;
  overflow: hidden;
}

/* ------------------------------------------------------------------------ */
/* Panel, header and panes */

.tools {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.tools-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tools-head .apply-head-host {
  flex: 1 1 auto;
  min-width: 0;
}

.tools-head .apply-head {
  gap: 1px;
}

.tools-head .apply-scope {
  font-size: 12.5px;
}

.tools-head .apply-stats,
.tools-head .apply-hint {
  font-size: 11.5px;
}

.tools-places {
  flex: none;
  display: flex;
  gap: 2px;
}

.tools-place {
  appearance: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.tools-place:hover {
  background: var(--row-hover);
  color: var(--text);
}

.tools-place[aria-pressed="true"] {
  background: var(--selection);
  border-color: var(--accent);
  color: var(--text);
}

.tools-place:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.tools-panes {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tools-at-bottom .tools-panes {
  flex-direction: row;
}

.tools-pane {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.tools-pane + .tools-pane {
  border-top: 1px solid var(--border);
}

.tools-at-bottom .tools-pane + .tools-pane {
  border-top: 0;
  border-left: 1px solid var(--border);
}

/* A pane with no tabs left: just room to drag one back. */
.tools-pane.is-empty {
  flex: none;
}

.tools-at-bottom .tools-pane.is-empty {
  flex: 0 0 120px;
}

/* ------------------------------------------------------------------------ */
/* Tab strips */

.tools-tabs {
  flex: none;
  display: flex;
  gap: 1px;
  min-height: 29px;
  padding: 0 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.tools-tabs::-webkit-scrollbar {
  display: none;
}

.tools-tab {
  position: relative;
  flex: 0 0 auto;
  appearance: none;
  margin-bottom: -1px;
  padding: 6px 8px 5px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: none;
  font: inherit;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tools-tab:hover {
  color: var(--text);
}

.tools-tab[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
  border-color: var(--border);
}

.tools-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tools-drop-hint {
  align-self: center;
  padding: 0 4px;
  font-size: 11.5px;
  font-style: italic;
  color: var(--text-muted);
}

/* Dragging a tab: where it will land. */
body.tools-dragging,
body.tools-dragging .tools-tab {
  cursor: grabbing;
}

.tools-tab.is-dragging {
  opacity: 0.5;
}

.tools-tab.drop-before::before,
.tools-tab.drop-after::after {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 2px;
  width: 2px;
  border-radius: 1px;
  background: var(--accent);
}

.tools-tab.drop-before::before {
  left: -2px;
}

.tools-tab.drop-after::after {
  right: -2px;
}

.tools-tabs.drop-end {
  box-shadow: inset -2px 0 0 var(--accent);
}

.tools-pane.is-empty .tools-tabs.drop-end {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* ------------------------------------------------------------------------ */
/* A tab's content */

.tools-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 10px;
  background: var(--surface);
}

.tools-body.setup-panel {
  padding: 8px 10px 10px;
}

.tools .setup-intro {
  margin-bottom: 8px;
  font-size: 11.5px;
}

/* The row at the bottom of a list that adds an item (apply.js, setup.js). */
.apply-add {
  list-style: none;
}

.apply-add-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 24px;
  padding: 2px 4px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  font: inherit;
  font-size: 12px;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
}

.apply-add-btn::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  font-weight: 600;
}

.apply-add-btn:hover {
  background: var(--row-hover);
}

.apply-add-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.setup-add-row {
  margin-top: 4px;
}

/* An editor's Delete button sits at the left of its actions. */
.popover-extra {
  margin-right: auto;
}

/* ------------------------------------------------------------------------ */
/* The Notes tab */

.notes {
  display: grid;
  gap: 14px;
}

.notes-heading {
  margin: 0 0 6px;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-text {
  display: block;
  height: auto;
  min-height: 84px;
  resize: vertical;
  line-height: 1.4;
}

.notes-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.notes-actions .apply-hint {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11.5px;
}

.notes-actions .setup-btn[aria-disabled="true"] {
  cursor: default;
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border-soft);
}

.notes-entry {
  appearance: none;
  display: grid;
  gap: 1px;
  width: 100%;
  padding: 5px 4px;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  background: none;
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.notes-entry:hover {
  background: var(--row-hover);
}

.notes-entry[aria-current="true"] {
  background: var(--selection);
}

.notes-entry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.notes-where {
  font-size: 11px;
  color: var(--text-muted);
}

.notes-desc {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notes-snippet {
  font-size: 12px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* Dated notes: one card per note, the review checklist, the author name */

.notes-cards {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.notes-card {
  padding: 5px 6px;
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--note);
  border-radius: var(--radius);
}

.notes-card.is-done {
  border-left-color: var(--border);
}

.notes-meta {
  margin: 0 0 2px;
  font-size: 11px;
  color: var(--text-muted);
}

.notes-body {
  margin: 0;
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.notes-card.is-done .notes-body {
  color: var(--text-muted);
}

.notes-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

.setup-btn.notes-mini {
  height: 20px;
  padding: 0 6px;
  font-size: 11.5px;
}

.notes-new {
  min-height: 52px;
}

.notes-all-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.notes-all-head .notes-heading {
  margin-bottom: 4px;
}

.notes-item {
  display: flex;
  align-items: flex-start;
  border-bottom: 1px solid var(--border-soft);
}

.notes-item .notes-entry {
  flex: 1 1 auto;
  min-width: 0;
  border-bottom: 0;
}

.notes-item.is-done .notes-snippet,
.notes-item.is-done .notes-desc {
  text-decoration: line-through;
  color: var(--text-muted);
}

.notes-check {
  appearance: none;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 26px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.notes-check:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.notes-check[aria-checked="true"] .apply-box {
  background: var(--accent);
  border-color: var(--accent);
}

.notes-check[aria-checked="true"] .apply-box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.notes-author {
  display: grid;
  gap: 3px;
}

.notes-author-input {
  height: 24px;
}

/* ------------------------------------------------------------------------ */
/* The Find tab (ui/js/find.js) */

.find {
  display: grid;
  gap: 8px;
}

.find-form {
  display: grid;
  gap: 6px;
}

.find-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.find-row > .setup-input {
  flex: 1 1 auto;
}

.find-row > .setup-btn {
  flex: 0 0 auto;
}

.find-mode[aria-pressed="true"] {
  background: var(--selection);
  border-color: var(--accent);
}

.find-options {
  gap: 12px;
}

.find-option {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  cursor: pointer;
}

.find-replace {
  display: grid;
  gap: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
}

.find-keys {
  margin: 0;
  font-size: 11.5px;
}

.find-suggest {
  list-style: none;
  margin: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.find-suggest-item {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  cursor: pointer;
}

.find-suggest-item:hover,
.find-suggest-item.is-active {
  background: var(--selection);
}

.find-suggest-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.find-suggest-hint {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 11.5px;
  text-align: right;
}

.find-status p {
  margin: 0;
}

.find-count {
  font-size: 12px;
  font-weight: 600;
}

.find-message {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.find-all {
  margin-bottom: 4px;
}

.find-list,
.find-hits {
  list-style: none;
  margin: 0;
  padding: 0;
}

.find-cat {
  padding: 6px 2px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.find-acct-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px 2px;
  border-bottom: 1px solid var(--border-soft);
}

.find-acct-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.find-acct-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-muted);
}

.find-hit {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  border-bottom: 1px solid var(--border-soft);
}

.find-hit > input,
.find-nocheck {
  flex: 0 0 auto;
  width: 13px;
  margin: 7px 0 0 2px;
}

.find-entry {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 1px;
  padding: 4px 4px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.find-entry:hover {
  background: var(--row-hover);
}

.find-entry[aria-current="true"] {
  background: var(--selection);
}

.find-entry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.find-where {
  font-size: 11px;
  color: var(--text-muted);
}

.find-desc,
.find-snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.find-desc {
  font-size: 12.5px;
}

.find-snippet {
  font-size: 12px;
  color: var(--formula);
}

/* ------------------------------------------------------------------------ */
/* The History tab (ui/js/history.js): every undo step, oldest first; the
   current one marked, the ones Redo would bring back fainter. */

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border-soft);
}

.history-step {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-soft);
}

.history-jump {
  appearance: none;
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 5px 4px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.history-jump:hover {
  background: var(--row-hover);
}

.history-jump:focus-visible,
.history-version:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.history-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.history-time {
  flex: none;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.history-step.is-current .history-jump {
  background: var(--selection);
  cursor: default;
}

.history-step.is-current .history-label {
  font-weight: 600;
}

.history-step.is-undone .history-label,
.history-step.is-undone .history-time {
  color: var(--text-muted);
  font-style: italic;
}

/* Shown on the step under the pointer or with focus, and on the current one. */
.history-version {
  appearance: none;
  flex: none;
  margin: 0 2px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  font: inherit;
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
  visibility: hidden;
}

.history-step:hover .history-version,
.history-step:focus-within .history-version,
.history-step.is-current .history-version {
  visibility: visible;
}

.history-version:hover {
  border-color: var(--border);
  color: var(--text);
  background: var(--surface);
}

.history-empty,
.history-error {
  margin: 6px 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.history-error {
  color: var(--danger);
}
