:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #263247;
  --muted: #6b7890;
  --line: #e7ebf2;
  --primary: #2d6cdf;
  --primary-dark: #1f56ba;
  --green: #1d8f52;
  --green-bg: #d9f7e4;
  --yellow: #a86900;
  --yellow-bg: #fff1c7;
  --red: #cf2f3d;
  --red-bg: #ffe0e3;
  --violet: #7c3aed;
  --violet-bg: #ede6ff;
  --shadow: 0 18px 50px rgba(38, 50, 71, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: #111827;
  color: #f8fafc;
  padding: 24px 18px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #2d6cdf;
  font-weight: 800;
}

.brand small {
  display: block;
  color: #a7b0c0;
  margin-top: 3px;
}

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

.nav-btn {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  padding: 12px;
  text-align: left;
}

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

.main {
  min-width: 0;
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 17px;
}

.topbar p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary,
.ghost,
.add-step {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 13px;
  font-weight: 700;
}

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

.primary:hover {
  background: var(--primary-dark);
}

.ghost,
.add-step {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

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

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 6px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.wide-left {
  grid-template-columns: 360px minmax(0, 1fr);
}

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

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.table-head input {
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 15px 16px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: #4b566b;
  font-weight: 800;
  background: #fafbfe;
  position: sticky;
  top: 0;
}

td small {
  display: block;
  color: #8a98ad;
  margin-top: 4px;
}

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

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.risk-ok,
.risk-completed {
  color: var(--green);
  background: var(--green-bg);
}

.risk-watch,
.risk-due-soon {
  color: var(--yellow);
  background: var(--yellow-bg);
}

.risk-overdue,
.risk-delay {
  color: var(--red);
  background: var(--red-bg);
}

.task-list,
.supplier-list,
.workflow-steps,
.risk-chart {
  padding: 14px;
}

.task-item,
.supplier-item,
.step-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}

.task-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.task-title {
  font-weight: 800;
}

.task-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.task-actions {
  display: flex;
  gap: 6px;
}

.supplier-item {
  cursor: pointer;
}

.supplier-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(45, 108, 223, 0.12);
}

.step-columns,
.step-item {
  display: grid;
  grid-template-columns: 30px minmax(180px, 1fr) 150px 90px 105px 105px 40px;
  gap: 8px;
  align-items: center;
}

.step-columns {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 12px 8px;
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  text-align: center;
}

.step-item input,
.step-item select,
.form-grid input,
.form-grid select,
.form-grid textarea,
#promptText {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.step-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.step-actions {
  display: grid;
  grid-template-columns: 34px;
  gap: 4px;
}

.insert-between {
  display: flex;
  align-items: center;
  height: 14px;
  margin: -3px 0;
  opacity: 0;
  transition: opacity 0.15s ease, height 0.15s ease, margin 0.15s ease;
}

.insert-between:hover,
.insert-between:focus-within {
  height: 34px;
  margin: 0;
  opacity: 1;
}

.insert-between::before,
.insert-between::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.insert-between button {
  border: 1px solid #bcd0fb;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--primary-dark);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.add-step {
  margin: 0 14px 14px;
}

.risk-bar {
  display: grid;
  grid-template-columns: 92px 1fr 40px;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.risk-fill {
  height: 12px;
  border-radius: 999px;
  background: var(--primary);
}

dialog {
  width: min(880px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.28);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.45);
}

.dialog-form {
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

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

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

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

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

#promptResult {
  max-height: 260px;
  overflow: auto;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: 0.2s ease;
  pointer-events: none;
}

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

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

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

  .brand {
    margin-bottom: 12px;
  }

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

  .nav-btn {
    text-align: center;
    padding: 10px 6px;
  }

  .topbar,
  .split,
  .wide-left {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .step-item {
    grid-template-columns: 28px 1fr;
  }
}
