:root {
  --bg: #f6f1e7;
  --surface: #fffdf9;
  --surface-soft: #fff6ea;
  --border: #e3d2b7;
  --text: #2f261d;
  --text-muted: #7f6b53;
  --brand: #8f5f2f;
  --brand-strong: #6f4721;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; background: radial-gradient(circle at top right, #fff8ec 0, var(--bg) 40%, #f1eadf 100%); color: var(--text); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(255, 253, 248, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(130%) blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid #d7c2a1;
  box-shadow: 0 8px 18px rgba(62, 37, 14, 0.16);
}
.brand-copy { min-width: 0; }
.brand-copy h1 { margin: 0; font-size: 18px; line-height: 1.15; white-space: nowrap; }
.brand-copy small { display: block; color: var(--text-muted); font-weight: 600; margin-top: 2px; }
.main-nav { display: flex; align-items: center; gap: 8px; }
.nav-link {
  text-decoration: none;
  color: var(--brand-strong);
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}
.nav-link:hover { background: #f6e9d3; border-color: #ead4b0; }
.nav-link.active {
  background: linear-gradient(120deg, var(--brand) 0, #bc8b54 100%);
  color: #fffef9;
  border-color: #8d5a2b;
  box-shadow: 0 8px 16px rgba(104, 61, 20, 0.22);
}
#app { max-width: 1320px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.breadcrumbs { font-size: 13px; color: var(--text-muted); }
.breadcrumbs a { color: var(--text-muted); text-decoration: none; font-weight: 600; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 6px 18px rgba(88, 69, 40, 0.06); }
.tabs-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tabs-main-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.tabs-main-actions button {
  border: 1px solid #8d5a2b;
  background: linear-gradient(120deg, #8f5f2f 0, #a6723a 100%);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}
.detail-tab {
  border: 1px solid #d4c1a6;
  background: #fff;
  color: #5e4a35;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
}
.detail-tab.active {
  border-color: #8d5a2b;
  background: linear-gradient(120deg, #8f5f2f 0, #a6723a 100%);
  color: #fffef9;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
#tab-enrichment .markdown-render,
#tab-enrichment .markdown-box {
  max-height: none;
  overflow: visible;
}
#tab-enrichment .enrichment-sidebar {
  max-height: none;
  overflow: visible;
}
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.kpis article { background: var(--surface-soft); border: 1px solid #e8d9c3; border-radius: 10px; padding: 10px; }
.kpis span { display: block; color: var(--text-muted); font-size: 12px; }
.kpis strong { font-size: 28px; }
h2, h3 { margin: 8px 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-top: 1px solid #efe2d1; padding: 8px; text-align: left; vertical-align: top; }
th { background: #f6ead7; cursor: pointer; border-top: none; }
td small { color: #7f6b54; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.grid2 article { background: #fff8ee; border: 1px solid #eadcc8; border-radius: 10px; padding: 10px; }
.grid2 span { display: block; color: #7f6b53; font-size: 12px; margin-bottom: 4px; }
.grid2 p { margin: 4px 0 0; color: #6d5a44; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 10px; }
.pager button { border: 1px solid #d4c1a6; background: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; }
a { color: #6e5739; font-weight: 600; }
.public-toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: #5f4d38; }
.public-toggle input { width: 16px; height: 16px; accent-color: #8f5f2f; }

.import-form { display: grid; gap: 10px; max-width: 580px; }
.import-form label { font-weight: 700; color: #5f4d38; display: grid; gap: 6px; }
.import-form input[type="file"] { border: 1px solid #d6c2a4; border-radius: 8px; padding: 8px; background: #fff; }
.import-actions { display: flex; gap: 10px; align-items: center; }
.import-actions button { border: 1px solid #8d5a2b; background: #8f5f2f; color: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 700; }
.import-status { font-size: 13px; color: #6a563f; }
.import-result { margin-top: 8px; font-size: 14px; }
.muted { color: #7f6b53; font-size: 13px; }

.enrichment-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(280px, 1fr);
  gap: 14px;
}
.enrichment-main,
.enrichment-sidebar {
  background: #fff9f0;
  border: 1px solid #e7d6bc;
  border-radius: 10px;
  padding: 12px;
}
.enrichment-sidebar {
  position: sticky;
  top: 86px;
  align-self: start;
  max-height: 72vh;
  overflow: auto;
}

.markdown-render {
  border: 1px solid #e0cfb4;
  background: #fffdf9;
  border-radius: 8px;
  padding: 12px;
  max-height: 360px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.45;
}
.markdown-render.compact {
  padding: 8px;
  max-height: 220px;
  font-size: 12px;
}
.markdown-render h1,
.markdown-render h2,
.markdown-render h3,
.markdown-render h4 { margin: 0 0 8px; }
.markdown-render p { margin: 0 0 8px; }
.markdown-render ul,
.markdown-render ol { margin: 0 0 10px 20px; }

.contacts-list {
  display: grid;
  gap: 8px;
}
.contact-card {
  border: 1px solid #e4d2b7;
  background: #fff;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  gap: 4px;
}
.contact-card strong { font-size: 13px; }
.contact-card span { color: #7f6b53; font-size: 12px; }
.contact-card p { margin: 0; font-size: 12px; word-break: break-word; }
.contact-card small { color: #6f5a41; font-size: 11px; display: flex; gap: 6px; }

.markdown-box {
  border: 1px solid #e0cfb4;
  background: #fff9f0;
  border-radius: 8px;
  padding: 10px;
  white-space: pre-wrap;
  max-height: 340px;
  overflow: auto;
  font-size: 12px;
}

.llc-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto 1fr;
  gap: 10px;
  align-items: end;
}
.llc-controls label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: #5f4d38;
  font-size: 13px;
}
.llc-controls input {
  border: 1px solid #d6c2a4;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}
.llc-controls button {
  border: 1px solid #8d5a2b;
  background: linear-gradient(120deg, #8f5f2f 0, #a6723a 100%);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}
.llc-table-wrap {
  margin-top: 10px;
  overflow: auto;
}

.hidden { display: none !important; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-info { font-weight: 700; color: var(--brand-strong); font-size: 13px; }
.logout-btn {
  border: 1px solid #8d5a2b;
  background: #fff;
  color: #6f4721;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 700;
}
.logout-btn:hover { background: #f6e9d3; }

.login-panel { max-width: 420px; margin: 64px auto; }
.login-panel input[type="text"],
.login-panel input[type="password"] {
  border: 1px solid #d6c2a4;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  width: 100%;
}

@media (max-width: 980px) {
  .kpis, .grid2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .brand-copy h1 { white-space: normal; font-size: 16px; }
  .main-nav { width: 100%; justify-content: flex-start; overflow-x: auto; padding-bottom: 4px; }
  .enrichment-layout { grid-template-columns: 1fr; }
  .enrichment-sidebar { position: static; max-height: none; }
  .tabs-header { flex-direction: column; align-items: stretch; }
  .tabs-main-actions { justify-content: flex-start; }
  .llc-controls { grid-template-columns: 1fr; align-items: stretch; }
}
