:root{
  --ink:#12213C;
  --bg:#EEF1F5;
  --surface:#FFFFFF;
  --accent:#0E7C86;
  --accent-dark:#0A5B63;
  --warm:#C97C1F;
  --live:#1F8A54;
  --border:#DCE1E8;
  --muted:#5B6472;
  --seg-a:#0E7C86;
  --seg-b:#12213C;
  --seg-c:#6E4A9E;
  --seg-d:#B0562D;
  --seg-e:#2E7D46;
  --seg-f:#A13D63;
  --seg-g:#3B5A8A;
  --radius:10px;
  --mono: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;height:100%;background:var(--bg);color:var(--ink);font-family:var(--sans);}
body{display:flex;flex-direction:column;height:100vh;overflow:hidden;}

header.topbar{
  background:var(--ink); color:#fff; padding:14px 20px;
  display:flex; flex-direction:column; gap:10px;
  border-bottom:3px solid var(--accent);
}
.topbar-row{
  display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:10px;
}
header.topbar .title{display:flex; flex-direction:column; gap:2px;}
header.topbar .title h1{font-size:17px; margin:0; font-weight:700; letter-spacing:0.2px;}
header.topbar .title p{font-size:12px; margin:0; color:#B9C2D4;}
header.topbar .stats{display:flex; gap:8px; flex-wrap:wrap;}
.stat-chip{
  background:rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.18);
  border-radius:8px; padding:6px 10px; font-size:12px; display:flex; gap:6px; align-items:baseline;
}
.stat-chip b{font-family:var(--mono); font-size:13px;}

