/* ==========================================================================
   KR Consulting portal — Notes view
   Owner: NOTES-DOCS.  Uses ONLY the design tokens from tokens.css.
   ========================================================================== */

/* The view host (<main id="view">) is a stretched grid item with no explicit
   height, exactly like the file browser assumes. We fill it edge to edge and
   keep a hard floor so the pane can never collapse. */
.notes {
  --nt-side-w: clamp(15.5rem, 26vw, 22rem);

  display: grid;
  grid-template-columns: var(--nt-side-w) 1fr;
  height: 100%;
  min-height: clamp(22rem, calc(100dvh - var(--topbar-h, 56px) - 5rem), 70rem);
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

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

.nt-side { border-right: 1px solid var(--border); }

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.nt-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
}

.nt-side-head {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 0.875rem 0.875rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

.nt-side-actions {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.nt-side-actions .nt-btn-primary { flex: 1 1 auto; }

/* ---- buttons ---- */

.nt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;          /* 44px touch target */
  padding: 0 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

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

.nt-btn:active { transform: translateY(1px) scale(0.99); }

.nt-btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}
.nt-btn-primary:hover { background: var(--accent-hi); }

.nt-btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-dim);
}
.nt-btn-ghost:hover {
  border-color: var(--border-hi);
  color: var(--text);
  background: var(--bg-elev);
}

.nt-btn-icon {
  width: 2.75rem;
  min-width: 2.75rem;
  padding: 0;
}

.nt-danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.nt-icon {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  display: block;
}

/* ---- search ---- */

.nt-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.625rem;
  min-height: 2.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-mute);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.nt-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  color: var(--text-dim);
}

.nt-search .nt-icon { width: 1rem; height: 1rem; }

.nt-search-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9375rem;
  padding: 0.4rem 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.nt-search-input::placeholder { color: var(--text-mute); }
.nt-search-input::-webkit-search-cancel-button { display: none; }

.nt-search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nt-search-clear:hover { background: var(--bg-elev); color: var(--text); }
.nt-search-clear[hidden] { display: none; }

/* ---- filter chips ---- */

.nt-chips {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.nt-chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-mute);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}
.nt-chip:hover { color: var(--text); border-color: var(--border-hi); }
.nt-chip.is-on {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-hi);
}
.nt-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- list ---- */

.nt-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.nt-list:focus { outline: none; }

.nt-row {
  position: relative;
  display: block;
  padding: 0.625rem 0.75rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 2.75rem;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.nt-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%);
  transition: height var(--dur) var(--ease);
}

.nt-row:hover { background: var(--surface-2); border-color: var(--border); }
.nt-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.nt-row.is-active {
  background: var(--bg-elev);
  border-color: var(--border-hi);
}
.nt-row.is-active::before { height: 60%; }

.nt-row-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nt-row-title mark,
.nt-row-prev mark {
  background: var(--accent-dim);
  color: var(--accent-hi);
  border-radius: 3px;
  padding: 0 0.1em;
}

.nt-row-tag {
  flex: 0 0 auto;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent-hi);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
}

.nt-row-prev {
  margin-top: 0.2rem;
  font-size: 0.8125rem;
  color: var(--text-dim);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 1.1em;
}
.nt-row-prev.is-mute { color: var(--text-mute); font-style: italic; }

.nt-row-when {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}

.nt-count {
  padding: 0.5rem 0.9rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-mute);
  background: var(--surface);
  min-height: 1.75rem;
}

/* ---- skeletons ---- */

.nt-skel { cursor: default; pointer-events: none; }

.nt-skel-line {
  height: 0.7rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--bg-elev) 40%,
    var(--surface-2) 80%
  );
  background-size: 300% 100%;
  animation: nt-shimmer 1.4s var(--ease) infinite;
  animation-delay: calc(var(--i, 0) * 60ms);
}
.nt-skel-title { width: 62%; }
.nt-skel-prev { width: 88%; margin-top: 0.45rem; height: 0.55rem; opacity: 0.7; }

.nt-prev-skel {
  display: inline-block;
  width: 70%;
  height: 0.55rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2), var(--bg-elev), var(--surface-2));
  background-size: 300% 100%;
  animation: nt-shimmer 1.4s var(--ease) infinite;
}

@keyframes nt-shimmer {
  0%   { background-position: 120% 0; }
  100% { background-position: -60% 0; }
}

/* ---- staggered entrance ---- */

.nt-in {
  animation: nt-rise var(--dur) var(--ease) both;
  animation-delay: calc(var(--i, 0) * 22ms);
}

@keyframes nt-rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Editor pane
   -------------------------------------------------------------------------- */

.nt-editor {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-elev);
}

.nt-editor[data-empty="true"] .nt-editor-inner { display: none; }
.nt-editor[data-empty="false"] > .nt-empty { display: none; }

