/* ==========================================================================
   CivNode — Component Library
   Buttons, inputs, cards, tags, modals, and all reusable UI pieces
   ========================================================================== */

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.6em 1.3em;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background-color var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition),
    opacity var(--transition);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
}

/* --- Primary --- */

.btn-primary {
  background-color: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 2px 12px rgba(201, 168, 76, 0.2);
}

.btn-primary:active {
  background-color: var(--accent);
  box-shadow: none;
}

/* --- Secondary --- */

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background-color: var(--bg-elevated);
  border-color: var(--text-muted);
}

.btn-secondary:active {
  background-color: var(--bg-surface);
}

/* --- Ghost --- */

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: var(--accent-subtle);
  color: var(--accent);
}

.btn-ghost:active {
  background-color: transparent;
}

/* --- Warning (retry state) --- */

.btn-warning {
  background-color: transparent;
  color: #e09040;
  border-color: #e09040;
}

.btn-warning:hover {
  background-color: rgba(224, 144, 64, 0.1);
  color: #d08030;
}

/* --- Sizes --- */

.btn-sm {
  padding: 0.35em 0.8em;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.75em 1.8em;
  font-size: 1.05rem;
}

/* --- Icon Button --- */

.btn-icon {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border-radius: var(--radius);
}

.btn-icon.btn-sm {
  width: 2rem;
  height: 2rem;
}

/* ==========================================================================
   Form Inputs
   ========================================================================== */

input:not([type]),
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.65em 0.9em;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background-color var(--transition);
  appearance: none;
}

/* Dark theme for native date/time picker chrome */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
  color-scheme: dark;
}

input:not([type]):hover,
input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="search"]:hover,
input[type="url"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
  border-color: var(--text-muted);
}

input:not([type]):focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle), 0 0 12px var(--accent-subtle);
}

/* Number input spinner arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
  filter: invert(0.7) sepia(1) saturate(3) hue-rotate(10deg);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--bg-surface);
}

/* Textarea specifics */
textarea {
  resize: vertical;
  min-height: 6em;
  line-height: 1.7;
}

/* Select arrow */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238a8680' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8em center;
  padding-right: 2.2em;
}

select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

/* --- Input Group --- */

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-group + .input-group {
  margin-top: 1.2rem;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.input-group .input-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.input-group .input-error {
  font-size: 0.8rem;
  color: var(--error);
  margin-top: 0.2rem;
}

/* Input with error state */
.input-group.has-error input,
.input-group.has-error textarea {
  border-color: var(--error);
}

.input-group.has-error input:focus,
.input-group.has-error textarea:focus {
  box-shadow: 0 0 0 3px rgba(204, 68, 68, 0.15);
}

/* --- Checkbox & Toggle --- */

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.6em;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.checkbox input[type="checkbox"] {
  width: 1.1em;
  height: 1.1em;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-secondary);
  cursor: pointer;
  display: grid;
  place-content: center;
}

.checkbox input[type="checkbox"]:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}

.checkbox input[type="checkbox"]:checked::before {
  content: '';
  width: 0.55em;
  height: 0.55em;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background-color: var(--bg-primary);
}

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.7em;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 2.6em;
  height: 1.4em;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1em;
  position: relative;
  transition:
    background-color var(--transition),
    border-color var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.4em - 6px);
  height: calc(1.4em - 6px);
  background-color: var(--text-muted);
  border-radius: 50%;
  transition:
    transform var(--transition),
    background-color var(--transition);
}

.toggle input:checked + .toggle-track {
  background-color: var(--accent-subtle);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(1.2em);
  background-color: var(--accent);
}

.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Segmented Toggle --- */

.segmented-toggle {
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented-btn {
  padding: 0.35em 0.7em;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  transition: color var(--transition), background-color var(--transition);
  white-space: nowrap;
}

.segmented-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.segmented-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.segmented-btn.active {
  color: var(--accent);
  background: var(--accent-subtle);
  font-weight: 600;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition:
    background-color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
}

.card-elevated {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transition:
    background-color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 16px var(--shadow);
}

.card-interactive:active {
  transform: scale(0.995);
}

/* ==========================================================================
   Tags & Mood Pills
   ========================================================================== */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.2em 0.65em;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 2em;
  white-space: nowrap;
  transition:
    color var(--transition),
    background-color var(--transition),
    border-color var(--transition);
}

