:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e1e8;
  --primary: #116a73;
  --primary-ink: #ffffff;
  --accent: #c56b32;
  --warning: #c2410c;
  --success: #16803c;
  --shadow: 0 14px 34px rgba(20, 32, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #17202a;
  color: #eef6f6;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

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

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #a6b5bf;
  margin-top: 3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 0;
  color: #dbe7ec;
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  text-align: left;
}

.nav-item span {
  width: 24px;
  text-align: center;
  flex: 0 0 auto;
}

.nav-item b {
  line-height: 1.3;
}

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

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

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.topbar p,
.muted {
  color: var(--muted);
}

.topbar p {
  margin-top: 6px;
}

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

.system-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 11px;
  color: var(--ink);
  min-width: 0;
}

.icon-button,
.primary-button,
.ghost-button,
.text-button,
.segmented button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 8px 12px;
  background: #fff;
  color: var(--ink);
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 20px;
}

.primary-button {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}

.ghost-button:disabled {
  color: #98a2b3;
  cursor: not-allowed;
}

.text-button {
  color: var(--primary);
  border-color: transparent;
  background: transparent;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
}

.import-note {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

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

.kpi-card {
  padding: 16px;
  min-height: 112px;
}

.kpi-card span {
  color: var(--muted);
  display: block;
  min-height: 22px;
}

.kpi-card strong {
  display: block;
  margin-top: 12px;
  font-size: 25px;
  line-height: 1.15;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel,
.form-panel {
  padding: 16px;
  margin-bottom: 14px;
}

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

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.status-dot.active {
  background: var(--success);
}

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

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

.item-row,
.agent-row,
.plan-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.item-row strong,
.agent-row strong {
  display: block;
}

.item-row small,
.agent-row small,
.plan-card small {
  color: var(--muted);
}

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

.agent-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  white-space: nowrap;
}

.pill.success {
  color: #166534;
  background: #dcfce7;
}

.pill.warning {
  color: #9a3412;
  background: #ffedd5;
}

.pill.info {
  color: #075985;
  background: #e0f2fe;
}

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

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

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 11px 9px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  background: #f8fafc;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label select,
label textarea {
  color: var(--ink);
  font-size: 14px;
}

label textarea {
  resize: vertical;
  min-height: 96px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-line input {
  width: auto;
}

.wide {
  grid-column: span 2;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.plan-card {
  display: grid;
  gap: 12px;
}

.plan-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.plan-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

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

.danger {
  color: var(--warning);
}

.draft-content {
  color: var(--ink);
  line-height: 1.55;
  white-space: pre-wrap;
}

.settings-status,
.status-grid {
  display: grid;
  gap: 12px;
}

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 10px 12px;
  }

  .brand {
    padding: 2px 4px;
  }

  .nav {
    flex-direction: row;
    overflow-x: auto;
  }

  .nav-item {
    width: auto;
    white-space: nowrap;
  }

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

  .two-column {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    flex-direction: column;
  }

  .filters,
  .filters select {
    width: 100%;
  }

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

  .wide {
    grid-column: span 1;
  }

  .plan-head,
  .item-row {
    flex-direction: column;
  }
}
