/* ═══════════════════════════════════════════════════════════════════════════
   DealTrack — visual design
derives from one idea: this is a confidential financial record, so it should
   feel like a ledger rather than a marketing page. Restrained colour, generous
   whitespace, strong hierarchy, and numbers that line up.

   NO WEB FONTS AND NO EXTERNAL CSS, deliberately. The page's own policy is
   default-src 'none' with style-src 'self'. Loading a font from another origin
   would mean widening it, and the look of a table is not worth telling the
   browser to trust one more host on a page that shows confidential deals.
   The system stack is used instead, which is also faster and never flashes.
   ═══════════════════════════════════════════════════════════════════════════ */

:root{
  color-scheme:light;

  /* THE PAGE IS MICROSOFT BLUE, and the exact value is a legibility decision.
     #0078D4 -- the Fluent primary -- carries white text at about 4.0:1, under
     the 4.5:1 that small text needs. #0067B8 is the same blue family (it is
     what microsoft.com uses for this job) and reaches about 4.9:1, so the
     headings and notes that sit directly on the page are actually readable.
     #0078D4 is kept as the accent, where it sits on white and is fine. */
  --page:#0067b8;
  --on-page:#ffffff;
  --on-page-muted:rgba(255,255,255,.82);
  --bg:#0067b8;
  --surface:#ffffff;
  --surface-2:#fafbfc;
  --ink:#15181d;
  --ink-soft:#3d4450;
  --muted:#6b7382;
  --line:#e3e6eb;
  --line-strong:#d2d7df;

  --accent:#0078d4;
  --accent-soft:#eaf3fb;
  --accent-ink:#005a9e;

  --ok:#0a6c45;
  --ok-soft:#e7f5ee;
  --warn:#9a5b00;
  --warn-soft:#fdf3e3;
  --danger:#a8231b;
  --danger-soft:#fdeceb;
  --restricted:#6338b5;
  --restricted-soft:#f1ecfd;

  --radius:10px;
  --radius-sm:7px;
  --shadow-sm:0 1px 2px rgba(16,24,40,.06);
  --shadow:0 1px 3px rgba(16,24,40,.09), 0 6px 16px -6px rgba(16,24,40,.10);
  --shadow-lg:0 12px 40px -8px rgba(16,24,40,.28);

  --sans:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;
}

@media (prefers-color-scheme:dark){
  :root{
    color-scheme:dark;
    /* Dark mode keeps the blue rather than abandoning it: a deep navy of the
       same family, so the two themes read as one product. */
    --page:#08243d;
    --on-page:#e9eef4;
    --on-page-muted:rgba(233,238,244,.72);
    --bg:#08243d;
    --surface:#0f1b28;
    --surface-2:#152434;
    --ink:#e7e9ee;
    --ink-soft:#c3c8d2;
    --muted:#949cab;
    --line:#262b35;
    --line-strong:#333a46;

    --accent:#4cb1f5;
    --accent-soft:#10314c;
    --accent-ink:#9ed6ff;

    --ok:#5ac795;
    --ok-soft:#132a21;
    --warn:#e0a955;
    --warn-soft:#2b2113;
    --danger:#f08b84;
    --danger-soft:#2e1817;
    --restricted:#b99bf5;
    --restricted-soft:#221a35;

    --shadow-sm:0 1px 2px rgba(0,0,0,.4);
    --shadow:0 1px 3px rgba(0,0,0,.45), 0 8px 20px -8px rgba(0,0,0,.6);
    --shadow-lg:0 16px 48px -10px rgba(0,0,0,.7);
  }
}

*,*::before,*::after{box-sizing:border-box}

body{
  margin:0;
  background:var(--page);
  color:var(--on-page);
  font:400 14.5px/1.55 var(--sans);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

::selection{background:var(--accent-soft);color:var(--accent-ink)}

/* ── header ──────────────────────────────────────────────────────────────── */
#topbar{
  position:sticky;top:0;z-index:20;
  /* Solid, not translucent: over a saturated page a blurred bar turns muddy. */
  display:flex;align-items:center;gap:20px;flex-wrap:wrap;
  padding:0 24px;min-height:56px;
  background:var(--surface);
  box-shadow:0 1px 3px rgba(0,0,0,.18);
  border-bottom:1px solid var(--line);
}

