:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --ink: #172026;
  --muted: #68737d;
  --line: #dfe4e8;
  --teal: #147d76;
  --coral: #c94c3c;
  --gold: #b87916;
  --indigo: #4457a6;
  --mint: #e8f5f1;
  --rose: #faebe8;
  --amber: #fff3d7;
  --shadow: 0 14px 42px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="date"],
input[type="search"],
input[type="file"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

button {
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: #b6c1c9;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #eef3f1;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
}

.mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

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

.brand p,
.panel p,
.section-head p,
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.control-group {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.control-group label {
  color: #52606a;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.control-group input,
.control-group select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
}

.check-row {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  margin-bottom: 8px;
  color: #34424c;
  font-size: 14px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.button-row button:first-child {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.dashboard {
  padding: 22px 26px 26px;
  overflow: hidden;
}

.topbar,
.section-head,
.panel-head,
.dialog-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.topbar h2 {
  max-width: 820px;
  margin: 0;
  font-size: clamp(22px, 2.1vw, 30px);
  line-height: 1.12;
}

.eyebrow {
  color: var(--teal) !important;
  font-weight: 800;
  text-transform: uppercase;
}

.segmented {
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 3px;
}

.segmented button {
  min-height: 32px;
  border: 0;
  background: transparent;
}

.segmented .active {
  background: var(--ink);
  color: #fff;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(128px, 1fr));
  gap: 12px;
  margin: 18px 0 16px;
}

.kpi {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.kpi small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.35;
}

.insight-band,
.issue-section,
.analysis-grid,
.conversation-section {
  margin-top: 16px;
}

.insight-band {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 16px;
}

.insight-band > div,
.issue-section,
.panel,
.conversation-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.insight-band > div {
  padding: 18px;
}

h3 {
  margin: 0;
  font-size: 17px;
}

ol {
  margin: 14px 0 0;
  padding-left: 22px;
}

li {
  margin: 8px 0;
  line-height: 1.45;
}

.watch-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.watch-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border-radius: 8px;
  background: var(--rose);
  border: 1px solid #f0c4bd;
}

.watch-item.flagged {
  border-color: #d38a2b;
  background: #fff6e4;
}

.watch-open {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.watch-item strong {
  display: block;
  margin-bottom: 4px;
}

.watch-item span {
  color: #6a3530;
  font-size: 13px;
}

.issue-section {
  padding: 18px;
}

.issue-map {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.issue-card {
  display: grid;
  gap: 10px;
  min-height: 116px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.issue-card:hover,
.issue-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 125, 118, 0.12);
}

.issue-card-top,
.issue-card-meta,
.issue-brief {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.issue-card-top strong {
  line-height: 1.2;
}

.issue-card-top span {
  font-size: 24px;
  font-weight: 800;
}

.issue-meter {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f3;
}

.issue-meter div {
  height: 100%;
  border-radius: 999px;
  background: var(--coral);
}

.issue-card-meta {
  color: var(--muted);
  font-size: 12px;
}

.issue-detail {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
}

.issue-brief h3 {
  margin-top: 2px;
  font-size: 22px;
}

.owner-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e9ecf8;
  color: #2f3c83;
  font-size: 12px;
  font-weight: 800;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.action-grid > div,
.action-plan > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

h4 {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  color: #52606a;
}

.action-grid p,
.action-plan p,
.draft-box p,
.issue-detail p {
  margin: 0;
  color: #34424c;
  font-size: 14px;
  line-height: 1.45;
}

.issue-examples {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.mini-conversation {
  display: grid;
  gap: 6px;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.mini-conversation span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.panel {
  min-height: 330px;
  padding: 18px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.chart {
  min-height: 260px;
  margin-top: 18px;
}

.line-chart {
  width: 100%;
  min-height: 258px;
}

.axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.bar-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(96px, 160px) 1fr 44px;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 8px;
  background: #edf1f3;
}

.bar-fill {
  height: 100%;
  border-radius: 8px;
  background: var(--teal);
}

.bar-fill.risk {
  background: var(--coral);
}

.bar-fill.gold {
  background: var(--gold);
}

.bar-value {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.response-box {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.response-metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
}

.response-metric strong {
  display: block;
  font-size: 26px;
}

.response-metric span {
  color: var(--muted);
  font-size: 13px;
}

.conversation-section {
  padding: 18px;
}

.conversation-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.conversation-row:hover,
.conversation-row.flagged {
  border-color: #b5c3ca;
  background: #fbfcfc;
}

.conversation-row.flagged {
  border-color: #d38a2b;
  background: #fffaf0;
}

.conversation-open {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.row-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
}

.row-title strong {
  font-size: 15px;
}

.row-meta,
.row-excerpt {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.row-excerpt {
  margin-top: 8px;
}

.row-next {
  margin-top: 10px;
  padding: 10px;
  border-left: 3px solid var(--teal);
  background: #f0f8f6;
  color: #254a47;
  font-size: 13px;
  line-height: 1.4;
}

.row-score {
  display: grid;
  justify-items: end;
  align-content: start;
  gap: 6px;
  min-width: 116px;
  color: var(--muted);
  font-size: 12px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--mint);
  color: #0d5d58;
  font-size: 12px;
  font-weight: 700;
}

.tag.risk {
  background: var(--rose);
  color: #a73629;
}

.tag.status {
  background: var(--amber);
  color: #7a4b07;
}

.tag.priority {
  background: #e9ecf8;
  color: #2f3c83;
}

.tag.flagged {
  background: #fff1d2;
  color: #81510b;
}

.flag-toggle {
  min-height: 30px;
  padding: 0 10px;
  border-color: #d2ac6c;
  background: #fff8e9;
  color: #7a4b07;
  font-size: 12px;
  font-weight: 800;
}

.flag-toggle.active {
  border-color: var(--gold);
  background: var(--gold);
  color: #fff;
}

dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: min(780px, calc(100vh - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(23, 32, 38, 0.28);
}

dialog::backdrop {
  background: rgba(23, 32, 38, 0.42);
}

#dialogMeta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.action-plan {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 14px;
}

.draft-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
}

.draft-box .panel-head {
  margin-bottom: 10px;
}

.message-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 8px;
}

.message {
  padding: 12px;
  border-radius: 8px;
  background: #f7f9f9;
  border: 1px solid var(--line);
}

.message.agent {
  background: #eef7f5;
}

.message.system {
  background: #f5f2ea;
}

.message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.empty {
  padding: 24px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

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

  .action-grid,
  .issue-examples,
  .action-plan {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .dashboard,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-head {
    display: grid;
  }

  .insight-band,
  .issue-map,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .conversation-row {
    grid-template-columns: 1fr;
  }

  .row-score {
    justify-items: start;
  }
}
