:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee7;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #027a48;
  --shadow: 0 8px 24px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Arial, sans-serif;
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  min-height: 36px;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--brand-dark); }
button.secondary { background: #e6eef0; color: #17323a; }
button.secondary:hover { background: #d4e2e6; }
button.danger { background: var(--danger); }

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

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

label {
  display: block;
  color: #344054;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.login-card p {
  color: var(--muted);
  margin: 0 0 20px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 10px 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(16, 24, 40, .06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  margin: 0;
  min-width: 170px;
}

.brand img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  padding: 3px;
}

.user-chip {
  color: #344054;
  font-size: 12px;
  text-align: right;
}

.user-chip span {
  display: block;
  color: var(--muted);
}

.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-menu {
  position: relative;
}

.nav-menu summary {
  list-style: none;
  cursor: pointer;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #17202a;
  font-weight: 700;
}

.nav-menu summary::-webkit-details-marker { display: none; }

.nav-menu[open] summary {
  border-color: #9ccfc9;
  background: #e9f7f5;
}

.nav-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 210px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-menu-list button {
  display: block;
  width: 100%;
  margin: 0 0 4px;
  text-align: left;
  background: transparent;
  color: #17202a;
}

.nav-menu-list button.active,
.nav-menu-list button:hover {
  background: #e9f7f5;
  color: #0f766e;
}

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

.notification-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #fedf89;
  border-radius: 8px;
  background: #fffbeb;
}

.notification-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  background: #fff7d6;
  color: #7a4d00;
  border: 1px solid #f7c948;
}

.notification-item:hover {
  background: #fef0b7;
}

.notification-item span,
.notification-item em {
  font-style: normal;
  color: #7a4d00;
}

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

.topbar h2 {
  margin: 0;
  font-size: 22px;
}

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

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

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

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

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

.metric .value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 2px;
}

.panel-head,
.workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h3,
.workspace-head h3 {
  margin: 0;
}

.action-panel {
  min-height: 230px;
}

.action-list {
  display: grid;
  gap: 8px;
}

.action-row {
  display: grid;
  grid-template-columns: 145px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}

.action-row:hover {
  background: #f8fafc;
}

.action-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-row em {
  color: var(--muted);
  font-style: normal;
  white-space: nowrap;
}

.workspace {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar input { max-width: 360px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.pager button:disabled {
  opacity: .45;
  cursor: default;
}

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

.row-actions button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
}

.bulk-box {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.bulk-box label {
  grid-column: 1 / -1;
}

.bulk-box textarea {
  min-height: 70px;
}

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

.detail-panel summary {
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 8px;
}

.inline-detail-row td {
  background: #f8fafc !important;
  padding: 10px;
}

.cell-input {
  min-height: 30px;
  padding: 4px 6px;
  border-radius: 4px;
  min-width: 78px;
}

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

.section-title h3 {
  margin: 0;
}

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

.metric-warn {
  border-color: #f59e0b;
  background: #fffbeb;
}

.crm-workspace {
  display: grid;
  grid-template-columns: minmax(320px, .72fr) minmax(560px, 1.28fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.crm-side-panel {
  display: grid;
  gap: 12px;
}

.crm-primary {
  min-width: 0;
}

.crm-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(175px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.crm-stage {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 170px;
  padding: 10px;
}

.crm-stage-head,
.crm-card-top,
.crm-card-meta,
.crm-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.crm-stage-head {
  font-weight: 700;
  margin-bottom: 4px;
}

.crm-stage-head strong {
  background: #e6eef0;
  border-radius: 999px;
  min-width: 26px;
  text-align: center;
  padding: 2px 7px;
}

.crm-stage-value {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.crm-stage-list {
  display: grid;
  gap: 8px;
}

.crm-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.crm-card-top strong {
  font-size: 13px;
}

.crm-card-top span,
.stage-badge {
  background: #e6f4f1;
  color: #115e59;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
  white-space: nowrap;
}

.crm-card-meta {
  margin-top: 8px;
  color: #344054;
  font-size: 12px;
}

.crm-card-actions {
  margin-top: 8px;
}

.crm-card-actions select {
  min-height: 30px;
  padding: 4px 7px;
}

.crm-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 10px;
}

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

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

.crm-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr);
  gap: 12px;
  margin-top: 12px;
}

.crm-timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  position: relative;
  padding-left: 22px;
  border-left: 2px solid #d8dee7;
}

.timeline-dot {
  position: absolute;
  left: -6px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--brand);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--brand);
}

.timeline-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

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

.linked-doc-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(16, 24, 40, .55);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(1100px, 96vw);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.email-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  max-height: 58vh;
  overflow: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-head h3 {
  margin: 0;
}

.report-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px auto;
  gap: 10px;
  align-items: end;
}

.report-filter textarea {
  min-height: 92px;
}

.buy-badge,
.lowest-price {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #dcfce7;
  color: #027a48;
  font-weight: 700;
}

.quote-cell,
.quote-price {
  min-height: 28px;
  padding: 5px 7px;
  border-bottom: 1px solid #eef2f7;
  line-height: 1.35;
}

.quote-cell:last-child,
.quote-price:last-child {
  border-bottom: 0;
}

.quote-price {
  white-space: nowrap;
}