.brand{
  display:flex;align-items:center;gap:9px;
  font-weight:640;letter-spacing:-.015em;font-size:15px;
}
.brand::before{
  content:"";width:9px;height:18px;border-radius:3px;
  background:linear-gradient(180deg,var(--accent) 0%,var(--restricted) 100%);
}

#topbar nav{display:flex;gap:2px;align-self:stretch;align-items:stretch}

.tab{
  border:0;background:none;cursor:pointer;
  padding:0 14px;margin:0;
  font:inherit;font-size:13.5px;font-weight:520;color:var(--muted);
  border-bottom:2px solid transparent;
  transition:color .12s ease,border-color .12s ease;
}
.tab:hover{color:var(--ink)}
.tab[aria-current="true"]{color:var(--accent);border-bottom-color:var(--accent)}

.who{
  margin-left:auto;display:flex;align-items:center;gap:10px;
  font-size:12.5px;color:var(--muted);
}
#whoami{
  padding:3px 9px;border-radius:999px;
  background:var(--surface-2);border:1px solid var(--line);
  white-space:nowrap;
}

main{max-width:1180px;margin:0 auto;padding:28px 24px 72px}

/* The body text colour is now the one that works ON THE BLUE. Every raised
   surface therefore restates its own, rather than inheriting white onto white. */
#topbar,.card,.filters,table,dialog{color:var(--ink)}

/* ── type ────────────────────────────────────────────────────────────────── */
h1{font-size:21px;font-weight:640;letter-spacing:-.02em;margin:0 0 6px}
h2{font-size:16.5px;font-weight:620;letter-spacing:-.01em;margin:28px 0 12px}
h3{font-size:13px;font-weight:620;text-transform:uppercase;letter-spacing:.06em;
   color:var(--muted);margin:24px 0 10px}
.note{color:var(--muted);font-size:12.8px;margin:6px 0}
.err{color:var(--danger);font-size:13px;margin:8px 0}
.warn{color:var(--warn);font-size:12.8px}
code{font-family:var(--mono);font-size:11.5px;color:var(--muted);word-break:break-all}

/* ── forms ───────────────────────────────────────────────────────────────── */
label{display:block;margin:0 0 14px;font-size:12.5px;font-weight:520;color:var(--muted)}

input,select,textarea{
  display:block;width:100%;margin-top:5px;
  padding:8px 11px;font:inherit;font-size:14px;
  color:var(--ink);background:var(--surface);
  border:1px solid var(--line-strong);border-radius:var(--radius-sm);
  box-shadow:var(--shadow-sm);
  transition:border-color .12s ease,box-shadow .12s ease;
}
input::placeholder,textarea::placeholder{color:var(--muted);opacity:.75}
input:hover,select:hover,textarea:hover{border-color:var(--muted)}
input:focus,select:focus,textarea:focus{
  outline:none;border-color:var(--accent);
  box-shadow:0 0 0 3px var(--accent-soft);
}
input:disabled,select:disabled,textarea:disabled{
  background:var(--surface-2);color:var(--muted);cursor:not-allowed;box-shadow:none;
}
textarea{resize:vertical;min-height:84px;line-height:1.55}
select{appearance:none;padding-right:30px;
  background-image:linear-gradient(45deg,transparent 50%,currentColor 50%),
                   linear-gradient(135deg,currentColor 50%,transparent 50%);
  background-position:calc(100% - 15px) 55%,calc(100% - 10px) 55%;
  background-size:5px 5px,5px 5px;background-repeat:no-repeat;
}

label.check{
  display:flex;align-items:center;gap:8px;color:var(--ink);font-weight:450;font-size:13.5px;
}
label.check input{width:auto;margin:0;box-shadow:none;accent-color:var(--accent)}

/* ── buttons ─────────────────────────────────────────────────────────────── */
button{
  font:inherit;font-size:13.5px;font-weight:520;
  padding:7px 14px;cursor:pointer;
  color:var(--ink-soft);background:var(--surface);
  border:1px solid var(--line-strong);border-radius:var(--radius-sm);
  box-shadow:var(--shadow-sm);
  transition:background .12s ease,border-color .12s ease,color .12s ease,transform .06s ease;
}
button:hover{background:var(--surface-2);border-color:var(--muted);color:var(--ink)}
button:active{transform:translateY(.5px)}
button:focus-visible{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
button:disabled{opacity:.55;cursor:progress}

button.primary,
#login-form button[type=submit],
#mfa-form button[type=submit],
#user-form button[type=submit],
#report-filters button[type=submit]{
  background:var(--accent);border-color:var(--accent);color:#fff;
}
button.primary:hover,
#login-form button[type=submit]:hover,
#mfa-form button[type=submit]:hover,
#user-form button[type=submit]:hover,
#report-filters button[type=submit]:hover{
  filter:brightness(1.07);color:#fff;border-color:var(--accent);
}
button.danger{color:var(--danger);border-color:var(--line-strong)}
button.danger:hover{background:var(--danger-soft);border-color:var(--danger);color:var(--danger)}

