:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  --text: #1b1f24;
  --muted: #6b7280;
  --brand: #0f62fe;
  --brand-dark: #0043ce;
  --ok: #0e8a5f;
  --warn: #b45309;
  --danger: #c02626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: #101828;
  color: #cbd5e1;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #0f62fe, #4f9bff);
  display: grid; place-items: center; font-size: 13px;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #cbd5e1; padding: 9px 10px; border-radius: 8px; font-size: 13.5px;
  display: flex; align-items: center; gap: 9px;
}
.nav a:hover { background: #1d2939; color: #fff; text-decoration: none; }
.nav a.active { background: #1d2939; color: #fff; font-weight: 600; }
.nav svg { width: 17px; height: 17px; opacity: .85; }

.sidebar .spacer { flex: 1; }
.who { border-top: 1px solid #243247; padding-top: 12px; font-size: 12.5px; color: #98a2b3; }
.who strong { display: block; color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.role-chip { display: inline-block; margin-top: 4px; font-size: 11px; background: #1d2939; color: #b9c0cc; padding: 2px 7px; border-radius: 999px; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 24px; position: sticky; top: 0; z-index: 5;
}
.crumbs { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.crumbs strong { color: var(--text); font-weight: 600; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { padding: 24px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.page-head p { margin: 0; color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.card-body.flush { overflow-x: auto; }
.card-body.flush table { min-width: 100%; }
.content { min-width: 0; }
.main { min-width: 0; }
.layout { min-width: 0; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 100%; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-head h2 { font-size: 15px; margin: 0; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-compact { font-size: 13px; }
.table-compact thead th { padding: 9px 10px; }
.table-compact tbody td { padding: 9px 10px; }
.table-compact .mono { font-family: var(--font); font-size: 13px; white-space: nowrap; }
.table-compact .sub { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.table-compact td.wrap { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-compact .badge { white-space: nowrap; }
.table-compact thead th:last-child, .table-compact tbody td:last-child {
  position: sticky; right: 0; background: var(--surface); z-index: 1;
  box-shadow: -8px 0 8px -8px rgba(16, 24, 40, .18);
}
.table-compact thead th:last-child { background: var(--surface-2); }
.table-compact tbody tr:hover td:last-child { background: #f9fafb; }
.scroll-hint { display: flex; align-items: center; gap: 6px; padding: 8px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.scroll-hint.hidden { display: none; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.draft { background: #eef2f6; color: #475467; }
.badge.submitted { background: #e8f1ff; color: #0a55d0; }
.badge.partially_po { background: #fff4e5; color: #b45309; }
.badge.fully_po { background: #e7f7ef; color: #0e8a5f; }
.badge.cancelled { background: #fdecec; color: #c02626; }
.badge.error { background: #fdecec; color: #c02626; }
.badge.warning { background: #fff4e5; color: #b45309; }
.badge.info { background: #eef2ff; color: #3730a3; }
.badge.plain::before { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; box-shadow: var(--shadow); transition: background .12s, border-color .12s;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f3c6c6; background: #fff; }
.btn.danger:hover { background: #fdf2f2; }
.btn.ghost { box-shadow: none; border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: #344054; margin-bottom: 5px; }
label.field > span .req { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: #fff; border: 1px solid #d0d5dd; border-radius: 8px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 98, 254, .15); }
textarea { resize: vertical; min-height: 34px; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brand); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { color: var(--danger); font-size: 12.5px; margin-top: 4px; }

.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 8px; border: 1px solid; font-size: 13.5px; }
.msg.error { background: #fdf2f2; border-color: #f3c6c6; color: #9b1c1c; }
.msg.success { background: #ecfdf3; border-color: #b7ebc6; color: #067647; }
.msg.warning { background: #fffaeb; border-color: #f7dfa6; color: #93370d; }
.msg.info { background: #eff8ff; border-color: #b2ddff; color: #175cd3; }

.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.issues { display: grid; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.issues li { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.issues li .badge { flex-shrink: 0; margin-top: 1px; }

.dropzone {
  display: block; width: 100%; box-sizing: border-box;
  border: 2px dashed #cbd5e1; border-radius: 12px; padding: 34px 20px; text-align: center;
  background: var(--surface); transition: border-color .12s, background .12s; cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: #f5f9ff; }
.dropzone .icon { color: var(--brand); display: block; }
.dropzone strong { display: block; margin: 8px 0 4px; font-size: 15px; }
.dropzone span { color: var(--muted); font-size: 12.5px; display: block; }
.dropzone .file-pill { display: inline-flex; }
.dropzone input { display: none; }

.file-pill { display: inline-flex; align-items: center; gap: 8px; background: #eef4ff; color: #0a55d0; padding: 6px 10px; border-radius: 8px; font-size: 13px; }

.totals { display: grid; gap: 6px; }
.totals .row { display: flex; justify-content: space-between; gap: 24px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.totals .row:last-child { border-bottom: none; font-weight: 700; font-size: 15px; }
.totals .row span { color: var(--muted); font-weight: 400; }
.totals .row.total span { color: var(--text); font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a { padding: 9px 14px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.tabs a.active { color: var(--brand); box-shadow: inset 0 -2px 0 var(--brand); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% -10%, #e8f0ff 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; }
.login-card .brand { color: var(--text); margin-bottom: 20px; }

.items-table td { padding: 8px 10px; }
.items-table input, .items-table textarea { padding: 6px 8px; font-size: 13px; }
.items-table td:nth-child(4) input { text-align: right; }
.items-table td:nth-child(6) input { text-align: right; }

.sticky-actions {
  position: sticky; bottom: 0; background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px);
  border-top: 1px solid var(--border); padding: 12px 18px; display: flex; gap: 10px; justify-content: flex-end;
  border-radius: 0 0 var(--radius) var(--radius);
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 14px; }
  .sidebar .spacer, .who { display: none; }
  .nav { flex-direction: row; overflow-x: auto; }
  .content { padding: 16px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.modal {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .55);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; overflow: hidden; animation: modal-in .12s ease-out;
}
@keyframes modal-in { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { padding: 18px 20px 0; }
.modal-head h2 { margin: 0 0 4px; font-size: 17px; }
.modal-head p { margin: 0; color: var(--muted); font-size: 13px; }
.modal-body { padding: 16px 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }
.warn-list { margin: 12px 0 0; padding-left: 18px; font-size: 13px; color: #93370d; }
.warn-list li { margin-bottom: 4px; }
.confirm-box { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-top: 14px; }

.ss { position: relative; }
.ss-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); max-height: 260px; overflow: auto; padding: 4px;
}
.ss-menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent;
  border-radius: 6px; font: inherit; font-size: 13px; color: var(--text); box-shadow: none;
}
.ss-menu button:hover, .ss-menu button.active { background: #eef4ff; color: var(--brand-dark); }
.ss-menu button[hidden], .ss-menu .ss-empty[hidden] { display: none; }
.ss-menu .ss-empty { padding: 10px; color: var(--muted); font-size: 12.5px; }
.ss .chev { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 11px; }
.ss input { padding-right: 26px; }
.filter-bar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
@media (max-width: 980px) { .filter-bar { grid-template-columns: 1fr; } }

.copy-pill {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 2px 6px; font: inherit; font-size: 11.5px; font-weight: 600;
  color: #0e8a5f; background: #e7f7ef;
}
.copy-pill:hover { border-color: #b7ebc6; }
.copy-pill.copied { background: #0e8a5f; color: #fff; }
.copy-pill::after { content: "⧉"; font-size: 11px; opacity: .7; }
.copy-pill.copied::after { content: "✓"; opacity: 1; }

.nav-count {
  margin-left: auto; background: #344054; color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 999px; font-weight: 600;
}
.nav a.active .nav-count { background: var(--brand); }

.nav-group { display: flex; flex-direction: column; }
.nav-group-toggle {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: 0; box-shadow: none; color: #cbd5e1;
  padding: 9px 10px; border-radius: 8px; font: inherit; font-size: 13.5px;
  font-weight: 500; cursor: pointer; text-align: left;
}
.nav-group-toggle:hover { background: #1d2939; color: #fff; }
.nav-group-toggle svg { width: 17px; height: 17px; opacity: .85; }
.nav-group-toggle .chev { margin-left: auto; font-size: 10px; transition: transform .15s; opacity: .8; }
.nav-group.open .nav-group-toggle .chev { transform: rotate(180deg); }
.nav-group-items { display: none; flex-direction: column; gap: 1px; margin: 2px 0 4px 14px; padding-left: 8px; border-left: 1px solid #243247; }
.nav-group.open .nav-group-items { display: flex; }
.nav-group-items a { padding: 7px 10px; font-size: 13px; color: #b9c3d1; }
.nav-group-items a:hover { background: #1d2939; color: #fff; text-decoration: none; }
.nav-group-items a.active { background: #1d2939; color: #fff; font-weight: 600; }