.tag:hover {
  color: var(--text-primary);
  border-color: var(--border);
}

.tag-mood {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.2em 0.65em;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  background-color: var(--accent-subtle);
  border: 1px solid transparent;
  border-radius: 2em;
  white-space: nowrap;
  transition:
    color var(--transition),
    background-color var(--transition),
    border-color var(--transition);
}

.tag-mood:hover {
  border-color: var(--accent);
}

.tag-mood.active,
.tag-mood[aria-pressed="true"] {
  background-color: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.tag-mood.disabled,
.tag-mood:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================================================
   Presence Indicator
   ========================================================================== */

/* ==========================================================================
   Server Status Indicator
   ========================================================================== */

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-right: 0.75rem;
}

.server-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transition: background-color 0.3s;
}

.server-status-dot.online {
  background-color: var(--text-muted, #5a5650);
}

.server-status-dot.offline {
  background-color: var(--error);
  animation: offline-pulse 1.5s ease-in-out infinite;
}

.server-status-label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@keyframes offline-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.presence {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary, #9a9590);
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

.presence-dot {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted, #5a5650);
  border-radius: 50%;
  animation: presence-pulse 3s ease-in-out infinite;
}

@keyframes presence-pulse {
  0%, 100% {
    opacity: 0.4;
    box-shadow: 0 0 0 0 rgba(201, 168, 76, 0.3);
  }
  50% {
    opacity: 1;
    box-shadow: 0 0 0 4px rgba(201, 168, 76, 0);
  }
}

/* Admin presence panel — dropdown showing online users */
.presence-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 1001;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  min-width: 320px;
  max-width: 400px;
  animation: popup-in 0.12s ease-out;
}

.presence-panel-header {
  padding: 0.6rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.presence-panel-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.presence-panel--pinned .presence-panel-dismiss,
.presence-panel:hover .presence-panel-dismiss {
  opacity: 0.6;
}
.presence-panel-dismiss:hover {
  opacity: 1 !important;
  color: var(--text-primary);
}

.presence-panel-list {
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.presence-panel-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
  transition: background var(--transition);
}

.presence-panel-card:hover {
  background: var(--bg-secondary);
}

.presence-panel-card + .presence-panel-card {
  border-top: 1px solid var(--border-subtle);
}

.presence-panel-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.presence-panel-avatar {
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.presence-panel-details {
  min-width: 0;
}

.presence-panel-name {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.presence-panel-name a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition);
}

.presence-panel-name a:hover {
  color: var(--accent);
}

.presence-panel-badge {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  line-height: 1;
}

.presence-panel-badge--owner {
  background: rgba(201,168,76,0.15);
  color: var(--accent);
}

.presence-panel-badge--mod {
  background: rgba(74,138,90,0.15);
  color: var(--success);
}

.presence-panel-badge--ai {
  background: rgba(140,120,200,0.15);
  color: #a090d0;
}

.presence-panel-badge--patron {
  background: rgba(212,165,116,0.15);
  color: var(--resonance);
}

.presence-panel-stats {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.presence-panel-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.presence-panel-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background var(--transition);
}

.presence-panel-action img {
  filter: brightness(0) invert(0.65);
  transition: filter var(--transition);
}

.presence-panel-action:hover {
  background: var(--bg-surface);
}

.presence-panel-action:hover img {
  filter: brightness(0) invert(0.85);
}

.presence-panel-flag {
  margin-left: 0.35em;
  font-size: 0.85em;
}
.presence-panel-activity {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.presence-panel-empty {
  padding: 1rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ==========================================================================
   User Link & Supporter Badge
   ========================================================================== */

.user-link {
  color: var(--text-secondary);
  font-weight: 500;
  transition: color var(--transition);
}

.user-link:hover {
  color: var(--accent);
}

.user-popup {
  position: absolute;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 140px;
  padding: 0.4rem 0;
  animation: popup-in 0.12s ease-out;
}

@keyframes popup-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-popup-alias {
  padding: 0.4rem 0.75rem 0.35rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
}

.user-popup-action {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.user-popup-action:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.patron-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.55em;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--patron-gold);
  background: linear-gradient(
    135deg,
    rgba(201, 168, 76, 0.1),
    rgba(201, 168, 76, 0.05)
  );
  border: 1px solid rgba(201, 168, 76, 0.2);
  border-radius: 2em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.patron-badge::before {
  content: '';
  width: 0.5em;
  height: 0.5em;
  background-color: var(--patron-gold);
  border-radius: 50%;
}

/* --- Author Tags (on CivPages) --- */

.author-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin-left: 0.5em;
  padding: 0.1em 0.5em;
  font-size: 0.68rem;
  font-weight: 600;
  border-radius: 2em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
}

.author-tag--owner {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.author-tag--supporter {
  color: var(--patron-gold);
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.1), rgba(201, 168, 76, 0.05));
  border: 1px solid rgba(201, 168, 76, 0.2);
}

/* ==========================================================================
   Divider
   ========================================================================== */

.divider {
  border: none;
  height: 1px;
  background-color: var(--border-subtle);
  margin: 1.5rem 0;
}

.divider-labeled {
  display: flex;
  align-items: center;
  gap: 1em;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 1.5rem 0;
}

.divider-labeled::before,
.divider-labeled::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--border-subtle);
}

