:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #152025;
  --muted: #65737a;
  --line: #d9e0e3;
  --panel: #ffffff;
  --panel-soft: #eef3f5;
  --brand: #0b6f59;
  --brand-deep: #084f41;
  --blue: #245a87;
  --amber: #a56b00;
  --red: #b64236;
  --shadow: 0 18px 45px rgba(21, 32, 37, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  background: #10251f;
  color: #fff;
  overflow-y: auto;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand);
  font-size: 24px;
  font-weight: 900;
}

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

.brand-block p {
  color: rgba(255, 255, 255, 0.7);
}

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

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.08;
}

h3 {
  margin-bottom: 4px;
  font-size: 20px;
}

.module-nav {
  display: grid;
  gap: 7px;
}

.module-nav button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.82);
  text-align: left;
  font-weight: 800;
}

.module-nav button:hover,
.module-nav .is-active {
  background: #ffffff;
  color: var(--brand-deep);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.workbench {
  min-width: 0;
  padding: 26px;
}

.topbar,
.top-actions,
.panel-title-row,
.dialog-header,
.dialog-actions,
.record-title,
.status-line,
.money-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 18px;
}

.top-actions {
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 330px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
}

.primary-button,
.ghost-button,
.icon-button,
.segmented button,
.chip {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

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

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

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.role-switcher {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.hubspot-warning {
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 13px;
  color: #92400E;
}

.hubspot-proxy-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #F1F5F9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 12px;
}

.hubspot-proxy-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94A3B8;
}

.hubspot-proxy-status.ok {
  background: #DCFCE7;
  border-color: #86EFAC;
  color: #166534;
}

.hubspot-proxy-status.ok .dot {
  background: #16A34A;
}

.hubspot-proxy-status.fail {
  background: #FEE2E2;
  border-color: #FCA5A5;
  color: #991B1B;
}

.hubspot-proxy-status.fail .dot {
  background: #DC2626;
}

.hubspot-proxy-status .text {
  flex: 1;
}

.hubspot-proxy-status code {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
}

.token-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.token-row input {
  flex: 1;
}

.hubspot-test-status {
  margin: 0;
  font-size: 13px;
}

.hubspot-test-status.ok {
  color: #15803D;
}

.hubspot-test-status.failed {
  color: #B91C1C;
}

.hubspot-search-panel {
  background: #F8FAFC;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  grid-column: 1 / -1;
}

.hubspot-search-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.ghost-button.mini {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
}

.inline-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: 6px;
}

.inline-actions .ghost-button {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
}

.hubspot-search-panel h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

.hubspot-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.hubspot-candidate-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.hubspot-candidate {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hubspot-candidate:hover {
  background: var(--brand-deep);
  color: #fff;
  border-color: var(--brand-deep);
}

.hubspot-candidate small {
  opacity: 0.7;
  font-size: 11px;
}

.hubspot-search-hint {
  font-size: 12px;
  color: #64748B;
}

.hubspot-search-hint.warn {
  color: #B91C1C;
}

.role-perm-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 12px;
  font-size: 13px;
  background: #F8FAFC;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.role-perm-grid dt {
  font-weight: 700;
  color: var(--ink);
}

.role-perm-grid dd {
  margin: 0;
  color: #475569;
  word-break: break-word;
}

.owner-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 13px;
  color: var(--ink);
}

.owner-cell.owner-self {
  background: #ECFCCB;
  border: 1px solid #BEF264;
  padding: 2px 8px;
  border-radius: 999px;
  color: #365314;
  font-weight: 600;
}

.owner-role {
  font-size: 11px;
  color: #64748B;
  font-weight: 400;
}

.owner-cell.owner-self .owner-role {
  color: #4D7C0F;
}

