/* ============================================
   URS-Checker — App-specific styles
   Design-kit provides base: layout, buttons, forms, tables, badges
   ============================================ */

/* ── Page layouts ── */

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

.page-header h1 {
  margin: 0;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
}

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted, #666);
}

.empty-state h3 {
  margin: 1rem 0 0.5rem;
}

/* ── Alert ── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alert-danger {
  background: var(--danger-dim, #fde8e8);
  color: var(--danger, #dc2626);
  border: 1px solid var(--danger, #dc2626);
}

.alert-success {
  background: #dcfce7;
  color: #16a34a;
  border: 1px solid #16a34a;
}

/* ── Specification list ── */

.spec-title {
  font-weight: 500;
}

.spec-ref {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
}

.table-row-clickable {
  cursor: pointer;
}

.table-row-clickable:hover {
  background: var(--bg-hover, #f5f5f5);
}

.action-buttons {
  display: flex;
  gap: 0.25rem;
}

/* ── Progress bars ── */

.progress-bar {
  height: 6px;
  background: var(--bg-muted, #e5e7eb);
  border-radius: 3px;
  overflow: hidden;
  flex: 1;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent, #7c5cbf);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-bar-mini {
  height: 4px;
  background: var(--bg-muted, #e5e7eb);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.25rem;
  width: 60px;
}

.progress-bar-mini .progress-bar-fill {
  height: 100%;
}

.progress-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
  white-space: nowrap;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
  min-width: 35px;
}

.processing-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--accent-dim, #f0ecf8);
  border-radius: 6px;
  margin-bottom: 1rem;
}

.processing-bar-label {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Specification detail — split view ── */

.spec-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.spec-detail-title h1 {
  margin: 0;
  font-size: 1.25rem;
}

.spec-detail-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.spec-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.spec-toolbar-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.spec-toolbar-actions {
  display: flex;
  gap: 0.5rem;
}

.select-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 4px;
  background: var(--bg, #fff);
  color: var(--text, #111);
}

.input-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 4px;
  background: var(--bg, #fff);
  color: var(--text, #111);
}

.spec-split {
  display: flex;
  gap: 0;
  height: calc(100vh - 220px);
  min-height: 500px;
}

.spec-pdf-panel {
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 250px;
}

.split-handle {
  flex: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  color: var(--text-muted, #9ca3af);
  background: var(--bg-muted, #f3f4f6);
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.split-handle:hover,
.split-handle:active {
  background: var(--accent-dim, #e8e0f4);
  color: var(--accent, #7c5cbf);
}

.spec-pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.spec-pdf-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
  color: var(--text-muted, #6b7280);
}

.spec-office-fullwidth {
  height: calc(100vh - 220px);
  min-height: 500px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  overflow: hidden;
}

.onlyoffice-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.onlyoffice-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-muted, #666);
  font-size: 0.8rem;
  z-index: 1;
}

.onlyoffice-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 2rem;
  color: var(--text-muted, #6b7280);
  font-size: 0.85rem;
}

.onlyoffice-fallback code {
  background: var(--bg-muted, #f3f4f6);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

/* ── PDF Viewer ── */

.pdf-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.pdf-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: var(--bg-muted, #f3f4f6);
  border-bottom: 1px solid var(--border, #d1d5db);
  flex-shrink: 0;
}

.pdf-toolbar-nav,
.pdf-toolbar-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pdf-page-info,
.pdf-zoom-level {
  font-size: 0.75rem;
  color: var(--text-muted, #6b7280);
  min-width: 50px;
  text-align: center;
}

.pdf-container {
  flex: 1;
  overflow: auto;
  background: #525659;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
}

.pdf-page-wrapper {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  margin-bottom: 8px;
}

.pdf-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  color: #999;
}

.pdf-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--danger, #ef4444);
  padding: 1rem;
}

.spec-req-panel {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
}

/* ── Requirements table ── */

.table-compact {
  font-size: 0.8rem;
}

.table-compact th,
.table-compact td {
  padding: 0.4rem 0.5rem;
}

.req-row-heading {
  background: var(--bg-muted, #f3f4f6);
}

.req-row-selected {
  background: var(--accent-dim, #f0ecf8) !important;
  outline: 2px solid var(--accent, #7c5cbf);
  outline-offset: -2px;
}

.req-row:hover {
  background: var(--bg-hover, #f9fafb);
}

.req-id {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.75rem;
  white-space: nowrap;
}

.req-location-icon {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.4;
  vertical-align: middle;
}

.req-text {
  line-height: 1.4;
  white-space: pre-line;
  word-break: break-word;
}

.req-remarks {
  min-width: 150px;
}

.remarks-text {
  cursor: pointer;
  font-size: 0.8rem;
  display: block;
  max-height: 4.5em;
  overflow: hidden;
}

.remarks-attribution {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted, #666);
  margin-top: 0.15rem;
  font-style: italic;
}

.req-actions-cell {
  white-space: nowrap;
}

.req-actions-row {
  display: flex;
  align-items: center;
  gap: 0.1rem;
}

.remarks-edit {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.remarks-edit-actions {
  display: flex;
  gap: 0.25rem;
}

.textarea-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 4px;
  resize: vertical;
  width: 100%;
  background: var(--bg, #fff);
  color: var(--text, #111);
}

/* ── Compliance badges ── */

.compliance-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.75rem;
}

.compliance-badge-btn {
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.compliance-badge-btn:hover {
  transform: scale(1.1);
}

.compliance-none {
  background: var(--bg-muted, #e5e7eb);
  color: var(--text-muted, #666);
}

.compliance-j {
  background: #dcfce7;
  color: #16a34a;
  border-color: #16a34a;
}

.compliance-t {
  background: #fef3c7;
  color: #d97706;
  border-color: #d97706;
}

.compliance-n {
  background: #fee2e2;
  color: #dc2626;
  border-color: #dc2626;
}

/* ── Department tags ── */

.dept-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.dept-tag {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.dept-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

/* ── AI Suggestion card ── */

.ai-suggest-btn {
  color: var(--accent, #7c5cbf);
}

.ai-suggestion-card {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  width: 320px;
  background: var(--bg, #fff);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0.75rem;
}

.ai-suggestion-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: var(--accent, #7c5cbf);
  font-weight: 500;
  font-size: 0.8rem;
}

.ai-confidence {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted, #666);
}

.ai-suggestion-body {
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.ai-suggestion-compliance {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ai-suggestion-remarks {
  font-size: 0.8rem;
  line-height: 1.4;
}

.ai-suggestion-reasoning {
  font-size: 0.75rem;
  color: var(--text-muted, #666);
  border-top: 1px solid var(--border, #d1d5db);
  padding-top: 0.5rem;
  line-height: 1.4;
}

.ai-suggestion-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ── Comments ── */

.comment-btn {
  position: relative;
}
.comment-btn-active {
  color: var(--accent, #7c5cbf);
}

.comment-count-dot {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  font-size: 0.6rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent, #7c5cbf);
  border-radius: 7px;
  padding: 0 3px;
}

.comment-thread {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  width: 340px;
  background: var(--bg, #fff);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  max-height: 400px;
}

.comment-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border, #d1d5db);
  flex-shrink: 0;
}

.comment-thread-title {
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.comment-count-badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent, #7c5cbf);
  background: var(--accent-dim, #f0ecf8);
  border-radius: 9px;
  padding: 0 5px;
}

.comment-thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.comment-empty {
  text-align: center;
  color: var(--text-muted, #666);
  font-size: 0.75rem;
  padding: 1rem 0;
}

.comment-group {
  margin-bottom: 0.5rem;
}

.comment-group:last-child {
  margin-bottom: 0;
}

.comment-reply-indent {
  margin-left: 1.75rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border, #d1d5db);
}

.comment-bubble {
  display: flex;
  gap: 0.5rem;
  padding: 0.35rem 0;
}

.comment-avatar {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  margin-top: 1px;
}

.comment-bubble-reply .comment-avatar {
  width: 20px;
  height: 20px;
  border-radius: 10px;
  font-size: 0.5rem;
}

.comment-content {
  flex: 1;
  min-width: 0;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-bottom: 0.15rem;
}

.comment-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink, #1a1a1a);
}

.comment-time {
  font-size: 0.65rem;
  color: var(--text-muted, #666);
}

.comment-text {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink, #1a1a1a);
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.15rem;
  opacity: 0;
  transition: opacity 100ms;
}

.comment-bubble:hover .comment-actions {
  opacity: 1;
}

.comment-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  color: var(--text-muted, #666);
  padding: 0;
  line-height: 1;
}
.comment-action-btn:hover {
  color: var(--accent, #7c5cbf);
}
.comment-action-delete:hover {
  color: var(--danger, #dc2626);
}

/* Compose */
.comment-compose {
  border-top: 1px solid var(--border, #d1d5db);
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.comment-reply-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.65rem;
  color: var(--text-muted, #666);
  margin-bottom: 0.35rem;
  padding: 0.2rem 0.4rem;
  background: var(--accent-dim, #f0ecf8);
  border-radius: 3px;
}
.comment-reply-bar strong {
  color: var(--accent, #7c5cbf);
}

.comment-compose-row {
  display: flex;
  gap: 0.35rem;
  align-items: flex-end;
}

.comment-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  font-family: inherit;
  line-height: 1.4;
  min-height: 32px;
  max-height: 80px;
  overflow-y: auto;
  background: var(--bg, #fff);
  color: var(--ink, #1a1a1a);
  outline: none;
  transition: border-color 100ms;
}
.comment-input:focus {
  border-color: var(--accent, #7c5cbf);
}
.comment-input::placeholder {
  color: var(--text-muted, #999);
}

.comment-send-btn {
  flex-shrink: 0;
  height: 32px;
  width: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Dashboard ── */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  background: var(--bg, #fff);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
}

.stat-card-sm {
  padding: 0.75rem 1rem;
  text-align: center;
}

.stat-card-sm .stat-card-value {
  font-size: 1.5rem;
}

.stat-card-icon {
  color: var(--accent, #7c5cbf);
  display: flex;
  align-items: center;
}

.stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card-label {
  font-size: 0.8rem;
  color: var(--text-muted, #666);
  margin-top: 0.25rem;
}

.stat-card-detail {
  font-size: 0.7rem;
  color: var(--text-muted, #666);
  margin-top: 0.25rem;
}

/* ── Knowledge Base ── */

.kb-search {
  margin-bottom: 1.5rem;
}

.kb-search-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  background: var(--bg, #fff);
}

.kb-search-input input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.9rem;
  background: transparent;
  color: var(--text, #111);
}

.kb-results {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.kb-result-card {
  padding: 1rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  background: var(--bg, #fff);
}

.kb-result-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.kb-result-id {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.8rem;
  font-weight: 500;
}

.kb-result-score {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--accent, #7c5cbf);
  font-weight: 500;
}

.kb-result-text {
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.kb-result-remarks {
  font-size: 0.8rem;
  color: var(--text-muted, #666);
  margin-bottom: 0.5rem;
}

.kb-result-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Utility classes ── */

.text-muted { color: var(--text-muted, #666); }
.text-xs { font-size: 0.7rem; }
.text-danger { color: var(--danger, #dc2626); }
.text-value { font-size: 0.9rem; padding: 0.25rem 0; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 0.25rem; }
.input { padding: 0.5rem 0.75rem; border: 1px solid var(--border, #d1d5db); border-radius: 6px; width: 100%; background: var(--bg, #fff); color: var(--text, #111); }

/* ── Button variants ── */

.btn-accent {
  background: var(--accent, #7c5cbf);
  color: #fff;
}

.btn-accent:hover {
  opacity: 0.9;
}

.btn-xs {
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
}

.btn-danger {
  color: var(--danger, #dc2626);
}

.badge-sm {
  font-size: 0.65rem;
  padding: 1px 4px;
}

/* ── Badge status variants ── */

.badge-muted { background: var(--bg-muted, #e5e7eb); color: var(--text-muted, #666); }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-info { background: #dbeafe; color: #2563eb; }
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-accent { background: var(--accent-dim, #f0ecf8); color: var(--accent, #7c5cbf); }
.badge-admin { background: var(--accent-dim, #f0ecf8); color: var(--accent, #7c5cbf); }
.badge-engineer { background: #dbeafe; color: #2563eb; }
.badge-viewer { background: var(--bg-muted, #e5e7eb); color: var(--text-muted, #666); }

/* ── Card ── */

.card {
  padding: 1.5rem;
  background: var(--bg, #fff);
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
}

.card h3 {
  margin: 0 0 1rem;
}

/* ── Responsive: collapse split view on small screens ── */

@media (max-width: 900px) {
  .spec-split {
    flex-direction: column;
    height: auto;
  }

  .spec-pdf-panel {
    flex: none;
    height: 300px;
  }
}
