/* ── Feedback surfaces: toasts + modals ────────────────────────────────
   Themed alternatives to alert / confirm / prompt that preserve the app's
   pill-and-card visual language. CSS-only animations; the JS in
   web/js/ui/feedback.js drives lifecycle (mount, dismiss, focus trap). */

/* ── Toast stack ────────────────────────────────────────────────────── */
#app-toast-stack {
  position: fixed;
  bottom: calc(var(--gap) + 36px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  pointer-events: none; /* individual toasts opt back in */
  max-width: calc(100vw - 2 * var(--gap));
}

.app-toast {
  pointer-events: auto;
  background: var(--bg);
  color: var(--text);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-pill);
  box-shadow: var(--elev-floating);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: 100%;
  border: 1px solid var(--border);
  transform: translateY(12px);
  opacity: 0;
  transition: transform 0.25s var(--easing-bounce),
              opacity 0.2s ease;
}

.app-toast.app-toast-visible {
  transform: translateY(0);
  opacity: 1;
}

.app-toast.app-toast-leaving {
  transform: translateY(8px);
  opacity: 0;
}

/* Variant accents — left-bar of theme-aware tint, body stays themed. */
.app-toast::before {
  content: '';
  display: block;
  width: 6px;
  height: 1.1em;
  border-radius: var(--radius-chip);
  flex-shrink: 0;
  background: var(--muted);
}
.app-toast.app-toast-info::before    { background: var(--accent); }
.app-toast.app-toast-success::before { background: var(--success); }
.app-toast.app-toast-warning::before { background: var(--warning); }
.app-toast.app-toast-error::before   { background: var(--error); }

.app-toast-message {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}

/* Multi-line toasts (long-op progress or multi-sentence errors) drop the
   ellipsis and wrap. Apply via .app-toast-multiline class from JS. */
.app-toast.app-toast-multiline .app-toast-message {
  white-space: normal;
  text-overflow: clip;
}

.app-toast-action {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-family: inherit;
}

.app-toast-action:hover {
  background: var(--hover-overlay);
  color: var(--text);
}

.app-toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: var(--text-md);
  line-height: 1;
  padding: 0 var(--space-2);
  margin: 0;
  cursor: pointer;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-toast-close:hover {
  color: var(--text);
  background: var(--hover-overlay);
}

/* Indeterminate progress shimmer for long-op toasts. The bar tracks the
   width of the toast and shimmers from the accent. */
.app-toast-progress {
  position: relative;
  height: 2px;
  width: 100%;
  margin-top: var(--space-2);
  background: var(--surface);
  border-radius: 1px;
  overflow: hidden;
}

.app-toast-progress::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
  animation: app-toast-shimmer 1.4s ease-in-out infinite;
}

.app-toast-progress[data-determinate="true"]::after {
  animation: none;
  background: var(--accent);
  transform: translateX(0);
  width: var(--app-toast-progress, 0%);
  transition: width 0.25s ease;
}

@keyframes app-toast-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ── Modal (confirm + prompt) ───────────────────────────────────────── */
#app-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--shadow);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap);
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.18s ease;
}

#app-modal-backdrop.app-modal-visible {
  opacity: 1;
}

#app-modal-backdrop.app-modal-leaving {
  opacity: 0;
}

.app-modal {
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-card);
  padding: var(--space-7) calc(var(--space-7) + var(--space-2));
  max-width: 480px;
  width: 100%;
  box-shadow: var(--elev-2);
  font-size: var(--text-base);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.22s var(--easing-bounce);
  border: 1px solid var(--border);
}

#app-modal-backdrop.app-modal-visible .app-modal {
  transform: translateY(0) scale(1);
}

.app-modal-title {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--h2);
}

.app-modal-message {
  margin: 0 0 var(--space-6);
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.app-modal-input {
  display: block;
  width: 100%;
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-base);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  margin-bottom: var(--space-6);
  box-sizing: border-box;
  outline: none;
}

.app-modal-input:focus,
.app-modal-input:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.app-modal-btn {
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: var(--space-4) var(--space-7);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  margin: 0;
  font-family: inherit;
}

