:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1b2130;
  --ink-2: #4a5468;
  --muted: #7b8496;
  --line: #e3e6ec;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e8edfc;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --warn: #b35c00;
  --navy: #1f2a44;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 28, 45, .06), 0 2px 8px rgba(20, 28, 45, .05);
  --st-lead: #868e96;
  --st-prospect: #1c7ed6;
  --st-customer: #2b8a3e;
  --st-partner: #7048e8;
  --st-inactive: #adb5bd;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans CJK TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: .5rem .9rem; font: inherit; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: #c5cad3; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #3049b8; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: .32rem .65rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
label { display: grid; gap: .25rem; font-size: .85rem; font-weight: 550; color: var(--ink-2); }
input[type=range] { padding: 0; }
input[type=checkbox] { width: auto; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--navy); padding: 1rem; }
.login-box { background: var(--panel); padding: 2rem; border-radius: 14px; width: min(380px, 100%); display: grid; gap: 1rem; box-shadow: var(--shadow); }
.login-box p { margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff;
  display: flex; align-items: center; gap: 1.2rem; padding: .55rem 1.2rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: inherit; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 1.4rem; color: var(--ink); }
.logo { width: 26px; height: 18px; border-radius: 4px; background: var(--accent); position: relative; display: inline-block; }
.logo::before { content: ""; position: absolute; left: 4px; top: 5px; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.logo::after { content: ""; position: absolute; left: 14px; top: 5px; width: 8px; height: 2px; background: #fff; box-shadow: 0 4px 0 #fff; }
.nav { display: flex; gap: .2rem; flex: 1; }
.nav a { color: #c8d0e3; padding: .4rem .7rem; border-radius: 7px; font-weight: 550; }
.nav a:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, .07); }
.nav a.active { color: #fff; background: rgba(255, 255, 255, .14); }
.top-actions { display: flex; gap: .4rem; align-items: center; }
.topbar .btn:not(.primary) { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .15); color: #fff; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 220px; padding: .3rem; display: grid;
}
.menu-pop a, .menu-pop button {
  padding: .5rem .7rem; border-radius: 6px; color: var(--ink); background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--bg); text-decoration: none; }