/* ── the sign-in card ────────────────────────────────────────────────────── */
.card{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:14px;
  box-shadow:var(--shadow);
  padding:32px;max-width:400px;margin:9vh auto 0;
}
.card h1{margin-bottom:20px}
.card button[type=submit]{width:100%;margin-top:4px;padding:9px}
.card .note{margin-top:18px;padding-top:16px;border-top:1px solid var(--line);line-height:1.5}
#mfa-secret{font-family:var(--mono);font-size:13px;letter-spacing:.13em;text-align:center}
#enrol details{margin:-4px 0 14px}
#enrol summary{cursor:pointer;font-size:12.5px;color:var(--muted)}
#enrol summary:hover{color:var(--accent)}

/* ── toolbars and filters ────────────────────────────────────────────────── */
.bar{display:flex;gap:8px;align-items:center;margin-bottom:16px;flex-wrap:wrap}
.bar .grow{flex:1}
#search{max-width:320px;margin:0}
.bar label.check{margin:0;color:var(--on-page)}

.filters{
  display:flex;gap:14px;align-items:flex-end;flex-wrap:wrap;
  background:var(--surface);border:1px solid var(--line);
  border-radius:var(--radius);box-shadow:var(--shadow-sm);
  padding:16px 18px;margin-bottom:18px;
}
.filters label{margin:0;min-width:128px}
.filters label.check{min-width:auto;align-self:center;padding-bottom:7px}

/* ── tables ──────────────────────────────────────────────────────────────── */
table{
  width:100%;border-collapse:separate;border-spacing:0;
  background:var(--surface);
  border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow-sm);overflow:hidden;
}
th,td{text-align:left;padding:10px 14px;font-size:13.8px;vertical-align:middle}
thead th{
  font-size:11px;font-weight:620;text-transform:uppercase;letter-spacing:.07em;
  color:var(--muted);background:var(--surface-2);
  border-bottom:1px solid var(--line);white-space:nowrap;
}
tbody td{border-bottom:1px solid var(--line);color:var(--ink-soft)}
tbody td:first-child{color:var(--ink);font-weight:520}
tbody tr:last-child td{border-bottom:0}
tbody tr{transition:background .1s ease}
tbody tr:hover{background:var(--surface-2)}

/* Money lines up. A financial table whose figures do not share a column edge
   is harder to scan than one with fewer features. */
td.num,th.num{text-align:right;font-variant-numeric:tabular-nums;font-feature-settings:"tnum" 1}

tfoot th{
  background:var(--surface-2);border-top:1px solid var(--line-strong);
  font-size:13px;text-transform:none;letter-spacing:0;color:var(--ink);font-weight:620;
}

td:last-child{white-space:nowrap}
td button{padding:4px 10px;font-size:12.5px}
td button + button{margin-left:5px}

button.sort{
  border:0;background:none;box-shadow:none;padding:0;margin:0;
  font:inherit;font-size:11px;font-weight:620;text-transform:uppercase;
  letter-spacing:.07em;color:var(--muted);cursor:pointer;
}
button.sort:hover{color:var(--accent);background:none}
button.sort[aria-sort]{color:var(--accent)}
button.sort[aria-sort="ascending"]::after{content:" ↑"}
button.sort[aria-sort="descending"]::after{content:" ↓"}

#report-summary{max-width:560px}

/* ── pills ───────────────────────────────────────────────────────────────── */
.pill{
  display:inline-block;padding:1.5px 8px;border-radius:999px;
  font-size:11px;font-weight:600;letter-spacing:.02em;
  border:1px solid var(--line-strong);color:var(--muted);background:var(--surface-2);
  vertical-align:1px;
}
.pill.restricted{color:var(--restricted);background:var(--restricted-soft);border-color:transparent}
.pill.owner{color:var(--warn);background:var(--warn-soft);border-color:transparent}