.app-modal-btn:hover {
  color: var(--text);
  background: var(--hover-overlay);
}

.app-modal-btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}

.app-modal-btn-primary:hover {
  background: var(--accent);
  color: var(--text-on-accent);
  filter: brightness(1.08);
}

.app-modal-btn-danger {
  background: var(--error);
  color: var(--text-on-error);
  border-color: var(--error);
}

.app-modal-btn-danger:hover {
  background: var(--error);
  color: var(--text-on-error);
  filter: brightness(1.08);
}

/* ── Unsaved changes indicator ──────────────────────────────────────────
   A tiny accent-tinted dot that fades in when the textarea has diverged
   from the last saved revision. Clicking it flushes the auto-save timer.
   Lives inside the toolbar pill so it shares the pill's hover lift. */
#unsaved-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 4px var(--space-3);
  margin: 0;
  cursor: pointer;
  border-radius: var(--radius-pill);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s ease, transform 0.2s var(--easing-bounce);
}

#unsaved-indicator[hidden] { display: none; }

body.has-unsaved #unsaved-indicator {
  opacity: 1;
  transform: scale(1);
}

@media (hover: hover) {
  #unsaved-indicator:hover {
    background-color: var(--surface);
  }
}

.unsaved-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* ── Read-only badge ────────────────────────────────────────────────────
   Sits in the toolbar pill alongside the unsaved-changes dot. Visible
   only when a generated/system note is open (Settings, Projects, Note
   Graph). Calm and labelled rather than just a disabled button — gives
   the user a one-glance answer to "why can't I edit this?". */
.readonly-badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-xs);
  padding: 2px var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  margin: 0 var(--space-2);
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}

.readonly-badge[hidden] { display: none; }

/* ── Schedule picker (F2 light) ─────────────────────────────────────────
   Lays the date/time/calendar inputs out vertically inside the standard
   .app-modal card. The all-day toggle reorders visibility (start/end
   times vs end-date) to keep only one branch visible at a time. */
.app-schedule-picker .app-modal-title {
  margin-bottom: var(--space-5);
}

.app-schedule-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  cursor: pointer;
  font-size: var(--text-base);
  user-select: none;
  -webkit-user-select: none;
}

.app-schedule-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.app-schedule-field-label {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 500;
}

.app-schedule-input {
  margin-bottom: 0;
  /* The native picker UIs (date / time) on iOS, Android, and the major
     desktop browsers all paint reasonably against our themed surface;
     no custom indicator restyling needed here. */
}

.app-schedule-times {
  display: flex;
  gap: var(--space-5);
}

.app-schedule-times .app-schedule-field {
  flex: 1 1 0;
  min-width: 0;
}

/* ── File-list context menu ─────────────────────────────────────────────
   Right-click on a file-list item opens this small themed popover. The
   menu lives at the document root so it can escape the panel's overflow
   clip. Closes on outside click, right-click, or Escape. */
.file-context-menu {
  position: fixed;
  z-index: 260;
  min-width: 180px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  box-shadow: var(--elev-1);
  padding: var(--space-2) 0;
  display: flex;
  flex-direction: column;
}

.file-context-item {
  background: none;
  border: none;
  text-align: left;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  margin: 0;
  border-radius: 0;
  font-family: inherit;
}

.file-context-item:hover,
.file-context-item:focus-visible {
  background: var(--hover-overlay);
  outline: none;
}

/* Touch-first devices: toasts hug the bottom edge above the status bar.
   Triggered by primary pointer (not viewport width) so an iPad in
   landscape gets the iOS-native bottom banner instead of the centered
   desktop stack — matching the bottom-sheet search and fixed-bottom
   status pill the rest of the UI now uses on touch. */
@media (pointer: coarse) {
  #app-toast-stack {
    bottom: calc(env(safe-area-inset-bottom) + 56px);
    left: var(--gap);
    right: var(--gap);
    transform: none;
    align-items: stretch;
  }

  .app-toast {
    border-radius: var(--radius-control);
  }
}
