:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #18202f;
  --muted: #667085;
  --line: #dfe4ec;
  --nav: #101828;
  --nav-soft: #1d2939;
  --blue: #2563eb;
  --green: #0f8a5f;
  --red: #c93c37;
  --orange: #d97706;
  --shadow: 0 18px 45px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Aptos, "Segoe UI", Arial, sans-serif;
}

button, input { font: inherit; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  color: #f9fafb;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f9fafb;
  color: var(--nav);
  font-weight: 800;
}

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

.brand p {
  margin: 3px 0 0;
  color: #98a2b3;
  font-size: 13px;
}

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

.nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 7px;
  font-size: 14px;
}

.nav a:hover,
.nav a.active {
  background: var(--nav-soft);
  color: white;
}

.side-note {
  margin-top: auto;
  border: 1px solid #344054;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #cbd5e1;
}

.side-note span { color: #98a2b3; line-height: 1.5; }

.main {
  padding: 28px;
  display: grid;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.upload-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}

input[type="file"] {
  max-width: 250px;
  font-size: 13px;
}

.button {
  border: 0;
  border-radius: 7px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

.button.primary { background: var(--blue); color: white; }
.button.secondary { background: #eef2f7; color: #344054; }
.button:hover { filter: brightness(.97); }

.status {
  border-radius: 8px;
  padding: 12px 14px;
  background: #ecfdf3;
  color: #05603a;
  border: 1px solid #abefc6;
}

.status.error {
  background: #fef3f2;
  color: #b42318;
  border-color: #fecdca;
}

.hidden { display: none !important; }

.settings-page {
  display: grid;
  gap: 20px;
}

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

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

.work-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  background: #fcfcfd;
  display: grid;
  align-content: start;
  gap: 10px;
}

.work-card.urgent { border-color: #fda29b; background: #fff6f5; }
.work-card.warning { border-color: #fedf89; background: #fffbeb; }
.work-card.good { border-color: #abefc6; background: #f0fdf4; }

.work-card h4 {
  margin: 0;
  font-size: 16px;
}

.work-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.mini-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(152, 162, 179, .28);
  padding-top: 9px;
  min-width: 0;
}

.mini-row div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.mini-row strong,
.mini-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-row strong { font-size: 13px; }
.mini-row span { color: var(--muted); font-size: 12px; }
.mini-row em { font-style: normal; font-weight: 900; white-space: nowrap; font-size: 13px; }
.mini-empty { color: var(--muted); font-size: 13px; border-top: 1px solid rgba(152, 162, 179, .28); padding-top: 9px; }

.email-summary {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.email-head {
  padding: 14px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.email-head h4 {
  margin: 0;
  font-size: 15px;
}

.email-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.email-summary pre {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.55;
  color: #344054;
  background: white;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.panel h3,
.panel h4 {
  margin: 0;
  letter-spacing: 0;
}

.panel h3 { font-size: 18px; }
.panel h4 { font-size: 15px; margin-bottom: 10px; }

.panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.brief-grid {
  display: grid;
  grid-template-columns: minmax(320px, 2fr) repeat(3, minmax(160px, 1fr));
  gap: 14px;
}

.brief-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 8px;
  min-height: 118px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brief-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.brief-card strong {
  font-size: 28px;
  letter-spacing: 0;
}

.brief-card h3 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.brief-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.primary-brief {
  background: #101828;
  color: white;
}

.primary-brief p,
.primary-brief span { color: #cbd5e1; }

.brief-card.danger { border-color: #fda29b; background: #fff6f5; }
.brief-card.warning { border-color: #fedf89; background: #fffbeb; }
.brief-card.good { border-color: #abefc6; background: #f0fdf4; }

.brief-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.brief-chips span {
  display: inline-flex;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: #f9fafb;
  font-size: 12px;
}

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

.insight {
  background: #f3f6fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.feed-tools {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search,
.select {
  width: 260px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: white;
}

.select { width: 170px; }
.wide-select { width: 260px; }

.category-snapshot {
  display: grid;
  grid-template-columns: 1.5fr repeat(3, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.category-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fcfcfd;
  display: grid;
  gap: 7px;
  min-width: 0;
}

.category-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.category-card strong {
  font-size: 19px;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.feed-list {
  display: grid;
  gap: 12px;
}

.empty-feed {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: #f8fafc;
}

.feed-card {
  border: 1px solid var(--line);
  border-left: 5px solid #fdb022;
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(320px, 1fr) minmax(320px, 1.2fr);
  gap: 16px;
  background: #ffffff;
}

.feed-card.urgent { border-left-color: var(--red); background: #fffafa; }

.feed-main,
.metric-stack,
.action-grid {
  min-width: 0;
}

.feed-topline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.feed-card h4 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.feed-card p {
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.asin-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.asin-line code {
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
}

.asin-line a {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.asin-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.asin-cell code {
  background: #f2f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
}

.asin-cell a {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

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

.metric-stack div {
  border: 1px solid #eef2f7;
  border-radius: 7px;
  padding: 10px;
  background: #fcfcfd;
}

.metric-stack span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 5px;
}

.metric-stack strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

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

.action-grid label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.action-select,
.action-input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
  font-size: 13px;
}

.review-state {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.status-open { background: #fee4e2; color: #b42318; }
.status-progress { background: #fef0c7; color: #b54708; }
.status-done { background: #dcfae6; color: #067647; }
.status-muted { background: #eef2f7; color: #475467; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pivot-scroll {
  overflow: auto;
  border: 1px solid #98a2b3;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  max-height: 720px;
  background: white;
  max-width: 100%;
}

.pivot-bottom-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  height: 16px;
  margin-top: 0;
  border: 1px solid #98a2b3;
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background: #f8fafc;
  max-width: 100%;
  width: 100%;
}

.pivot-bottom-scroll > div {
  height: 1px;
}

.pivot-table {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

.pivot-table th,
.pivot-table td {
  border: 1px solid #98a2b3;
  padding: 4px 7px;
  height: 22px;
  white-space: nowrap;
  min-width: 48px;
}

.pivot-table th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #d9e2f3;
  color: #111827;
  font-weight: 800;
  text-align: right;
}

.pivot-table .pivot-name {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 520px;
  width: 520px;
  max-width: 520px;
  text-align: left;
  background: #ffffff;
}

.pivot-table th.pivot-name {
  z-index: 5;
  background: #d9e2f3;
}

.pivot-category-row td {
  background: #ffffff;
  font-weight: 800;
}

.pivot-category-row .pivot-name {
  background: #ffffff;
}

.pivot-total-row td,
.pivot-total-row .pivot-name {
  background: #d9e2f3;
  font-weight: 900;
}

.pivot-subhead-row td {
  background: #f8fafc;
  color: #475467;
  font-weight: 800;
  font-size: 12px;
}

.pivot-asin-row td {
  background: #fcfcfd;
  color: #344054;
}

.pivot-asin-row .pivot-name {
  background: #fcfcfd;
  padding-left: 22px;
}

.pivot-toggle {
  width: 15px;
  height: 15px;
  border: 1px solid #667085;
  border-radius: 2px;
  background: #f8fafc;
  color: #344054;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  margin-right: 4px;
  cursor: pointer;
  vertical-align: middle;
}

.asin-pivot-name {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.asin-pivot-name > span {
  color: #667085;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-pill,
.segment-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.rank-pill {
  background: #eef2f7;
  color: #344054;
}

.segment-top {
  background: #dcfae6;
  color: #067647;
}

.segment-mid {
  background: #d1e9ff;
  color: #175cd3;
}

.segment-tail {
  background: #f2f4f7;
  color: #667085;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 760px;
}

.compact table { min-width: 560px; }

th {
  background: #f8fafc;
  color: #667085;
  text-align: left;
  font-size: 12px;
  font-weight: 800;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid #eef2f7;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfcfd; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.loss { color: var(--red); font-weight: 800; }
.gain { color: var(--green); font-weight: 800; }

.flag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.flag-critical { background: #fee4e2; color: #b42318; }
.flag-watch { background: #fef0c7; color: #b54708; }
.flag-rising { background: #dcfae6; color: #067647; }
.flag-opportunity { background: #d1e9ff; color: #175cd3; }
.flag-stable { background: #eef2f7; color: #344054; }
.flag-low { background: #f2f4f7; color: #667085; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

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

.rules-grid label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.rules-grid input {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: #344054;
}

.history-item strong { color: var(--ink); }
.history-item span { color: var(--muted); font-size: 13px; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
  }
  .nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .side-note { display: none; }
  .topbar,
  .upload-box,
  .panel-heading,
  .feed-tools { align-items: stretch; flex-direction: column; }
  .brief-grid,
  .today-grid,
  .split,
  .rules-grid { grid-template-columns: 1fr; }
  .feed-card {
    grid-template-columns: 1fr;
  }
  .category-snapshot {
    grid-template-columns: 1fr;
  }
  .action-grid,
  .metric-stack {
    grid-template-columns: 1fr;
  }
  .search,
  .select,
  input[type="file"] { width: 100%; max-width: none; }
}

@media (max-width: 640px) {
  body {
    background: #ffffff;
  }

  .sidebar {
    gap: 14px;
    padding: 14px 12px 10px;
    border-bottom: 1px solid #344054;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 7px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand p {
    font-size: 12px;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .nav a {
    flex: 0 0 auto;
    padding: 9px 11px;
    font-size: 13px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
  }

  .main {
    padding: 12px;
    gap: 14px;
  }

  .topbar {
    gap: 12px;
  }

  .topbar h2 {
    font-size: 22px;
  }

  .topbar p {
    font-size: 13px;
    line-height: 1.45;
  }

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

  .button {
    width: 100%;
    min-height: 42px;
  }

  .panel,
  .brief-card,
  .work-card {
    border-radius: 8px;
    padding: 14px;
    box-shadow: none;
  }

  .panel-heading {
    gap: 10px;
    margin-bottom: 12px;
  }

  .panel h3 {
    font-size: 17px;
  }

  .panel p {
    font-size: 13px;
    line-height: 1.45;
  }

  .today-grid,
  .brief-grid {
    gap: 10px;
  }

  .brief-card {
    min-height: auto;
  }

  .brief-card h3 {
    font-size: 20px;
  }

  .brief-card strong {
    font-size: 24px;
  }

  .email-summary pre {
    max-height: 260px;
    overflow: auto;
    font-size: 12px;
  }

  .mini-row {
    align-items: flex-start;
  }

  .mini-row strong,
  .mini-row span {
    white-space: normal;
  }

  .feed-card {
    padding: 14px;
    border-left-width: 4px;
    gap: 12px;
  }

  .feed-card h4 {
    font-size: 16px;
    overflow-wrap: anywhere;
  }

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

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

  .table-wrap {
    border-radius: 8px;
    max-width: calc(100vw - 24px);
  }

  table {
    min-width: 700px;
  }

  th,
  td {
    padding: 9px 10px;
  }

  .pivot-scroll,
  .pivot-bottom-scroll {
    max-width: calc(100vw - 24px);
  }

  .pivot-scroll {
    max-height: 560px;
  }

  .pivot-table {
    font-size: 12px;
  }

  .pivot-table th,
  .pivot-table td {
    padding: 4px 6px;
    min-width: 44px;
  }

  .pivot-table .pivot-name {
    min-width: 330px;
    width: 330px;
    max-width: 330px;
  }

  .asin-pivot-name {
    gap: 5px;
  }

  .asin-cell {
    gap: 5px;
  }

  .rank-pill,
  .segment-pill {
    padding: 3px 6px;
    font-size: 10px;
  }

  .rules-grid {
    gap: 10px;
  }

  .history-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
}