/* ==========================================================================
   Tabs
   ========================================================================== */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

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

.tab {
  padding: 0.7em 1.2em;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color var(--transition),
    border-color var(--transition);
  margin-bottom: -1px;
}

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

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

/* ==========================================================================
   Skeleton Loading
   ========================================================================== */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--bg-surface) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 1em;
  margin-bottom: 0.8em;
  border-radius: var(--radius-sm);
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-title {
  height: 1.8em;
  width: 70%;
  margin-bottom: 1.2em;
  border-radius: var(--radius-sm);
}

.skeleton-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
}

.skeleton-block {
  height: 6em;
  border-radius: var(--radius);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==========================================================================
   Spinner
   ========================================================================== */

.spinner {
  display: inline-block;
  width: 1.5em;
  height: 1.5em;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 1em;
  height: 1em;
  border-width: 1.5px;
}

.spinner-lg {
  width: 2.5em;
  height: 2.5em;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Page-level centered spinner */
.spinner-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  min-height: 20vh;
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.25;
}

.empty-state-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 30ch;
  line-height: 1.6;
}

.empty-state .btn {
  margin-top: 1.5rem;
}

/* Error pages (SPA 404) */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6rem 2rem 4rem;
  min-height: 50vh;
}

.error-page-code {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.error-page-heading {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.error-page-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 36ch;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.error-page-nav {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  font-size: 0.8rem;
}

.error-page-nav a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}

.error-page-nav a:hover {
  color: var(--accent);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.8em 1.2em;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px var(--shadow);
  pointer-events: auto;
  animation: toast-in 300ms ease forwards;
  max-width: 380px;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--error);
}

.toast-info {
  border-left: 3px solid var(--accent);
}

.toast-exit {
  animation: toast-out 200ms ease forwards;
}

.toast-close {
  margin-left: auto;
  padding: 0.2em;
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 1.1em;
  line-height: 1;
  transition: color var(--transition);
}

.toast-close:hover {
  color: var(--text-primary);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(1rem) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(0.5rem) scale(0.95);
  }
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: modal-overlay-in 200ms ease forwards;
}

.modal-overlay[aria-hidden="true"] {
  animation: modal-overlay-out 150ms ease forwards;
  pointer-events: none;
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 64px var(--shadow);
  padding: 2rem;
  animation: modal-in 250ms ease forwards;
}

