/* Base styles ported from the Apps Script version (Index.html). */
:root {
  --navy: #1F3864; --blue: #3756B0; --green: #3FA535; --bg: #F3F5F9; --card: #FFFFFF; --text: #1D2433;
  --muted: #5B6475; --line: #D6DCE8; --soft: #EAF0F8; --warn-bg: #FFF4C2; --warn: #8A6100; --bad: #C62828;
  --bad-bg: #FDE7E7; --ok: #1E7B34; --ok-bg: #DDF3E2; --draft-bg: #FFF1D6; --draft: #8A5A00;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 Arial, Helvetica, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--blue); }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: #fff;
  border-bottom: 3px solid var(--navy); position: sticky; top: 0; z-index: 20; }
.topbar .logo { height: 34px; width: auto; display: block; }
.topbar .title { font-weight: bold; color: var(--navy); font-size: 16px; }
.topbar .spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox .who { text-align: right; line-height: 1.2; }
.userbox .who small { color: var(--muted); display: block; }
.mainnav { background: #fff; padding: 0 16px; margin: 0; position: sticky; top: 57px; z-index: 19; }
.mainnav a { display: inline-block; padding: 11px 14px; font-weight: bold; color: var(--muted); text-decoration: none;
  border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.mainnav a.active { color: var(--navy); border-bottom-color: var(--green); }
main { max-width: 1240px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 22px; color: var(--navy); margin: 0 0 14px; }
h2 { font-size: 17px; color: var(--navy); margin: 0; }
h3 { font-size: 15px; color: var(--navy); margin: 0 0 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.narrow { max-width: 420px; margin: 40px auto; }
label { display: block; font-size: 12px; font-weight: bold; color: var(--muted); margin-bottom: 10px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 9px; border: 1px solid #C3CBDB;
  border-radius: 6px; font: inherit; color: var(--text); background: #fff; }
textarea { resize: vertical; min-height: 54px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(55, 86, 176, .35); border-color: var(--blue); }
input:disabled, select:disabled, textarea:disabled { background: #F6F7FA; color: #3a4252; }
.missing { background: var(--warn-bg) !important; border-color: #E0B400 !important; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
  border-radius: 6px; border: 1px solid #C3CBDB; background: #fff; color: var(--navy); font: inherit;
  font-weight: bold; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #2C478F; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.success:hover { background: #2F8A27; }
.btn.danger { color: var(--bad); border-color: #E7B4B4; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.wide { width: 100%; }
.error { color: var(--bad); font-weight: bold; min-height: 18px; margin: 4px 0 8px; white-space: pre-line; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.err-text { color: var(--bad); font-weight: bold; }
.section-head h3 { margin: 0; }
.ms-head { font-size: 12px; font-weight: bold; color: var(--muted); margin: 4px 0 6px; }
label.check.ms-update { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.mat-list .tbl td { vertical-align: middle; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 16px; font: inherit; font-weight: bold; color: var(--muted);
  cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--green); }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.toolbar label { margin: 0; }
.toolbar .spacer { flex: 1; }
.datebox { display: flex; align-items: flex-end; gap: 6px; }
.datebox input { width: 160px; }
.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: bold;
  background: var(--draft-bg); color: var(--draft); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.wait { background: #E9EDF5; color: var(--muted); }
.chip.new { background: var(--soft); color: var(--blue); }
.banner { padding: 10px 14px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-weight: bold;
  margin-bottom: 14px; }
.banner.corr { background: var(--warn-bg); color: var(--warn); border: 1px solid #E0B400; }
.changes { margin: 6px 0 12px 18px; padding: 0; max-height: 260px; overflow-y: auto; }
.changes li { margin: 3px 0; }
.hist { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.hist-item { margin: 6px 0; }
.hist-item details { margin: 2px 0 0 0; }
.hist-item summary { cursor: pointer; color: var(--blue); font-size: 12px; }
.att-item.del-pending a { text-decoration: line-through; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.grid .span2 { grid-column: span 2; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 8px; margin-bottom: 14px; }
.kpi { background: var(--soft); border-radius: 8px; padding: 10px 8px; text-align: center; }
.kpi-v { font-size: 20px; font-weight: bold; color: var(--navy); }
.kpi-l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 10px; }
.contact { border-left: 4px solid var(--blue); }
.contact-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.contact-head .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 13px; }
.contact-head input { margin: 0; font-weight: bold; font-size: 15px; }
.contact-head .company { flex: 1 1 240px; min-width: 0; }
.nipbox { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.contact-head .nipbox input { width: 150px; font-weight: normal; font-size: 14px; }
.nip-info { font-size: 12px; margin: -4px 0 10px 38px; color: var(--muted); }
.nip-info.ok { color: var(--ok); }
.nip-info.warn { color: var(--warn); font-weight: bold; }
.nip-info.err { color: var(--bad); font-weight: bold; }
.invalid { border-color: var(--bad) !important; background: var(--bad-bg) !important; }
.att { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; border-top: 1px dashed var(--line);
  padding-top: 10px; margin-top: 2px; }
.att-title { font-size: 12px; font-weight: bold; color: var(--muted); margin-right: 2px; }
.att-where { font-weight: normal; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: normal; color: var(--text); }
label.check input { display: inline-block; width: auto; margin: 0; }
.hint.ok { color: var(--ok); }
.hint.warn { color: var(--warn); font-weight: bold; }
.att-list { display: contents; }
.att-item { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; background: var(--soft);
  border: 1px solid #D5DEEE; border-radius: 999px; padding: 2px 2px 2px 10px; font-size: 12px; }
.att-item a { color: var(--navy); font-weight: bold; text-decoration: none; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; max-width: 280px; }
.att-item a:hover { text-decoration: underline; }
.att-item .size { color: var(--muted); white-space: nowrap; margin-left: 4px; }
.att-del { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1;
  padding: 2px 7px; border-radius: 50%; }
.att-del:hover { background: var(--bad-bg); color: var(--bad); }
.att-add { position: relative; overflow: hidden; margin: 0; }
.att-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; margin: 0; padding: 0; }
.att-add.busy { opacity: .6; pointer-events: none; }
.att-status { font-size: 12px; color: var(--muted); }
.att-empty { font-size: 12px; color: var(--muted); }
.att-mini { margin-top: 4px; font-size: 12px; }
.att-mini a { display: inline-block; margin-right: 8px; color: var(--blue); }
.actions-bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; font-size: 13px; }
.tbl th { background: var(--navy); color: #fff; text-align: left; padding: 7px 8px; font-size: 12px; white-space: nowrap; }
.tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: top; }
.tbl tr:nth-child(even) td { background: #FAFBFD; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl td.clickable { cursor: pointer; }
.tbl td.clickable:hover { background: var(--soft); }
.tbl .overdue td:first-child { color: var(--bad); font-weight: bold; }
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 14px; }
.person h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.person .stats { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.person .kpis { margin: 0; grid-template-columns: repeat(3, 1fr); }
.person.total { border-color: var(--navy); }
.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.linkbox code { background: var(--soft); padding: 6px 8px; border-radius: 6px; word-break: break-all; flex: 1; min-width: 200px; }
.pwd { font: bold 22px/1.2 'Courier New', monospace; letter-spacing: 2px; color: var(--navy); background: var(--soft);
  padding: 10px; border-radius: 8px; text-align: center; margin: 8px 0 12px; }
.overlay { position: fixed; inset: 0; background: rgba(255, 255, 255, .55); z-index: 90; display: flex;
  align-items: center; justify-content: center; }
.spinner { width: 42px; height: 42px; border: 4px solid var(--soft); border-top-color: var(--blue); border-radius: 50%;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(680px, 92vw);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 8px; z-index: 100; white-space: pre-line;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }
.toast.warn { background: #9A6A00; }
.toast .toast-action { margin-left: 10px; background: rgba(255, 255, 255, .18); color: #fff; border-color: rgba(255, 255, 255, .6); }
.modal { position: fixed; inset: 0; background: rgba(20, 28, 45, .45); z-index: 80; display: flex;
  align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal-card { background: #fff; border-radius: 10px; width: min(760px, 100%); padding: 18px 20px; }
.modal-card.wide { width: min(1180px, 100%); }
.modal-card h2 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.btn .sm { display: none; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
@media (max-width: 640px) {
  .topbar { padding: 8px 10px; gap: 8px; }
  .topbar .logo { height: 26px; }
  .topbar .title, .userbox .who, .btn .lg { display: none; }
  .btn .sm { display: inline; }
  .userbox { gap: 6px; }
  .mainnav { top: 45px; padding: 0 6px; }
  .mainnav a { padding: 10px 9px; }
  main { padding: 14px 10px 50px; }
  .tabs button { padding: 10px 10px; }
  .grid .span2 { grid-column: auto; }
  .contact-head .company { flex-basis: 120px; }
  .nipbox { order: 5; flex: 1 1 100%; }
  .contact-head .nipbox input { flex: 1; width: auto; }
  .nip-info { margin-left: 0; }
  .person .kpis { grid-template-columns: repeat(2, 1fr); }
  .datebox input { width: 140px; }
}
@media print {
  .topbar, .mainnav, .toolbar, .actions-bar, .btn { display: none !important; }
  main { max-width: none; padding: 0; }
}
/* View-specific sections are appended below by view authors. */
/* === report view === */
.contact-head .co-link { font-size: 12px; font-weight: bold; white-space: nowrap; text-decoration: none; }
.contact-head .co-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .contact-head .co-link { order: 6; }
  #reportView .toolbar > .btn { flex: 1 1 auto; }
}
/* === end report view === */

/* === auth, history, tasks, companies (Agent G2) === */
.auth-links { margin: 12px 0 0; text-align: center; font-size: 13px; }
.hist-export h3 { margin-bottom: 10px; }
.hist-export .toolbar { margin-bottom: 8px; }
.hist-export input[type=date] { width: 160px; }
.tbl .due-today td:first-child { color: var(--blue); font-weight: bold; }
.co-search .co-q { flex: 1 1 280px; }
.co-tbl tr.co-row { cursor: pointer; }
.co-tbl tr.co-row:hover td { background: var(--soft); }
.co-back { margin: 0 0 8px; }
.co-card .section-head { align-items: flex-start; flex-wrap: wrap; }
.co-title { margin: 0; word-break: break-word; }
.co-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.co-infos { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 16px; margin-top: 6px; }
.co-info > span, .co-notes > span { display: block; font-size: 12px; font-weight: bold; }
.co-info div { word-break: break-word; }
.co-notes { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.co-task { border-left: 4px solid var(--green); }
.co-task.overdue { border-left-color: var(--bad); }
.co-task.none { border-left-color: var(--line); }
.co-task .section-head { margin-top: 0; }
.co-timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.co-tl-item { position: relative; padding: 0 0 14px 12px; }
.co-tl-item::before { content: ''; position: absolute; left: -21px; top: 4px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--blue); border: 2px solid #fff; }
.co-tl-head { margin-bottom: 2px; }
.co-tl-link { font-size: 12px; margin-left: 6px; }
.co-tl-outcome { margin: 4px 0; }
.co-tl-facts { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; }
.co-tl-desc { font-size: 13px; margin-top: 2px; }
.co-tl-item .att-mini .muted { margin-right: 8px; }
.co-merge-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.co-merge-list label.check { margin: 0 0 6px; align-items: flex-start; }
@media (max-width: 640px) {
  .hist-export input[type=date] { width: 140px; }
  .co-timeline { padding-left: 10px; }
}
/* === end auth, history, tasks, companies === */

/* === admin views (dashboard, reports, users, settings, email-log, import) === */
.dash-matrix td.clickable .chip { text-decoration: underline dotted; }
.set-guide { background: var(--soft); border-radius: 8px; padding: 10px 12px; margin-top: 14px; line-height: 1.5; }
.set-guide code { background: #fff; padding: 1px 5px; border-radius: 4px; }
.set-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 14px; }
.set-lists textarea { font: 13px/1.45 Arial, Helvetica, sans-serif; min-height: 180px; }
.set-audit { max-height: 520px; overflow-y: auto; }
.set-detail { word-break: break-word; max-width: 460px; font-size: 12px; }
.el-to { word-break: break-all; max-width: 240px; }
.el-extra { font-size: 12px; margin-top: 3px; }
.el-err { font-size: 12px; font-weight: normal; margin-top: 4px; max-width: 320px; word-break: break-word; }
.imp-steps { margin: 0 0 6px 18px; padding: 0; }
.imp-steps li { margin: 4px 0; }
.imp-errors { max-height: 260px; overflow-y: auto; margin-bottom: 12px; }
.imp-preview { max-height: 480px; overflow: auto; }
.imp-preview td { font-size: 12px; max-width: 260px; word-break: break-word; }
@media (max-width: 640px) {
  .set-lists { grid-template-columns: 1fr; }
}
