:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f9fbfb;
  --text: #1c2428;
  --muted: #637178;
  --line: #dbe2e5;
  --line-strong: #c7d0d5;
  --blue: #2367a8;
  --green: #2f7d56;
  --amber: #b36b13;
  --red: #b4433f;
  --teal: #237c83;
  --ink: #0f191f;
  --shadow: 0 12px 30px rgba(20, 35, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.drawer-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #11191f;
  color: #f7fbfc;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-block {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #ffffff;
  background: #1d4f63;
}

.brand-block h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.15;
}

.brand-block p,
.source-note,
.eyebrow,
small {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.brand-block p,
.source-note {
  color: rgba(255, 255, 255, 0.64);
}

.view-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 40px;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255, 255, 255, 0.74);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.16);
}

.source-note {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.mobile-tabbar {
  display: none;
}

.mobile-nav-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mobile-nav-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 24px;
  border-radius: 8px;
  background: #edf2f4;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

.title-group h2 {
  margin: 3px 0 0;
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.control {
  display: grid;
  gap: 5px;
  min-width: 145px;
}

.control span {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

.control input,
.control select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
}

.search-control {
  min-width: 220px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.icon-button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.kpi {
  min-height: 82px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  align-content: space-between;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
}

.kpi strong {
  font-size: 27px;
  line-height: 1;
}

.kpi.green,
.kpi.high {
  border-left-color: var(--green);
}

.kpi.medium {
  border-left-color: var(--amber);
}

.kpi.red,
.kpi.low {
  border-left-color: var(--red);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.wide {
  grid-column: span 1;
}

.full {
  grid-column: 1 / -1;
}

.panel,
.lane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel-head,
.lane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-head h3,
.lane-head h3 {
  margin: 0;
  font-size: 15px;
}

.panel-head span,
.lane-head span {
  color: var(--muted);
  font-size: 12px;
}

.decision-table,
.source-list {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-row,
.source-row {
  width: 100%;
  border: 0;
  background: var(--panel);
  display: grid;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  text-align: left;
}

.table-row {
  grid-template-columns: minmax(220px, 1.5fr) 120px 150px minmax(160px, 1fr) 110px 140px;
}

.source-row {
  grid-template-columns: 16px 86px minmax(220px, 1fr) 150px 150px;
}

.table-row:not(.table-head),
.source-row {
  cursor: pointer;
}

.table-row:not(.table-head):hover,
.source-row:hover,
.mini-card:hover,
.card:hover,
.bar-row:hover {
  background: var(--panel-soft);
}

.table-head {
  background: #edf2f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: default;
}

.table-row small,
.source-row small,
.bar-name small {
  display: block;
  margin-top: 3px;
}

.stack {
  display: grid;
  gap: 10px;
}

.action-strip .stack {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mini-card,
.card,
.bar-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
  cursor: pointer;
}

.mini-card,
.card {
  padding: 12px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.card h4,
.mini-card h4 {
  margin: 8px 0 7px;
  font-size: 15px;
  line-height: 1.25;
}

.card p,
.mini-card p,
.legend-stack p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.score-line {
  display: grid;
  gap: 6px;
}

.score-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.bar-track,
.bar-meter {
  height: 8px;
  background: #e7ecef;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill,
.bar-meter i {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.bar-fill.high,
.bar-meter i.high {
  background: var(--green);
}

.bar-fill.medium,
.bar-meter i.medium {
  background: var(--amber);
}

.bar-fill.low,
.bar-meter i.low {
  background: var(--red);
}

.bar-list {
  display: grid;
  gap: 8px;
}

.bar-cell {
  display: block;
}

.bar-row {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(210px, 0.7fr) minmax(220px, 1fr) 44px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

.offer-grid,
.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.metric-row span {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  align-content: center;
  gap: 3px;
}

.metric-row small {
  color: var(--muted);
}

.metric-row b {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.kanban {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.lane {
  padding: 12px;
  min-height: 360px;
}

.mode,
.pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  font-style: normal;
}

.mode.push,
.pill.ok {
  color: #165734;
  background: #e0f2e8;
}

.mode.defend,
.pill.caution {
  color: #784607;
  background: #fff0d5;
}

.mode.watch,
.pill.watch,
.pill.neutral {
  color: #215d7a;
  background: #deeff7;
}

.mode.investigate,
.pill.danger,
.pill.warning {
  color: #8d2f2d;
  background: #fce3e1;
}

.legend-stack {
  display: grid;
  gap: 12px;
}

.legend-stack div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--amber);
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.danger {
  background: var(--red);
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(480px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(20, 35, 45, 0.14);
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  min-height: 86px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.drawer-header h3 {
  margin: 3px 0 0;
  font-size: 19px;
  line-height: 1.2;
}

.drawer-body {
  padding: 18px;
  overflow: auto;
  display: grid;
  gap: 10px;
}

.detail-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}

.detail-row span {
  color: var(--muted);
  text-transform: capitalize;
  font-size: 12px;
}

.detail-row strong {
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.evidence-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  text-decoration: none;
}

.chip.link {
  color: var(--blue);
  background: #e7f0fa;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .view-nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .source-note {
    display: none;
  }

  .topbar,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .kpi-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kanban {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-strip .stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .app-shell {
    min-height: auto;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 16;
    height: auto;
    padding: 10px 12px;
    background: var(--ink);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand-block {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-block h1 {
    font-size: 14px;
  }

  .brand-block p {
    font-size: 11px;
  }

  .view-nav {
    display: none;
  }

  .mobile-tabbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    min-height: calc(66px + env(safe-area-inset-bottom));
    padding: 7px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -12px 28px rgba(20, 35, 45, 0.12);
    backdrop-filter: blur(10px);
  }

  .mobile-nav-item {
    min-width: 0;
    min-height: 50px;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
  }

  .mobile-nav-item.active {
    color: var(--blue);
    background: #edf6fb;
  }

  .mobile-nav-item.active .mobile-nav-icon {
    background: var(--blue);
    color: #ffffff;
  }

  .workspace {
    padding: 12px 12px 0;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 12px;
  }

  .title-group h2 {
    font-size: 21px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr 42px 42px;
    gap: 8px;
    align-items: end;
    justify-content: stretch;
  }

  .control {
    min-width: 0;
  }

  .search-control {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .control input,
  .control select,
  .icon-button {
    height: 42px;
  }

  #resetButton {
    grid-column: 3;
  }

  #exportButton {
    grid-column: 4;
  }

  .kpi-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 0 -12px 12px;
    padding: 0 12px 4px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .kpi-row::-webkit-scrollbar {
    display: none;
  }

  .kpi {
    min-width: 150px;
    min-height: 72px;
    scroll-snap-align: start;
  }

  .kpi strong {
    font-size: 23px;
  }

  .content-grid {
    gap: 12px;
  }

  .panel {
    padding: 12px;
    box-shadow: none;
  }

  .decision-table,
  .source-list {
    background: transparent;
    border: 0;
    gap: 10px;
    overflow: visible;
  }

  .table-row,
  .source-row,
  .bar-row {
    grid-template-columns: 1fr;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
  }

  .table-row > span,
  .source-row > span,
  .bar-row > span,
  .bar-row > strong {
    display: grid;
    gap: 3px;
  }

  .table-row > span::before,
  .source-row > span::before,
  .bar-row > span::before,
  .bar-row > strong::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .source-row .status-dot {
    justify-self: start;
  }

  .source-row .status-dot::before {
    content: none;
  }

  .table-row > span:first-child::before,
  .source-row > span:nth-child(2)::before,
  .bar-row > span:first-child::before {
    display: none;
  }

  .table-head {
    display: none;
  }

  .offer-grid,
  .share-grid,
  .kanban,
  .action-strip .stack,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .lane {
    min-height: auto;
    box-shadow: none;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .drawer {
    inset: auto 0 0;
    width: 100%;
    max-height: 88vh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    transform: translateY(100%);
  }

  .drawer.open {
    transform: translateY(0);
  }

  .drawer-header {
    min-height: 76px;
    padding: 14px;
  }

  .drawer-body {
    padding: 14px 14px calc(22px + env(safe-area-inset-bottom));
  }
}