main { max-width: 1240px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head h1 { flex: 1; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); gap: .5rem; }
.panel-body { padding: .4rem 1rem 1rem; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; font-size: .9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { padding: 1rem 1.1rem; }
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- name cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.namecard {
  position: relative; display: flex; flex-direction: column; gap: .5rem; padding: 1rem 1.1rem .9rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  aspect-ratio: 1.75 / 1; color: inherit; overflow: hidden; border-top: 4px solid var(--stage, var(--st-lead));
  transition: transform .12s, box-shadow .12s;
}
a.namecard:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(20, 28, 45, .1); }
.namecard .top { display: flex; gap: .75rem; align-items: center; }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 1rem; background: var(--av, #5c7cfa); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.4rem; }
.namecard .who { min-width: 0; }
.namecard .name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.namecard .role { font-size: .85rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.namecard .company { font-weight: 600; font-size: .9rem; }
.namecard .lines { font-size: .82rem; color: var(--ink-2); display: grid; gap: .1rem; margin-top: auto; }
.namecard .lines div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.namecard .foot { display: flex; align-items: center; justify-content: space-between; font-size: .78rem; color: var(--muted); gap: .5rem; }

.badge {
  display: inline-flex; align-items: center; font-size: .72rem; font-weight: 650; padding: .12rem .5rem; border-radius: 999px;
  background: color-mix(in srgb, var(--c, #868e96) 13%, white); color: color-mix(in srgb, var(--c, #868e96) 85%, black);
  text-transform: capitalize; white-space: nowrap;
}
.st-lead { --c: var(--st-lead); --stage: var(--st-lead); }
.st-prospect { --c: var(--st-prospect); --stage: var(--st-prospect); }
.st-customer { --c: var(--st-customer); --stage: var(--st-customer); }
.st-partner { --c: var(--st-partner); --stage: var(--st-partner); }
.st-inactive { --c: var(--st-inactive); --stage: var(--st-inactive); }
.b-planned { --c: #1c7ed6; }
.b-done { --c: #2b8a3e; }
.b-cancelled { --c: #868e96; }
.b-overdue { --c: #c92a2a; }
.tag { font-size: .72rem; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: .05rem .4rem; color: var(--ink-2); }
.tags { display: flex; gap: .25rem; flex-wrap: wrap; }
.dots { display: inline-flex; gap: 2px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }

/* ---------- contact detail ---------- */
.detail { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .detail { grid-template-columns: 1fr; } }
.profile { padding: 1.2rem; display: grid; gap: .9rem; }
.profile .head { display: flex; gap: .9rem; align-items: center; }
.profile .head h1 { font-size: 1.3rem; }
.kv { display: grid; grid-template-columns: 82px 1fr; gap: .35rem .6rem; font-size: .9rem; }
.kv dt { color: var(--muted); font-size: .8rem; padding-top: .1rem; }
.kv dd { margin: 0; word-break: break-word; }
.card-photo { width: 100%; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; display: block; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.profile-note h3 { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .3rem; }
.notes { white-space: pre-wrap; font-size: .9rem; background: var(--bg); border-radius: 8px; padding: .6rem .75rem; }

.rel-list { display: grid; gap: .4rem; }
.rel { display: flex; gap: .6rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.rel:last-child { border-bottom: 0; }
.rel .avatar { width: 32px; height: 32px; font-size: .8rem; }
.rel .txt { flex: 1; min-width: 0; font-size: .9rem; }
.rel .type { font-size: .78rem; font-weight: 650; color: var(--accent); }

/* ---------- timeline / meetings ---------- */
.timeline { display: grid; gap: 0; }
.mtg { display: grid; grid-template-columns: 74px 1fr; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mtg:last-child { border-bottom: 0; }
.mtg:hover .mtg-title { color: var(--accent); }
.mtg .when { text-align: center; border-radius: 8px; background: var(--bg); padding: .35rem .2rem; align-self: start; }
.mtg .when .d { font-size: 1.25rem; font-weight: 700; line-height: 1.1; }
.mtg .when .mo { font-size: .7rem; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.mtg .when .t { font-size: .74rem; color: var(--ink-2); }
.mtg.future .when { background: var(--accent-soft); }
.mtg-title { font-weight: 650; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.mtg-meta { font-size: .82rem; color: var(--ink-2); }
.mtg-out { font-size: .85rem; margin-top: .25rem; white-space: pre-wrap; color: var(--ink); }
.mtg-next { font-size: .82rem; color: var(--warn); margin-top: .15rem; }
.kind { font-size: 1rem; }
.day-head { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 1rem 0 .2rem; border-bottom: 1px solid var(--line); }
.day-head:first-child { padding-top: .4rem; }

.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; padding: .35rem .85rem; border-radius: 7px; cursor: pointer; color: var(--ink-2); }
.tabs button.active { background: var(--accent); color: #fff; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.cal-head h2 { min-width: 170px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.calendar .dow { font-size: .75rem; font-weight: 700; color: var(--muted); padding: .35rem .5rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--bg); }
.calendar .day { min-height: 104px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: .3rem; display: flex; flex-direction: column; gap: 3px; cursor: pointer; background: var(--panel); }
.calendar .day:hover { background: #fafbfd; }
.calendar .day.other { background: #fafbfc; color: var(--muted); }
.calendar .day .n { font-size: .8rem; font-weight: 650; }
.calendar .day.today .n { background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.chip { font-size: .72rem; padding: .1rem .35rem; border-radius: 4px; background: var(--accent-soft); color: #23399b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.done { background: #e6f4ea; color: #1e6b31; }
.chip.cancelled { background: #f1f3f5; color: #868e96; text-decoration: line-through; }
@media (max-width: 700px) { .calendar .day { min-height: 64px; } .chip { font-size: 0; height: 6px; padding: 0; } }

/* network */
.network-wrap { position: relative; height: calc(100vh - 210px); min-height: 420px; overflow: hidden; }
.network-wrap svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.network-wrap text { font-size: 11px; fill: var(--ink); pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.network-wrap line { stroke: #c3c9d4; stroke-width: 1.4; }
.network-wrap .edge-label { font-size: 9.5px; fill: var(--muted); }
.network-wrap circle { stroke: #fff; stroke-width: 2; cursor: pointer; }
.legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-right: .3rem; vertical-align: -1px; }

/* ---------- modal ---------- */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink); }
dialog::backdrop { background: rgba(18, 24, 38, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-body { padding: 1rem 1.2rem; display: grid; gap: .8rem; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .9rem 1.2rem; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }
.modal-foot .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem .8rem; margin: 0; }
legend { font-size: .8rem; font-weight: 700; color: var(--muted); padding: 0 .3rem; text-transform: uppercase; letter-spacing: .03em; }
.close-x { background: none; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* contact picker */
.picker { position: relative; }
.picker .selected { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .35rem; }
.picker .sel { background: var(--accent-soft); color: #23399b; border-radius: 999px; padding: .15rem .3rem .15rem .6rem; font-size: .82rem; display: inline-flex; align-items: center; gap: .2rem; font-weight: 550; }
.picker .sel button { border: 0; background: none; cursor: pointer; color: inherit; font-size: 1rem; line-height: 1; padding: 0 .2rem; }
.picker .opts { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto; z-index: 5; }
.picker .opt { padding: .45rem .65rem; cursor: pointer; font-size: .9rem; }
.picker .opt:hover, .picker .opt.hl { background: var(--accent-soft); }
.picker .opt small { color: var(--muted); }

.photo-preview { max-width: 100%; max-height: 180px; border-radius: 8px; border: 1px solid var(--line); display: block; }

.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%) translateY(150%); background: var(--navy); color: #fff;
  padding: .6rem 1.1rem; border-radius: 9px; font-weight: 550; transition: transform .2s, opacity .2s; z-index: 100; pointer-events: none;
  opacity: 0;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { gap: .5rem; padding: .5rem .8rem; }
  .brand-text { display: none; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .top-actions { margin-left: auto; }
  main { padding: 1rem .8rem 4rem; }
  .namecard { aspect-ratio: auto; min-height: 170px; }
}
