:root {
  /* Brand, sampled from STARBIRD_Logo_Pos.png */
  --brand-navy: #222b41;
  --brand-cyan: #01aaff;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-strong: #cbd1da;
  --text: #222b41;
  --muted: #6b7382;
  /* Brand cyan is only 2.6:1 on white, too low for text or controls, so
     interactive elements use a darkened version of the same hue (5.1:1) and
     the cyan itself is kept for graphics: bars, dots, active states. */
  --accent: #0072be;
  --accent-soft: #e6f2fb;
  --green: #12805c;
  --green-soft: #e3f5ee;
  --amber: #9a6600;
  --amber-soft: #fdf1da;
  --red: #b3261e;
  --red-soft: #fdeceb;
  --purple: #6b3fa0;
  --purple-soft: #f0e9fa;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.topbar {
  background: var(--brand-navy);
  color: #fff;
  padding: 7px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  /* min-height rather than height: the nav wraps on narrow windows and the
     bar should grow with it instead of spilling over. */
  min-height: 52px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { display: flex; align-items: center; flex-shrink: 0; }
.topbar .brand img { height: 21px; width: auto; display: block; }
.topbar nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  color: #aab3c6;
  padding: 6px 9px;
  border-radius: 6px;
  font-weight: 500;
  white-space: nowrap;
}
.topbar nav a:hover { background: #303b55; color: #fff; text-decoration: none; }
.topbar nav a.active { background: #3a4661; color: #fff; }
.topbar .me { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #aab3c6; white-space: nowrap; }
.topbar .me img { width: 26px; height: 26px; border-radius: 50%; }
.topbar .me a { color: #aab3c6; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 20px 64px; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; margin: 0 0 2px; font-weight: 640; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card > h2, .card > .card-head {
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 620;
  background: #fafbfc;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card > h2 .count { color: var(--muted); font-weight: 500; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 3px; letter-spacing: -.5px; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 1px; }
.stat.alert .value { color: var(--red); }
.stat.good .value { color: var(--green); }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap, th.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---- badges ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: #eef0f3; color: #4a5160; border: 1px solid transparent;
}
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.ghost { background: transparent; border-color: var(--border-strong); color: var(--muted); }

.stage-lead, .stage-reaching_out { background: #eef0f3; color: #4a5160; }
.stage-discovery { background: var(--accent-soft); color: var(--accent); }
.stage-poc { background: var(--purple-soft); color: var(--purple); }
.stage-proposal, .stage-negotiation { background: var(--amber-soft); color: var(--amber); }
.stage-closed_won { background: var(--green-soft); color: var(--green); }
.stage-closed_lost { background: var(--red-soft); color: var(--red); }
.stage-dormant { background: #eef0f3; color: var(--muted); }

/* ---- buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: #fff; color: var(--text); font-size: 13px; font-weight: 550;
  cursor: pointer; font-family: inherit; line-height: 1.3;
}
.btn:hover { background: #f4f6f9; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #005b98; }
.btn.danger { color: var(--red); border-color: #e8bfbc; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 2px 4px; }
.btn.link:hover { background: none; text-decoration: underline; }

label { display: block; font-size: 12px; font-weight: 600; color: #3d4450; margin-bottom: 4px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=url], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: 6px; font-size: 13.5px; font-family: inherit; background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(1,170,255,.18);
}
textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
select[multiple] { min-height: 92px; }
.field { margin-bottom: 14px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 6px; }
.inline-form { display: inline; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; }
.check input { width: auto; }

/* ---- filter bar ---- */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.filters .field { margin-bottom: 0; }
.filters .field.grow { flex: 1; min-width: 180px; }
.filters select, .filters input { min-width: 130px; }

/* ---- misc ---- */
.flash {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 13px; border: 1px solid;
}
.flash.err { background: var(--red-soft); border-color: #f0c9c6; color: var(--red); }
.flash.ok { background: var(--green-soft); border-color: #bfe5d7; color: var(--green); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.strong { font-weight: 620; }
.overdue { color: var(--red); font-weight: 600; }
.due-today { color: var(--amber); font-weight: 600; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pre-wrap { white-space: pre-wrap; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
details.inline-edit summary { cursor: pointer; font-size: 12px; color: var(--accent); list-style: none; }
details.inline-edit summary::-webkit-details-marker { display: none; }
details.inline-edit[open] summary { margin-bottom: 10px; }
.timeline-item { padding: 13px 16px; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 3px; }
.bar { height: 7px; border-radius: 4px; background: var(--brand-cyan); min-width: 2px; }
.bar-track { background: #eef0f3; border-radius: 4px; width: 100%; }

.login-wrap { max-width: 400px; margin: 90px auto; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 30px; box-shadow: 0 4px 20px rgba(16,24,40,.08); text-align: center; }
.login-card .logo { display: block; width: 220px; max-width: 100%; height: auto; margin: 2px auto 20px; }
.login-card h1 { font-size: 17px; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 13px; }

@media (max-width: 860px) {
  .topbar { padding: 8px 14px; flex-wrap: wrap; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .topbar .me { margin-left: auto; }
  .wrap { padding: 16px 14px 48px; }
  th, td { padding: 8px 10px; }
}

/* ---- company cards ---- */
.company-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.company-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.company-card:hover { border-color: var(--border-strong); }
.company-card.is-stale { border-left: 3px solid var(--red); }
.company-card.is-archived { opacity: .72; }

/* The header carries the two things asked for first: what stage the deal is
   at, and who leads it. Everything else sits below the rule. */
.company-card .cc-head { padding: 13px 15px 12px; }
.company-card .cc-title {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; margin-bottom: 9px;
}
.company-card .cc-name {
  font-size: 15.5px; font-weight: 640; line-height: 1.3; letter-spacing: -.1px;
}
.company-card .cc-name a { color: var(--text); }
.company-card .cc-name a:hover { color: var(--accent); }

.company-card .cc-owner { display: flex; align-items: center; gap: 8px; }
.company-card .cc-owner .avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-navy); color: #fff;
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  display: flex; align-items: center; justify-content: center;
}
.company-card .cc-owner .who { line-height: 1.25; min-width: 0; }
.company-card .cc-owner .who .label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 600;
}
.company-card .cc-owner .who .name {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.company-card .cc-body { border-top: 1px solid var(--border); }

.cc-figures {
  /* minmax(0, 1fr), not 1fr: a wide value in one column must not steal
     width from the others and wrap their headings. */
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
}
.cc-figures div { padding: 9px 12px; min-width: 0; }
.cc-figures div + div { border-left: 1px solid var(--border); }
.cc-figures .k {
  font-size: 10px; text-transform: uppercase; letter-spacing: .3px;
  color: var(--muted); font-weight: 600; white-space: nowrap;
}
.cc-figures .v {
  font-size: 14.5px; font-weight: 640; margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.cc-figures .v .sub { font-size: 11px; font-weight: 500; color: var(--muted); }

.cc-next { padding: 10px 15px; border-bottom: 1px solid var(--border); font-size: 13px; }
.cc-next .k {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600; margin-bottom: 2px;
}
.cc-next .none { color: var(--muted); }

.cc-meta {
  padding: 9px 15px; font-size: 12px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 5px 9px; align-items: center;
  margin-top: auto;
}
.cc-meta .badge { font-size: 10.5px; }
.cc-meta .cc-edit {
  margin-left: auto; font-weight: 600; font-size: 12px;
  padding: 2px 8px; border: 1px solid var(--border-strong); border-radius: 5px;
  color: var(--accent); background: #fff; white-space: nowrap;
}
.cc-meta .cc-edit:hover { background: var(--accent-soft); text-decoration: none; }

.view-toggle { display: flex; gap: 0; }
.view-toggle .btn { border-radius: 0; margin-left: -1px; }
.view-toggle .btn:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.view-toggle .btn:last-child { border-radius: 0 6px 6px 0; }

@media (max-width: 420px) {
  .company-grid { grid-template-columns: 1fr; }
  .cc-figures { grid-template-columns: 1fr 1fr; }
  .cc-figures div:nth-child(3) { border-left: none; border-top: 1px solid var(--border); grid-column: 1 / -1; }
}

/* ---- attachments ---- */
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px 3px 4px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: #fff; font-size: 12.5px;
  max-width: 100%; white-space: nowrap;
}
.file-chip:hover { border-color: var(--accent); text-decoration: none; }
.file-chip .ext {
  background: var(--brand-navy); color: #fff; border-radius: 4px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .4px;
  padding: 2px 5px; flex-shrink: 0;
}
.file-chip a { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.file-chip .muted { font-size: 11.5px; }
.file-chip .chip-x {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 15px; line-height: 1; padding: 0 2px; font-family: inherit;
}
.file-chip .chip-x:hover { color: var(--red); }

input[type=file] {
  width: 100%; padding: 7px 10px; font-size: 13px; font-family: inherit;
  border: 1px dashed var(--border-strong); border-radius: 6px; background: #fff;
}
input[type=file]:hover { border-color: var(--accent); }

/* A destructive button sits at the far end of its row, never directly under
   the primary action where the pointer already is. */
.form-actions .push-right { margin-left: auto; }

/* The per-person edit panel: summary sits in the card footer, the panel it
   opens spans the whole card. */
.person-edit { border-top: 1px solid var(--border); }
.person-edit > summary {
  padding: 8px 15px; font-size: 12px; font-weight: 600; color: var(--accent);
  cursor: pointer; list-style: none;
}
.person-edit > summary::-webkit-details-marker { display: none; }
.person-edit > summary:hover { background: var(--accent-soft); }
.person-edit[open] > summary { background: var(--accent-soft); }

/* ---- deals inside a company card ---- */
.cc-deals { border-bottom: 1px solid var(--border); }
.deal-line {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 15px; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 13px;
}
.deal-line:last-child { border-bottom: none; }
.deal-line:hover { background: var(--accent-soft); text-decoration: none; }
.deal-line.is-stale { box-shadow: inset 3px 0 0 var(--red); }
.deal-line .deal-name {
  flex: 1; min-width: 0; font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.deal-line .deal-value { font-variant-numeric: tabular-nums; font-weight: 620; white-space: nowrap; }
.timeline-item.is-archived { opacity: .6; }