.sidebar .ghost-button {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.file-control {
  position: relative;
  overflow: hidden;
}

.file-control input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

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

.kpi-card,
.content-panel,
.detail-panel,
.dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 16px;
  min-height: 108px;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.kpi-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.kpi-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.content-panel,
.detail-panel {
  min-width: 0;
  overflow: hidden;
}

.panel-title-row {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-title-row p,
.detail-panel p,
td small {
  margin-bottom: 0;
  color: var(--muted);
}

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

.segmented button {
  min-height: 34px;
  border-color: var(--line);
  background: var(--panel-soft);
  color: var(--ink);
}

.segmented .is-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #fafbfb;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: #f1f7f5;
}

.line-detail-table {
  margin-top: 4px;
  font-size: 12px;
}

.line-detail-table th,
.line-detail-table td {
  padding: 8px;
  white-space: normal;
}

.line-detail-table small {
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-color: var(--line);
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 12px;
}

.chip.green {
  background: #e5f4ee;
  color: var(--brand-deep);
  border-color: #b9ddcf;
}

.chip.blue {
  background: #e7f0f8;
  color: var(--blue);
  border-color: #bdd4e6;
}

.chip.amber {
  background: #fff3d9;
  color: var(--amber);
  border-color: #eed18d;
}

.chip.red {
  background: #fde9e6;
  color: var(--red);
  border-color: #f1c4bd;
}

.detail-panel {
  position: sticky;
  top: 24px;
  padding: 18px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.detail-actions button {
  min-height: 36px;
}

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

.table-action-button {
  min-height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
}

.top-actions button:disabled,
.table-action-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.danger-button {
  color: var(--red);
  border-color: #f1c4bd;
  background: #fff8f7;
}

.quote-template-dialog {
  width: min(620px, calc(100vw - 28px));
}

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

.template-upload-control {
  justify-content: center;
}

.template-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
}

.template-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.template-list-item strong {
  display: block;
  font-size: 13px;
}

.template-list-item small {
  color: var(--muted);
}

.detail-section {
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-section:first-child {
  padding-top: 0;
  margin-top: 0;
  border-top: 0;
}

.detail-section h4 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
}

.fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.fact {
  min-height: 70px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

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

.fact strong {
  overflow-wrap: anywhere;
}

dialog {
  width: min(900px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

dialog::backdrop {
  background: rgba(11, 31, 27, 0.38);
}

.dialog-card {
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

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

.rate-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(90px, 1fr));
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.rate-panel div {
  display: grid;
  gap: 4px;
}

.rate-panel strong {
  font-size: 14px;
}

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

.sni-check-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.sni-check-panel strong {
  font-size: 14px;
}

.sni-check-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.sni-check-badge {
  width: max-content;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
}

.sni-check-badge.certified {
  background: #dff4e7;
  color: #08733f;
}

.sni-check-badge.open {
  background: #fff1d6;
  color: #9a5a00;
}

.sni-check-badge.neutral {
  background: #eaf0f2;
  color: var(--muted);
}

.line-editor {
  display: grid;
  gap: 8px;
}

.line-row,
.line-head {
  display: grid;
  grid-template-columns: 1.6fr 0.75fr 0.9fr 0.9fr 0.9fr;
  gap: 8px;
}

.quote-line,
.line-row:has([name^="quote_"]) {
  grid-template-columns: 1.5fr 0.65fr 0.95fr 0.85fr 0.95fr;
}

.line-head {
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.line-row {
  position: relative;
  padding: 8px 36px 8px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.purchase-line {
  grid-template-columns: 1.25fr 1.45fr 1fr 0.8fr 0.8fr;
}

.line-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.line-remove:hover {
  background: #fee;
  color: #c33;
  border-color: #fbb;
}

.line-add {
  margin-top: 4px;
  align-self: flex-start;
  font-size: 13px;
  padding: 6px 14px;
}

.dialog-actions {
  justify-content: flex-end;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

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

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

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

  .module-nav button {
    text-align: center;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .workbench {
    padding: 18px;
  }

  .topbar,
  .panel-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .search-box {
    width: 100%;
    min-width: 0;
  }

  .primary-button {
    width: 100%;
  }

  .kpi-grid,
  .form-grid,
  .fact-grid,
  .rate-panel,
  .line-row,
  .purchase-line {
    grid-template-columns: 1fr;
  }

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

  th,
  td {
    padding: 12px;
  }
}