.modal-overlay[aria-hidden="true"] .modal {
  animation: modal-out 150ms ease forwards;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 1.2rem;
  transition:
    color var(--transition),
    background-color var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
  background-color: var(--bg-elevated);
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-y: auto;
  min-height: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* Focus trap: keep focus inside modal */
.modal:focus {
  outline: none;
}

@keyframes modal-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-overlay-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(1rem) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modal-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(0.5rem) scale(0.96);
  }
}

/* ==========================================================================
   Changelog
   ========================================================================== */

.changelog-body {
  max-height: 50vh;
  overflow-y: auto;
}

.changelog-release {
  margin-bottom: 1.5rem;
}

.changelog-release:last-child {
  margin-bottom: 0;
}

.changelog-release-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.changelog-version {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

.changelog-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.changelog-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.changelog-list li {
  position: relative;
  padding-left: 1.1rem;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.changelog-list li::before {
  content: '\2022';
  position: absolute;
  left: 0;
  color: var(--accent);
}

.changelog-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent);
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* ==========================================================================
   Progress Dots (for step-based flows)
   ========================================================================== */

.progress-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--border);
  transition: background-color var(--transition);
}

.progress-dot.active {
  background-color: var(--accent);
}

.progress-dot.completed {
  background-color: var(--text-muted);
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 1rem 0;
}

.pagination-btn {
  min-width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5em;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    color var(--transition),
    background-color var(--transition),
    border-color var(--transition);
}

.pagination-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border-color: var(--border);
}

.pagination-btn.active {
  color: var(--accent);
  background-color: var(--accent-subtle);
  border-color: var(--accent);
}

.pagination-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ==========================================================================
   Word / Character Counter
   ========================================================================== */

.char-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  transition: color var(--transition);
}

.char-count.warning {
  color: var(--resonance);
}

