:root {
  color-scheme: light;
  --ink: #232421;
  --muted: #6f706a;
  --line: #e7e4dc;
  --line-strong: #d2cec3;
  --surface: #ffffff;
  --surface-soft: #fafaf8;
  --surface-wash: #f6f6f3;
  --nav: #ffffff;
  --nav-2: #f4f5f2;
  --accent: #27754f;
  --accent-strong: #1d5d3e;
  --accent-soft: #e8f4ed;
  --green: #2fae55;
  --green-soft: #eaf7ed;
  --sky: #2b7b59;
  --blue-soft: #edf6f0;
  --amber: #b88300;
  --amber-soft: #fff7df;
  --yellow: #f2bd34;
  --yellow-soft: #fff7d7;
  --red: #c84f2e;
  --red-soft: #fdece7;
  --shadow: 0 10px 30px rgba(35, 36, 33, 0.06);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--nav);
  color: var(--ink);
  padding: 18px 12px;
  z-index: 20;
}

.brand-block {
  display: grid;
  place-items: center;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  display: block;
  width: min(198px, 100%);
  height: auto;
  object-fit: contain;
}

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

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

.module-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.module-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.module-button:hover,
.module-button:focus-visible {
  background: var(--surface-wash);
  outline: none;
}

.module-button.active {
  background: var(--accent-soft);
  color: var(--ink);
}

.module-code {
  display: grid;
  height: 36px;
  place-items: center;
  border-radius: 6px;
  background: var(--surface-wash);
  font-weight: 800;
  font-size: 13px;
}

.module-button.active .module-code {
  background: #ffffff;
  color: var(--accent);
}

.module-name {
  display: block;
  overflow: hidden;
  color: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
}

.module-meta {
  display: block;
  margin-top: 4px;
  color: currentColor;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.65;
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 76px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.page-title p {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.page-title h2 {
  margin: 0;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.15;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-box {
  display: flex;
  align-items: center;
  width: min(32vw, 390px);
  min-width: 240px;
  height: 42px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--surface-wash);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.ghost-button,
.solid-button,
.danger-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: var(--radius);
  font-weight: 800;
  white-space: nowrap;
}

.ghost-button {
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  text-decoration: none;
}

.ghost-button:hover {
  border-color: var(--line-strong);
}

.solid-button {
  gap: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  padding: 0 14px;
}

.danger-button {
  gap: 8px;
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: var(--red);
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
}

.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
}

.app-main {
  padding: 24px;
}

.view-grid {
  display: grid;
  gap: 18px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 14px;
}

.metric-card,
.agent-card,
.module-card,
.alert-card,
.promotion-card,
.report-tile,
.portal-row,
.visit-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(35, 36, 33, 0.03);
}

.metric-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 132px;
  padding: 15px;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-value {
  margin: 10px 0 4px;
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}

.metric-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
}

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

.section-block {
  min-width: 0;
  padding: 4px 0 0;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

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

.section-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tool-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 740px;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-wash);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

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

.row-title {
  display: block;
  font-weight: 850;
}

.row-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.field,
.select-field {
  display: grid;
  gap: 5px;
}

.field label,
.select-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.select-field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.status-pill,
.priority-pill,
.tier-pill,
.access-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.access-pill {
  min-width: 78px;
  border: 1px solid transparent;
}

.access-none {
  border-color: var(--line);
  background: var(--surface-wash);
  color: var(--muted);
}

.access-view {
  background: var(--blue-soft);
  color: var(--sky);
}

.access-work {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.access-all {
  background: var(--green-soft);
  color: var(--green);
}

.access-approve {
  background: var(--yellow-soft);
  color: var(--amber);
}

.access-admin {
  background: var(--red-soft);
  color: var(--red);
}

.status-ok,
.priority-must {
  background: var(--green-soft);
  color: var(--green);
}

.status-watch,
.priority-should {
  background: var(--blue-soft);
  color: var(--sky);
}

.status-risk,
.priority-nice {
  background: var(--yellow-soft);
  color: var(--amber);
}

.status-critical {
  background: var(--red-soft);
  color: var(--red);
}

.tier-gold {
  background: var(--yellow-soft);
  color: #8a6600;
}

.tier-silver {
  background: var(--surface-wash);
  color: #62645d;
}

.tier-bronze {
  background: #f4efe7;
  color: #7b6346;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-wash);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.progress-fill.warn {
  background: var(--amber);
}

.progress-fill.danger {
  background: var(--red);
}

.chart-bars {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 118px minmax(120px, 1fr) 72px;
  gap: 10px;
  align-items: center;
}

.bar-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-wash);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--yellow));
}