.nt-editor-inner {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.nt-swap { animation: nt-swap-in var(--dur) var(--ease) both; }

@keyframes nt-swap-in {
  from { opacity: 0; transform: translateY(8px) scale(0.995); }
  to   { opacity: 1; transform: none; }
}

.nt-editor-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.nt-back { display: none; }

.nt-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nt-title-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 650;
  padding: 0.45rem 0.5rem;
  outline: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.nt-title-input::placeholder { color: var(--text-mute); font-weight: 500; }
.nt-title-input:hover:not(.is-locked) { background: var(--surface-2); }
.nt-title-input:focus {
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.nt-title-input.is-locked { cursor: default; color: var(--text); }
.nt-title-input.is-locked:focus { box-shadow: none; border-color: transparent; background: transparent; }

.nt-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent-hi);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
}
.nt-badge .nt-icon { width: 0.85rem; height: 0.85rem; }
.nt-badge[hidden] { display: none; }

/* ---- save-state pill ---- */

.nt-state {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2rem;
  padding: 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-mute);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
  transition:
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}
.nt-state:hover { border-color: var(--border-hi); }
.nt-state:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nt-state-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
  flex: 0 0 auto;
  transition: background var(--dur-fast) var(--ease), transform var(--dur) var(--ease);
}

.nt-state[data-state="saved"],
.nt-state[data-state="idle"] { color: var(--text-mute); }
.nt-state[data-state="saved"] .nt-state-dot { background: var(--ok); }

.nt-state[data-state="saving"] { color: var(--text-dim); }
.nt-state[data-state="saving"] .nt-state-dot {
  background: var(--accent);
  animation: nt-pulse 1s var(--ease) infinite;
}

.nt-state[data-state="dirty"] { color: var(--warn); border-color: var(--warn); }
.nt-state[data-state="dirty"] .nt-state-dot { background: var(--warn); }

.nt-state[data-state="error"] { color: var(--danger); border-color: var(--danger); }
.nt-state[data-state="error"] .nt-state-dot { background: var(--danger); }

@keyframes nt-pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.5); opacity: 0.55; }
}

/* ---- writing surface ---- */

.nt-body-input {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  padding: 1.25rem clamp(1rem, 6vw, 3.5rem) 1.25rem;
  max-width: none;
  tab-size: 2;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity var(--dur-fast) var(--ease);
}
.nt-body-input::placeholder { color: var(--text-mute); }
.nt-body-input[data-loading="true"] { opacity: 0.35; pointer-events: none; }
.nt-body-input:focus { outline: none; }

.nt-editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.875rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.75rem;
  color: var(--text-mute);
}

.nt-meta,
.nt-stats {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nt-stats { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Empty / error states
   -------------------------------------------------------------------------- */

.nt-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  margin: auto;
  animation: nt-rise var(--dur-slow) var(--ease) both;
}

.nt-empty-icon {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-mute);
}
.nt-empty-icon .nt-icon { width: 1.5rem; height: 1.5rem; }

.nt-empty-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}

.nt-empty-body {
  margin: 0;
  max-width: 26rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-dim);
}

.nt-empty .nt-btn { margin-top: 0.75rem; }

/* --------------------------------------------------------------------------
   Phone / narrow: one pane at a time
   -------------------------------------------------------------------------- */

@media (max-width: 46rem) {
  .notes {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .nt-side { border-right: 0; }

  .nt-side,
  .nt-editor {
    grid-area: 1 / 1;
    min-width: 0;
  }

  .notes[data-pane="list"] .nt-editor {
    opacity: 0;
    pointer-events: none;
    transform: translateX(4%);
    visibility: hidden;
  }
  .notes[data-pane="editor"] .nt-side {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-4%);
    visibility: hidden;
  }

  .nt-side,
  .nt-editor {
    transition:
      opacity var(--dur) var(--ease),
      transform var(--dur) var(--ease),
      visibility 0s linear var(--dur);
  }
  .notes[data-pane="list"] .nt-side,
  .notes[data-pane="editor"] .nt-editor {
    opacity: 1;
    transform: none;
    visibility: visible;
    transition-delay: 0s;
  }

  .nt-back { display: inline-flex; }

  .nt-body-input {
    font-size: 1rem;                 /* >= 16px so iOS Safari does not zoom */
    padding: 1rem 1rem 1.5rem;
    line-height: 1.65;
  }

  .nt-title-input { font-size: 1rem; }

  .nt-editor-foot { font-size: 0.6875rem; }

  .nt-row { padding: 0.7rem 0.75rem; }
}

/* Very small phones: hide the character/line detail, keep the word count. */
@media (max-width: 26rem) {
  .nt-side-actions .nt-btn-primary { font-size: 0.875rem; }
  .nt-chips { gap: 0.3rem; }
  .nt-chip { padding: 0.28rem 0.6rem; font-size: 0.75rem; }
}

/* --------------------------------------------------------------------------
   Motion preferences
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .notes *,
  .notes *::before,
  .notes *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .nt-skel-line,
  .nt-prev-skel {
    animation: none !important;
    opacity: 0.6;
  }
  .nt-state[data-state="saving"] .nt-state-dot { animation: none !important; }
}
