:root {
  --navy: #1a2744;
  --teal: #2c5f8a;
  --teal-light: #3a7aad;
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #e5e8ee;
  --text: #1a2744;
  --muted: #6b7280;
  --success: #059669;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(26, 39, 68, 0.08), 0 4px 16px rgba(26, 39, 68, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100%;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(26,39,68,0.04);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.app-header .brand img {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.app-header .brand .titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-header .brand .titles .brand-title {
  font-size: 1.35rem;
  line-height: 1.15;
  color: var(--navy);
  font-weight: 700;
}

.app-header .brand .titles span {
  font-size: 0.75rem;
  color: var(--muted);
}

.app-header .nav-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.readonly-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  border: 1px solid var(--border);
}

.container-wide {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.footer-note {
  margin-top: 2rem;
  margin-bottom: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.1s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover { background: var(--teal-light); }
.btn-ghost {
  background: #fff;
  color: var(--navy);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f8fafc; }
.btn.btn-sm {
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

/* —— Chat —— */
.chat-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem 1.15rem;
  margin-bottom: 1.25rem;
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.chat-head h2 {
  font-size: 1.1rem;
  color: var(--navy);
  margin-bottom: 0.15rem;
}

.chat-honesty {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 280px;
  overflow: auto;
  padding: 0.25rem 0 0.75rem;
  min-height: 72px;
}

.chat-bubble {
  max-width: 92%;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: var(--navy);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.chat-bubble.bot .chat-meta {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.prompt-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--teal);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}
.prompt-chip:hover {
  border-color: var(--teal);
  background: #f0f9ff;
}

.chat-ask {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chat-ask textarea {
  width: 100%;
  min-height: 220px;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.5;
  resize: vertical;
  background: #fff;
  color: var(--navy);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.chat-ask textarea:focus {
  outline: 2px solid rgba(44, 95, 138, 0.25);
  border-color: var(--teal);
}

.chat-ask-bar {
  display: flex;
  justify-content: flex-end;
}

/* —— List toolbar —— */
.list-panel { margin-bottom: 1rem; }

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.toolbar-left input[type="search"] {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--card);
  min-height: 40px;
}
.toolbar-left input[type="search"]:focus {
  outline: 2px solid rgba(44, 95, 138, 0.25);
  border-color: var(--teal);
}

.icon-menu-wrap { position: relative; }

.icon-btn {
  appearance: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  color: var(--navy);
  cursor: pointer;
  position: relative;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] {
  border-color: var(--teal);
  background: #f0f9ff;
  color: var(--teal);
}

.filter-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}

.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  width: min(340px, calc(100vw - 2rem));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(26, 39, 68, 0.14);
  padding: 0.9rem 1rem;
}

.sort-popover {
  width: 220px;
  padding: 0.5rem;
}

.popover-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.filter-group label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.filter-group select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  min-height: 38px;
}

.bv-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.55rem;
}

.bv-checks label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
}

.inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.chip-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
}
.chip-btn.active {
  background: #e0f2fe;
  color: var(--teal);
  border-color: #7dd3fc;
}
.chip-btn:hover { border-color: var(--teal); }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.popover-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.sort-opt {
  appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--navy);
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}
.sort-opt:hover { background: #f0f9ff; }
.sort-opt.active { background: #e0f2fe; color: var(--teal); }

/* —— Table —— */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 220px);
}

table.suppliers {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.suppliers thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
}

table.suppliers th,
table.suppliers td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

table.suppliers th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

table.suppliers td.num,
table.suppliers th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.suppliers tbody tr {
  cursor: pointer;
  transition: background 0.1s ease;
}
table.suppliers tbody tr:hover { background: #f0f9ff; }
table.suppliers tbody tr.active { background: #e0f2fe; }
table.suppliers tbody tr.chat-hit { background: #ecfdf5; }

.supplier-name { font-weight: 700; color: var(--navy); }
.supplier-sub { font-size: 0.75rem; color: var(--muted); font-weight: 500; }

.bv-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  background: #eef2ff;
  color: #3730a3;
  margin: 0.1rem 0.15rem 0.1rem 0;
}
.bv-tag.holding { background: #e0f2fe; color: var(--teal); }
.bv-tag.opco { background: #ecfdf5; color: #047857; }
.bv-tag.propco { background: #fef3c7; color: #b45309; }
.bv-tag.bouw { background: #fce7f3; color: #9d174d; }

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 39, 68, 0.35);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100vw);
  height: 100%;
  background: var(--card);
  box-shadow: -8px 0 32px rgba(26, 39, 68, 0.15);
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 {
  font-size: 1.15rem;
  color: var(--navy);
  flex: 1;
  min-width: 0;
}
.drawer-body {
  padding: 1.1rem 1.25rem;
  overflow: auto;
  flex: 1;
}
.drawer-close {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--navy);
  line-height: 1;
}
.drawer-close:hover { background: #f8fafc; }

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.detail-meta .field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.detail-meta .field label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.detail-meta .field .val {
  font-weight: 600;
  color: var(--navy);
  font-size: 0.95rem;
}

.bv-breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}
.bv-breakdown th,
.bv-breakdown td {
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.bv-breakdown th {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
}
.bv-breakdown td.num { text-align: right; font-variant-numeric: tabular-nums; }

.loading, .error-box, .empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}
.error-box { color: var(--danger); }

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--navy);
  color: #fff;
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  z-index: 100;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 640px) {
  .chat-input-row { flex-direction: column; }
  .toolbar-left input[type="search"] { max-width: none; width: 100%; }
  .detail-meta { grid-template-columns: 1fr; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