.status{
  display:inline-block;padding:1.5px 9px;border-radius:999px;
  font-size:11.5px;font-weight:600;border:1px solid transparent;text-transform:capitalize;
}
.status-open{color:var(--accent);background:var(--accent-soft)}
.status-in_progress{color:var(--warn);background:var(--warn-soft)}
.status-won{color:var(--ok);background:var(--ok-soft)}
.status-lost{color:var(--danger);background:var(--danger-soft)}
.status-archived{color:var(--muted);background:var(--surface-2);border-color:var(--line)}

/* ── dialogs ─────────────────────────────────────────────────────────────── */
dialog{
  border:1px solid var(--line);border-radius:14px;
  background:var(--surface);color:var(--ink);
  padding:26px 28px;width:min(580px,94vw);
  box-shadow:var(--shadow-lg);
}
dialog::backdrop{background:rgba(12,16,24,.5);backdrop-filter:blur(2px)}
dialog h2{margin:0 0 18px;font-size:17px}
dialog menu{display:flex;gap:8px;align-items:center;padding:0;
  margin:22px 0 0;padding-top:18px;border-top:1px solid var(--line)}
dialog menu button:last-child{margin-left:auto}
#grants ul{list-style:none;padding:0;margin:0 0 12px}
#grants li{display:flex;align-items:center;gap:8px;padding:7px 0;
  border-bottom:1px solid var(--line);font-size:13.5px}
#grants li:last-child{border-bottom:0}
.row{display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap}
.row label{margin:0}

/* ── toast ───────────────────────────────────────────────────────────────── */
#toast{
  position:fixed;left:50%;bottom:28px;transform:translateX(-50%);margin:0;
  background:var(--ink);color:var(--bg);
  padding:10px 18px;border-radius:999px;font-size:13px;font-weight:500;
  box-shadow:var(--shadow-lg);z-index:50;max-width:90vw;
}

/* ── printing ────────────────────────────────────────────────────────────── */
/* A printed report leaves the building and outlives the screen that made it:
   controls go, the confidentiality line appears, and the header repeats so
   page four still says what it is. */
