/* ============================================================
   InfiniteQ Brand Design System — R&S Doors Ownership Report
   ============================================================ */

:root {
  --color-primary:    #0A2540;
  --color-secondary:  #00B9A7;
  --color-accent:     #F5A623;
  --color-surface:    #FFFFFF;
  --color-surface-2:  #F5F7FA;
  --color-text:       #0A2540;
  --color-text-muted: #5A6B7C;
  --color-border:     #E1E7EE;
  --color-success:    #10B981;
  --color-danger:     #EF4444;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(10,37,64,.08), 0 1px 2px rgba(10,37,64,.04);
  --shadow-md: 0 4px 12px rgba(10,37,64,.12), 0 2px 4px rgba(10,37,64,.06);
  --shadow-lg: 0 8px 24px rgba(10,37,64,.16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--color-surface-2);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.site-header {
  background: var(--color-primary);
  color: #fff;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0 2rem;
  height: 64px;
  border-bottom: 3px solid var(--color-secondary);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-img {
  height: 38px;
  width: auto;
  display: block;
  filter: brightness(0) invert(1);
}

.header-title h1 {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
}

.header-meta {
  text-align: right;
}

.timestamp {
  font-size: .75rem;
  color: rgba(255,255,255,.6);
  white-space: nowrap;
}

/* ── Tab bar ── */
.tab-bar {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  display: flex;
  padding: 0 2rem;
  gap: 0;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: .75rem 1.5rem;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
  margin-bottom: -2px;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--color-primary); }

.tab-btn.active {
  color: var(--color-secondary);
  border-bottom-color: var(--color-secondary);
}

/* ── Error banner ── */
.error-banner {
  background: var(--color-danger);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 2rem;
  font-size: .875rem;
}

.error-banner.hidden { display: none; }

.retry-btn {
  background: rgba(255,255,255,.2);
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  padding: .25rem .75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  transition: background .15s;
}

.retry-btn:hover { background: rgba(255,255,255,.35); }

/* ── Main / sections ── */
.main-content {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-secondary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 3rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── KPI Cards (Dashboard) ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--color-secondary);
}

.kpi-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  margin-bottom: .4rem;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--color-primary);
  line-height: 1.1;
}

.kpi-sub {
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}

/* ── Section headings ── */
.section-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--color-border);
}

/* ── Data tables ── */
.data-table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.data-table th {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .6rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--color-surface-2); }

.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }

.card-table {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ── Dashboard top-owners bar ── */
.owner-rank { color: var(--color-text-muted); font-size: .8rem; font-weight: 700; }

.pct-cell { min-width: 120px; }

.pct-bar-bg {
  background: var(--color-surface-2);
  border-radius: 99px;
  height: 6px;
  margin-top: 4px;
  overflow: hidden;
}

.pct-bar-fill {
  height: 100%;
  background: var(--color-secondary);
  border-radius: 99px;
  transition: width .4s ease;
}

/* ── Shop grid ── */
.shops-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.shops-layout.detail-open {
  grid-template-columns: 1fr 400px;
}

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

.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary);
}

.sort-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .3rem .8rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.sort-btn:hover { border-color: var(--color-secondary); color: var(--color-secondary); }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .875rem;
}

.shop-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.125rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s, border-color .2s;
  position: relative;
}

.shop-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--color-secondary);
}

.shop-card.selected {
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 2px rgba(0,185,167,.2);
}

.shop-card-number {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  margin-bottom: .3rem;
}

.shop-card-name {
  font-size: .9rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .5rem;
  line-height: 1.3;
}

.shop-card-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--color-secondary);
  font-family: var(--font-mono);
}

.shop-card-shares {
  font-size: .75rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}

.holding-badge {
  display: inline-block;
  background: var(--color-accent);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .15rem .4rem;
  border-radius: var(--radius-sm);
  position: absolute;
  top: .75rem;
  right: .75rem;
}

/* ── Detail panel ── */
.detail-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  position: relative;
  align-self: start;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

.detail-panel.hidden { display: none; }

.close-btn {
  position: absolute;
  top: .75rem;
  right: .75rem;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background .15s;
  line-height: 1;
}

.close-btn:hover { background: var(--color-surface-2); }

.detail-heading {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: .25rem;
  padding-right: 2rem;
}

.detail-sub {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--color-border);
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem .75rem;
  margin-bottom: 1rem;
}

.meta-item-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}

.meta-item-value {
  font-size: .88rem;
  font-weight: 600;
  color: var(--color-text);
  font-family: var(--font-mono);
}

.detail-section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  margin: 1rem 0 .5rem;
}

/* ── Owners tab ── */
.owners-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.owners-layout.detail-open {
  grid-template-columns: 1fr 400px;
}

.owner-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .875rem 1.125rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, border-color .2s;
  margin-bottom: .5rem;
}

.owner-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-secondary); }
.owner-card.selected { border-color: var(--color-secondary); box-shadow: 0 0 0 2px rgba(0,185,167,.2); }

