:root {
  color-scheme: light;
  --ink: #1e2530;
  --muted: #6b7785;
  --line: #dde3e9;
  --paper: #f9fbfd;
  --canvas: #edf1f5;
  --surface: #ffffff;
  --panel: #f3f6f9;
  --surface-soft: #f3f6f9;
  --surface-warm: #f7f9fc;
  --detail-start: rgba(249, 251, 253, 0.9);
  --detail-end: rgba(249, 251, 253, 0.97);
  --detail-glow: #d4e4f7;
  --row-hover: rgba(255, 255, 255, 0.75);
  --status-positive-bg: #e3f0e8;
  --status-empty-bg: #eef1f4;
  --accent: #2e6fba;
  --accent-dark: #245a99;
  --accent-soft: #dbeaf8;
  --plum: #2c3e50;
  --green: #3d8b63;
  --shadow: 0 22px 70px rgba(30, 45, 65, 0.1);
}

[data-theme="dark"] {
  --ink: #ffffff;
  --muted: #a0a8b2;
  --line: #2e343b;
  --paper: #141820;
  --canvas: #0e1118;
  --surface: #1c2028;
  --panel: #171b23;
  --surface-soft: #222730;
  --surface-warm: #1a1e26;
  --detail-start: rgba(20, 24, 32, 0.92);
  --detail-end: rgba(20, 24, 32, 0.98);
  --detail-glow: #1c2e4a;
  --row-hover: rgba(255, 255, 255, 0.05);
  --status-positive-bg: #1a2e24;
  --status-empty-bg: #252930;
  --accent: #1d5fa0;
  --accent-dark: #174d84;
  --accent-soft: #1e2d42;
  --plum: #c8d4e0;
  --green: #6dbf8b;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(46, 111, 186, 0.07), transparent 32%),
    linear-gradient(135deg, #edf1f5, #e0e6ed);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 19px;
  line-height: 1.5;
}

body[data-theme="dark"] {
  color-scheme: dark;
  background:
    radial-gradient(circle at 10% 10%, rgba(91, 158, 235, 0.08), transparent 32%),
    linear-gradient(135deg, #151922, #0c0f16);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1500px, calc(100% - 32px));
  min-height: min(780px, calc(100vh - 48px));
  margin: 24px auto;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid rgba(30, 50, 80, 0.08);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 31px;
  height: 31px;
  position: relative;
  display: inline-block;
}

.brand-mark span {
  width: 18px;
  height: 18px;
  position: absolute;
  border: 2px solid var(--accent);
  border-radius: 50%;
}

.brand-mark span:nth-child(1) {
  top: 0;
  left: 0;
}

.brand-mark span:nth-child(2) {
  top: 0;
  right: 0;
}

.brand-mark span:nth-child(3) {
  bottom: 0;
  left: 7px;
}

.privacy-label {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 650;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.theme-icon {
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
}

.privacy-dot {
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(61, 139, 99, 0.12);
}

.user-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--plum);
  font-size: 16px;
  font-weight: 750;
}

.workspace {
  --people-column: 330px;
  --patterns-column: 300px;
  min-height: 700px;
  display: grid;
  grid-template-columns: var(--people-column) minmax(0, 1fr) var(--patterns-column);
}

.workspace[data-people-collapsed="true"] {
  --people-column: 62px;
}

.workspace[data-patterns-collapsed="true"] {
  --patterns-column: 62px;
}

.people-panel,
.patterns-panel {
  min-width: 0;
  position: relative;
}

.people-panel {
  padding: 38px 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.people-panel-content,
.patterns-panel-content {
  padding-top: 25px;
}

.panel-toggle {
  width: 34px;
  height: 34px;
  position: absolute;
  top: 17px;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.panel-toggle:hover {
  color: var(--accent-dark);
  border-color: var(--accent);
}

.people-panel-toggle {
  right: 17px;
}

.patterns-panel-toggle {
  left: 17px;
}

.workspace[data-people-collapsed="true"] .people-panel,
.workspace[data-patterns-collapsed="true"] .patterns-panel {
  padding-right: 0;
  padding-left: 0;
}

.workspace[data-people-collapsed="true"] .people-panel-content,
.workspace[data-patterns-collapsed="true"] .patterns-panel-content {
  display: none;
}

.workspace[data-people-collapsed="true"] .people-panel-toggle,
.workspace[data-patterns-collapsed="true"] .patterns-panel-toggle {
  right: 14px;
  left: 14px;
}

.panel-heading {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 23px;
}

.sort-control {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sort-control select {
  max-width: 145px;
  padding: 7px 9px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  text-transform: none;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: inherit;
  color: var(--ink);
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
  letter-spacing: -0.03em;
}

h1 span {
  margin-left: 5px;
  color: var(--muted);
  font-family: inherit;
  font-size: 22px;
  font-weight: 400;
}

.add-person-form {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 5px 18px rgba(30, 50, 80, 0.04);
}

.add-person-form input {
  min-width: 0;
  flex: 1;
  padding: 9px 10px;
  border: 0;
  outline: none;
  background: transparent;
}

.add-person-form button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 15px;
  border: 0;
  border-radius: 9px;
  color: white;
  background: var(--accent);
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
}

.add-person-form button:hover,
.save-button:hover {
  background: var(--accent-dark);
}

.form-error {
  min-height: 17px;
  margin: 6px 2px 3px;
  color: #c0392b;
  font-size: 16px;
}

.people-list {
  display: grid;
  gap: 7px;
}

.person-row {
  width: 100%;
  display: grid;
  grid-template-columns: 43px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: 150ms ease;
}

.person-row:hover {
  background: var(--row-hover);
}

.person-row.selected {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(30, 50, 80, 0.06);
}

.avatar,
.large-avatar {
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 50%;
  font-weight: 800;
}

.avatar {
  width: 43px;
  height: 43px;
  font-size: 16px;
}

.person-row-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.person-row-copy strong,
.person-row-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-row-copy strong {
  font-size: 16px;
}

.person-row-copy span {
  color: var(--muted);
  font-size: 16px;
}

.row-intensity {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 700;
}

.row-arrow {
  color: #9eaab6;
}

.detail-panel {
  position: relative;
  padding: 55px 65px;
  background:
    linear-gradient(var(--detail-start), var(--detail-end)),
    radial-gradient(circle at 80% 10%, var(--detail-glow), transparent 36%);
}

.patterns-panel {
  padding: 38px 24px;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.patterns-panel .metrics-panel {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.patterns-panel .metrics-grid {
  grid-template-columns: 1fr;
}

.patterns-context {
  margin: -8px 0 22px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.person-detail {
  max-width: 610px;
  margin: 0 auto;
}

.person-header {
  display: flex;
  align-items: center;
  gap: 19px;
  margin-bottom: 34px;
}

.person-title {
  min-width: 0;
  flex: 1;
}

.person-actions,
.history-actions {
  display: flex;
  gap: 8px;
}

.quiet-button,
.danger-button {
  padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
}

.quiet-button:hover {
  background: var(--surface-soft);
}

.danger-button {
  color: var(--accent-dark);
}

.danger-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.large-avatar {
  width: 64px;
  height: 64px;
  border: 1px solid #b8d4ee;
  font-family: inherit;
  font-size: 22px;
}

.person-header h2 {
  margin: 0;
  font-size: 31px;
}

.interaction-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(30, 50, 80, 0.06);
}

.interaction-editor {
  margin-bottom: 20px;
}

.general-notes-card {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.general-notes-card summary {
  padding: 8px 16px;
  cursor: pointer;
  font-size: inherit;
  color: var(--muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.general-notes-card summary::-webkit-details-marker {
  display: none;
}

.general-notes-card summary::before {
  content: "▸";
  font-size: 16px;
  transition: transform 0.15s;
}

.general-notes-card[open] summary::before {
  transform: rotate(90deg);
}

.notes-preview {
  font-style: italic;
  color: var(--muted);
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.general-notes-card[open] .notes-preview {
  display: none;
}

.general-notes-card .field.notes-field {
  padding: 0 16px 4px;
}

.notes-status {
  margin: 0;
  padding: 0 16px 8px;
  font-size: 16px;
  color: var(--muted);
  min-height: 1.2em;
}

.metrics-panel {
  margin-bottom: 24px;
  padding: 22px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.metrics-heading h3 {
  margin: 0 0 17px;
  font-size: 18px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.metric-period {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.metric-period > strong {
  display: block;
  margin-bottom: 13px;
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
}

.metric-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.metric-row span {
  color: var(--muted);
  font-size: 16px;
}

.metric-row b {
  color: var(--ink);
  font-size: 16px;
  white-space: nowrap;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 25px 28px 18px;
}

.card-title-row.compact {
  padding: 12px 20px 6px;
}

.card-title-row h3,
.form-heading h3 {
  margin: 0;
  color: var(--ink);
  font-size: 19px;
}

.status-pill {
  padding: 6px 10px;
  color: var(--green);
  background: var(--status-positive-bg);
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
}

.status-pill.empty {
  color: var(--muted);
  background: var(--status-empty-bg);
}

.interaction-summary {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  margin: 0 28px 28px;
  padding: 22px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.summary-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.interaction-summary strong {
  color: var(--ink);
  font-family: inherit;
  font-size: 18px;
}

.summary-metric {
  min-width: 88px;
  padding-left: 22px;
  border-left: 1px solid var(--line);
  text-align: right;
}

.summary-metric strong {
  font-size: 24px;
}

.intensity-display strong {
  color: var(--ink);
  font-size: 32px;
  line-height: 0.8;
}

.summary-metric small {
  margin-left: 3px;
  color: var(--muted);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
}

.interaction-summary.empty .summary-metric strong {
  color: var(--muted);
}

.interaction-form {
  padding: 14px 20px 16px;
  background: var(--surface-warm);
  border-top: 1px solid var(--line);
}

.form-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.form-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1.15fr 0.9fr 0.75fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  font-size: 19px;
}

.notes-field {
  margin-top: 10px;
}

.notes-field > span small,
.notes-field > small {
  color: var(--muted);
  font-weight: 500;
}

.notes-field textarea {
  width: 100%;
  padding: 10px 12px;
  resize: vertical;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  font-family: inherit;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.55;
}

.notes-field textarea:focus {
  border-color: rgba(46, 111, 186, 0.7);
  box-shadow: 0 0 0 3px rgba(46, 111, 186, 0.12);
}

.history-section {
  padding-bottom: 40px;
}

.history-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-heading h3 {
  margin: 0;
  font-size: 22px;
}

.history-heading h3 span {
  margin-left: 4px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
}

.history-order {
  color: var(--muted);
  font-size: 16px;
}

.interactions-list {
  display: grid;
  gap: 12px;
}

.history-card {
  padding: 21px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: 0 8px 24px rgba(30, 50, 80, 0.04);
}

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.history-meta {
  display: grid;
  gap: 3px;
}

.history-meta strong {
  color: var(--ink);
  font-family: inherit;
  font-size: 19px;
}

.history-meta span,
.history-notes-label {
  color: var(--muted);
  font-size: 16px;
}

.history-intensity {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
}

.history-notes-label {
  display: none;
}

.history-notes {
  margin: 6px 0 18px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.history-empty {
  padding: 30px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 14px;
  text-align: center;
}

.history-empty strong {
  color: var(--ink);
}

.history-empty p {
  margin: 6px 0 0;
  font-size: 16px;
}

.field input:focus,
.add-person-form:focus-within {
  border-color: rgba(46, 111, 186, 0.7);
  box-shadow: 0 0 0 3px rgba(46, 111, 186, 0.12);
}

input[type="date"]::-webkit-clear-button {
  display: none;
}

.date-shortcuts {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.date-shortcuts button {
  padding: 3px 10px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.date-shortcuts button:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.number-input-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.number-input-wrap input {
  min-width: 0;
  border: 0;
  border-radius: 0;
  font-family: inherit;
  font-weight: 600;
}

.number-input-wrap > span {
  padding-right: 15px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.form-footer .form-error {
  margin: 0;
}

.save-button {
  flex: 0 0 auto;
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.empty-state {
  max-width: 400px;
  margin: 150px auto 0;
  text-align: center;
}

.empty-icon {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  margin: 0 auto 17px;
  color: var(--muted);
  background: var(--surface-soft);
  border-radius: 50%;
  font-size: 29px;
  font-weight: 300;
}

.empty-state h2 {
  margin-bottom: 8px;
  font-size: 26px;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.6;
}

.sr-only {
  width: 1px;
  height: 1px;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .page-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .workspace {
    --people-column: 1fr;
    --patterns-column: 1fr;
    grid-template-columns: 1fr;
  }

  .workspace[data-people-collapsed="true"],
  .workspace[data-patterns-collapsed="true"] {
    --people-column: 1fr;
    --patterns-column: 1fr;
  }

  .people-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .patterns-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .workspace[data-people-collapsed="true"] .people-panel,
  .workspace[data-patterns-collapsed="true"] .patterns-panel {
    min-height: 62px;
  }

  .detail-panel {
    padding: 42px 24px;
  }
}

@media (max-width: 520px) {
  .privacy-label {
    display: none;
  }

  .topbar {
    padding: 0 20px;
  }

  .people-panel {
    padding: 30px 20px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .interaction-summary {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .summary-metric {
    padding: 18px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
    text-align: left;
  }
}

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  padding: 36px 32px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(30, 50, 80, 0.06);
  text-align: center;
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  color: var(--ink);
}

.auth-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 16px;
}

.auth-form {
  display: grid;
  gap: 12px;
  text-align: left;
}

.auth-form .field input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font: inherit;
}

.auth-form .field input:focus {
  border-color: var(--accent);
}

.auth-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.auth-buttons .save-button {
  flex: 1;
}

.auth-buttons .quiet-button {
  flex: 1;
}
