:root {
  --navy: #1e2a4a;
  --navy-2: #26355c;
  --ink: #1a1f2b;
  --paper: #f5f6f8;
  --card: #ffffff;
  --line: #e3e6ec;
  --muted: #6b7280;
  --dim: #8a91a0;
  --gold: #b8862b;
  --gold-soft: #f3ead2;
  --green: #1f7a4d;
  --red: #b4322a;
  --shadow: 0 1px 3px rgba(20,30,60,.06), 0 6px 20px rgba(20,30,60,.05);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3, .serif { font-family: Georgia, "Times New Roman", serif; }
a { color: var(--navy); }
button { font-family: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 32px 28px;
}
.login-card h1 { font-size: 21px; margin: 0 0 4px; color: var(--navy); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 5px; text-transform: uppercase; letter-spacing: .04em; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; background: #fbfcfd;
}
.login-card input:focus { outline: none; border-color: var(--navy); background: #fff; }
.btn-primary {
  width: 100%; margin-top: 20px; padding: 12px; background: var(--navy); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
}
.btn-primary:hover { background: var(--navy-2); }
.login-err { color: var(--red); font-size: 13px; margin-top: 14px; min-height: 18px; }
.login-foot { margin-top: 22px; font-size: 11.5px; color: var(--dim); text-align: center; line-height: 1.5; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
/* Documents the AI assistant surfaces in a response */
.ai-chat-docs { position: fixed; right: 20px; bottom: 100px; width: 320px; max-height: 60vh;
  background: #fff; border: 1px solid #dfe3e6; border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18);
  z-index: 9500; display: flex; flex-direction: column; overflow: hidden; }
.ai-chat-docs-head { display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: #5c5a56; border-bottom: 1px solid #eee; }
.ai-chat-docs-x { background: none; border: none; font-size: 18px; line-height: 1; cursor: pointer; color: #888; }
.ai-chat-docs-x:hover { color: #222; }
.ai-chat-docs-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.ai-chat-doc { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 8px;
  text-decoration: none; color: inherit; }
.ai-chat-doc:hover { background: #f4f3f0; }
.ai-chat-doc-img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex: none; }
.ai-chat-doc-icon { width: 44px; height: 44px; border-radius: 6px; background: #f0efec; display: flex;
  align-items: center; justify-content: center; color: #8a8a86; flex: none; }
.ai-chat-doc-cap { min-width: 0; }
.ai-chat-doc-ex { font-size: 10px; font-weight: 700; color: #8a6d00; }
.ai-chat-doc-name { font-size: 12.5px; font-weight: 600; color: #1a1a1a; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-doc-meta { font-size: 10.5px; color: #8a8a86; }

/* AI Chat theme override — off-white background, 90% black text */
:root {
  --aic-bg: #f7f6f3;
  --aic-surface: #fbfaf8;
  --aic-surface-2: #eeece7;
  --aic-border: #ddd9d2;
  --aic-text: #1a1a1a;
  --aic-muted: #5c5a56;
}
.aic-composer-inner { border-radius: 999px; padding-left: 16px; }
.sidebar { background: var(--navy); color: #cdd4e4; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand .t { font-family: Georgia, serif; font-size: 16px; color: #fff; line-height: 1.25; }
.sidebar .brand .s { font-size: 11px; color: #8f9abb; margin-top: 4px; }
.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; color: #cdd4e4; cursor: pointer; margin-bottom: 2px; user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; opacity: .9; flex: none; }
.ic-svg { display: inline-block; vertical-align: middle; flex: none; }
.ic-text { display: inline-flex; align-items: center; gap: 5px; }
.ic-text .ic-svg { opacity: .85; }
.tile-geo.ic-text, .tile-geo { display: inline-flex; align-items: center; gap: 5px; }
.nav-sep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b779b; padding: 14px 12px 6px; }
.sidebar .foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #9aa4c0; }
.sidebar .foot .who { color: #fff; font-weight: 600; }
.sidebar .foot .role { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 20px; margin-top: 6px; }
.role-admin { background: var(--gold-soft); color: var(--gold); }
.role-family { background: #dcf0e4; color: #1e6e46; }
.role-bank { background: #dbe7f5; color: #24547e; }
.logout { margin-top: 10px; background: none; border: 1px solid rgba(255,255,255,.2); color: #cdd4e4; padding: 6px 12px; border-radius: 7px; font-size: 12.5px; }
.logout:hover { background: rgba(255,255,255,.08); color: #fff; }

.main { padding: 30px 38px 60px; max-width: 1180px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 25px; margin: 0 0 4px; color: var(--navy); }
.page-head .sub { color: var(--muted); font-size: 14px; }

/* ---------- overview ---------- */
.cover { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow); margin-bottom: 22px; font-size: 15.5px; line-height: 1.65; }
.stat-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); min-width: 130px; }
.stat .n { font-size: 26px; font-weight: 700; font-family: Georgia, serif; color: var(--navy); }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }

/* ---------- section blocks ---------- */
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.block-head { padding: 14px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.block-head h3 { margin: 0; font-size: 15px; color: var(--navy); }
.block-body { padding: 18px 20px; }

/* ---------- documents gallery ---------- */
.folder-group { margin-bottom: 26px; }
.folder-head { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 12px; }
.folder-head .fh-t { font-family: Georgia, serif; font-size: 17px; color: var(--navy); }
.folder-head .fh-c { font-size: 12.5px; color: var(--dim); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s; position: relative; display: flex; flex-direction: column; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(20,30,60,.12); }
.tile-thumb { height: 150px; background: #eef0f4; display: grid; place-items: center; overflow: hidden; position: relative; }
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-thumb .frame { width: 100%; height: 100%; border: 0; pointer-events: none; background: #fff; }
.tile-thumb .ic { color: var(--dim); display: grid; place-items: center; }
.tile-cap { padding: 9px 11px 11px; }
.tile-ex { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; color: var(--gold); text-transform: uppercase; }
.tile-name { font-size: 12.5px; color: var(--ink); line-height: 1.35; margin-top: 2px; word-break: break-word; }
.tile-meta { font-size: 11px; color: var(--dim); margin-top: 5px; }
.tile-geo { font-size: 11px; color: var(--green); margin-top: 4px; }
.badge-share { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 20px; background: var(--green); color: #fff; letter-spacing: .03em; }
.badge-private { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 20px; background: #e7e9ee; color: var(--muted); }

/* ---------- controls / buttons ---------- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 7px; font-size: 13px; font-weight: 500; }
.btn:hover { border-color: var(--navy); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-nav { background: var(--navy); color: #fff; border: none; }
.btn-nav:hover { background: var(--navy-2); }
.btn-danger { color: var(--red); border-color: #eccdca; }
.btn-danger:hover { background: #fbeceb; border-color: var(--red); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { display: none; }
.toggle .sw { width: 38px; height: 22px; border-radius: 20px; background: #cfd4dd; position: relative; transition: background .15s; flex: none; }
.toggle .sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + .sw { background: var(--green); }
.toggle input:checked + .sw::after { transform: translateX(16px); }
.input, textarea.input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 13.5px; font-family: inherit; background: #fbfcfd; }
.input:focus, textarea.input:focus { outline: none; border-color: var(--navy); background: #fff; }
textarea.input { resize: vertical; min-height: 60px; }

/* ---------- copy chips (reference data) ---------- */
.kd-group { margin-bottom: 18px; }
.kd-group h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--gold); margin: 0 0 8px; }
.kd { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 7px; background: #fbfcfd; }
.kd .kd-l { font-size: 12.5px; color: var(--muted); }
.kd .kd-v { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.kd .kd-copy { flex: none; }

/* ---------- portals ---------- */
.portal { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; overflow: hidden; }
.portal-head { padding: 13px 16px; background: #fbfcfd; border-bottom: 1px solid var(--line); }
.portal-head .pt { font-weight: 600; color: var(--navy); font-size: 14.5px; }
.portal-head .pb { font-size: 11px; color: var(--gold); background: var(--gold-soft); padding: 2px 8px; border-radius: 20px; margin-left: 8px; }
.portal-head .pu { font-size: 12px; margin-top: 4px; display: inline-block; }
.portal-body { padding: 14px 16px; font-size: 13.5px; }
.portal-body .pp { color: var(--muted); margin: 0 0 10px; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.chip { font-size: 12px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 20px; background: #fff; cursor: pointer; }
.chip:hover { border-color: var(--navy); background: #f2f4f8; }

/* ---------- notes ---------- */
.note { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px; background: #fffdf7; }
.note-meta { font-size: 11.5px; color: var(--dim); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.note-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.note-acts { margin-top: 8px; display: flex; gap: 8px; }
.note-privacy { font-size: 11px; color: var(--gold); background: var(--gold-soft); padding: 2px 8px; border-radius: 20px; }

/* ---------- map ---------- */
.map-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 18px; }
.map-head { padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.map-head .mc { font-weight: 600; color: var(--navy); }
.map-head .mm { font-size: 12.5px; color: var(--muted); }
.map-frame { width: 100%; height: 340px; border: 0; display: block; }
.map-strip { display: flex; gap: 8px; padding: 12px 16px; overflow-x: auto; }
.map-thumb { flex: none; width: 74px; text-align: center; cursor: pointer; }
.map-thumb img { width: 74px; height: 74px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.map-thumb .tt { font-size: 10px; color: var(--dim); margin-top: 3px; }

/* ---------- lightbox ---------- */
.lb { position: fixed; inset: 0; background: rgba(16,20,30,.92); z-index: 1200; display: none; }
.lb.open { display: grid; grid-template-columns: 1fr 340px; }
.lb.open.no-side { grid-template-columns: 1fr; }
.lb-stage { position: relative; display: grid; place-items: center; padding: 40px; overflow: auto; }
.lb-stage img { max-width: 100%; max-height: 86vh; object-fit: contain; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lb-stage .frame { width: 88%; height: 88vh; border: 0; background: #fff; border-radius: 4px; }
.lb-side { background: var(--card); overflow-y: auto; padding: 22px; }
.lb-side h2 { font-size: 17px; margin: 0 0 3px; color: var(--navy); }
.lb-side .lx { font-size: 11px; font-weight: 700; letter-spacing: .05em; color: var(--gold); text-transform: uppercase; }
.lb-side .lmeta { font-size: 12.5px; color: var(--muted); margin: 10px 0; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.lb-side .lmeta div { margin-bottom: 4px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; border: none; font-size: 22px; display: grid; place-items: center; }
.lb-nav:hover { background: rgba(255,255,255,.28); }
.lb-prev { left: 18px; } .lb-next { right: 18px; }
.lb.no-side .lb-next { right: 18px; }
.lb-close { position: absolute; top: 16px; right: 20px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; border: none; font-size: 22px; z-index: 5; }
.lb-close:hover { background: rgba(255,255,255,.28); }
.lb-field label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 5px; font-weight: 600; }

/* ---------- misc ---------- */
.empty { color: var(--dim); font-size: 14px; padding: 30px; text-align: center; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13.5px; z-index: 1400; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }
.note-limit { font-size: 12.5px; color: var(--gold); background: var(--gold-soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.hidden { display: none !important; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { display: flex; flex-wrap: wrap; }
  .lb.open { grid-template-columns: 1fr; }
  .lb-side { display: none; }
  .main { padding: 20px; }
}
