:root {
  color-scheme: light;
  --bg: #f4f1e9;
  --surface: #fffdf8;
  --surface-2: #eee9df;
  --ink: #171916;
  --muted: #676a63;
  --border: #d8d2c5;
  --accent: #ad2f24;
  --accent-dark: #7d1d17;
  --accent-soft: #f5dcd7;
  --green: #1f7656;
  --green-soft: #dceee5;
  --warning: #a45a12;
  --shadow: 0 12px 28px rgba(39, 31, 22, 0.08);
  --radius: 18px;
}

body.dark {
  color-scheme: dark;
  --bg: #151714;
  --surface: #1e211d;
  --surface-2: #292d27;
  --ink: #f3f0e8;
  --muted: #aeb2a8;
  --border: #3c4139;
  --accent: #e26154;
  --accent-dark: #f07a6e;
  --accent-soft: #482924;
  --green: #69c69e;
  --green-soft: #203c30;
  --warning: #efad62;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.site-header {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  min-height: clamp(280px, 28vw, 410px);
  overflow: hidden;
  padding: 34px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--border);
  background: #f8f2e8;
}

.hero-art {
  position: absolute;
  inset: 0;
  z-index: -3;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.hero-shade {
  position: absolute;
  inset: 0;
  z-index: -2;
  background: linear-gradient(90deg,
    rgba(255, 253, 248, .99) 0%,
    rgba(255, 253, 248, .96) 34%,
    rgba(255, 253, 248, .72) 49%,
    rgba(255, 253, 248, .08) 72%);
}

body.dark .hero-art { filter: brightness(.55) saturate(.8); }
body.dark .hero-shade {
  background: linear-gradient(90deg,
    rgba(21, 23, 20, .99) 0%,
    rgba(21, 23, 20, .96) 36%,
    rgba(21, 23, 20, .72) 53%,
    rgba(21, 23, 20, .18) 76%);
}

.header-copy {
  width: min(610px, 54%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 12px;
}

.brand-lockup .eyebrow,
.brand-lockup h1 { margin-bottom: 0; }

.brand-icon {
  width: clamp(66px, 7vw, 94px);
  height: clamp(66px, 7vw, 94px);
  flex: 0 0 auto;
  object-fit: contain;
  border: 1px solid color-mix(in srgb, var(--border) 68%, transparent);
  border-radius: 23%;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  box-shadow: 0 12px 28px rgba(39, 31, 22, .13);
}

.site-header .subtitle {
  max-width: 570px;
  font-size: clamp(.98rem, 1.4vw, 1.1rem);
  line-height: 1.55;
}

.site-header .header-actions { margin-top: 20px; }
.site-header .button.ghost {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(8px);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 5vw, 3.8rem); letter-spacing: -0.055em; line-height: .95; }
h2 { margin-bottom: 6px; font-size: 1.25rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 6px; font-size: 1rem; }
.subtitle { max-width: 760px; margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 7px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .15em; }
.optional { color: var(--muted); font-weight: 400; }
.header-actions, .toolbar-buttons, .filter-group, .dialog-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.app-shell { padding: 20px clamp(14px, 3vw, 40px) 32px; }
.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 16px;
}

.search-control, .file-control, label { display: grid; gap: 7px; font-size: .83rem; font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
.filter-group { align-items: center; min-height: 42px; padding: 0 4px; }
.filter-group label { display: flex; align-items: center; gap: 6px; font-weight: 650; }
.filter-group input { width: auto; accent-color: var(--accent); }

.button {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 14px;
  font-weight: 750;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 22%, transparent); }
.button.ghost { background: var(--surface); color: var(--ink); border-color: var(--border); }
.button.danger-button { background: var(--accent); color: white; }
.button.full { width: 100%; }
.text-button { border: 0; background: transparent; padding: 7px 0; text-align: left; font-weight: 750; }
.text-button.danger { color: var(--accent); }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.summary-card span { color: var(--muted); font-size: .8rem; font-weight: 700; }
.summary-card strong { font-size: 1.45rem; }

