:root {
  --green: #087054;
  --green-mid: #075943;
  --green-deep: #034739;
  --green-soft: #eaf4f0;
  --gold: #c5a15c;
  --gold-deep: #a57c31;
  --ink: #17221f;
  --muted: #66756f;
  --quiet: #96a29e;
  --line: #dde5e2;
  --line-strong: #cbd6d2;
  --page: #f5f8f7;
  --danger: #c73b3b;
  --danger-soft: #fff0f0;
  --radius: 6px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--page); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(8,112,84,.18); outline-offset: 1px; }
[hidden] { display: none !important; }
svg { width: 19px; height: 19px; stroke-width: 1.8; }

.crm-shell { display: grid; min-height: 100vh; grid-template-columns: 178px minmax(0, 1fr); }
.crm-sidebar { display: flex; position: sticky; top: 0; height: 100vh; flex-direction: column; padding: 26px 10px 18px; color: #fff; background: var(--green-deep); }
.crm-brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 30px; color: #fff; text-decoration: none; }
.crm-brand strong { font-family: Georgia, "Songti SC", serif; font-size: 19px; font-weight: 600; }
.crm-mark { display: grid; width: 25px; height: 25px; flex: 0 0 auto; grid-template-columns: 1fr 1fr; gap: 2px; transform: rotate(45deg); }
.crm-mark i { border: 1px solid var(--gold); }
.crm-sidebar nav { display: grid; gap: 4px; }
.crm-sidebar nav button {
  display: flex;
  height: 48px;
  align-items: center;
  gap: 12px;
  padding: 0 13px;
  color: rgba(255,255,255,.72);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font-size: 13px;
  text-align: left;
}
.crm-sidebar nav button:hover, .crm-sidebar nav button.is-active { color: #fff; background: rgba(255,255,255,.11); }
.crm-sidebar nav button.is-active { box-shadow: inset 3px 0 var(--gold); }
.sidebar-back { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 12px 13px; color: rgba(255,255,255,.65); font-size: 11px; text-decoration: none; }
.sidebar-back:hover { color: #fff; }

.crm-main { min-width: 0; }
.crm-topbar {
  display: flex;
  position: sticky;
  z-index: 20;
  top: 0;
  height: 66px;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.crm-topbar > div { display: flex; align-items: center; gap: 10px; }
.crm-topbar h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 23px; font-weight: 500; }
.icon-button { display: inline-grid; width: 38px; height: 38px; place-items: center; padding: 0; background: transparent; border: 1px solid transparent; border-radius: 50%; }
.icon-button:hover { background: var(--page); border-color: var(--line); }
.topbar-user { position: relative; }
.topbar-user > .icon-button b { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; color: #fff; background: var(--danger); border: 2px solid #fff; border-radius: 10px; font-size: 9px; line-height: 13px; }
#userMenu { display: flex; height: 40px; align-items: center; gap: 8px; padding: 0 6px; background: transparent; border: 0; }
#userMenu > span { display: grid; width: 30px; height: 30px; place-items: center; color: #fff; background: var(--green); border-radius: 50%; font-size: 11px; }
#userMenu strong { font-size: 12px; }
#userMenu svg { width: 14px; }

.crm-view { padding: 24px 26px 72px; }
.command-row { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.command-actions { display: flex; gap: 10px; }
.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; color: var(--green-deep); background: #fff; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 12px; font-weight: 650; }
.button:hover { border-color: var(--green); }
.button-primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: var(--green-deep); }
.button-danger { color: var(--danger); }
.search-control { display: flex; width: min(380px, 100%); height: 42px; align-items: center; gap: 8px; padding: 0 12px; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
.search-control svg { width: 17px; color: var(--quiet); }
.search-control input { width: 100%; min-width: 0; background: transparent; border: 0; outline: none; font-size: 12px; }

.today-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; }
.reminder-feed, .summary-rail section, .data-surface, .import-workspace, .account-profile, .account-actions, .admin-panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.reminder-group + .reminder-group { border-top: 8px solid var(--page); }
.reminder-group > header { display: flex; min-height: 52px; align-items: center; justify-content: space-between; padding: 0 17px; border-bottom: 1px solid var(--line); }
.reminder-group > header h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; }
.reminder-group > header h2 b { display: grid; min-width: 20px; height: 20px; place-items: center; padding: 0 6px; color: #fff; background: var(--green); border-radius: 10px; font-size: 10px; }
.reminder-group.is-overdue > header h2 { color: var(--danger); }
.reminder-group.is-overdue > header h2 b { background: var(--danger); }
.reminder-group > header button { color: var(--muted); background: none; border: 0; font-size: 11px; }
.reminder-row { display: grid; min-height: 68px; align-items: center; grid-template-columns: minmax(150px, 1.3fr) minmax(170px, 1.5fr) 110px 120px 170px; border-bottom: 1px solid var(--line); }
.reminder-row:last-child { border-bottom: 0; }
.reminder-row > div { min-width: 0; padding: 12px 14px; }
.reminder-row strong, .entity-main strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.reminder-row small, .entity-main small { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.reminder-date { color: var(--muted); font-size: 11px; }
.reminder-amount { color: var(--gold-deep); font-family: Georgia, serif; font-size: 15px; text-align: right; }
.reminder-status { display: flex; align-items: center; justify-content: flex-end; gap: 6px; color: var(--green); font-size: 11px; }
.is-overdue .reminder-status { color: var(--danger); }
.reminder-actions { display: flex; justify-content: flex-end; gap: 4px; }
.reminder-actions button { padding: 7px 8px; color: var(--green); background: transparent; border: 0; font-size: 10px; }
.reminder-actions button:last-child { color: var(--muted); }
.empty-list { display: grid; min-height: 300px; place-items: center; color: var(--muted); font-size: 12px; }

.summary-rail { display: grid; align-content: start; gap: 18px; }
.summary-rail section { overflow: hidden; }
.summary-rail header { display: flex; min-height: 50px; align-items: center; justify-content: space-between; padding: 0 15px; border-bottom: 1px solid var(--line); }
.summary-rail h2 { margin: 0; font-size: 13px; }
.summary-rail header small { color: var(--quiet); font-size: 9px; }
.summary-rail dl { margin: 0; padding: 8px 15px 14px; }
.summary-rail dl > div { display: flex; min-height: 39px; align-items: center; justify-content: space-between; }
.summary-rail dt { color: var(--muted); font-size: 11px; }
.summary-rail dd { margin: 0; font-size: 13px; font-weight: 700; }
.summary-rail .gold dd { color: var(--gold-deep); }
.mini-list p { margin: 0; padding: 24px 15px; color: var(--quiet); font-size: 11px; text-align: center; }
.mini-list > div { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; border-bottom: 1px solid var(--line); font-size: 11px; }
.mini-list > div:last-child { border-bottom: 0; }

.data-surface > header { display: flex; align-items: flex-end; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.data-surface h2, .page-heading h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 24px; font-weight: 500; }
.data-surface header p, .page-heading p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.data-surface header > span { color: var(--muted); font-size: 10px; }
.entity-row { display: grid; min-height: 68px; align-items: center; grid-template-columns: minmax(180px, 1.4fr) 1fr 1fr 120px 38px; padding: 0 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.entity-row:last-child { border-bottom: 0; }
.entity-row:hover { background: #f8fbfa; }
.entity-row > div { min-width: 0; padding: 11px 10px; }
.entity-row .entity-value { color: var(--muted); font-size: 11px; }
.entity-row .entity-value.gold { color: var(--gold-deep); font-family: Georgia, serif; font-size: 14px; text-align: right; }
.status-text { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font-size: 10px; }
.status-text.is-warning { color: #a66c17; }
.status-text.is-muted { color: var(--muted); }

.page-heading { margin-bottom: 24px; }
.import-dropzone { display: grid; min-height: 310px; place-items: center; align-content: center; gap: 12px; padding: 30px; background: #fff; border: 1px dashed #9fb8af; border-radius: var(--radius); text-align: center; }
.import-dropzone.is-dragging { background: var(--green-soft); border-color: var(--green); }
.import-dropzone > svg { width: 40px; height: 40px; color: var(--green); }
.import-dropzone strong { font-size: 16px; }
.import-dropzone span { margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.import-workspace { overflow: hidden; }
.import-workspace > header, .import-workspace > footer { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.import-workspace > footer { border-top: 1px solid var(--line); border-bottom: 0; }
.import-workspace h3 { margin: 0; font-size: 14px; }
.import-workspace header p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.mapping-fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 14px 18px; background: var(--page); border-bottom: 1px solid var(--line); }
.mapping-fields label { display: grid; gap: 5px; color: var(--muted); font-size: 9px; }
.mapping-fields select { height: 34px; padding: 0 8px; background: #fff; border: 1px solid var(--line); border-radius: 3px; font-size: 10px; }
.table-scroll { overflow: auto; }
.import-workspace table { width: 100%; min-width: 820px; border-collapse: collapse; }
.import-workspace th, .import-workspace td { padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 10px; text-align: left; }
.import-workspace th { color: var(--muted); background: #fff; }
.import-workspace tr.has-warning { background: #fffaf1; }
#importWarnings { color: #a66c17; font-size: 10px; }

.account-layout { display: grid; gap: 16px; }
.account-profile { display: flex; align-items: center; gap: 16px; padding: 22px; }
.account-profile > span { display: grid; width: 48px; height: 48px; place-items: center; color: #fff; background: var(--green); border-radius: 50%; }
.account-profile h3 { margin: 0; font-size: 15px; }
.account-profile p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.account-profile .button { margin-left: auto; }
.account-actions button { display: grid; width: 100%; min-height: 70px; align-items: center; grid-template-columns: 32px 1fr 24px; padding: 0 18px; background: #fff; border: 0; text-align: left; }
.account-actions button + button { border-top: 1px solid var(--line); }
.account-actions button > svg:first-child { color: var(--green); }
.account-actions span { display: flex; flex-direction: column; }
.account-actions strong { font-size: 12px; }
.account-actions small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.admin-panel > header { display: flex; align-items: center; justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.admin-panel h3 { margin: 0; font-size: 14px; }
.admin-panel > header span { color: var(--muted); font-size: 9px; }
.invite-advisor-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; padding: 18px 20px; }
.invite-advisor-form label { display: grid; gap: 6px; }
.invite-advisor-form label span { font-size: 10px; font-weight: 700; }
.invite-advisor-form input, .invite-link-result input { width: 100%; height: 40px; min-width: 0; padding: 0 11px; background: #fff; border: 1px solid var(--line); border-radius: 4px; outline: none; }
.invite-advisor-form input:focus, .invite-link-result input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.invite-link-result { display: grid; gap: 11px; padding: 16px 20px; background: var(--green-soft); border-top: 1px solid var(--line); }
.invite-link-result > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.invite-link-result strong { font-size: 12px; }
.invite-link-result small { color: var(--muted); font-size: 9px; }
.invite-link-result > div:last-child { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
.admin-list-section { border-top: 8px solid var(--page); }
.admin-list-section > header { display: flex; min-height: 48px; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); }
.admin-list-section h4 { margin: 0; font-size: 12px; }
.admin-list-section header span { color: var(--muted); font-size: 9px; }
.approval-row { display: grid; min-height: 64px; align-items: center; grid-template-columns: 1fr auto; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.approval-row:last-child { border-bottom: 0; }
.approval-row strong, .approval-row small { display: block; }
.approval-row strong { font-size: 12px; }
.approval-row small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.approval-row > div:last-child { display: flex; gap: 8px; }
.empty-list.compact { min-height: 100px; }

.settings-backdrop { display: grid; position: fixed; z-index: 160; inset: 0; place-items: center; padding: 20px; background: rgba(7,26,21,.42); backdrop-filter: blur(5px); }
.settings-backdrop[hidden] { display: none; }
.settings-dialog { width: min(460px, 100%); overflow: hidden; background: #fff; border: 1px solid rgba(200,164,94,.45); border-radius: 6px; box-shadow: 0 20px 60px rgba(7,36,29,.2); }
.settings-dialog > header { display: grid; min-height: 86px; align-items: center; grid-template-columns: 44px 1fr 36px; gap: 13px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.settings-dialog > header small { color: var(--gold-deep); font-size: 9px; font-weight: 700; }
.settings-dialog h2 { margin: 3px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 500; }
.settings-icon { display: grid; width: 42px; height: 42px; place-items: center; color: var(--gold); background: var(--green); border-radius: 50%; }
.settings-icon svg { width: 20px; height: 20px; }
.settings-content { display: grid; gap: 14px; padding: 20px; }
.push-state { display: grid; align-items: start; grid-template-columns: 24px 1fr; gap: 12px; padding: 16px; background: var(--green-soft); border-left: 3px solid var(--gold); border-radius: 4px; }
.push-state > svg { width: 21px; height: 21px; color: var(--green); }
.push-state strong { font-size: 13px; }
.push-state p, .push-install-note p, .push-privacy { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.7; }
.push-install-note { padding: 15px 16px; border: 1px solid var(--line); border-radius: 4px; }
.push-install-note strong { font-size: 12px; }
.push-privacy { margin: 0; }
.settings-dialog > footer { display: flex; justify-content: flex-end; gap: 9px; padding: 15px 20px; background: var(--page); border-top: 1px solid var(--line); }
body.has-modal { overflow: hidden; }

.drawer-backdrop { position: fixed; z-index: 100; inset: 0; background: rgba(7,26,21,.34); }
.drawer-backdrop:not([hidden]) { display: flex; justify-content: flex-end; }
.form-drawer { display: flex; width: min(520px, 100%); height: 100%; flex-direction: column; background: #fff; box-shadow: -12px 0 36px rgba(7,36,29,.14); }
.form-drawer > header { display: flex; min-height: 76px; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); }
.form-drawer header small { color: var(--gold-deep); font-size: 9px; font-weight: 700; }
.form-drawer h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 24px; font-weight: 500; }
.form-drawer form { display: grid; overflow: auto; gap: 17px; padding: 22px 24px max(30px, env(safe-area-inset-bottom)); }
.form-drawer label { display: grid; gap: 7px; }
.form-drawer label > span { font-size: 11px; font-weight: 700; }
.form-drawer input, .form-drawer select, .form-drawer textarea { width: 100%; min-height: 42px; padding: 9px 11px; background: #fff; border: 1px solid var(--line); border-radius: 4px; outline: none; }
.form-drawer textarea { min-height: 88px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-section-title { margin: 6px 0 -4px; padding-top: 15px; border-top: 1px solid var(--line); font-size: 12px; }
.form-actions { display: flex; position: sticky; bottom: -30px; justify-content: flex-end; gap: 10px; margin: 8px -24px -30px; padding: 15px 24px max(15px, env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
.reminder-settings { padding: 14px; background: var(--page); border: 1px solid var(--line); border-radius: 4px; }
.reminder-settings label { display: flex; align-items: center; justify-content: space-between; }
.reminder-settings input[type="checkbox"] { width: 18px; min-height: 18px; }
.crm-toast { position: fixed; z-index: 200; right: 24px; bottom: 24px; max-width: 320px; padding: 12px 16px; color: #fff; background: var(--green-deep); border-left: 3px solid var(--gold); border-radius: 4px; font-size: 11px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.crm-toast.is-visible { opacity: 1; transform: translateY(0); }
.mobile-nav, .mobile-only { display: none; }
.admin-mode .crm-sidebar nav button:not([data-view="account"]),
.admin-mode #mobileMenu,
.admin-mode #notificationButton,
.admin-mode .account-actions,
.admin-mode .mobile-nav button:not([data-view="account"]) { display: none; }
.admin-mode .mobile-nav { grid-template-columns: 1fr; }

@media (max-width: 980px) {
  .today-layout { grid-template-columns: 1fr; }
  .summary-rail { grid-template-columns: 1fr 1fr; }
  .reminder-row { grid-template-columns: minmax(150px, 1.3fr) minmax(170px, 1.3fr) 100px 130px; }
  .reminder-date { display: none; }
  .mapping-fields { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 700px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .crm-shell { display: block; }
  .crm-sidebar { display: none; }
  .crm-topbar { height: 64px; padding: 0 16px; }
  .crm-topbar h1 { display: none; }
  .mobile-only { display: inline-grid; }
  #userMenu strong, #userMenu > svg { display: none; }
  .crm-view { padding: 18px 16px 36px; }
  .command-row { align-items: stretch; flex-direction: column-reverse; gap: 10px; }
  .command-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .search-control { width: 100%; }
  .summary-rail { display: none; }
  .reminder-feed { border: 0; background: transparent; }
  .reminder-group { background: #fff; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .reminder-group + .reminder-group { margin-top: 14px; border-top: 1px solid var(--line); }
  .reminder-group > header { padding: 0 2px; background: var(--page); border-bottom: 1px solid var(--line); }
  .reminder-row { display: grid; min-height: 112px; grid-template-columns: minmax(0, 1fr) 112px; padding: 12px 0; }
  .reminder-row > div { padding: 3px 10px; }
  .reminder-date { display: block; grid-column: 1; }
  .reminder-amount { grid-column: 2; grid-row: 1; }
  .reminder-status { grid-column: 1; justify-content: flex-start; }
  .reminder-actions { grid-column: 2; grid-row: 2 / span 2; align-items: flex-end; justify-content: center; flex-direction: column; border-left: 1px solid var(--line); }
  .reminder-actions button { width: 100%; text-align: center; }
  .data-surface { margin: 0 -16px; border-right: 0; border-left: 0; border-radius: 0; }
  .data-surface > header { padding: 15px 16px; }
  .entity-row { grid-template-columns: minmax(0, 1fr) 120px 28px; padding: 8px 8px; }
  .entity-row .desktop-field { display: none; }
  .entity-row .entity-value.gold { text-align: right; }
  .page-heading h2, .data-surface h2 { font-size: 21px; }
  .import-dropzone { min-height: 280px; }
  .mapping-fields { grid-template-columns: 1fr; }
  .import-workspace { margin: 0 -16px; border-right: 0; border-left: 0; border-radius: 0; }
  .account-profile { align-items: flex-start; flex-wrap: wrap; }
  .account-profile .button { width: 100%; margin-left: 0; }
  .admin-panel > header { align-items: flex-start; flex-direction: column; gap: 5px; }
  .invite-advisor-form { grid-template-columns: 1fr; padding: 16px; }
  .invite-link-result { padding: 16px; }
  .invite-link-result > div:first-child { align-items: flex-start; flex-direction: column; gap: 4px; }
  .invite-link-result > div:last-child { grid-template-columns: 1fr; }
  .approval-row { grid-template-columns: 1fr; gap: 10px; }
  .settings-backdrop { align-items: end; padding: 0; }
  .settings-dialog { width: 100%; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 6px 6px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .settings-dialog > footer { display: grid; grid-template-columns: 1fr 1fr; }
  .settings-dialog > footer .button-primary { grid-column: 1 / -1; }
  .mobile-nav { display: grid; position: fixed; z-index: 40; right: 0; bottom: 0; left: 0; height: calc(62px + env(safe-area-inset-bottom)); grid-template-columns: repeat(4, 1fr); padding-bottom: env(safe-area-inset-bottom); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); backdrop-filter: blur(12px); }
  .mobile-nav button { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 3px; color: var(--muted); background: transparent; border: 0; font-size: 9px; }
  .mobile-nav button.is-active { color: var(--green); }
  .mobile-nav svg { width: 20px; height: 20px; }
  .form-drawer { width: 100%; }
  .form-drawer > header { min-height: 68px; }
  .form-drawer form { padding: 20px 18px max(26px, env(safe-area-inset-bottom)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { margin-right: -18px; margin-left: -18px; padding-right: 18px; padding-left: 18px; }
  .crm-toast { right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); left: 16px; max-width: none; }
}

@media (max-width: 360px) {
  .command-actions { grid-template-columns: 1fr; }
  .button { padding: 0 10px; }
  .reminder-row { grid-template-columns: minmax(0, 1fr) 96px; }
}
