/* ComplianceHQ — exact match to reference design */

:root {
  --bg: #ffffff;
  --bg-sidebar: #F8F9FA;
  --bg-bubble: #f3f4f6;
  --border: #e5e7eb;
  --text: #333333;
  --text-muted: #666666;
  --accent: #1e3a5f;
  --accent-hover: #152a47;
  --tab-active-bg: #e5e7eb;
  --font-sans: "DM Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: Lora, Georgia, serif;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* ——— Header ——— */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 14px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  flex-shrink: 0;
}

.logo-icon svg {
  display: block;
}

.logo-img {
  display: block;
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.logo {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  color: #333333;
  line-height: 1.2;
}

.subtitle {
  font-family: var(--font-serif);
  font-size: 0.8125rem;
  color: #666666;
  font-weight: 400;
  line-height: 1.2;
}

.web-nav {
  display: flex;
  gap: 4px;
}

.web-nav button {
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, font-weight 0.15s, border-color 0.15s;
}

.web-nav button:hover {
  background: var(--border);
}

.web-nav button.active {
  background: #dbeafe;
  border: 1px solid #2563eb;
  font-weight: 600;
  color: #1e3a5f;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}


/* ——— Body: sidebar + main ——— */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

/* ——— Inline quick topics ——— */
.quick-topics-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 4px 0 20px;
  opacity: 1;
  transition: opacity 0.18s ease;
}

.quick-topics-inline.fading-out {
  opacity: 0;
  pointer-events: none;
}

.quick-topics-label {
  display: block;
  width: 100%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.quick-topic-chip {
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.quick-topic-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ——— Main content ——— */
.web-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.web-panel {
  display: none !important;
}

.web-panel.active {
  display: flex !important;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ——— Chat panel ——— */
#panel-chat {
  padding: 0;
}

.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.chat-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-new-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-new-btn:hover {
  background: var(--accent-hover);
}

.chat-sidebar-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0;
  padding: 4px 0 0;
}

.chat-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.chat-history-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  border-radius: 8px;
}

.chat-history-row:hover .chat-delete-btn {
  opacity: 1;
}

.chat-history-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-history-item:hover {
  background: var(--border);
}

.chat-history-item.active {
  background: rgba(30, 58, 95, 0.12);
  color: #1e3a5f;
  font-weight: 500;
}

.chat-delete-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.chat-delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.15s ease;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: scaleIn 0.15s ease;
}

.modal-title {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  margin: 0 0 24px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s;
}

.modal-btn-cancel {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.modal-btn-cancel:hover {
  background: var(--border);
}

.modal-btn-danger {
  background: #dc2626;
  color: #fff;
}

.modal-btn-danger:hover {
  background: #b91c1c;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.chat-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding: 24px 24px 0;
}

.chat-messages {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  padding: 0 0 20px;
  isolation: isolate;
}

.welcome-bubble {
  padding: 18px 20px;
  background: var(--bg-bubble);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 24px;
}

.welcome-bubble p {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 85%;
}

.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

.message .avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-sidebar);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.message.user .avatar {
  background: var(--accent);
  color: #fff;
}

.message .bubble {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-bubble);
  border: 1px solid var(--border);
}

.message.user .bubble {
  background: #e8eef5;
  border-color: rgba(30, 58, 95, 0.3);
}

.message .bubble p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}

.typing-cursor {
  display: inline-block;
  animation: blink 0.7s step-end infinite;
  font-size: 13px;
  opacity: 0.7;
  margin-left: 1px;
}

@keyframes blink {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0; }
}

.related-chat-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  animation: slideDown 0.2s ease;
}

.related-chat-banner.hidden {
  display: none;
}

.related-chat-icon {
  flex-shrink: 0;
  font-size: 15px;
}

.related-chat-text {
  flex: 1;
  color: var(--text-muted);
}

.related-chat-text strong {
  color: var(--text);
}

.related-chat-view-btn {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.related-chat-view-btn:hover {
  background: var(--accent);
  color: #fff;
}

.related-chat-dismiss-btn {
  flex-shrink: 0;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
}

.related-chat-dismiss-btn:hover {
  color: var(--text);
  background: var(--border);
}

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

.chat-input-row {
  flex-shrink: 0;
  display: flex;
  gap: 12px;
  padding: 16px 0 20px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
  padding: 14px 18px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-bubble);
  color: var(--text);
  transition: border-color 0.2s;
}

.chat-input-row input::placeholder {
  color: var(--text-muted);
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-input-row button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 22px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-input-row button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat-input-row button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.send-icon {
  flex-shrink: 0;
}

/* ——— Document Library panel (reference design) ——— */
#panel-docs {
  padding: 0;
}

.doc-library-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.doc-filters {
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.doc-filters-jurisdiction {
  width: 180px;
  overflow-y: auto;
  padding: 20px 14px;
}

.doc-filters-category {
  width: 0;
  overflow: hidden;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.doc-filters-category.visible {
  width: 220px;
  border-left: 1px solid var(--border);
}

.doc-filters-category-inner {
  width: 220px;
  min-width: 220px;
  padding: 20px 14px;
  overflow-y: auto;
  height: 100%;
}

.filter-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.filter-hint.hidden {
  display: none;
}

#doc-category-options .filter-option {
  margin-bottom: 4px;
}

.filter-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  margin: 0 0 12px 0;
}

.filter-group {
  margin-bottom: 24px;
}

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

.filter-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: 6px;
  background: none;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-option:hover {
  color: var(--text);
  background: var(--border);
}

.filter-option.active {
  background: #1e3a5f;
  color: #fff;
}

.doc-library-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 24px 24px 0;
}

.doc-library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-shrink: 0;
}

.doc-search-wrap {
  flex: 1;
  max-width: 400px;
  position: relative;
}

.doc-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.doc-search-input {
  width: 100%;
  padding: 12px 14px 12px 44px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.doc-search-input::placeholder {
  color: var(--text-muted);
}

.doc-search-input:focus {
  outline: none;
  border-color: #1e3a5f;
}

.doc-count {
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.doc-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  align-content: start;
  align-items: start;
}

.doc-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-align: left;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.doc-card:hover {
  border-color: #1e3a5f;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.doc-card-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.doc-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px 0;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: calc(1.35em * 2);
}

.doc-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0 0 10px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: calc(1.45em * 2);
}

.doc-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: auto;
}

.doc-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.doc-detail-overlay.hidden {
  display: none !important;
}

.doc-detail-panel {
  background: var(--bg);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  position: relative;
}

.doc-detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-sidebar);
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  z-index: 2;
}

.doc-detail-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  padding: 24px 24px 8px;
}

.doc-detail-meta {
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 24px 16px;
}

.doc-detail-content {
  flex: 1;
  overflow: auto;
  padding: 0 24px 24px;
  font-size: 14px;
  line-height: 1.7;
}

.doc-detail-content p {
  margin: 0 0 12px 0;
}

.doc-detail-content table,
.doc-detail-content .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  display: table;
  table-layout: auto;
}

.doc-detail-content thead {
  display: table-header-group;
}

.doc-detail-content tbody {
  display: table-row-group;
}

.doc-detail-content tr {
  display: table-row;
}

.doc-detail-content th,
.doc-detail-content td {
  display: table-cell;
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.doc-detail-content th {
  background: var(--bg-sidebar);
  font-weight: 600;
  white-space: nowrap;
}

.doc-detail-content tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

.doc-detail-content tbody tr:hover {
  background: rgba(0, 0, 0, 0.03);
}

.doc-detail-content a {
  color: var(--accent);
  text-decoration: none;
}

.doc-detail-content a:hover {
  text-decoration: underline;
}