.lowest-price-chip {
  background: #dcfce7;
  color: #027a48;
  border: 1px solid #86efac;
  border-radius: 6px;
  font-weight: 800;
}

.lowest-price-chip .muted {
  color: #05603a;
}

.table-wrap table[data-table-key="report:rfq-compact"] {
  min-width: 980px;
}

.table-wrap table[data-table-key="report:rfq-compact"] th:nth-child(1),
.table-wrap table[data-table-key="report:rfq-compact"] td:nth-child(1) {
  min-width: 150px;
}

.table-wrap table[data-table-key="report:rfq-compact"] th:nth-child(4),
.table-wrap table[data-table-key="report:rfq-compact"] td:nth-child(4),
.table-wrap table[data-table-key="report:rfq-compact"] th:nth-child(5),
.table-wrap table[data-table-key="report:rfq-compact"] td:nth-child(5),
.table-wrap table[data-table-key="report:rfq-compact"] th:nth-child(6),
.table-wrap table[data-table-key="report:rfq-compact"] td:nth-child(6) {
  min-width: 180px;
  vertical-align: top;
}

.rfq-compare-groups {
  display: grid;
  gap: 10px;
}

.rfq-part-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.rfq-part-group summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.sub-panel summary {
  cursor: pointer;
  font-weight: 700;
}

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

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

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

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

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

th {
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
  position: sticky;
  top: 0;
}

tr:hover td { background: #f8fafc; }

.right { text-align: right; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-warn { color: var(--warn); font-weight: 600; }
.error { color: var(--danger); margin-top: 8px; }
.success { color: var(--ok); margin-top: 8px; }

.line-editor {
  display: grid;
  grid-template-columns: 1.5fr 80px 90px 110px auto;
  gap: 8px;
  align-items: end;
}

.part-picker {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 6px;
  margin-bottom: 6px;
}

.part-picker input,
.part-picker button {
  min-height: 32px;
}

@media (max-width: 900px) {
  .app-header { align-items: flex-start; flex-wrap: wrap; }
  .brand { min-width: 140px; }
  .top-nav { order: 3; width: 100%; }
  .nav-menu-list { position: fixed; left: 12px; right: 12px; top: 118px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .span-2, .span-4 { grid-column: auto; }
  .line-editor { grid-template-columns: 1fr; }
  .part-picker { grid-template-columns: 1fr; }
  .crm-kpis, .crm-workspace, .crm-bottom { grid-template-columns: 1fr; }
  .crm-board { grid-template-columns: repeat(6, minmax(210px, 1fr)); }
  .crm-form, .crm-form .span-2 { grid-template-columns: 1fr; grid-column: auto; }
  .report-filter { grid-template-columns: 1fr; }
  .linked-doc-picker { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
  }

  button,
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 15px;
  }

  button {
    padding: 10px 12px;
  }

  .login-page {
    padding: 16px;
    align-items: start;
  }

  .login-card {
    margin-top: 18px;
    padding: 20px;
  }

  .app-header {
    gap: 10px;
    padding: 10px;
    min-height: 0;
  }

  .brand {
    min-width: 0;
    flex: 1 1 auto;
    font-size: 16px;
  }

  .brand img {
    width: 36px;
    height: 36px;
  }

  .user-area {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }

  .user-chip {
    text-align: left;
    min-width: 0;
  }

  .top-nav {
    order: 2;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-menu {
    flex: 0 0 auto;
  }

  .nav-menu summary {
    min-height: 42px;
  }

  .nav-menu-list {
    position: fixed;
    top: 126px;
    left: 10px;
    right: 10px;
    max-height: calc(100vh - 146px);
    overflow: auto;
    z-index: 200;
  }

  .nav-menu-list button {
    min-height: 44px;
    margin-bottom: 6px;
  }

  .main {
    padding: 12px 10px 18px;
  }

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

  .topbar h2 {
    font-size: 20px;
  }

  .panel,
  .metric,
  .detail-panel,
  .sub-panel {
    border-radius: 7px;
    padding: 12px;
  }

  .toolbar,
  .row-actions,
  .panel-head,
  .workspace-head,
  .section-title,
  .modal-head {
    align-items: stretch;
  }

  .toolbar input,
  .toolbar select,
  .toolbar button,
  .row-actions button,
  .panel-head button,
  .workspace-head button {
    max-width: none;
    width: 100%;
  }

  .panel-head,
  .workspace-head,
  .section-title,
  .modal-head {
    flex-direction: column;
  }

  .bulk-box,
  .part-picker,
  .linked-doc-picker {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .action-row em {
    white-space: normal;
  }

  .crm-board {
    grid-template-columns: repeat(6, minmax(240px, 1fr));
  }

  .crm-activity-form,
  .crm-form {
    grid-template-columns: 1fr;
  }

  .crm-form .span-2 {
    grid-column: auto;
  }

  .modal-backdrop {
    padding: 8px;
    place-items: stretch;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - 16px);
    padding: 12px;
  }

  .notification-bar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .notification-item {
    width: 100%;
    justify-content: flex-start;
    white-space: normal;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 720px;
  }

  th,
  td {
    padding: 9px 8px;
  }
}

@media (max-width: 430px) {
  .brand span {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-area {
    gap: 8px;
  }

  .user-area button {
    width: auto;
  }

  .nav-menu-list {
    top: 132px;
  }

  .metric .value {
    font-size: 22px;
  }
}
