/* ===========================================================================
   CSMC app shell — the chrome every app wears.

   NOT specific to Special Loans. In production a user switches apps via the
   waffle in the top-left; each app drops its own nav items and content into
   this same frame. Keep app-specific styling in the prototype, not in here.

   Deliberately LIGHT, unlike the navy .sidebar in design-system.css. That one
   suits a reporting surface; this suits a working tool you sit in all day —
   closer to Linear or Asana. Both draw from the same tokens.

   Layout:   topbar across the top
             nav (230px) | main | properties (340px, optional)

   340px matches Moonshot/designs/deal-workspace.html so this shell and the
   existing mockups agree rather than nearly agreeing.
   =========================================================================== */

/* ---- Frame --------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--card);
}

.shell-body {
  display: grid;
  grid-template-columns: 230px 1fr;
  overflow: hidden;
}
.shell-body.with-props {
  grid-template-columns: 230px 1fr 340px;
}

/* ---- Top bar ------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.waffle {
  width: 30px; height: 30px;
  border: none; background: transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  grid-template-columns: repeat(3, 3px);
  grid-template-rows: repeat(3, 3px);
  gap: 3px;
  place-content: center;
  flex-shrink: 0;
}
.waffle i { background: var(--muted); border-radius: 1px; }
.waffle:hover { background: var(--bg); }
.waffle:hover i { background: var(--navy); }

.app-badge {
  width: 22px; height: 22px; border-radius: var(--r-sm);
  background: var(--navy); color: #fff;
  font-size: .62rem; font-weight: 800; letter-spacing: .02em;
  display: grid; place-items: center; flex-shrink: 0;
}
.app-name {
  font-size: .8rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink);
}

.topbar .spacer { flex: 1; }

.kbd {
  font: 600 .68rem "Segoe UI", system-ui, sans-serif;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 7px;
  background: var(--bg);
  cursor: pointer;
}
.kbd:hover { border-color: var(--bronze); color: var(--navy); }

.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--bronze); color: #fff;
  font-size: .64rem; font-weight: 700;
  display: grid; place-items: center; flex-shrink: 0;
}

/* App-switcher popover */
.app-grid {
  position: absolute; top: 44px; left: 10px; z-index: 200;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-2);
  padding: 12px; width: 260px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.app-grid a {
  display: grid; place-items: center; gap: 6px;
  padding: 12px 6px; border-radius: var(--r-md);
  text-decoration: none; color: var(--ink); font-size: .68rem; text-align: center;
}
.app-grid a:hover { background: var(--bg); }
.app-grid .tile {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-size: .6rem; font-weight: 800; color: #fff;
}

/* ---- Left nav ------------------------------------------------------------ */
.nav {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-group {
  font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--faint); font-weight: 700;
  margin: 18px 0 6px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px; border-radius: var(--r-sm);
  font-size: .82rem; color: var(--ink);
  cursor: pointer; text-decoration: none;
  border: none; background: none; width: 100%;
  font-family: inherit; text-align: left;
}
.nav-item:hover  { background: #e8ecf1; }
.nav-item.active { background: #dfe7f2; font-weight: 600; color: var(--navy); }

.nav-item .sq { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.nav-item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .cnt { font-size: .72rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav-item.active .cnt { color: var(--navy); }

/* ---- Main ---------------------------------------------------------------- */
.content { overflow-y: auto; background: var(--card); }
.content-head {
  padding: 18px 26px 0;
  position: sticky; top: 0; background: var(--card); z-index: 5;
}
.content-body { padding: 0 26px 60px; }

/* ---- Filter bar ---------------------------------------------------------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.filters select, .filters input[type=text] {
  width: auto; min-width: 130px;
  padding: 6px 9px; font-size: .8rem;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
}
.filters .clear {
  font-size: .76rem; color: var(--blue); cursor: pointer;
  background: none; border: none; font-family: inherit;
}

/* ---- Properties panel ---------------------------------------------------- */
.props {
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 18px 16px 60px;
  overflow-y: auto;
}
.props h4 {
  font-size: .62rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--faint); font-weight: 700;
  margin: 22px 0 8px;
}
.props h4:first-child { margin-top: 0; }

.prop {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 5px 0; font-size: .8rem;
}
.prop .pk { width: 116px; flex-shrink: 0; color: var(--muted); padding-top: 3px; }
.prop .pv { flex: 1; min-width: 0; }

/* Click-to-edit value — Linear's core interaction */
.editable {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 7px; margin: -3px -7px;
  border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid transparent;
  width: calc(100% + 14px);
  font-family: inherit; font-size: inherit; color: var(--ink);
  background: none; text-align: left;
}
.editable:hover { background: #e8ecf1; border-color: var(--line); }
.editable .caret { margin-left: auto; color: var(--faint); font-size: .7rem; }
.editable.empty { color: var(--faint); font-style: italic; }

/* Internal-only band — load-bearing, not decoration (NPLX-04) */
.internal-band {
  border: 1px dashed #e0cda0; background: #fbf7ee;
  border-radius: var(--r-md); padding: 10px 12px; margin-top: 8px;
}
.internal-band .tag {
  font-size: .58rem; font-weight: 800; letter-spacing: .1em;
  text-transform: uppercase; color: var(--bronze);
  display: flex; align-items: center; gap: 5px; margin-bottom: 8px;
}

/* ---- Breadcrumb ---------------------------------------------------------- */
.crumb {
  display: flex; align-items: center; gap: 7px;
  font-size: .78rem; color: var(--muted);
}
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--navy); }
.crumb .sep { color: var(--faint); }
.crumb .right { margin-left: auto; font-weight: 700; color: var(--ink); }

/* ---- Stage track (chevron rail) ------------------------------------------
   Four states. `skipped` is the one that matters and the one a plain progress
   bar gets wrong: a file that went straight from demand letter to enforcement
   never entered forbearance, and painting that as "still to come" misreads it. */
.track { display: flex; gap: 3px; margin: 14px 0 4px; }

.track-step {
  flex: 1; min-width: 0;
  padding: 9px 14px 9px 24px;
  background: #eef1f5;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%, 12px 50%);
}
.track-step:first-child {
  padding-left: 14px;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%);
}
.track-step:last-child {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 12px 50%);
}

