/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  /* Consistent with other elements */
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.modal h2 {
  margin: 0 0 1.5rem 0;
  font-size: var(--ui-font-xl);
  /* Major heading */
  font-weight: 600;
}

.modal .form-group {
  margin-bottom: 1.5rem;
}

.modal label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: var(--ui-font-md);
  /* Consistent with body text */
}

.modal select,
.modal input[type="radio"] {
  margin-right: 0.5rem;
}

.modal .radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal .radio-option {
  display: flex;
  align-items: center;
}

.modal .radio-option input[type="radio"] {
  margin-right: 0.5rem;
}

.modal .radio-option label {
  margin: 0;
  font-weight: normal;
  cursor: pointer;
}

.modal .radio-option .description {
  font-size: var(--ui-font-sm);
  /* 13px - smaller for descriptions */
  color: var(--text-secondary);
  margin-left: 1.5rem;
}

.modal .button-group {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 2rem;
}

.modal button.primary {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.modal button.primary:hover {
  opacity: 0.9;
}

.modal button.secondary {
  background-color: transparent;
}

.modal .error {
  color: #dc3545;
  margin-top: 0.5rem;
  font-size: var(--ui-font-md);
  /* Consistent typography */
}

.modal .disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Settings Modal — Tag List */
.settings-modal {
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

.field-hint {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  margin: 0 0 0.5rem 0;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 1.75rem;
  margin-bottom: 0.5rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: var(--ui-font-sm);
  line-height: 1.4;
}

.tag-chip .tag-text {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-chip .tag-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  min-width: auto;
}

.tag-chip .tag-remove:hover {
  color: #c0392b;
}

.tag-input-row {
  display: flex;
  gap: 0.4rem;
}

.tag-input-row input[type="text"] {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--ui-font-sm);
}

.tag-input-row button.small {
  padding: 0.35rem 0.75rem;
  font-size: var(--ui-font-sm);
  min-width: auto;
}

/* Search Modal */
.search-modal {
  max-width: 560px;
  padding: 0;
  overflow: hidden;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  gap: 0.5rem;
}

.search-input-wrapper input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--ui-font-lg);
  padding: 0.25rem 0;
}

.search-badge {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
}

.search-meta {
  padding: 0.4rem 1rem;
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  min-height: 1.5rem;
}

.search-meta.search-truncated {
  color: #e67e22;
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--text-primary);
  border-top: 1px solid var(--border-color);
  cursor: pointer;
}

.search-result-item:hover,
.search-result-item.active {
  background-color: var(--bg-primary);
}

.search-icon {
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1.4;
}

.search-result-body {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-size {
  font-weight: normal;
  color: var(--text-secondary);
  font-size: var(--ui-font-sm);
  margin-left: 0.4rem;
}

.search-result-path {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-snippet {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  font-family: monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}

/* Version History Modal */
.history-modal {
  max-width: 800px;
}

.history-list {
  max-height: 400px;
  overflow-y: auto;
}

.history-empty {
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem 1rem;
  font-size: var(--ui-font-md);
  line-height: 1.6;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.1s;
}

.history-item:hover {
  background-color: var(--bg-primary);
}

.history-item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-time {
  font-size: var(--ui-font-md);
}

.history-badge {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  padding: 0.05rem 0.4rem;
}

.history-item-meta {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
}

.history-detail {
  padding: 0;
}

.history-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.history-detail-header span {
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  flex: 1;
}

.history-content-pre {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  max-height: 350px;
  overflow: auto;
  font-size: var(--ui-font-sm);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
}

/* Diff Comparison View */
.history-diff-container {
  max-height: 400px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-primary);
}

.diff-legend {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  font-size: var(--ui-font-sm);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.diff-legend-removed {
  color: #b31d28;
  padding-left: 0.5rem;
  border-left: 3px solid #fdb8c0;
}

.diff-legend-added {
  color: #22863a;
  padding-left: 0.5rem;
  border-left: 3px solid #acf2bd;
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  table-layout: fixed;
}

.diff-table td {
  vertical-align: top;
}

.diff-line-num {
  width: 40px;
  min-width: 40px;
  text-align: right;
  padding: 0 6px;
  color: var(--text-secondary);
  opacity: 0.6;
  user-select: none;
  font-size: 11px;
}

.diff-marker {
  width: 20px;
  min-width: 20px;
  text-align: center;
  padding: 0;
  font-weight: 600;
  user-select: none;
}

.diff-content {
  padding: 0 8px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.diff-row-removed {
  background-color: rgba(255, 220, 220, 0.4);
}

.diff-row-removed .diff-marker {
  color: #b31d28;
}

.diff-row-added {
  background-color: rgba(220, 255, 220, 0.4);
}

.diff-row-added .diff-marker {
  color: #22863a;
}

.diff-row-context {
  background: transparent;
}

/* Dark theme overrides for diff */
[data-theme="dark"] .diff-row-removed {
  background-color: rgba(180, 40, 40, 0.2);
}

[data-theme="dark"] .diff-row-added {
  background-color: rgba(40, 160, 40, 0.2);
}

[data-theme="dark"] .diff-legend-removed {
  color: #f97583;
  border-left-color: rgba(249, 117, 131, 0.4);
}

[data-theme="dark"] .diff-legend-added {
  color: #85e89d;
  border-left-color: rgba(133, 232, 157, 0.4);
}

/* DB Status in Settings */
.db-status-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.db-status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: var(--ui-font-sm);
  margin-bottom: 0.75rem;
}

.db-status-grid dt {
  color: var(--text-secondary);
}

.db-status-grid dd {
  margin: 0;
}

/* Settings Tools Button Grid */
.settings-actions {
  margin-bottom: 0.5rem;
}

.settings-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.settings-btn-grid button {
  text-align: center;
}

/* FTS5 search snippet highlights */
.search-snippet mark {
  background-color: rgba(255, 193, 7, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* Inline rename input */
.rename-input {
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--accent-color);
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  width: 100%;
  outline: none;
}