.bar-value {
  text-align: right;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.stage-column {
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
}

.stage-column h4 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 13px;
}

.stage-item {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  border-left: 3px solid var(--accent);
  padding: 8px 8px 8px 10px;
  background: var(--surface-wash);
}

.stage-item strong {
  font-size: 13px;
}

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

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.module-card {
  padding: 14px;
}

button.module-card {
  text-align: left;
}

.module-card h4 {
  margin: 8px 0 6px;
  font-size: 15px;
}

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

.role-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(230px, 1fr));
  gap: 12px;
}

.role-grid.compact {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.role-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 2px 10px rgba(35, 36, 33, 0.03);
}

.role-card-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.role-card-head strong,
.role-card-head em {
  display: block;
}

.role-card-head strong {
  font-size: 15px;
}

.role-card-head em {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

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

.role-modules {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.role-modules span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-wash);
  color: var(--ink);
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.permission-table {
  min-width: 1240px;
}

.inventory-table {
  min-width: 1180px;
}

.permission-table th,
.permission-table td {
  white-space: nowrap;
}

.guardrail-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.guardrail-list article {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.guardrail-list article:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.guardrail-list strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.guardrail-list p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.alert-list,
.agent-list,
.visit-list,
.promotion-list,
.portal-list {
  display: grid;
  gap: 10px;
}

.alert-card,
.agent-card,
.visit-card,
.promotion-card,
.portal-row {
  padding: 13px;
}

.alert-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-left: 4px solid var(--amber);
}

.alert-card.critical {
  border-left-color: var(--red);
}

.alert-card.ok {
  border-left-color: var(--green);
}

.alert-card h4,
.agent-card h4,
.visit-card h4,
.promotion-card h4 {
  margin: 0 0 5px;
  font-size: 15px;
}

.alert-card p,
.agent-card p,
.visit-card p,
.promotion-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.agent-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  text-align: left;
  width: 100%;
}

button.agent-card {
  border: 1px solid var(--line);
}

button.agent-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
}

.detail-panel h3 {
  margin: 0 0 5px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}

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

.mini-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-stat strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

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

.form-grid .span-2 {
  grid-column: span 2;
}

.route-map {
  position: relative;
  overflow: hidden;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(39, 117, 79, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(242, 189, 52, 0.08) 1px, transparent 1px),
    #ffffff;
  background-size: 46px 46px;
}

.route-map svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-agent {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  min-width: 86px;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  padding: 7px;
  box-shadow: 0 8px 18px rgba(28, 39, 48, 0.08);
}

.map-agent strong {
  font-size: 12px;
}

.map-agent span {
  color: var(--muted);
  font-size: 11px;
}

.map-agent.gold {
  border-color: var(--yellow);
}

.map-agent.silver {
  border-color: var(--line-strong);
}

.map-agent.bronze {
  border-color: #bfa47e;
}

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

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}

.check-row:last-child {
  border-bottom: 0;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--line-strong);
  transition: 160ms ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(28, 39, 48, 0.18);
  content: "";
  transition: 160ms ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.mobile-preview {
  max-width: 360px;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: #ffffff;
  padding: 10px;
  box-shadow: var(--shadow);
}

.mobile-screen {
  overflow: hidden;
  min-height: 590px;
  border-radius: 18px;
  background: var(--surface-soft);
}

.mobile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  background: var(--accent);
  color: #ffffff;
}

.mobile-head strong {
  font-size: 15px;
}

.mobile-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.portal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(380px, calc(100vw - 32px));
  border-radius: var(--radius);
  background: #1c2730;
  color: #ffffff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 800;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .metrics-grid,
  .module-grid,
  .role-grid,
  .role-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kanban {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }
}

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

  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-104%);
    width: min(320px, 86vw);
    transition: transform 180ms ease;
  }

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

  .menu-toggle {
    display: inline-flex;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .topbar-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .search-box {
    flex: 1 1 220px;
    width: auto;
    min-width: 0;
  }

  .section-grid,
  .section-grid.equal {
    grid-template-columns: 1fr;
  }

  .route-map {
    min-height: 360px;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 12px;
  }

  .app-main {
    padding: 14px;
  }

  .metrics-grid,
  .module-grid,
  .role-grid,
  .role-grid.compact,
  .stat-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2 {
    grid-column: span 1;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right,
  .ghost-button,
  .solid-button,
  .danger-button {
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 84px minmax(80px, 1fr) 56px;
  }

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