.workspace { display: grid; grid-template-columns: 290px minmax(420px, 1fr) 290px; gap: 16px; align-items: stretch; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.add-panel, .detail-panel { padding: 18px; }
.panel-heading, .detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.local-badge, .source-badge { display: inline-flex; border-radius: 999px; padding: 5px 8px; background: var(--green-soft); color: var(--green); font-size: .68rem; font-weight: 800; white-space: nowrap; }
form { display: grid; gap: 11px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.swap-button { width: 38px; height: 30px; justify-self: center; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 900; }
.panel-divider { height: 1px; margin: 19px 0; background: var(--border); }
.export-section { display: grid; gap: 9px; }
.export-section p, .admin-content p { color: var(--muted); font-size: .86rem; line-height: 1.5; }
.status { min-height: 1.2em; margin: 0; color: var(--green); font-size: .82rem; font-weight: 650; }
.status.error { color: var(--accent); }

.graph-panel { position: relative; min-height: 680px; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
#cy { width: 100%; height: 100%; min-height: 680px; background-image: radial-gradient(var(--border) 0.7px, transparent 0.7px); background-size: 18px 18px; }
.graph-message { position: absolute; inset: 50% auto auto 50%; z-index: 4; transform: translate(-50%, -50%); color: var(--muted); font-weight: 750; }
.graph-legend { position: absolute; left: 12px; bottom: 12px; z-index: 3; display: flex; gap: 12px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); color: var(--muted); font-size: .72rem; font-weight: 700; }
.graph-legend span { display: flex; align-items: center; gap: 5px; }
.legend-node { width: 12px; height: 12px; border: 2px solid var(--ink); border-radius: 50%; background: var(--surface-2); }
.legend-node.local { border-color: var(--green); background: var(--green-soft); }
.legend-line { width: 20px; border-top: 2px solid var(--muted); }
.legend-line.cycle { border-top: 2px dashed var(--accent); }

.empty-details { display: grid; place-items: center; text-align: center; min-height: 300px; color: var(--muted); }
.empty-details h2 { color: var(--ink); }
.empty-icon { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 1.8rem; }
.detail-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.detail-stats div { display: grid; gap: 3px; padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
.detail-stats span { color: var(--muted); font-size: .7rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.detail-stats strong { font-size: 1.2rem; }
.quick-actions { display: grid; gap: 8px; margin-bottom: 20px; }
.record-section { margin-top: 14px; }
.record-list { display: grid; gap: 7px; list-style: none; margin: 0; padding: 0; }
.record-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; }
.record-item button { border: 0; background: transparent; color: var(--accent); font-weight: 900; }
.record-meta { display: block; color: var(--muted); font-size: .72rem; margin-top: 2px; }
.empty-record { color: var(--muted); font-size: .84rem; }

.admin-panel { margin-top: 16px; padding: 0; overflow: hidden; box-shadow: none; }
.admin-panel summary { padding: 15px 18px; cursor: pointer; font-weight: 800; }
.admin-content { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(190px, .6fr) auto; align-items: end; gap: 14px; padding: 0 18px 18px; border-top: 1px solid var(--border); }
.admin-content > div { padding-top: 16px; }
.admin-content .status { grid-column: 1 / -1; }
code { border-radius: 5px; padding: 2px 5px; background: var(--surface-2); }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 18px clamp(18px, 4vw, 56px); color: var(--muted); border-top: 1px solid var(--border); font-size: .78rem; }

dialog { width: min(520px, calc(100% - 28px)); border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 25px 70px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.46); backdrop-filter: blur(3px); }
.dialog-card { position: relative; padding: 24px; }
.dialog-card.compact { gap: 16px; }
.dialog-card p, .dialog-card li { color: var(--muted); line-height: 1.55; }
.dialog-close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; }
.dialog-actions { justify-content: flex-end; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 280px 1fr; }
  .detail-panel { grid-column: 1 / -1; }
  .detail-panel #personDetails { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .detail-heading, .detail-stats, .quick-actions { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .site-header {
    align-items: flex-end;
    min-height: 500px;
    padding-top: 210px;
  }
  .hero-art { object-position: 68% center; }
  .hero-shade {
    background: linear-gradient(0deg,
      rgba(255, 253, 248, .99) 0%,
      rgba(255, 253, 248, .96) 44%,
      rgba(255, 253, 248, .35) 72%,
      rgba(255, 253, 248, .02) 100%);
  }
  body.dark .hero-shade {
    background: linear-gradient(0deg,
      rgba(21, 23, 20, .99) 0%,
      rgba(21, 23, 20, .96) 44%,
      rgba(21, 23, 20, .46) 74%,
      rgba(21, 23, 20, .08) 100%);
  }
  .header-copy { width: 100%; }
  .brand-lockup { gap: 12px; }
  .brand-icon { width: 72px; height: 72px; }
  .toolbar { grid-template-columns: 1fr; align-items: stretch; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .graph-panel { min-height: 590px; }
  #cy { min-height: 590px; }
  .add-panel { order: 2; }
  .graph-panel { order: 1; }
  .detail-panel { order: 3; }
  .admin-content { grid-template-columns: 1fr; align-items: stretch; }
  .detail-panel #personDetails { display: block; }
}

@media (max-width: 520px) {
  .site-header { min-height: 470px; padding: 190px 16px 24px; }
  .hero-art { object-position: 72% center; }
  .brand-lockup { align-items: flex-end; }
  .brand-icon { width: 62px; height: 62px; }
  h1 { font-size: clamp(2.35rem, 13vw, 3.2rem); }
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary-card { padding: 11px 12px; }
  .form-row { grid-template-columns: 1fr; }
  .graph-legend { right: 12px; }
  footer { flex-direction: column; }
}
