:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --text: #18212b;
  --muted: #667381;
  --line: #d9e0e7;
  --primary: #176b87;
  --primary-dark: #0d4f65;
  --accent: #d58a1f;
  --ok: #237a57;
  --warn: #a66312;
  --danger: #a33a3a;
  --shadow: 0 12px 28px rgba(24, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: #a8b8c5;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: #16232d;
  color: #eef7fb;
}

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

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

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

.brand span {
  margin-top: 2px;
  color: #aebdc8;
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #c6d2dc;
  border-color: transparent;
}

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

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

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

.topbar p,
.panel-head p {
  color: var(--muted);
  margin-top: 4px;
}

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

input,
select,
textarea {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  min-height: 36px;
  border-radius: 6px;
  padding: 0 10px;
}

textarea {
  padding: 10px;
  resize: vertical;
}

#globalSearch {
  width: min(360px, 34vw);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
}

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

.kpi span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 8px;
}

.kpi strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

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

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

.filters select {
  width: 180px;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f4;
  font-size: 13px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #40505e;
  font-weight: 700;
  z-index: 1;
}

tr:hover td {
  background: #f8fbfd;
}

.planned-cancel-row td {
  background: #fff6f6;
  color: #7d4242;
}

.planned-cancel-row:hover td {
  background: #ffeded;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.mini-note {
  display: inline-block;
  margin-left: 6px;
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #41515d;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: #e7f4ef;
}

.badge.warn {
  color: var(--warn);
  background: #fff3df;
}

.badge.danger {
  color: var(--danger);
  background: #fae9e9;
}

.badge.stage {
  color: #176b87;
  background: #e5f5f8;
}

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

.accordion-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.vendor-summary-head {
  display: grid;
  grid-template-columns: 28px minmax(180px, 1.25fr) repeat(4, minmax(140px, 1fr));
  align-items: center;
  gap: 14px;
  padding: 0 14px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.vendor-summary-head span:nth-child(n + 3) {
  text-align: right;
}

.vendor-drawer {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.vendor-drawer summary {
  list-style: none;
  display: grid;
  grid-template-columns: 28px minmax(180px, 1.25fr) repeat(4, minmax(140px, 1fr));
  align-items: center;
  gap: 14px;
  min-height: 66px;
  padding: 12px 14px;
  cursor: pointer;
  background: #fbfcfd;
}

.vendor-drawer summary::-webkit-details-marker {
  display: none;
}

.vendor-drawer summary::before {
  content: "+";
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--primary);
  font-weight: 800;
  grid-column: 1;
}

.vendor-drawer[open] summary::before {
  content: "-";
}

.drawer-vendor {
  grid-column: 2;
  font-weight: 800;
  color: var(--text);
}

.drawer-metric {
  display: grid;
  gap: 2px;
  justify-items: end;
}

.drawer-metric strong {
  font-size: 16px;
  color: var(--text);
}

.drawer-metric small {
  display: none;
}

.drawer-body {
  border-top: 1px solid var(--line);
  background: #fff;
}

.drawer-table table {
  min-width: 900px;
}

.qty-edit,
.date-edit {
  width: 108px;
  min-height: 32px;
  font-weight: 700;
}

.qty-edit {
  text-align: right;
}

.date-edit {
  width: 150px;
}

.qty-edit:disabled,
.date-edit:disabled {
  color: var(--muted);
  background: #eef3f7;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 190px) 1fr minmax(92px, auto);
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #344653;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e6edf2;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #21a0a0, #d58a1f);
}

.bar-value {
  text-align: right;
  color: var(--muted);
  font-size: 12px;
}

dialog {
  width: min(1040px, calc(100vw - 36px));
  max-height: calc(100vh - 42px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(15, 24, 32, 0.45);
}

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

.dialog-head p {
  color: var(--muted);
  margin-top: 4px;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

#detailContent {
  padding: 16px;
  display: grid;
  gap: 16px;
  overflow: auto;
  max-height: calc(100vh - 132px);
}

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

.field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfd;
}

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

.field strong {
  display: block;
  overflow-wrap: anywhere;
}

#paymentForm {
  padding: 0 16px 16px;
  display: grid;
  gap: 12px;
}

#paymentForm label {
  display: grid;
  gap: 6px;
  color: #344653;
  font-weight: 700;
  font-size: 13px;
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

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

@media (max-width: 760px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .toolbar,
  .filters,
  .vendor-summary-head,
  .vendor-drawer summary,
  .grid.two {
    display: grid;
    grid-template-columns: 1fr;
  }

  .vendor-summary-head {
    display: none;
  }

  .drawer-vendor {
    grid-column: auto;
  }

  .drawer-metric {
    justify-items: start;
    padding-left: 38px;
  }

  .filters select {
    width: 100%;
  }

  #globalSearch {
    width: 100%;
  }

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

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