:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #657084;
  --line: #dce3ee;
  --primary: #176b87;
  --primary-dark: #0f4f63;
  --accent: #d99b2b;
  --success: #198754;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(23, 32, 51, 0.08);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

body.locked {
  overflow: hidden;
}

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

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: #111827;
}

.login-screen.active {
  display: grid;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
}

.login-brand {
  color: var(--ink);
}

.login-brand p {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  background: #111827;
  color: #f9fafb;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

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

.brand p,
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

.brand p {
  color: #aeb8c7;
}

.brand strong {
  display: block;
  line-height: 1.1;
}

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

.nav-item {
  display: block;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: #273244;
  color: #ffffff;
}

.workspace {
  width: 100%;
  min-width: 0;
  padding: 28px;
}

.topbar,
.panel-header,
.form-footer,
.line-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 22px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 6px;
  font-size: 16px;
}

.top-actions,
.segmented,
.inline-actions,
.report-controls,
.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
  min-width: 0;
}

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

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 20px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
}

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

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.report-panel {
  box-shadow: none;
}

.month-control {
  min-width: 210px;
}

.report-controls {
  justify-content: flex-end;
}

.section-heading {
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.primary-button,
.ghost-button,
.icon-button,
.segment,
.action-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: var(--primary);
  color: #ffffff;
}

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

.ghost-button,
.segment,
.action-button {
  background: #edf4f7;
  color: var(--primary-dark);
  border-color: #cfe0e7;
}

.segment.active {
  background: var(--primary);
  color: #ffffff;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: #e8edf5;
  color: var(--ink);
  border-color: var(--line);
}

.inline-form,
.quote-form {
  display: grid;
  gap: 12px;
}

.inline-form {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  align-items: end;
}

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

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

input,
select,
textarea {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
}

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

.vendor-tools {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 160px;
  gap: 10px;
}

.vendor-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.vendor-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.vendor-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.vendor-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.vendor-name {
  display: grid;
  gap: 4px;
}

.vendor-name small,
.muted {
  color: var(--muted);
}

.vendor-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.checkbox-section {
  display: grid;
  gap: 10px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.checkbox-grid label {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
}

.checkbox-grid input {
  width: 16px;
  min-height: 16px;
}

.single-check {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  color: var(--ink);
}

.single-check input {
  width: 18px;
  min-height: 18px;
}

input[type="file"] {
  padding: 8px;
}

.document-upload-row {
  display: grid;
  grid-template-columns: minmax(240px, 360px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.upload-status {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.upload-status.success {
  border-color: #b7e2c7;
  background: #edf9f1;
  color: var(--success);
}

.upload-status.warn {
  border-color: #f4d48c;
  background: #fff8e7;
  color: #8a5a00;
}

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

.bom-spec-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.bom-spec-card label {
  color: var(--ink);
}

.bom-spec-card small {
  color: var(--muted);
  font-weight: 700;
}

.spec-source {
  max-height: 56px;
  overflow: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.danger-action {
  background: #fee4e2;
  border-color: #fecaca;
  color: var(--danger);
}

.line-item-row {
  justify-content: stretch;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 90px 130px 120px;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  width: 100%;
  overflow-x: auto;
  contain: layout paint;
  margin-top: 18px;
}

.compact {
  margin-top: 0;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td {
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf4f7;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 800;
}

.badge.success {
  background: #dff3e8;
  color: var(--success);
}

.badge.warn {
  background: #fff2d8;
  color: #8a5a00;
}

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

.cards-grid,
.catalogue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.vendor-card,
.catalogue-card,
.order-card,
.summary-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.vendor-card p,
.catalogue-card p,
.order-card p,
.summary-item p {
  color: var(--muted);
  margin-bottom: 8px;
  font-size: 13px;
}

.pipeline,
.summary-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.pipeline-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) 42px;
  gap: 12px;
  align-items: center;
}

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

.bar span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.order-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.order-column {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 220px;
}

.order-column h3 {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.order-card {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.search {
  max-width: 320px;
}

dialog {
  width: min(980px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(17, 24, 39, 0.28);
}

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

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

#dialogBody {
  padding: 16px;
}

.profile-section {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.profile-section:first-child {
  margin-top: 0;
}

.profile-section h3 {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.profile-filter {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

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

.document-item {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

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

.hidden {
  display: none;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 14px;
  }

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

  .metrics,
  .split-layout,
  .cards-grid,
  .catalogue-grid,
  .order-board,
  .form-grid,
  .bom-spec-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 720px) {
  .workspace {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .split-layout,
  .cards-grid,
  .catalogue-grid,
  .order-board,
  .form-grid,
    .profile-filter,
    .document-grid,
    .document-upload-row,
    .bom-spec-grid,
    .vendor-tools,
    .inline-form,
    .line-item-row {
    grid-template-columns: 1fr;
  }

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

  .nav-item {
    text-align: center;
    padding-inline: 8px;
  }

  .panel,
  .metric {
    box-shadow: none;
  }
}