.track-step .tl {
  font-size: .62rem; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.track-step .td {
  font-size: .7rem; color: var(--faint); margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.track-step.done    { background: #cfe0f2; }
.track-step.done .tl { color: var(--navy); }
.track-step.done .td { color: #4a6f96; }

.track-step.current { background: var(--navy-deep); }
.track-step.current .tl { color: #fff; }
.track-step.current .td { color: #a9bed4; }

.track-step.pending { background: #f4f6f9; }

.track-step.skipped {
  background: repeating-linear-gradient(135deg, #f4f6f9, #f4f6f9 5px, #e9edf2 5px, #e9edf2 10px);
}
.track-step.skipped .tl { color: var(--faint); text-decoration: line-through; }

/* ---- Tabs ---------------------------------------------------------------- */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-top: 16px;
}
.tab {
  padding: 9px 16px; border: none; background: none;
  font-family: inherit; font-size: .84rem; font-weight: 600;
  color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--navy); }
.tab.on    { color: var(--navy); border-bottom-color: var(--bronze); }
.tab .n {
  font-size: .68rem; color: var(--faint); font-weight: 600;
  margin-left: 5px; font-variant-numeric: tabular-nums;
}

/* ---- Financial table ----------------------------------------------------- */
table.fin { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.fin th {
  text-align: right; font-size: .66rem; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line);
}
table.fin th:first-child { text-align: left; }
table.fin td {
  padding: 9px 12px; border-bottom: 1px solid #eef1f4;
  text-align: right; font-variant-numeric: tabular-nums;
}
table.fin td:first-child { text-align: left; }
table.fin tr.costs td { color: var(--muted); font-style: italic; }
table.fin tr.total td {
  border-top: 2px solid var(--navy); border-bottom: none;
  font-weight: 700; padding-top: 11px;
}
.pos {
  display: inline-block; min-width: 20px; text-align: center;
  font-size: .7rem; font-weight: 800; color: var(--blue);
  background: var(--blue-bg); border-radius: 4px; padding: 1px 6px;
}

/* ---- Charts --------------------------------------------------------------
   Palette lives in JS (validated with the dataviz validator against the white
   card surface); this file carries only geometry and chrome. Marks stay thin,
   grid recessive, and every chart ships a table-view twin. */
.chart-card { background: var(--card); border: 1px solid var(--line);
              border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: 18px 20px; }
.chart-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.chart-head h3 { margin: 0; font-size: .96rem; }
.chart-head .sub { font-size: .74rem; color: var(--muted); }
.chart-head .toggle {
  margin-left: auto; border: none; background: none; font-family: inherit;
  font-size: .72rem; color: var(--blue); cursor: pointer; padding: 2px 4px;
}
.chart-head .toggle:hover { text-decoration: underline; }

.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut-hole { position: relative; flex-shrink: 0; }
.donut-hole .mid {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  pointer-events: none;
}
.donut-hole .mid .v { font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
.donut-hole .mid .k { font-size: .64rem; color: var(--muted); }
.donut-hole path { stroke: var(--card); stroke-width: 2; cursor: pointer; }
.donut-hole path:hover { opacity: .82; }

/* Legend is always present for >= 2 series; identity is never colour-alone. */
.legend { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.legend-item .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-item .nm { color: var(--ink); }
.legend-item .vl { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Horizontal bars. One hue: length carries the magnitude, not colour. */
.bar-row { display: grid; grid-template-columns: 120px 1fr 54px; align-items: center;
           gap: 10px; padding: 4px 0; font-size: .8rem; }
.bar-row .bl { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bt { background: #eef1f5; border-radius: 3px; height: 14px; overflow: hidden; }
.bar-row .bf { height: 100%; border-radius: 0 3px 3px 0; }
.bar-row .bv { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }

/* Single stacked bar for part-to-whole of a ranked pair. */
.stack { display: flex; height: 26px; border-radius: 4px; overflow: hidden; gap: 2px; }
.stack .seg { height: 100%; position: relative; }

.viz-tip {
  position: fixed; z-index: 500; pointer-events: none;
  background: var(--navy-deep); color: #fff; border-radius: var(--r-sm);
  padding: 7px 10px; font-size: .76rem; box-shadow: var(--sh-2); max-width: 240px;
}
.viz-tip .t { font-weight: 700; margin-bottom: 2px; }

/* ---- Photo gallery -------------------------------------------------------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.shot { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: #fff; }
.shot img { width: 100%; height: 150px; object-fit: cover; display: block; }
.shot .cap { padding: 9px 11px; font-size: .8rem; }
.shot .cap .m { font-size: .72rem; color: var(--muted); margin-top: 2px;
                display: flex; align-items: center; gap: 8px; }
.shot .cap .m button { margin-left: auto; border: none; background: none;
                       color: var(--red); font-size: .72rem; cursor: pointer; font-family: inherit; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--r-md);
  padding: 26px; text-align: center; color: var(--muted); font-size: .86rem;
}
.dropzone label {
  display: inline-block; margin-top: 8px; color: var(--blue);
  cursor: pointer; font-weight: 600; font-size: .84rem;
}

/* ---- Popover (shared by property editors and the palette) ---------------- */
/* fixed, not absolute — anchored from getBoundingClientRect, so it must not
   shift when an ancestor scrolls */
.pop {
  position: fixed; z-index: 300;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--sh-2);
  padding: 5px; min-width: 210px; max-height: 320px; overflow-y: auto;
}
.pop button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 9px;
  border: none; background: none; border-radius: var(--r-sm);
  font: inherit; font-size: .82rem; color: var(--ink);
  cursor: pointer; text-align: left;
}
.pop button:hover     { background: var(--bg); }
.pop button.on        { background: #dfe7f2; font-weight: 600; }
.pop button:disabled  { opacity: .35; cursor: not-allowed; }
.pop .pop-head {
  font-size: .6rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint); font-weight: 700; padding: 7px 9px 4px;
}
.pop input[type=text] {
  width: 100%; padding: 7px 9px; font-size: .84rem;
  border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: 4px;
}

/* ---- Command palette ----------------------------------------------------- */
.palette-scrim {
  position: fixed; inset: 0; background: rgba(16,40,68,.28);
  z-index: 400; display: grid; place-items: start center; padding-top: 14vh;
}
.palette {
  width: min(560px, 92vw);
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: 0 20px 60px rgba(16,40,68,.32);
  overflow: hidden;
}
.palette input {
  width: 100%; border: none; border-bottom: 1px solid var(--line);
  padding: 15px 18px; font-size: .98rem; font-family: inherit; outline: none;
}
.palette .results { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette .results button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: none; background: none;
  border-radius: var(--r-sm); font: inherit; font-size: .86rem;
  cursor: pointer; text-align: left; color: var(--ink);
}
.palette .results button:hover,
.palette .results button.sel { background: var(--bg); }
.palette .results .hint { margin-left: auto; font-size: .68rem; color: var(--faint); }
.palette .empty { padding: 22px; text-align: center; color: var(--muted); font-size: .86rem; }