.print-only{display:none}
@media print{
  /* --page too, not just --bg: the body background moved to --page when the
     app went blue, and a print rule that still only resets --bg would put a
     saturated blue behind every printed report. */
  :root{--page:#fff;--on-page:#000;--on-page-muted:#444;
        --bg:#fff;--surface:#fff;--surface-2:#fff;--ink:#000;--ink-soft:#000;
        --muted:#444;--line:#bbb;--line-strong:#888}
  @page{size:landscape;margin:14mm}
  body{background:#fff;color:#000;font-size:10.5pt}
  #topbar,.no-print,.filters,#toast,dialog{display:none!important}
  main{max-width:none;padding:0}
  .print-only{display:block}
  .view[hidden]{display:none!important}
  table{border:1px solid #999;box-shadow:none;border-radius:0;page-break-inside:auto}
  thead{display:table-header-group}
  tfoot{display:table-footer-group}
  tr{page-break-inside:avoid}
  th,td{border-bottom:1px solid #ccc;padding:4pt 6pt}
  thead th{background:#f0f0f0;color:#000}
  .pill,.status{border:1px solid #999;background:none;color:#000}
  button.sort{color:#000}
  button.sort::after{content:""!important}
  a[href]::after{content:""}
}

/* ── tablets and phones ──────────────────────────────────────────────────── */
/* A wide table scrolls INSIDE its own box. Without this, a table with more
   columns than the screen is wide pushes the whole page sideways, and every
   heading and button on it slides off the left edge along with the table. */
@media (max-width:1024px){
  table{display:block;overflow-x:auto}
}

@media (max-width:640px){
  main{padding:20px 14px 60px}
  .card{margin-top:5vh;padding:24px}

  /* The top bar wraps instead of widening the page. Its right-hand group --
     name, Handbook, Change password, Sign out -- was one row that could not
     break, about 450px on a 390px phone, and that one row made the entire page
     wider than the screen. Not sticky here: two or three wrapped lines pinned
     to the top would take a fifth of a phone's height. */
  #topbar{position:static;padding:6px 14px 10px;gap:6px 12px}
  .who{margin-left:0;flex-wrap:wrap;gap:8px}
  #whoami{white-space:normal}

  /* THE DEAL LIST IS ONE CARD PER DEAL. Eight columns cannot fit a phone, and
     the column that fell off the edge was the one holding the button that opens
     the deal. Same rows, same code path: each cell carries its column name in
     data-label (app.js), shown here because the header row is not. */
  #deals{display:block;background:none;border:0;box-shadow:none;overflow:visible}
  #deals thead{display:none}
  #deals tbody{display:block}
  #deals tbody tr{
    display:block;margin:0 0 10px;padding:12px 14px;
    background:var(--surface);border:1px solid var(--line);
    border-radius:var(--radius);box-shadow:var(--shadow-sm);
  }
  #deals tbody tr:hover{background:var(--surface)}
  #deals td{display:flex;gap:12px;align-items:baseline;padding:3px 0;border:0;white-space:normal}
  #deals td::before{
    content:attr(data-label);flex:0 0 74px;
    font-size:11px;font-weight:620;text-transform:uppercase;letter-spacing:.07em;color:var(--muted);
  }
  #deals td:first-child{display:block;font-size:15px;padding:0 0 6px}
  #deals td:first-child::before{content:none}
  /* An empty cell -- no location recorded -- is left out rather than shown as a
     label with nothing beside it. */
  #deals td:empty{display:none}
  #deals td.actions{display:block;padding:10px 0 0}
  #deals td.actions::before{content:none}
  #deals td.actions button{width:100%;margin:0}
}

/* ── touch screens, at any width ─────────────────────────────────────────── */
@media (pointer:coarse){
  /* iPhones and iPads zoom the page in when a text box smaller than 16px is
     tapped, and leave it zoomed. 16px is the size that does not trigger it. */
  input,select,textarea{font-size:16px}
  /* About 44px is what a fingertip needs. */
  button,.topbtn,.tab{min-height:44px}
  td button{padding:8px 14px;font-size:14px}
  button.sort{min-height:0}
}

@media (prefers-reduced-motion:reduce){
  *{transition:none!important;animation:none!important}
}

/* ── page headings ───────────────────────────────────────────────────────── */
.page-head{margin:0 0 20px}
.page-head h1{margin:0 0 2px;color:var(--on-page)}
.page-head .note{margin:0;color:var(--on-page-muted)}
main > .view > h2,
main > .view > h3{color:var(--on-page)}
#report-count,#report-meta,#deals-empty{color:var(--on-page-muted)}

.card-brand{
  display:flex;align-items:center;gap:9px;
  font-weight:640;letter-spacing:-.015em;font-size:14px;color:var(--muted);
  margin:0 0 22px;
}
.card-brand::before{
  content:"";width:9px;height:18px;border-radius:3px;
  background:linear-gradient(180deg,var(--accent) 0%,var(--restricted) 100%);
}

/* ── people on a deal ────────────────────────────────────────────────────── */
.contact-form{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px 14px;
  margin:12px 0 4px;align-items:end}
.contact-form label{margin:0}
.contact-form label.wide{grid-column:1 / -1}
.contact-form button{grid-column:1 / -1;justify-self:start}
#contact-add summary{cursor:pointer;font-size:13px;color:var(--accent);margin:10px 0 0}
#contact-add summary:hover{text-decoration:underline}
#contact-table td{vertical-align:top}
.contact-lines{display:block;font-size:12.5px;color:var(--muted);line-height:1.45}
.contact-lines b{font-weight:600;color:var(--ink-soft)}
@media (max-width:560px){ .contact-form{grid-template-columns:1fr} }

/* ── the note log ────────────────────────────────────────────────────────── */
#note-entries{list-style:none;margin:0 0 6px;padding:0;max-height:260px;overflow-y:auto}
#note-entries li{padding:9px 0;border-bottom:1px solid var(--line)}
#note-entries li:last-child{border-bottom:0}
.note-head{font-size:11.5px;font-weight:600;color:var(--muted);letter-spacing:.02em}
.note-body{font-size:13.5px;color:var(--ink);white-space:pre-wrap;margin-top:3px}

/* A link that has to sit among buttons and read as one of them. */
.topbtn{
  display:inline-flex;align-items:center;
  font:520 13.5px/1 var(--sans);text-decoration:none;
  padding:7px 14px;color:var(--ink-soft);background:var(--surface);
  border:1px solid var(--line-strong);border-radius:var(--radius-sm);
  box-shadow:var(--shadow-sm);
  transition:background .12s ease,border-color .12s ease,color .12s ease;
}
.topbtn:hover{background:var(--surface-2);border-color:var(--muted);color:var(--ink)}
.topbtn:focus-visible{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
