:root {
  --canvas: #f6f8fc;
  --canvas-deep: #e9eef6;
  --paper: #ffffff;
  --paper-soft: #f8fafc;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c8d4e3;
  --accent: #1d4ed8;
  --accent-strong: #1e3a8a;
  --accent-soft: #dbeafe;
  --accent-pale: #eff6ff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #475569;
  --warning-soft: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .045), 0 5px 15px rgba(15, 23, 42, .04);
  --shadow-md: 0 16px 42px rgba(15, 23, 42, .11);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 80% -15%, #dbeafe 0, transparent 29rem), var(--canvas);
  font: 15px/1.52 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid rgba(29, 78, 216, .28); outline-offset: 2px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.85rem, 3.2vw, 2.55rem); letter-spacing: -.055em; line-height: 1.08; }
h2 { margin: 0; color: var(--ink); font-size: 1.02rem; letter-spacing: -.018em; line-height: 1.25; }
h3 { margin: 0; font-size: .93rem; }
small, .muted { color: var(--muted); }

.auth-body { display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 13% 12%, #dbeafe 0, transparent 30rem), radial-gradient(circle at 90% 95%, #e2e8f0 0, transparent 28rem), #f8fafc; }
.auth-card { width: min(100%, 438px); padding: 2.1rem; border: 1px solid rgba(203, 213, 225, .9); border-radius: var(--radius-lg); background: rgba(255, 255, 255, .92); box-shadow: var(--shadow-md); }
.auth-brand { display: flex; align-items: center; gap: .65rem; margin-bottom: 2.25rem; color: var(--ink); font-weight: 750; letter-spacing: -.025em; }
.auth-card h1 { max-width: 12ch; }
.auth-card > p { margin-bottom: 1.55rem; color: var(--muted); }

.site-header { position: sticky; z-index: 10; top: 0; border-bottom: 1px solid rgba(203, 213, 225, .9); background: rgba(248, 250, 252, .94); backdrop-filter: blur(14px); }
.site-header-inner { display: flex; align-items: center; gap: 1.9rem; width: min(1440px, calc(100% - 3rem)); min-height: 72px; margin: 0 auto; }
.brand { display: inline-flex; flex: 0 0 auto; align-items: center; gap: .65rem; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-mark { display: inline-grid; width: 31px; height: 31px; place-items: center; border-radius: 10px; color: #fff; background: linear-gradient(145deg, #2563eb, #1e3a8a); box-shadow: 0 5px 12px rgba(29, 78, 216, .24); font-size: .98rem; font-weight: 800; letter-spacing: -.06em; }
.brand-copy { display: grid; gap: 0; line-height: 1.08; }
.brand-copy strong { letter-spacing: -.035em; }
.brand-copy small { color: var(--muted); font-size: .67rem; font-weight: 600; letter-spacing: .055em; text-transform: uppercase; }
.primary-nav { display: flex; align-items: center; gap: .15rem; min-width: 0; }
.primary-nav a { display: inline-flex; align-items: center; gap: .42rem; padding: .55rem .7rem; border-radius: 8px; color: #475569; font-size: .88rem; font-weight: 650; white-space: nowrap; }
.primary-nav a span { color: #94a3b8; font-size: .95rem; }
.primary-nav a:hover { color: var(--ink); background: #eef2f7; }
.primary-nav a.is-active { color: var(--accent-strong); background: var(--accent-soft); }
.primary-nav a.is-active span { color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 1rem; margin-left: auto; white-space: nowrap; }
.header-add { display: inline-flex; align-items: center; gap: .36rem; padding: .56rem .78rem; border-radius: 9px; color: #fff; background: var(--accent); box-shadow: 0 4px 10px rgba(29, 78, 216, .18); font-size: .85rem; font-weight: 720; }
.header-add:hover { color: #fff; background: var(--accent-strong); }
.header-add span:first-child { font-size: 1.1rem; font-weight: 400; line-height: .7; }
.link-button { padding: .35rem; border: 0; color: #64748b; background: transparent; font-size: .86rem; }
.link-button:hover { color: var(--danger); }

.container { width: min(1240px, calc(100% - 2.5rem)); margin: 0 auto; }
.app-main { padding: 2.25rem 0 4rem; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.4rem; margin-bottom: 1.7rem; }
.page-heading > div > p { max-width: 640px; margin: .35rem 0 0; color: var(--muted); }
.eyebrow { display: block; margin-bottom: .45rem; color: var(--accent); font-size: .71rem; font-weight: 780; letter-spacing: .115em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: .7rem; color: var(--muted); font-size: .84rem; font-weight: 650; }
.back-link:hover { color: var(--accent); }

.button, button:not(.link-button):not(.link-danger):not(.subtle-danger) { display: inline-flex; align-items: center; justify-content: center; gap: .42rem; min-height: 39px; padding: .58rem .85rem; border: 1px solid var(--accent); border-radius: 9px; color: #fff; background: var(--accent); box-shadow: 0 2px 5px rgba(29, 78, 216, .15); font-size: .87rem; font-weight: 710; line-height: 1.1; transition: transform .16s ease, background .16s ease, box-shadow .16s ease; }
.button:hover, button:not(.link-button):not(.link-danger):not(.subtle-danger):hover { color: #fff; background: var(--accent-strong); box-shadow: 0 5px 14px rgba(29, 78, 216, .22); transform: translateY(-1px); }
.button-large { min-height: 44px; padding: .7rem 1rem; }
.secondary { border-color: #cbd8eb !important; color: #334155 !important; background: #eef4ff !important; box-shadow: none !important; }
.secondary:hover { background: #dbeafe !important; }
.danger { border-color: var(--danger) !important; background: var(--danger) !important; }
.danger:hover { background: #991b1b !important; }
.compact-button { min-height: 33px !important; padding: .43rem .62rem !important; font-size: .78rem !important; }
.actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.actions form { margin: 0; }

.messages { display: grid; gap: .5rem; margin-bottom: 1rem; }
.message { padding: .75rem .9rem; border: 1px solid #bfdbfe; border-radius: var(--radius-sm); color: #1e3a8a; background: #eff6ff; box-shadow: var(--shadow-sm); }
.message.error { border-color: #fecaca; color: #991b1b; background: var(--danger-soft); }

.panel { padding: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .94); box-shadow: var(--shadow-sm); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin-bottom: 1rem; }
.panel-heading > div { display: flex; align-items: center; gap: .62rem; }
.panel-icon { display: inline-grid; width: 28px; height: 28px; place-items: center; border-radius: 8px; color: var(--accent-strong); background: var(--accent-soft); font-size: .86rem; font-weight: 800; }
.danger-icon { color: #991b1b; background: #fee2e2; }
.birthday-icon { color: #1e40af; background: #dbeafe; }
.count-chip, .panel-caption { display: inline-flex; min-width: 26px; min-height: 24px; align-items: center; justify-content: center; padding: .15rem .44rem; border-radius: 999px; color: #475569; background: #eef2f7; font-size: .72rem; font-weight: 750; }
.panel-caption { color: var(--muted); background: transparent; }
.dashboard-grid, .detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.dashboard-grid > .panel { min-height: 205px; }
.full { grid-column: 1 / -1; }

.task-row { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.task-row:first-of-type { padding-top: 0; }
.task-row:last-child { padding-bottom: 0; border-bottom: 0; }
.task-copy { display: grid; gap: .13rem; min-width: 0; }
.task-copy strong { font-size: .9rem; line-height: 1.35; }
.task-copy a { width: fit-content; font-size: .84rem; font-weight: 600; }
.task-copy small { font-size: .77rem; }
.timeline { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.timeline:last-child { border-bottom: 0; }

.search-form { position: relative; display: flex; align-items: center; gap: .5rem; margin: 0 0 1.15rem; padding: .35rem; border: 1px solid var(--line-strong); border-radius: 13px; background: var(--paper); box-shadow: var(--shadow-sm); }
.search-form:focus-within { border-color: rgba(29, 78, 216, .62); box-shadow: 0 0 0 3px rgba(29, 78, 216, .12); }
.search-symbol { padding-left: .45rem; color: #64748b; font-size: 1.5rem; line-height: 1; }
.search-form input { border: 0; box-shadow: none; }
.search-form input:focus { outline: 0; }
.search-form button { flex: 0 0 auto; }
.search-state { margin: -.35rem 0 1rem; color: var(--muted); font-size: .87rem; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: .9rem; }
.person-card { display: flex; min-height: 204px; flex-direction: column; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: rgba(255,255,255,.9); box-shadow: var(--shadow-sm); transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.person-card:hover { color: var(--ink); border-color: #b7c8e6; box-shadow: 0 12px 25px rgba(30, 58, 138, .12); transform: translateY(-2px); }
.person-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; }
.person-avatar { display: inline-grid; width: 36px; height: 36px; place-items: center; overflow: hidden; border-radius: 12px; color: #1d4ed8; background: linear-gradient(145deg, #dbeafe, #eff6ff); font-size: .78rem; font-weight: 800; letter-spacing: -.04em; }
.person-avatar.large { width: 47px; height: 47px; border-radius: 14px; font-size: .95rem; }
.person-status { padding: .2rem .45rem; border-radius: 999px; color: #1e40af; background: #eff6ff; font-size: .68rem; font-weight: 760; }
.person-status.archive { color: #475569; background: var(--warning-soft); }
.person-card h2 { margin-bottom: .22rem; font-size: 1.03rem; }
.person-card p { margin-bottom: .65rem; color: var(--muted); font-size: .82rem; }
.next-contact { display: block; margin-top: auto; padding-top: .75rem; font-size: .76rem; }
.badge { display: inline-block; margin: .07rem .18rem .1rem 0; padding: .18rem .42rem; border-radius: 999px; color: #1e40af; background: #eaf2ff; font-size: .7rem; font-weight: 670; line-height: 1.25; }
.badge.archive { color: #475569; background: var(--warning-soft); }

.stack-form { display: grid; gap: .82rem; }
.stack-form p { display: grid; gap: .32rem; margin: 0; color: var(--ink-soft); font-size: .89rem; font-weight: 650; }
.stack-form p label { display: block; }
.form-spaced { margin-top: .3rem; }
.field { display: grid; gap: .35rem; min-width: 0; color: var(--ink-soft); font-size: .87rem; font-weight: 680; }
.field > label { color: var(--ink-soft); }
.required { margin-left: .12rem; color: var(--danger); }
input, select, textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 9px; color: var(--ink); background: #fff; padding: .64rem .7rem; line-height: 1.25; transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
input::placeholder, textarea::placeholder { color: #94a3b8; }
textarea { min-height: 5.2rem; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #9fb0c7; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px rgba(29, 78, 216, .14); }
input[type="checkbox"] { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }
.errorlist { display: grid; gap: .2rem; margin: 0; padding: 0; color: var(--danger); font-size: .78rem; font-weight: 600; list-style: none; }
.narrow { max-width: 680px; margin: 0 auto; }
.simple-editor { margin-top: 1.5rem; }
.simple-editor h1 { margin-bottom: 1.25rem; }

.person-editor { max-width: 1180px; }
.editor-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.4rem; }
.editor-heading h1 { margin-bottom: .25rem; }
.editor-heading p { max-width: 650px; margin: 0; color: var(--muted); }
.editor-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(295px, .8fr); gap: 1rem; align-items: start; }
.editor-main { display: grid; gap: 1rem; }
.editor-side { position: sticky; top: 92px; display: grid; gap: 1rem; }
.form-section { padding: 1.3rem; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.94); box-shadow: var(--shadow-sm); }
.form-section-heading { display: flex; align-items: flex-start; gap: .72rem; margin-bottom: 1.1rem; }
.form-section-heading > span { display: inline-grid; flex: 0 0 auto; width: 27px; height: 27px; place-items: center; border-radius: 8px; color: var(--accent-strong); background: var(--accent-soft); font-size: .66rem; font-weight: 820; letter-spacing: .02em; }
.form-section-heading h2 { margin: .03rem 0 .18rem; }
.form-section-heading p { margin: 0; color: var(--muted); font-size: .79rem; line-height: 1.45; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.person-name-grid { grid-template-columns: 1fr 1fr; }
.birthday-grid { max-width: 440px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: .9rem; }
.field-wide { grid-column: 1 / -1; }
.stack-fields { display: grid; gap: .78rem; }
.tag-picker .field > div { display: grid; gap: .45rem; max-height: 370px; overflow: auto; padding-right: .25rem; }
.tag-picker .field > div > div { min-width: 0; }
.tag-picker .field label:not(:first-child), .tag-picker .field > div label { display: flex; align-items: center; gap: .48rem; padding: .42rem .48rem; border-radius: 8px; color: var(--ink-soft); font-size: .8rem; font-weight: 590; }
.tag-picker .field > div label:hover { background: var(--accent-pale); }
.tag-picker .text-action { display: inline-block; margin-top: .8rem; }
.editor-save-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; padding: .75rem .9rem; border: 1px solid #bfdbfe; border-radius: 12px; background: #eff6ff; color: #334155; font-size: .8rem; }

.person-title { display: flex; align-items: center; gap: .85rem; }
.person-title h1 { margin: 0 0 .22rem; }
.person-title p { margin: 0; color: var(--muted); }
.detail-grid { align-items: start; }
.detail-grid .panel > h2 { margin-bottom: .85rem; }
.facts { display: grid; grid-template-columns: minmax(145px, 26%) 1fr; gap: .7rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .82rem; }
.facts dd { margin: 0; color: var(--ink-soft); }
details { margin-top: .9rem; padding-top: .8rem; border-top: 1px solid var(--line); }
summary { color: var(--accent); cursor: pointer; font-size: .84rem; font-weight: 680; }
details .stack-form { margin-top: .85rem; }
.inline-form { display: inline-flex; align-items: center; gap: .45rem; margin: .2rem 0; }
.inline-form input, .inline-form select { width: auto; }

.organization-layout { grid-template-columns: minmax(0, 1.25fr) minmax(310px, .75fr); }
.organization-list { display: grid; gap: .15rem; }
.organization-row { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.organization-row:last-child { border-bottom: 0; }
.organization-row strong { font-size: .92rem; }
.organization-row p { margin: .18rem 0 0; color: var(--muted); font-size: .82rem; }
.empty-state { margin: .7rem 0 0; color: var(--muted); }

.tag-layout { grid-template-columns: minmax(0, 1.35fr) minmax(305px, .65fr); }
.tag-categories { display: grid; gap: 1rem; }
.tag-category { padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tag-category:last-child { padding-bottom: 0; border-bottom: 0; }
.tag-category-heading { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .6rem; }
.tag-category-heading h3 { color: var(--ink-soft); }
.text-action { color: var(--accent); font-size: .78rem; font-weight: 680; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag-manage-chip { display: inline-flex; align-items: center; gap: .28rem; padding: .26rem .3rem .26rem .54rem; border: 1px solid #cbd8eb; border-radius: 999px; color: #1e3a8a; background: #eff6ff; font-size: .76rem; font-weight: 650; }
.tag-manage-chip a { color: #2563eb; font-size: .85rem; }
.tag-manage-chip form { margin: 0; }
.link-danger { display: inline-grid; width: 19px; height: 19px; place-items: center; padding: 0; border: 0; border-radius: 50%; color: #b4534b; background: transparent; line-height: 1; }
.link-danger:hover { color: #fff; background: var(--danger); }
.subtle-danger { margin-top: .65rem; padding: 0; border: 0; color: #a13f37; background: transparent; font-size: .76rem; font-weight: 650; }
.subtle-danger:hover { color: var(--danger); text-decoration: underline; }
.create-tags-panel h3 { margin: .1rem 0 .7rem; color: var(--ink-soft); }
.section-divider { height: 1px; margin: 1.2rem 0; background: var(--line); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%); }

@media (max-width: 1080px) {
  .site-header-inner { gap: 1rem; width: min(100% - 2rem, 1240px); }
  .primary-nav { gap: 0; }
  .primary-nav a { padding: .55rem .48rem; }
  .primary-nav a span { display: none; }
  .editor-layout { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 860px) {
  .site-header-inner { flex-wrap: wrap; gap: .65rem 1rem; padding: .75rem 0; }
  .primary-nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: .05rem; }
  .header-actions { margin-left: auto; }
  .container { width: min(100% - 1.5rem, 720px); }
  .app-main { padding-top: 1.45rem; }
  .editor-layout, .organization-layout, .tag-layout { grid-template-columns: 1fr; }
  .editor-side { position: static; grid-template-columns: 1fr 1fr; }
  .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
  .dashboard-grid > .panel { min-height: auto; }
}

@media (max-width: 620px) {
  body { font-size: 14px; }
  .site-header-inner { width: min(100% - 1.1rem, 720px); min-height: 0; }
  .brand-copy small { display: none; }
  .header-add span:last-child { display: none; }
  .header-add { width: 34px; height: 34px; padding: 0; justify-content: center; }
  .header-actions { gap: .45rem; }
  .primary-nav a { padding: .48rem .63rem; font-size: .82rem; }
  .page-heading, .editor-heading { align-items: flex-start; flex-direction: column; }
  .page-heading .button, .editor-heading .button { width: 100%; }
  .list-grid { grid-template-columns: 1fr; }
  .person-card { min-height: 178px; }
  .form-grid, .person-name-grid, .birthday-grid, .editor-side { grid-template-columns: 1fr; }
  .birthday-grid { max-width: none; }
  .field-wide { grid-column: auto; }
  .form-section, .panel { padding: 1rem; border-radius: 14px; }
  .editor-save-bar { align-items: stretch; flex-direction: column; }
  .editor-save-bar .button { width: 100%; }
  .facts { grid-template-columns: 1fr; gap: .14rem; }
  .facts dd { margin-bottom: .55rem; }
  .task-row { align-items: stretch; flex-direction: column; }
  .task-row form, .task-row button { width: 100%; }
  .search-form { gap: .25rem; }
  .search-form button { min-height: 35px; padding: .5rem .65rem; }
  .auth-card { padding: 1.55rem; }
}