.headerRight{display:flex; align-items:center; gap:14px; flex-wrap:wrap;}
.whoami{font-size:12px; color:#B9C2D4; display:flex; align-items:center; gap:6px;}
.whoami b{color:#fff;}
.whoami button{
  background:none; border:1px solid rgba(255,255,255,0.25); color:#B9C2D4;
  padding:3px 8px; border-radius:6px; font-size:11px; cursor:pointer;
}
.whoami button:hover{color:#fff; border-color:#fff;}

.searchwrap{display:flex; align-items:center; gap:8px;}
#search{
  padding:8px 12px; border-radius:8px; border:1px solid rgba(255,255,255,0.25);
  background:rgba(255,255,255,0.08); color:#fff; font-size:13px; width:220px; outline:none;
}
#search::placeholder{color:#9AA6BC;}
#search:focus{border-color:var(--accent);}

.tabbar{
  background:var(--surface); border-bottom:1px solid var(--border);
  padding:0 20px; display:flex; flex-wrap:wrap; gap:4px;
}
.tab{
  background:none; border:none; border-bottom:3px solid transparent; color:var(--muted);
  padding:10px 14px 8px 14px; font-size:13px; font-weight:600; cursor:pointer; white-space:nowrap;
}
.tab:hover{color:var(--ink);}
.tab.active{color:var(--accent-dark); border-bottom-color:var(--accent);}

.filterbar{
  background:var(--surface); border-bottom:1px solid var(--border);
  padding:10px 20px; display:flex; gap:10px; align-items:center; flex-wrap:wrap;
}
.filterbar select{
  padding:6px 8px; border-radius:7px; border:1px solid var(--border); background:#fff;
  font-size:12.5px; color:var(--ink); max-width:220px;
}
.filterbar label{font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:0.4px; margin-right:-4px;}
.filterbar .group{display:flex; align-items:center; gap:6px;}
#clearFilters{
  margin-left:auto; background:none; border:1px solid var(--border); color:var(--muted);
  padding:6px 12px; border-radius:7px; font-size:12px; cursor:pointer;
}
#clearFilters:hover{background:var(--bg);}
#resultCount{font-size:12px; color:var(--muted); white-space:nowrap;}

main.board{
  flex:1; display:flex; gap:14px; padding:16px 20px; overflow-x:auto; overflow-y:hidden;
}
.column{
  background:#E4E8EE; border-radius:12px; min-width:290px; max-width:320px;
  display:flex; flex-direction:column; flex-shrink:0;
}
.column-head{
  padding:12px 14px 8px 14px; display:flex; align-items:center; justify-content:space-between;
}
.column-head h2{font-size:13px; margin:0; font-weight:700; text-transform:uppercase; letter-spacing:0.5px;}
.column-head .count{
  font-family:var(--mono); font-size:12px; background:#fff; border-radius:20px; padding:2px 9px; color:var(--ink);
}
.column[data-status="Not Contacted"] .column-head{color:var(--muted);}
.column[data-status="In Discussion"] .column-head{color:var(--warm);}
.column[data-status="Contracted"] .column-head{color:var(--accent-dark);}
.column[data-status="Live Billing"] .column-head{color:var(--live);}
.cardlist{flex:1; overflow-y:auto; padding:0 10px 12px 10px; display:flex; flex-direction:column; gap:8px;}
.cardlist::-webkit-scrollbar{width:7px;}
.cardlist::-webkit-scrollbar-thumb{background:#c3cad4; border-radius:6px;}

.card{
  background:var(--surface); border-radius:8px; padding:10px 11px 9px 11px; cursor:pointer;
  border-left:4px solid var(--seg-a); box-shadow:0 1px 2px rgba(18,33,60,0.06);
  transition:transform 0.08s ease, box-shadow 0.08s ease;
}
.card:hover{transform:translateY(-1px); box-shadow:0 3px 10px rgba(18,33,60,0.14);}
.card h3{font-size:13px; margin:0 0 5px 0; font-weight:650; line-height:1.25;}
.card .badges{display:flex; flex-wrap:wrap; gap:4px; margin-bottom:5px;}
.badge{
  font-size:10px; padding:2px 6px; border-radius:5px; background:var(--bg); color:var(--muted);
  font-weight:600; letter-spacing:0.2px; white-space:nowrap;
}
.badge.tier-High{background:#FCEBE0; color:#9A3B12;}
.badge.tier-Medium{background:#FCF3DC; color:#8A6404;}
.badge.tier-Low{background:#E7EEF0; color:#3E6A70;}
.card .meta{font-size:11px; color:var(--muted); display:flex; justify-content:space-between; align-items:center; gap:6px;}
.card .meta .contact-flag{color:var(--accent-dark); font-weight:600;}
.card .meta .owner-flag{font-weight:600;}
.card .meta .metaLeft{display:flex; align-items:center; gap:6px; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.empty-col{padding:20px 10px; text-align:center; font-size:12px; color:var(--muted);}

.urgency-badge{
  font-size:9.5px; font-weight:700; text-transform:uppercase; letter-spacing:0.3px;
  padding:2px 6px; border-radius:5px; white-space:nowrap; flex-shrink:0;
}
.urgency-badge.overdue{background:#FBE2DE; color:#A62B1B;}
.urgency-badge.due-soon{background:#FCF3DC; color:#8A6404;}
.loading{padding:20px; text-align:center; font-size:13px; color:var(--muted);}

.seg-A{border-left-color:var(--seg-a);}
.seg-B{border-left-color:var(--seg-b);}
.seg-C{border-left-color:var(--seg-c);}
.seg-D{border-left-color:var(--seg-d);}
.seg-E{border-left-color:var(--seg-e);}
.seg-F{border-left-color:var(--seg-f);}
.seg-G{border-left-color:var(--seg-g);}

.overlay{
  position:fixed; inset:0; background:rgba(18,33,60,0.35); display:none; z-index:50;
}
.overlay.open{display:block;}
.drawer{
  position:fixed; top:0; right:-460px; width:440px; max-width:92vw; height:100%;
  background:#fff; z-index:60; box-shadow:-6px 0 24px rgba(18,33,60,0.25);
  transition:right 0.22s ease; display:flex; flex-direction:column;
}
.drawer.open{right:0;}
.drawer-head{
  padding:16px 18px 12px 18px; border-bottom:1px solid var(--border);
  display:flex; justify-content:space-between; align-items:flex-start; gap:10px;
}
.drawer-head h2{font-size:16px; margin:0 0 4px 0;}
.drawer-head .sub{font-size:12px; color:var(--muted);}
.drawer-close{background:none; border:none; font-size:20px; cursor:pointer; color:var(--muted); line-height:1;}
.drawer-body{flex:1; overflow-y:auto; padding:16px 18px;}
.drawer-section{margin-bottom:18px;}
.drawer-section h4{font-size:11px; text-transform:uppercase; letter-spacing:0.5px; color:var(--muted); margin:0 0 8px 0;}
.hookbox{
  background:#F3F6F8; border-left:3px solid var(--accent); border-radius:6px; padding:10px 12px;
  font-size:13px; line-height:1.5; font-style:italic; color:#26364F;
}
.field-row{display:flex; flex-direction:column; gap:4px; margin-bottom:10px;}
.field-row label{font-size:11.5px; color:var(--muted); font-weight:600;}
.field-row input, .field-row select, .field-row textarea{
  padding:7px 9px; border:1px solid var(--border); border-radius:7px; font-size:13px; font-family:var(--sans);
  resize:vertical;
}
.contactline{font-size:13px; margin-bottom:4px; display:flex; gap:6px;}
.contactline .lbl{color:var(--muted); min-width:56px;}
.drawer-footer{
  padding:12px 18px; border-top:1px solid var(--border); display:flex; gap:8px; align-items:center;
}
.btn{
  padding:8px 14px; border-radius:7px; border:none; font-size:13px; font-weight:600; cursor:pointer;
}
.btn-primary{background:var(--accent); color:#fff;}
.btn-primary:hover{background:var(--accent-dark);}
.btn-ghost{background:none; color:var(--muted); border:1px solid var(--border);}
.btn-ghost:hover{background:var(--bg);}
.btn-small{padding:6px 10px; font-size:12px;}
.savedflag{font-size:11.5px; color:var(--live); margin-left:auto;}
.banner{
  background:#FFF6E8; border-bottom:1px solid #F0D9A8; color:#7A5A0E; font-size:12px;
  padding:6px 20px;
}

.note-list, .activity-list{display:flex; flex-direction:column; gap:8px; max-height:220px; overflow-y:auto;}
.note-item{
  background:#F3F6F8; border-radius:7px; padding:8px 10px; font-size:12.5px; line-height:1.45;
}
.note-item .note-meta{font-size:11px; color:var(--muted); margin-bottom:3px; display:flex; justify-content:space-between;}
.note-item .note-meta b{color:var(--ink);}
.note-item .note-body{white-space:pre-wrap; word-break:break-word;}
.note-attachment{margin-top:8px;}
.note-attachment a{display:inline-block;}
.note-attachment img{
  max-width:100%; max-height:260px; border-radius:6px; border:1px solid var(--border); display:block;
  object-fit:contain; background:#fff;
}
.note-attachment .cap{font-size:10.5px; color:var(--muted); margin-top:3px;}
.empty-note{font-size:12px; color:var(--muted); font-style:italic;}
.activity-item{font-size:12px; color:var(--muted); padding:4px 0; border-bottom:1px dashed var(--border);}
.activity-item:last-child{border-bottom:none;}
.activity-item b{color:var(--ink);}
.activity-item .ts{float:right; font-family:var(--mono); font-size:10.5px;}
.addnote-row{display:flex; flex-direction:column; gap:6px; margin-top:10px;}
.attach-row{display:flex; align-items:center; gap:8px; flex-wrap:wrap;}
.attach-label{cursor:pointer; display:inline-block;}
.attach-name{font-size:11.5px; color:var(--muted); word-break:break-all;}

/* My Day view */
.mydayview, .districtview{
  flex:1; overflow-y:auto; padding:16px 20px;
}
.myday-controls{
  display:flex; align-items:center; gap:14px; margin-bottom:16px; flex-wrap:wrap;
}
.scope-toggle{display:flex; border:1px solid var(--border); border-radius:8px; overflow:hidden;}
.scope-btn{
  background:#fff; border:none; padding:7px 14px; font-size:12.5px; font-weight:600; color:var(--muted);
  cursor:pointer; border-right:1px solid var(--border);
}
.scope-btn:last-child{border-right:none;}
.scope-btn.active{background:var(--ink); color:#fff;}
.myday-hint{font-size:12px; color:var(--muted);}

.myday-bucket{margin-bottom:22px;}
.myday-bucket h3{
  font-size:12px; text-transform:uppercase; letter-spacing:0.5px; margin:0 0 8px 0; padding-bottom:6px;
  border-bottom:1px solid var(--border); display:flex; align-items:center; gap:8px;
}
.myday-bucket h3 .n{font-family:var(--mono); color:var(--muted); font-weight:400;}
.myday-bucket.overdue h3{color:#A62B1B;}
.myday-bucket.due-today h3{color:var(--warm);}
.myday-bucket.upcoming h3{color:var(--accent-dark);}
.myday-bucket.no-date h3{color:var(--muted);}

.myday-row{
  background:var(--surface); border-radius:8px; padding:10px 14px; margin-bottom:6px; cursor:pointer;
  display:flex; align-items:center; justify-content:space-between; gap:12px; box-shadow:0 1px 2px rgba(18,33,60,0.06);
  border-left:4px solid var(--seg-a);
}
.myday-row:hover{box-shadow:0 3px 10px rgba(18,33,60,0.14);}
.myday-row .mdr-main{min-width:0;}
.myday-row .mdr-name{font-size:13px; font-weight:650; margin-bottom:2px;}
.myday-row .mdr-action{font-size:12px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.myday-row .mdr-right{display:flex; align-items:center; gap:8px; flex-shrink:0;}
.myday-row .mdr-date{font-family:var(--mono); font-size:11.5px; color:var(--muted);}
.myday-row .mdr-owner{font-size:11px; color:var(--muted); background:var(--bg); padding:2px 7px; border-radius:5px;}
.myday-empty{font-size:13px; color:var(--muted); padding:10px 0;}

/* District view */
.district-group{margin-bottom:18px;}
.district-head{
  display:flex; align-items:center; gap:10px; padding:8px 4px; cursor:pointer; user-select:none;
  border-bottom:1px solid var(--border); margin-bottom:8px;
}
.district-head h3{font-size:14px; margin:0; font-weight:700;}
.district-head .count{font-family:var(--mono); font-size:12px; color:var(--muted);}
.district-head .caret{margin-left:auto; font-size:11px; color:var(--muted);}
.district-cards{
  display:grid; grid-template-columns:repeat(auto-fill, minmax(260px, 1fr)); gap:8px;
}
.district-group.collapsed .district-cards{display:none;}

/* note type quick-log */
.note-type-row{display:flex; gap:5px; flex-wrap:wrap;}
.note-type-btn{
  background:var(--bg); border:1px solid var(--border); color:var(--muted);
  padding:4px 9px; border-radius:14px; font-size:11px; font-weight:600; cursor:pointer;
}
.note-type-btn.active{background:var(--accent); color:#fff; border-color:var(--accent);}
.note-tag{
  display:inline-block; font-size:9.5px; font-weight:700; text-transform:uppercase; letter-spacing:0.3px;
  padding:1px 6px; border-radius:4px; background:var(--bg); color:var(--muted); margin-right:6px;
}
.note-tag.Call{background:#E3EEFB; color:#1F5C99;}
.note-tag.Visit{background:#E5F1E9; color:var(--live);}
.note-tag.Email{background:#F1E9F8; color:var(--seg-c);}
.note-tag.Meeting{background:#FDEBDD; color:var(--seg-d);}

/* login screen */
.login-overlay{
  position:fixed; inset:0; background:var(--ink); z-index:100;
  display:flex; align-items:center; justify-content:center;
}
.login-box{
  background:#fff; border-radius:12px; padding:28px 26px; width:340px; max-width:90vw;
  box-shadow:0 10px 40px rgba(0,0,0,0.35);
}
.login-box h2{margin:0 0 4px 0; font-size:18px;}
.login-sub{margin:0 0 18px 0; font-size:12.5px; color:var(--muted);}
.login-box .field-row{margin-bottom:12px;}
.login-box input{
  width:100%; padding:9px 10px; border:1px solid var(--border); border-radius:7px; font-size:14px;
}
.login-error{
  background:#FBE2DE; color:#A62B1B; font-size:12.5px; padding:8px 10px; border-radius:7px; margin-bottom:12px;
}

/* read-only display for fields the current role can't edit */
.readonly-field{
  font-size:13px; padding:7px 0; color:var(--ink);
}
.readonly-field.muted{color:var(--muted); font-style:italic;}

/* team management view */
.teamview{flex:1; overflow-y:auto; padding:16px 20px;}
.team-columns{display:grid; grid-template-columns:1fr 1.4fr; gap:24px; max-width:900px;}
.team-col h3{font-size:13px; text-transform:uppercase; letter-spacing:0.5px; color:var(--muted); margin:0 0 10px 0;}
.team-list{display:flex; flex-direction:column; gap:6px; margin-bottom:14px;}
.team-item{
  background:var(--surface); border-radius:7px; padding:8px 10px; font-size:13px;
  display:flex; align-items:center; justify-content:space-between; gap:8px; box-shadow:0 1px 2px rgba(18,33,60,0.06);
}
.team-item .ti-main{min-width:0;}
.team-item .ti-name{font-weight:650;}
.team-item .ti-meta{font-size:11.5px; color:var(--muted);}
.team-item .ti-actions{display:flex; gap:6px; flex-shrink:0;}
.team-item.inactive{opacity:0.5;}
.role-badge{
  font-size:9.5px; font-weight:700; text-transform:uppercase; letter-spacing:0.3px;
  padding:1px 6px; border-radius:4px; background:var(--bg); color:var(--muted); margin-left:6px;
}
.role-badge.management{background:#12213C; color:#fff;}
.role-badge.regional_lead{background:#E3EEFB; color:#1F5C99;}
.role-badge.client_partner{background:#E5F1E9; color:var(--live);}
.inline-form{display:flex; flex-direction:column; gap:8px; max-width:320px;}
.inline-form input, .inline-form select{
  padding:7px 9px; border:1px solid var(--border); border-radius:7px; font-size:13px;
}
.team-error{
  background:#FBE2DE; color:#A62B1B; font-size:12px; padding:6px 10px; border-radius:6px; margin-top:8px; max-width:320px;
}
.btn-tiny{padding:3px 8px; font-size:11px; border-radius:5px;}
.team-hint{
  background:#F3F6F8; border-left:3px solid var(--accent); border-radius:6px; padding:9px 11px;
  font-size:12.5px; color:#26364F; line-height:1.4; margin-bottom:14px; max-width:320px;
}

/* add-institution modal (and any other centered dialog) */
.modal-card{
  position:fixed; top:50%; left:50%; transform:translate(-50%,-50%);
  background:#fff; border-radius:12px; z-index:80; width:460px; max-width:92vw;
  max-height:88vh; display:flex; flex-direction:column; box-shadow:0 10px 40px rgba(18,33,60,0.3);
}
.modal-card-head{
  padding:16px 18px 12px 18px; border-bottom:1px solid var(--border);
  display:flex; justify-content:space-between; align-items:center;
}
.modal-card-head h3{margin:0; font-size:16px;}
.modal-card-body{flex:1; overflow-y:auto; padding:16px 18px;}
.modal-card-foot{padding:12px 18px; border-top:1px solid var(--border); display:flex; gap:8px;}
.overlay.modal-overlay{z-index:75;}

/* ---------- responsive (phone / small tablet) ---------- */
@media (max-width: 760px){
  header.topbar{padding:10px 12px;}
  header.topbar .title h1{font-size:15px;}
  header.topbar .title p{display:none;}
  header.topbar .stats{display:none;}
  .headerRight{width:100%; justify-content:space-between;}
  #search{width:100%;}
  .searchwrap{flex:1;}

  .tabbar{padding:0 10px; overflow-x:auto;}
  .tab{padding:10px 10px 8px 10px; font-size:12.5px; white-space:nowrap;}

  .filterbar{padding:8px 10px; gap:8px; overflow-x:auto; flex-wrap:nowrap;}
  .filterbar .group{flex-shrink:0;}
  .filterbar select{max-width:150px;}
  #clearFilters{margin-left:0;}
  #resultCount{display:none;}

  main.board{padding:10px 10px; gap:10px;}
  .column{min-width:82vw; scroll-snap-align:start;}
  main.board{scroll-snap-type:x mandatory;}

  .card{padding:13px 12px;}
  .card h3{font-size:14px;}

  .drawer{width:100%; max-width:100vw; right:-100%;}
  .drawer.open{right:0;}

  .mydayview, .districtview, .teamview{padding:12px;}
  .myday-controls{gap:10px;}
  .myday-row{padding:12px;}
  .district-cards{grid-template-columns:1fr;}
  .team-columns{grid-template-columns:1fr; gap:20px;}

  .login-box{width:88vw;}
}
