:root {
  --bg: #f1f2f1;
  --surface: #ffffff;
  --surface-soft: #f6f7f6;
  --ink: #202322;
  --muted: #5e6561;
  --line: #ccd2cf;
  --accent: #25584f;
  --accent-strong: #1d463f;
  --warning: #9b641f;
  --danger: #8f3f3f;
  --success: #2d6542;
  --focus: #2a6f82;
}

* {
  box-sizing: border-box;
}

html {
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100vh;
}

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

button {
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

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

.sidebar {
  background: #303735;
  color: #f4f6f5;
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 18px;
  border-right: 1px solid #222826;
}

.brand {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
}

.brand-name {
  font-weight: 800;
  font-size: 17px;
}

.brand-subtitle {
  color: #cbd1ce;
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-item {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #eef4ef;
  background: transparent;
  text-align: left;
  padding: 0 10px;
}

.nav-item:hover,
.nav-item.active {
  background: #3b4441;
  border-color: #4b5552;
}

.nav-item:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.sidebar-footer {
  margin-top: auto;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c4cec7;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8fc6a0;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.topbar-actions,
.toolbar,
.product-picker,
.button-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

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

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

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(46, 124, 151, 0.24);
  outline-offset: 2px;
}

.search {
  min-width: 260px;
}

.primary-button,
.secondary-button {
  border-radius: 6px;
  min-height: 36px;
  border: 1px solid transparent;
  padding: 0 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

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

.secondary-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: #aeb8ad;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: view-in 180ms ease-out;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.split-layout,
.content-grid,
.offer-layout,
.order-layout {
  display: grid;
  gap: 14px;
  align-items: start;
}

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

.content-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.offer-layout,
.order-layout {
  grid-template-columns: minmax(360px, 0.85fr) minmax(0, 1.15fr);
}

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

.panel-heading {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
}

.panel-counter {
  min-height: 26px;
  display: inline-grid;
  place-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  font-size: 12px;
  color: var(--muted);
  background: #fbfcfa;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 13px;
}

tbody tr {
  min-height: 40px;
}

tbody tr:hover {
  background: #f9fbf7;
}

.row-button {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-weight: 800;
  text-align: left;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
  background: #edf2ee;
  color: var(--muted);
  white-space: nowrap;
}

.badge.open {
  background: #fff4df;
  color: var(--warning);
}

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

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

.priority-block {
  padding: 14px;
  display: grid;
  gap: 14px;
}

.priority-block p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.detail-panel {
  padding-bottom: 12px;
}

.detail-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

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

.field-row {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  font-size: 13px;
}

.field-row span {
  color: var(--muted);
  font-weight: 700;
}

.toolbar {
  min-height: 52px;
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  min-height: 36px;
}

.segment {
  min-width: 112px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 0 12px;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

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

.product-picker {
  padding: 0 14px 14px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 110px auto;
}

.lines table {
  min-width: 760px;
}

.internal-grid {
  margin: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.internal-grid div {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.internal-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.comment-box {
  margin: 14px;
}

.hidden {
  display: none;
}

.extracted-grid {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 10px;
}

.extracted-field {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  display: grid;
  gap: 4px;
  background: #fbfcfa;
}

.extracted-field span {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.extracted-field strong {
  font-size: 14px;
  word-break: break-word;
}

.button-row {
  padding: 0 14px 14px;
}

.button-row.compact {
  padding: 0;
}

a {
  color: var(--accent);
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(32, 35, 34, 0.38);
  animation: fade-in 150ms ease-out;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(920px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(32, 35, 34, 0.22);
  animation: modal-in 170ms ease-out;
}

.review-modal {
  width: min(680px, 100%);
}

.modal-heading {
  min-height: 58px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
}

.modal-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.modal-body {
  overflow: auto;
  padding: 16px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.modal-grid .span-2 {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.icon-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

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

.review-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.review-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.review-row strong {
  font-size: 14px;
  word-break: break-word;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

  .sidebar {
    position: static;
  }

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

  .split-layout,
  .content-grid,
  .offer-layout,
  .order-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions,
  .search {
    width: 100%;
  }

  .form-grid,
  .internal-grid,
  .extracted-grid,
  .modal-grid {
    grid-template-columns: 1fr;
  }

  .product-picker {
    grid-template-columns: 1fr;
  }

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

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