:root {
  --bg: #eef4f1;
  --panel: #ffffff;
  --soft: #f6faf7;
  --ink: #13231d;
  --muted: #66746d;
  --line: #d8e4dd;
  --green: #0f6b55;
  --green-dark: #0a483a;
  --yellow: #f2c94c;
  --blue: #2868b7;
  --red: #c74d45;
  --shadow: 0 18px 48px rgba(19, 35, 29, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, sans-serif;
  background: linear-gradient(180deg, #f4f8f6 0%, var(--bg) 100%);
  color: var(--ink);
}

button, select { font: inherit; }
button { border: 0; cursor: pointer; }
h1, h2, p { margin: 0; }
h1 { font-size: 32px; letter-spacing: 0; }

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

.sidebar {
  background: #13231d;
  color: #edf7f1;
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 28px;
}

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

.brand img { width: 48px; height: 48px; }
.brand strong { display: block; font-size: 18px; }
.brand span, .integrationCard span, .integrationCard small { color: #b9cbc2; }

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

.nav button {
  min-height: 42px;
  padding: 0 12px;
  text-align: left;
  background: transparent;
  color: #dce8e1;
  border-left: 3px solid transparent;
}

.nav button.active {
  background: rgba(242, 201, 76, 0.14);
  border-left-color: var(--yellow);
  color: #fff7dc;
}

.integrationCard {
  align-self: end;
  display: grid;
  gap: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.workspace {
  padding: 24px;
  display: grid;
  gap: 18px;
}

.topbar, .panelHead, .topActions, .actionStrip {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
}

.topbar p {
  margin-top: 7px;
  color: var(--muted);
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 4px 9px;
  background: #e5f3ed;
  color: var(--green-dark);
  font-weight: 700;
  border: 1px solid #bdd9cd;
}

.topActions, .actionStrip { gap: 10px; flex-wrap: wrap; }

.primary, .secondary, .actionStrip button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.primary {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.primary:hover { background: var(--green-dark); }
.secondary:hover, .actionStrip button:hover { border-color: var(--green); }
.small { min-height: 32px; }

.kpiGrid, .mainGrid, .detailGrid, .automationList, .contextList {
  display: grid;
  gap: 14px;
}

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

.kpiGrid article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.kpiGrid article {
  min-height: 108px;
  padding: 16px;
  display: grid;
  gap: 6px;
}

.kpiGrid span, .kpiGrid small, .detailGrid span, .eventLog small, .softText {
  color: var(--muted);
}

.kpiGrid strong { font-size: 28px; }

.mainGrid {
  grid-template-columns: minmax(310px, 0.9fr) minmax(460px, 1.3fr) minmax(320px, 0.95fr);
  align-items: start;
}

.mainGrid:not(.view-operations) {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
}

.mainGrid.view-operations .workspacePanel {
  display: none;
}

.mainGrid:not(.view-operations) .ordersPanel,
.mainGrid:not(.view-operations) .detailPanel,
.mainGrid:not(.view-operations) .automationPanel,
.mainGrid:not(.view-operations) .crmPanel,
.mainGrid:not(.view-operations) .oneCPanel,
.mainGrid:not(.view-operations) .incidentPanel,
.mainGrid:not(.view-operations) .contextPanel {
  display: none;
}

.mainGrid:not(.view-operations) .workspacePanel {
  grid-column: 1 / 2;
}

.mainGrid:not(.view-operations) .assistantPanel {
  grid-column: 2 / 3;
}

.mainGrid:not(.view-operations) .eventPanel {
  grid-column: 1 / -1;
}

.panel { padding: 16px; }
.contextPanel { grid-column: 1 / 2; }
.eventPanel { grid-column: 2 / 4; }

.panelHead {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panelHead h2 { font-size: 18px; }

select {
  min-height: 36px;
  max-width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 10px;
}

.ordersList, .eventLog, .oneCDocuments { display: grid; gap: 10px; }

.orderCard, .contextItem {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  text-align: left;
}

.orderCard.active {
  border-color: var(--green);
  box-shadow: inset 0 0 0 2px rgba(15, 107, 85, 0.17);
}

.orderCard strong { font-size: 16px; }
.orderCard span, .orderCard small { color: var(--muted); }

.badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid #d5a92f;
  background: #fff3c8;
  color: #775300;
  font-weight: 700;
  white-space: nowrap;
}

.badge.red { border-color: #df8b82; background: #fde8e5; color: #9b2d25; }
.badge.green { border-color: #8fc6ae; background: #e5f6ee; color: var(--green-dark); }

.routeMap {
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 14px;
  background: #f8fbf9;
}

.routeMap img { width: 100%; display: block; }

.detailGrid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.detailGrid div, .automationList div {
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 6px;
}

.detailGrid strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.actionStrip button { background: #fbfcfa; }
.actionStrip.vertical { align-items: stretch; flex-direction: column; }
.actionStrip.vertical button { width: 100%; }

.automationPanel {
  border-color: #9ccbb7;
  background: #fbfffd;
}

.crmPanel {
  border-color: #a9bfdf;
  background: #f8fbff;
}

.workspacePanel {
  border-color: #a9bfdf;
  background: #f8fbff;
}

.assistantPanel {
  border-color: #8fc6ae;
  background: #f7fffb;
}

.crmList {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.viewWorkspace,
.viewList,
.viewCards,
.workActions,
.assistantSuggestion {
  display: grid;
  gap: 10px;
}

.viewHero {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #c8d8ef;
  background: #fff;
}

.viewHero.danger {
  border-color: #efb6ae;
  background: #fff5f3;
}

.viewHero span,
.viewItem span,
.viewItem small,
.viewCards small,
.assistantSuggestion span,
.assistantSuggestion small {
  color: var(--muted);
  line-height: 1.45;
}

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

.viewCards article,
.viewItem {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.viewCards strong {
  font-size: 20px;
}

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

.workActions button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--ink);
}

.workActions button:hover {
  border-color: var(--green);
}

.assistantSuggestion {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #c6e3d5;
  background: #ffffff;
}

.crmItem {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #c8d8ef;
  background: #ffffff;
}

.crmItem span,
.crmItem small {
  color: var(--muted);
}

.incidentCard {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #fff8f2;
  border: 1px solid #efcfb4;
  margin-bottom: 12px;
}

.oneCPanel {
  border-color: #cfb357;
  background: #fffdf5;
}

.oneCStatus, .oneCDoc {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #ead082;
  background: #fff7dc;
}

.oneCStatus { margin-bottom: 12px; }
.oneCStatus span, .oneCDoc span, .oneCDoc small { color: #715b1c; }

.payloadPreview {
  max-height: 280px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  background: #14211c;
  color: #dff7eb;
  border: 1px solid #2d5144;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.eventItem {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-left: 4px solid var(--green);
  background: var(--soft);
}

.eventItem.error { border-left-color: var(--red); }

@media (max-width: 1180px) {
  .appShell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mainGrid, .kpiGrid, .detailGrid, .viewCards, .workActions { grid-template-columns: 1fr; }
  .eventPanel, .contextPanel { grid-column: auto; }
  .topbar { align-items: flex-start; flex-direction: column; }
}