.owner-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.owner-card-name { font-size: .95rem; font-weight: 700; color: var(--color-primary); }
.owner-card-value { font-size: .9rem; font-weight: 800; color: var(--color-secondary); font-family: var(--font-mono); }

.owner-pct-label { font-size: .75rem; color: var(--color-text-muted); margin-bottom: .3rem; }

/* ── Matrix ── */
.matrix-wrapper { overflow-x: auto; }

.matrix-table {
  border-collapse: collapse;
  font-size: .78rem;
  white-space: nowrap;
  min-width: 100%;
}

.matrix-table th {
  background: var(--color-primary);
  color: rgba(255,255,255,.85);
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .5rem .75rem;
  text-align: right;
  position: sticky;
  top: 0;
  z-index: 10;
}

.matrix-table th.row-header {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 20;
  min-width: 160px;
}

.matrix-table td {
  padding: .45rem .75rem;
  border: 1px solid var(--color-border);
  text-align: right;
  font-family: var(--font-mono);
  font-size: .78rem;
}

.matrix-table td.row-label {
  text-align: left;
  font-family: var(--font);
  font-weight: 600;
  background: var(--color-surface);
  position: sticky;
  left: 0;
  color: var(--color-primary);
  border-right: 2px solid var(--color-border);
}

.matrix-table tr:hover td { background: rgba(0,185,167,.04); }
.matrix-table tr:hover td.row-label { background: var(--color-surface-2); }

.cell-nonzero { background: rgba(16,185,129,.06); color: var(--color-primary); }
.cell-large   { background: rgba(16,185,129,.18); font-weight: 700; }
.cell-xlarge  { background: rgba(16,185,129,.32); font-weight: 800; }

.matrix-table .total-row td { background: var(--color-surface-2); font-weight: 700; border-top: 2px solid var(--color-border); }
.matrix-table .total-row td.row-label { background: var(--color-surface-2); font-weight: 800; }

.matrix-table .total-col { background: rgba(245,166,35,.08); font-weight: 700; border-left: 2px solid var(--color-border); }
.matrix-table .total-row .total-col { background: rgba(245,166,35,.18); font-weight: 900; color: var(--color-primary); }

/* ── Footer ── */
.site-footer {
  background: var(--color-primary);
  color: rgba(255,255,255,.55);
  font-size: .75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .875rem 2rem;
  gap: 1rem;
  border-top: 2px solid var(--color-secondary);
  flex-wrap: wrap;
}

.footer-brand { color: rgba(255,255,255,.7); font-weight: 600; }
.footer-ts { font-variant-numeric: tabular-nums; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .site-header { grid-template-columns: auto 1fr; padding: 0 1rem; }
  .header-meta { display: none; }
  .main-content { padding: 1rem; }
  .tab-btn { padding: .65rem .9rem; font-size: .8rem; }
  .tab-bar { padding: 0 .5rem; overflow-x: auto; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .shops-layout.detail-open { grid-template-columns: 1fr; }
  .owners-layout.detail-open { grid-template-columns: 1fr; }
  .shop-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .detail-meta-grid { grid-template-columns: 1fr; }
}

/* ── Map tab ── */
.map-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  height: calc(100vh - 200px);
  min-height: 700px;
}

.map-layout.detail-open {
  grid-template-columns: 1fr 380px;
}

.map-canvas-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: 100%;
}

#cy {
  width: 100%;
  height: 100%;
  min-height: 700px;
}

.map-legend {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: rgba(255,255,255,.93);
  backdrop-filter: blur(4px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .7rem 1rem;
  z-index: 10;
  box-shadow: var(--shadow-sm);
  font-size: .78rem;
  pointer-events: none;
}

.legend-title {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  margin-bottom: .5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  color: var(--color-text);
  margin-bottom: .3rem;
  font-size: .76rem;
}

.legend-item:last-child { margin-bottom: 0; }

.legend-shape {
  display: inline-block;
  flex-shrink: 0;
}

.person-shape {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #00B9A7;
}

.shop-shape {
  width: 13px;
  height: 13px;
  background: #0A2540;
  border-radius: 2px;
}

.holding-shape {
  width: 13px;
  height: 13px;
  background: #F5A623;
  clip-path: polygon(50% 0%,100% 50%,50% 100%,0% 50%);
}

.legend-edge-line {
  display: inline-block;
  width: 22px;
  height: 2px;
  background: #CBD5E0;
  border-radius: 1px;
}

.map-reset-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .35rem .85rem;
  font-size: .78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color .15s, color .15s;
  box-shadow: var(--shadow-sm);
}

.map-reset-btn:hover {
  border-color: var(--color-secondary);
  color: var(--color-secondary);
}

@media (max-width: 768px) {
  .map-layout { height: calc(100vh - 160px); }
  .map-layout.detail-open { grid-template-columns: 1fr; }
}