.char-count.limit {
  color: var(--error);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Mobile: < 640px */
@media (max-width: 639px) {
  .container,
  .container-narrow,
  .container-wide {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .card,
  .card-elevated {
    padding: 1.2rem;
    border-radius: var(--radius);
  }

  .modal-overlay {
    padding: 0.75rem;
    align-items: flex-end;
  }

  .modal {
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1.5rem;
  }

  .toast-container {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
  }

  .toast {
    max-width: 100%;
  }

  .tabs {
    gap: 0;
  }

  .tab {
    padding: 0.6em 0.8em;
    font-size: 0.8rem;
  }

  .btn-lg {
    padding: 0.65em 1.4em;
    font-size: 1rem;
  }

  .hide-mobile {
    display: none !important;
  }
}

/* Tablet: 640px - 1024px */
@media (min-width: 640px) and (max-width: 1023px) {
  .hide-tablet {
    display: none !important;
  }
}

/* Desktop: > 1024px */
@media (min-width: 1024px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ==========================================================================
   Highlights
   ========================================================================== */

.hl {
  border-radius: 2px;
  padding: 1px 2px;
  cursor: pointer;
  transition: opacity 150ms ease;
}
.hl:hover { opacity: 0.9; }

.hl-yellow, .hl-1  { background-color: var(--hl-color-1, #ffeb3b); color: var(--hl-text-1, inherit); }
.hl-green, .hl-2   { background-color: var(--hl-color-2, #66bb6a); color: var(--hl-text-2, inherit); }
.hl-blue, .hl-3    { background-color: var(--hl-color-3, #42a5f5); color: var(--hl-text-3, inherit); }
.hl-pink, .hl-4    { background-color: var(--hl-color-4, #ef5350); color: var(--hl-text-4, inherit); }
.hl-orange, .hl-5  { background-color: var(--hl-color-5, #ffa726); color: var(--hl-text-5, inherit); }
.hl-feedback       { background-color: var(--hl-feedback, rgba(149, 117, 205, 0.30)); cursor: pointer; }

.highlight-picker {
  position: absolute;
  z-index: 1000;
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--shadow);
  animation: fade-in 150ms ease;
}

.hl-color {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease;
  padding: 0;
  outline: none;
}
.hl-color:hover {
  transform: scale(1.25);
  border-color: var(--text-secondary);
}

.hl-color-yellow  { background-color: var(--hl-dot-1, #ffeb3b); }
.hl-color-green   { background-color: var(--hl-dot-2, #66bb6a); }
.hl-color-blue    { background-color: var(--hl-dot-3, #42a5f5); }
.hl-color-pink    { background-color: var(--hl-dot-4, #ef5350); }
.hl-color-orange  { background-color: var(--hl-dot-5, #ffa726); }

mark.hl {
  cursor: pointer;
  border-radius: 2px;
  transition: filter 150ms ease;
}

mark.hl:hover {
  cursor: pointer;
}

.highlight-remove-tooltip {
  position: absolute;
  z-index: 1001;
  padding: 4px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--shadow);
  animation: fade-in 150ms ease;
}

.highlight-remove-btn {
  background: none;
  border: none;
  color: var(--error, #cc4444);
  font-size: 0.8rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.highlight-remove-btn:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Bookmark Button
   ========================================================================== */

.bookmark-btn.bookmarked {
  color: var(--accent);
  font-weight: 600;
}
.bookmark-btn.bookmarked:hover {
  color: var(--accent-hover, var(--accent));
}

/* ==========================================================================
   Rich Editor (Markdown toolbar + textarea)
   ========================================================================== */

/* ==========================================================================
   Forum ProseMirror Editor
   ========================================================================== */

.forum-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  overflow: hidden;
  transition: border-color var(--transition);
}

.forum-editor:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.forum-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 5px 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.forum-editor-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  transition: all 120ms ease;
  padding: 0;
}

.forum-editor-btn:hover {
  background: var(--accent-subtle);
  color: var(--accent);
}

.forum-editor-btn:active {
  background: var(--accent);
  color: var(--bg-primary);
}

.forum-editor-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.forum-editor-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.forum-editor-btn.tb-italic {
  font-style: italic;
}

.forum-editor-sep {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 4px 4px;
  align-self: center;
}

.forum-editor-content .ProseMirror {
  outline: none;
  padding: 0.7em 0.9em;
  min-height: 6em;
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.forum-editor-content .ProseMirror:focus {
  outline: none;
}

.forum-editor-content .ProseMirror p {
  margin: 0 0 0.6em 0;
}

.forum-editor-content .ProseMirror p:last-child {
  margin-bottom: 0;
}

.forum-editor-content .ProseMirror h2 {
  font-size: 1.35rem;
  margin: 1.2em 0 0.4em;
  font-weight: 600;
}

.forum-editor-content .ProseMirror h3 {
  font-size: 1.15rem;
  margin: 1em 0 0.3em;
  font-weight: 600;
}

.forum-editor-content .ProseMirror blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0;
  padding: 0.5em 1em;
  background: var(--accent-subtle);
  color: var(--text-secondary);
}

.forum-editor-content .ProseMirror pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.8em 1em;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.5;
  overflow-x: auto;
  margin: 1em 0;
}

.forum-editor-content .ProseMirror code {
  background: var(--bg-elevated);
  border-radius: 2px;
  padding: 0.15em 0.35em;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.forum-editor-content .ProseMirror pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

.forum-editor-content .ProseMirror ul,
.forum-editor-content .ProseMirror ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.forum-editor-content .ProseMirror li {
  margin-bottom: 0.2em;
}

.forum-editor-content .ProseMirror hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 1.5em 0;
}

.forum-editor-content .ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
}

.forum-editor-content .ProseMirror strong,
.forum-editor-content .ProseMirror em,
.forum-editor-content .ProseMirror s,
.forum-editor-content .ProseMirror code,
.forum-editor-content .ProseMirror a {
  display: inline;
  line-height: inherit;
}

.forum-editor-content .ProseMirror img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.forum-editor-content .ProseMirror table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.forum-editor-content .ProseMirror th,
.forum-editor-content .ProseMirror td {
  border: 1px solid var(--border-subtle);
  padding: 0.4em 0.6em;
  text-align: left;
}

.forum-editor-content .ProseMirror th {
  background: var(--bg-elevated);
  font-weight: 600;
}

/* Placeholder text when editor is empty */
.forum-editor-empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  float: left;
  height: 0;
}

@media (max-width: 639px) {
  .forum-editor-btn {
    width: 26px;
    height: 26px;
    font-size: 0.78rem;
  }
  .forum-editor-toolbar {
    gap: 1px;
    padding: 4px 6px;
  }
}

/* ==========================================================================
   Floating Notepad
   ========================================================================== */

.notepad-trigger {
  position: relative;
  z-index: 9500;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  padding: 0;
  color: var(--text-secondary);
}

.notepad-trigger-icon {
  display: block;
  width: 16px;
  height: 16px;
  background-color: currentColor;
  -webkit-mask-image: url('/icons/notepad.png');
  mask-image: url('/icons/notepad.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.notepad-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.notepad-trigger.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.notepad-panel {
  position: fixed;
  bottom: 4.5rem;
  left: 1.2rem;
  z-index: 9500;
  width: 320px;
  max-width: calc(100vw - 2.4rem);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: notepad-in 200ms ease;
}

@keyframes notepad-in {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.notepad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  cursor: grab;
  user-select: none;
}

.notepad-header:active {
  cursor: grabbing;
}

.notepad-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.notepad-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 120ms ease;
  padding: 0;
}

.notepad-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.notepad-body {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 80px;
  padding: 0.7rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
  border: none;
  resize: none;
  outline: none;
}

.notepad-body::placeholder {
  color: var(--text-muted);
}

.notepad-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.9rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.notepad-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-sans);
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: all 120ms ease;
}

.notepad-clear:hover {
  color: var(--error, #c44);
  background: rgba(200, 60, 60, 0.08);
}

@media (max-width: 639px) {
  .notepad-trigger {
    bottom: 5rem;
    left: 0.8rem;
    width: 38px;
    height: 38px;
  }
  .notepad-panel {
    bottom: auto;
    left: 0.5rem;
    right: 0.5rem;
    top: 4rem;
    width: auto;
    max-width: none;
    max-height: calc(100vh - 8rem);
  }
}

/* --- Notepad Resize Handle --- */
.notepad-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
}
.notepad-resize::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0.5;
}
.notepad-resize:hover::after {
  opacity: 1;
}

/* --- Notepad Header Grip (move indicator) --- */
.notepad-grip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 6px;
}
.notepad-grip span {
  display: block;
  width: 12px;
  height: 1.5px;
  background: var(--text-muted);
  border-radius: 1px;
  opacity: 0.5;
}

/* --- Notepad Tab Bar --- */
.notepad-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  min-height: 30px;
}
.notepad-tab {
  padding: 3px 10px;
  font-size: 0.72rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
}
.notepad-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-elevated);
}
.notepad-tab.active {
  color: var(--text-primary);
  background: var(--accent-subtle);
}
.notepad-tab-add {
  padding: 2px 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.notepad-tab-add:hover {
  color: var(--accent);
  background: var(--accent-subtle);
}

/* --- Notepad Tab Context Menu --- */
.notepad-ctx-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 120px;
  padding: 4px 0;
}
.notepad-ctx-item {
  display: block;
  width: 100%;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.notepad-ctx-item:hover {
  background: var(--accent-subtle);
}
.notepad-ctx-item--danger:hover {
  color: var(--error);
}

/* --- Notepad Preview --- */
.notepad-preview {
  flex: 1;
  min-height: 80px;
  padding: 0.7rem 0.9rem;
  overflow-y: auto;
  font-family: var(--font-serif);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-primary);
}

/* --- Notepad Preview Toggle --- */
.notepad-preview-btn {
  padding: 2px 8px;
  font-size: 0.7rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 120ms ease;
}
.notepad-preview-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.notepad-preview-btn.active {
  color: var(--accent);
  background: var(--accent-subtle);
  border-color: var(--accent);
}

/* --- Notepad History Panel --- */
.notepad-history-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-surface);
  z-index: 3;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
}
.notepad-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.notepad-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.notepad-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-sans);
  transition: background 120ms ease;
}
.notepad-history-item:hover {
  background: var(--accent-subtle);
}
.notepad-history-time {
  color: var(--text-secondary);
}
.notepad-history-words {
  color: var(--text-muted);
  font-size: 0.7rem;
}
.notepad-history-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all 120ms ease;
}
.notepad-history-item:hover .notepad-history-delete {
  opacity: 1;
}
.notepad-history-delete:hover {
  color: var(--error);
  background: rgba(200, 60, 60, 0.08);
}

/* --- Notepad Panel Overrides for Resize --- */
.notepad-panel {
  min-width: 280px;
  min-height: 200px;
}

@media (max-width: 639px) {
  .notepad-resize { display: none; }
}

/* ==========================================================================
   Word Usage Bar
   ========================================================================== */

.word-usage { margin: -0.5rem 0 1rem; }
.word-usage-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.word-usage-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.word-usage-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }
.word-usage-warn { background: var(--danger, #c44); }

/* Settings tabs */
.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.settings-tab {
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.settings-tab:hover { color: var(--text-primary); }
.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.settings-tab-panel { display: none; }
.settings-tab-panel.active { display: block; }
.settings-tab--danger { color: var(--error, #c0392b); }
.settings-tab--danger.active { border-bottom-color: var(--error, #c0392b); }

/* ==========================================================================
   AI Setup Provider Capabilities
   ========================================================================== */

.ai-setup-provider-caps {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
  opacity: 0.8;
}

/* ==========================================================================
   Tooltips
   ========================================================================== */

.civ-tooltip {
  position: absolute;
  z-index: 9999;
  padding: 0.5rem 0.65rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--shadow);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.45;
  pointer-events: none;
  animation: tooltip-fade-in 120ms ease;
}

.civ-tooltip-content {
  word-wrap: break-word;
}

@keyframes tooltip-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.civ-tooltip-arrow {
  position: absolute;
  width: 0;
  height: 0;
  border: 6px solid transparent;
}

/* Arrow below tooltip (tooltip is above target) */
.civ-tooltip-arrow--below {
  bottom: -12px;
  border-top-color: var(--border);
  transform: translateX(-50%);
}
.civ-tooltip-arrow--below::after {
  content: '';
  position: absolute;
  top: -7px;
  left: -5px;
  border: 5px solid transparent;
  border-top-color: var(--bg-elevated);
}

/* Arrow above tooltip (tooltip is below target) */
.civ-tooltip-arrow--above {
  top: -12px;
  border-bottom-color: var(--border);
  transform: translateX(-50%);
}
.civ-tooltip-arrow--above::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: -5px;
  border: 5px solid transparent;
  border-bottom-color: var(--bg-elevated);
}

/* Arrow right of tooltip (tooltip is left of target) */
.civ-tooltip-arrow--right {
  right: -12px;
  border-left-color: var(--border);
  transform: translateY(-50%);
}
.civ-tooltip-arrow--right::after {
  content: '';
  position: absolute;
  left: -7px;
  top: -5px;
  border: 5px solid transparent;
  border-left-color: var(--bg-elevated);
}

/* Arrow left of tooltip (tooltip is right of target) */
.civ-tooltip-arrow--left {
  left: -12px;
  border-right-color: var(--border);
  transform: translateY(-50%);
}
.civ-tooltip-arrow--left::after {
  content: '';
  position: absolute;
  right: -7px;
  top: -5px;
  border: 5px solid transparent;
  border-right-color: var(--bg-elevated);
}

/* --- Mention Links --- */
.mention-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}
.mention-link:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

/* --- Mention Autocomplete Dropdown --- */
.mention-dropdown {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  min-width: 220px;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.mention-dropdown-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 12px 2px;
  font-family: var(--font-sans);
}
.mention-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  transition: background var(--transition);
}
.mention-dropdown-item:hover,
.mention-dropdown-item.selected {
  background: var(--accent-subtle);
}
.mention-item-label {
  color: var(--text-primary);
  font-weight: 500;
}
.mention-item-sublabel {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ==========================================================================
   Markdown tables in reading context
   ========================================================================== */

.reading table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.88rem;
}
.reading th,
.reading td {
  padding: 0.5em 0.8em;
  border: 1px solid var(--border);
  text-align: left;
}
.reading th {
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}
.reading tr:nth-child(even) td {
  background: var(--bg-secondary);
}

/* ==========================================================================
   Passage Comment Editor (floating panel from context menu)
   ========================================================================== */

.passage-comment-editor {
  position: fixed;
  z-index: 1002;
  width: 420px;
  min-width: 280px;
  max-width: calc(100vw - 2rem);
  padding: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px var(--shadow);
  animation: fade-in 150ms ease;
  resize: both;
  overflow: auto;
}

.passage-comment-drag-handle {
  cursor: move;
  padding: 0.25rem 0;
  margin: -0.4rem -0.4rem 0.4rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  user-select: none;
}

.passage-comment-quote {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.6rem;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}

.passage-comment-editor .forum-editor {
  margin-bottom: 0;
}

.passage-comment-btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ==========================================================================
   Feedback Tooltip (passage comment thread)
   ========================================================================== */

.feedback-tooltip {
  position: absolute;
  z-index: 1003;
  width: 320px;
  max-width: calc(100vw - 2rem);
  max-height: 420px;
  overflow-y: auto;
  padding: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px var(--shadow);
  animation: fade-in 150ms ease;
}

.feedback-tooltip-quote {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}

.feedback-tooltip-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0.5rem 0;
}

.feedback-tooltip-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  margin-bottom: 0.3rem;
}

.feedback-alias {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
.feedback-alias:hover {
  text-decoration: underline;
}

.feedback-time {
  color: var(--text-muted);
}

.feedback-tooltip-body {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-primary);
}
.feedback-tooltip-body p {
  margin: 0.3em 0;
}

.feedback-tooltip-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}

.feedback-resonate-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.2rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.feedback-resonate-btn:hover {
  border-color: var(--resonance);
  color: var(--resonance);
}
.feedback-resonate-btn.resonated {
  background: var(--resonance);
  border-color: var(--resonance);
  color: #fff;
}

.feedback-tooltip .forum-editor {
  margin-top: 0.3rem;
}

@media (max-width: 639px) {
  .passage-comment-editor,
  .feedback-tooltip {
    width: calc(100vw - 2rem);
    left: 1rem !important;
  }
}

/* ==========================================================================
   Divider Picker
   ========================================================================== */

.divider-picker {
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  max-height: 400px;
  overflow-y: auto;
}

.divider-picker-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0.5rem 0 0.25rem;
  padding: 0 0.25rem;
}

.divider-picker-label:first-child {
  margin-top: 0;
}

.divider-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.divider-picker-item {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  transition: border-color 0.15s, background 0.15s;
}

.divider-picker-item:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.divider-picker-item.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.divider-picker-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.divider-picker-preview svg {
  max-width: 140px;
  height: auto;
}

/* ==========================================================================
   Export Dialog
   ========================================================================== */

.export-dialog {
  max-width: 480px;
  width: 90vw;
}

.export-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  max-height: 60vh;
  overflow-y: auto;
}

/* Format selector buttons row */
.export-format-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}

.export-format-sep {
  width: 100%;
  height: 0;
  flex-basis: 100%;
}

.export-format-btn {
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.export-format-btn:hover {
  background: var(--bg-hover);
}

.export-format-btn.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
}

/* Section labels */
.export-dialog-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* Form rows */
.export-dialog-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.export-dialog-row label {
  min-width: 110px;
  color: var(--text-secondary);
}

.export-dialog-row select,
.export-dialog-row input[type="text"] {
  flex: 1;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

/* Note text */
.export-dialog-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Save defaults checkbox */
.export-dialog-save-defaults {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
