:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --border: #e5e7eb;
  --black: #111827;
  --blue: #2563eb;
  --green: #16a34a;
  --yellow: #ca8a04;
  --orange: #ea580c;
  --red: #dc2626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: 238px;
  height: 100vh;
  background: #111827;
  color: #fff;
  padding: 22px 16px;
  overflow-y: auto;
}

.brand {
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: .08em;
  margin-bottom: 26px;
  font-weight: 700;
}

.brand span {
  display: block;
  margin-top: 5px;
  color: #cbd5e1;
  font-size: 12px;
  letter-spacing: 0;
  font-weight: 400;
}

.sidebar a {
  display: block;
  color: #d1d5db;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 9px;
  margin-bottom: 5px;
}

.sidebar a:hover,
.sidebar a.active {
  background: #1f2937;
  color: #fff;
}

.sidebar .logout {
  margin-top: 24px;
  color: #fca5a5;
}

.main {
  margin-left: 238px;
  padding: 28px;
}

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

h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 650;
}

h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 650;
}

h3 {
  margin: 20px 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

p {
  color: var(--muted);
  margin: 0 0 12px;
}

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

.cards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

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

.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.metric {
  font-size: 30px;
  font-weight: 700;
  color: var(--black);
}

.label {
  color: var(--muted);
  margin-top: 5px;
}

.btn,
button {
  display: inline-block;
  background: var(--black);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
  margin-right: 8px;
}

button:hover,
.btn:hover {
  background: #374151;
}

.filters,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

label {
  color: var(--muted);
  font-size: 12px;
  display: block;
  margin-bottom: 6px;
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

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

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

th {
  font-size: 12px;
  color: var(--muted);
  background: #f9fafb;
  font-weight: 600;
}

td a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.pill {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
  font-size: 12px;
  font-weight: 600;
}

.pill.green { background: #dcfce7; color: #166534; }
.pill.yellow { background: #fef9c3; color: #854d0e; }
.pill.orange { background: #ffedd5; color: #9a3412; }
.pill.red { background: #fee2e2; color: #991b1b; }

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

.field {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: #fbfdff;
}

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

.field b {
  font-weight: 500;
  word-break: break-word;
}

.barrow {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.doc {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.doc a {
  display: block;
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

.doc span {
  color: var(--muted);
  font-size: 12px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

.alert {
  padding: 10px 12px;
  border-radius: 9px;
  margin-bottom: 12px;
}

.alert.danger {
  background: #fee2e2;
  color: #991b1b;
}

.errorbox {
  white-space: pre-wrap;
  background: #111827;
  color: #f9fafb;
  padding: 18px;
  border-radius: 12px;
  overflow-x: auto;
}

.login-body {
  background: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  width: 360px;
  background: #fff;
  padding: 28px;
  border-radius: 16px;
}

.login-card h1 {
  font-size: 18px;
  letter-spacing: .1em;
}

.login-card h2 {
  margin-top: 4px;
}

.login-card button {
  width: 100%;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
    height: auto;
  }

  .main {
    margin-left: 0;
    padding: 18px;
  }

  .cards,
  .two,
  .fields,
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* V1B data quality improvements */
.cards .card .metric {
  word-break: break-word;
}

.panel + .panel {
  margin-top: 16px;
}

/* V1B-FIX */
.cards .card .metric {
  word-break: break-word;
}

.panel + .panel {
  margin-top: 16px;
}

/* V1C import and operational pages */
.table-wrap table td {
  max-width: 320px;
  word-break: break-word;
}

.table-wrap table th {
  white-space: nowrap;
}

.hint {
  color: #5b6b84;
  margin-top: 14px;
}

.panel form button,
.panel form .btn {
  margin-top: 12px;
}

/* V1D Operational Insights */
.warn-card {
  border-color: #f59e0b !important;
  background: #fffbeb !important;
}

.mini-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.mini-list div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #ffffff;
}

.mini-list strong {
  font-size: 22px;
  color: #0f172a;
}

.mini-list span {
  color: #475569;
  text-align: right;
}

/* V1E Reporting / Export */
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.export-grid .export-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.export-card p {
  margin-top: 6px;
  color: #5b6b84;
}

.export-count {
  margin-top: 14px;
  font-size: 14px;
  color: #334155;
  font-weight: 600;
}

.btn.secondary {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #d8dee8;
}

.btn.secondary:hover {
  background: #f8fafc;
}

@media (max-width: 900px) {
  .export-grid .export-card {
    flex-direction: column;
  }
}

/* V1F Link Repair */
.inline-repair-form {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 220px;
}

.inline-repair-form input {
  width: 110px;
  padding: 8px 10px;
  border: 1px solid #d8dee8;
  border-radius: 10px;
  font-size: 14px;
}

.inline-repair-form button {
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.inline-repair-form button:hover {
  background: #1e293b;
}

/* V1G Factory Profile 360 */
.v1g-search {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.v1g-search input {
  flex: 1;
  min-width: 280px;
  padding: 13px 14px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 15px;
}

.v1g-search button {
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn.small {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.v1g-tabs-panel {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
}

.v1g-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.v1g-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border: 1px solid #d8dee8;
  border-radius: 999px;
  color: #0f172a;
  text-decoration: none;
  background: #fff;
  font-weight: 700;
}

.v1g-tab:hover {
  background: #f8fafc;
}

.v1g-tab span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
}

.v1g-section {
  scroll-margin-top: 100px;
}

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

.v1g-section-head h2 {
  margin: 0;
}

.v1g-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: #0f172a;
  font-weight: 800;
}

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

.v1g-info-item {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.v1g-info-label {
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.v1g-info-value {
  color: #0f172a;
  font-weight: 700;
  word-break: break-word;
}

.v1g-table-wrap table td {
  max-width: 340px;
  white-space: normal;
  word-break: break-word;
}

.empty-state {
  padding: 18px;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  color: #64748b;
  background: #f8fafc;
}

@media (max-width: 1200px) {
  .v1g-info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .v1g-info-grid {
    grid-template-columns: 1fr;
  }

  .v1g-search {
    flex-direction: column;
    align-items: stretch;
  }

  .v1g-search input {
    min-width: 0;
  }
}

/* V1H Factory 360 Export + PDF Pack */
.export-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .export-actions {
    justify-content: flex-start;
  }
}

/* V1I Role Permission + Vendor View + Supplier Actions */
.v1i-filter,
.v1i-access-form {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.v1i-filter input,
.v1i-filter select,
.v1i-access-form input,
.v1i-access-form select {
  min-width: 240px;
  padding: 12px 14px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
}

.v1i-filter button,
.v1i-access-form button,
.v1i-action-form button,
.v1i-small-button {
  padding: 11px 15px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.v1i-small-button {
  padding: 8px 11px;
  font-size: 12px;
}

.v1i-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  margin: 2px;
  white-space: nowrap;
}

.v1i-badge.ok {
  background: #dcfce7;
  color: #166534;
}

.v1i-badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.v1i-badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.v1i-chip-wrap {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 180px;
}

.v1i-chip-wrap.large {
  gap: 10px;
}

.v1i-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #eef2f7;
  color: #334155;
}

.v1i-chip.ok {
  background: #dcfce7;
  color: #166534;
}

.v1i-chip.warn {
  background: #fef3c7;
  color: #92400e;
}

.v1i-chip.danger {
  background: #fee2e2;
  color: #991b1b;
}

.v1i-action-form {
  display: grid;
  grid-template-columns: 2fr 140px 160px 160px 180px;
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}

.v1i-action-form input,
.v1i-action-form select,
.v1i-action-form textarea {
  padding: 12px 14px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
}

.v1i-action-form textarea {
  grid-column: 1 / -2;
  min-height: 88px;
  resize: vertical;
}

.v1i-action-form button {
  min-height: 46px;
}

@media (max-width: 1100px) {
  .v1i-action-form {
    grid-template-columns: 1fr 1fr;
  }

  .v1i-action-form textarea {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .v1i-filter,
  .v1i-access-form {
    flex-direction: column;
    align-items: stretch;
  }

  .v1i-filter input,
  .v1i-filter select,
  .v1i-access-form input,
  .v1i-access-form select {
    min-width: 0;
    width: 100%;
  }

  .v1i-action-form {
    grid-template-columns: 1fr;
  }

  .v1i-action-form textarea {
    grid-column: auto;
  }
}

/* V1J Supplier Action Auto-Generation */
.inline-action-form {
  display: inline-flex;
  margin: 0;
}

.inline-action-form button.btn {
  border: 0;
  cursor: pointer;
}

.v1j-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.v1j-pill {
  display: inline-flex;
  align-items: center;
  padding: 10px 13px;
  border: 1px solid #d8dee8;
  border-radius: 999px;
  background: #fff;
  color: #0f172a;
  text-decoration: none;
  font-weight: 800;
}

.v1j-pill.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.v1j-result {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.v1j-result h2 {
  color: #166534;
}

/* V1K Supplier Email Reminder + Weekly Digest */
.v1k-email-header {
  display: grid;
  gap: 12px;
}

.v1k-email-header div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
}

.v1k-email-header span {
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 12px;
  font-weight: 700;
}

.v1k-copy-box {
  width: 100%;
  min-height: 420px;
  padding: 16px;
  border: 1px solid #d8dee8;
  border-radius: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  background: #fff;
}

.v1k-email-preview {
  padding: 20px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #fff;
  overflow-x: auto;
}

@media (max-width: 720px) {
  .v1k-email-header div {
    grid-template-columns: 1fr;
  }
}

/* V1L Email Sending Integration */
.v1l-config-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.v1l-config-grid div {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  min-width: 0;
}

.v1l-config-grid span {
  display: block;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 6px;
}

.v1l-config-grid strong {
  display: block;
  word-break: break-word;
}

.v1l-ready,
.v1l-not-ready {
  margin-top: 16px;
  padding: 13px 15px;
  border-radius: 12px;
  font-weight: 700;
}

.v1l-ready {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.v1l-not-ready,
.v1l-error {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.v1l-success {
  background: #f0fdf4;
  color: #166534;
  border-color: #bbf7d0;
}

.v1l-test-form {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.v1l-test-form input {
  min-width: 320px;
  padding: 12px 14px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
}

.v1l-test-form button {
  padding: 11px 15px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.v1l-code {
  padding: 16px;
  border-radius: 14px;
  background: #0f172a;
  color: #e5e7eb;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 1100px) {
  .v1l-config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .v1l-config-grid {
    grid-template-columns: 1fr;
  }

  .v1l-test-form {
    flex-direction: column;
    align-items: stretch;
  }

  .v1l-test-form input {
    min-width: 0;
    width: 100%;
  }
}

/* V1M Email Recipient Management + Draft Editing */
.v1m-recipient-form {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.2fr 120px 1fr;
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}

.v1m-recipient-form input,
.v1m-recipient-form select,
.v1m-recipient-form textarea,
.v1m-draft-edit-form input,
.v1m-draft-edit-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
}

.v1m-recipient-form textarea {
  grid-column: 1 / -2;
  min-height: 76px;
  resize: vertical;
}

.v1m-recipient-form button,
.v1m-draft-edit-form button {
  padding: 12px 15px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.v1m-draft-edit-form {
  display: grid;
  gap: 16px;
  max-width: 1200px;
}

.v1m-draft-edit-form label {
  display: grid;
  gap: 7px;
}

.v1m-draft-edit-form label span {
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 12px;
  font-weight: 800;
}

.v1m-draft-edit-form textarea {
  min-height: 520px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.5;
  resize: vertical;
}

.danger-button {
  background: #991b1b !important;
}

@media (max-width: 1200px) {
  .v1m-recipient-form {
    grid-template-columns: 1fr 1fr;
  }

  .v1m-recipient-form textarea {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .v1m-recipient-form {
    grid-template-columns: 1fr;
  }

  .v1m-recipient-form textarea {
    grid-column: auto;
  }
}

/* V1N Supplier Portal Access Hardening */
.v1n-denied-wrap {
  max-width: 760px;
  margin: 60px auto;
}

.v1n-denied-panel {
  text-align: center;
  padding: 42px 34px;
}

.v1n-denied-icon {
  width: 58px;
  height: 58px;
  border-radius: 999px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-weight: 900;
  font-size: 30px;
}

.v1n-denied-panel h1 {
  margin-bottom: 10px;
}

.v1n-denied-panel p {
  color: #52637a;
  font-size: 16px;
}

.v1n-denied-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
}

/* V1N-R2 Vendor Navigation Cleanup + Login Redirect */
.v1nr2-portal-note {
  padding: 12px 14px;
  border-radius: 12px;
  background: #eff6ff;
  color: #1e3a8a;
  border: 1px solid #bfdbfe;
  font-weight: 700;
}

.sidebar a[href="/my-portal"],
nav a[href="/my-portal"] {
  font-weight: 800;
}

.sidebar a[href="/supplier-actions?filter=open"],
nav a[href="/supplier-actions?filter=open"] {
  font-weight: 800;
}

/* V1N-R3 User Account Management + Vendor Login */
.v1nr3-user-form {
  display: grid;
  grid-template-columns: 1.2fr 1fr 160px 1fr 1.2fr auto;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.v1nr3-user-form input,
.v1nr3-user-form select,
.v1nr3-inline-form input,
.v1nr3-inline-form select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #d8dee8;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
}

.v1nr3-user-form button,
.v1nr3-inline-form button {
  padding: 11px 14px;
  border: 0;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.v1nr3-inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 320px;
}

.v1nr3-inline-form input {
  min-width: 150px;
}

.v1nr3-inline-form select {
  min-width: 220px;
}

@media (max-width: 1300px) {
  .v1nr3-user-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .v1nr3-user-form {
    grid-template-columns: 1fr;
  }

  .v1nr3-inline-form {
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .v1nr3-inline-form input,
  .v1nr3-inline-form select {
    min-width: 0;
  }
}
