:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --text: #18202a;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button, input, textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}

.brand {
  min-height: 44px;
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  padding: 6px 12px;
  cursor: pointer;
}

.brand-logo {
  display: block;
  width: auto;
  height: 30px;
  max-width: 210px;
  object-fit: contain;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 52px;
}

.heading { margin-bottom: 22px; }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-weight: 800; font-size: 13px; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(30px, 4vw, 44px); letter-spacing: 0; }
h2 { margin: 0 0 14px; font-size: 20px; }

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

.panel, .notice, .empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.notice { margin-bottom: 18px; border-color: #99d7ca; background: #ecfdf8; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; }
.print-message-text { display: none; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}

.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

.notify-button {
  position: relative;
}

.bell-icon {
  width: 20px;
  height: 20px;
}

.notification-dot {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #dc2626;
}

.notification-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 152px;
  border-radius: 6px;
  padding: 8px 10px;
  background: #dc2626;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  text-align: left;
  white-space: nowrap;
  box-shadow: 0 10px 20px rgba(24, 32, 42, .18);
  pointer-events: none;
}

.notification-popover::before {
  content: "";
  position: absolute;
  top: -5px;
  right: 14px;
  width: 10px;
  height: 10px;
  background: #dc2626;
  transform: rotate(45deg);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--accent-dark);
  background: #e6fffa;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button.active {
  border-color: var(--accent);
  background: #e6fffa;
  color: var(--accent-dark);
}

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

.summary-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.summary-card strong {
  font-size: 26px;
}

.error-text {
  color: #b42318;
  font-weight: 800;
}

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filters .active { border-color: var(--accent); background: #e6fffa; color: var(--accent-dark); }

.request-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  margin-bottom: 10px;
  text-align: left;
}

.request-row span { display: grid; gap: 4px; }
small { color: var(--muted); }
.status { color: var(--accent-dark); font-weight: 800; }

.product-line {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr .8fr .7fr;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.product-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.product-table-head,
.product-table-row {
  display: grid;
  grid-template-columns: var(--product-columns);
  gap: 10px;
  min-width: 780px;
  align-items: end;
}

.product-table-head {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.product-table-row {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.compact-field {
  font-size: 12px;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  margin-top: 10px;
}

.api-help {
  margin-top: 16px;
}

.bill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.bill-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  align-items: start;
  border-bottom: 2px solid var(--text);
  padding-bottom: 16px;
}

.bill-header h1 {
  font-size: 34px;
}

.bill-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.bill-meta {
  display: grid;
  gap: 8px;
}

.bill-receiver {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.bill-meta select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  font-size: 13px;
}

.bill-top-actions {
  justify-content: flex-end;
}

.bill-products {
  display: grid;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.bill-product-head,
.bill-product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 14px;
  align-items: start;
  padding: 12px;
}

.bill-product-head {
  background: #f1f5f9;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.bill-product-row + .bill-product-row {
  border-top: 1px solid var(--line);
}

.bill-product-row p {
  margin: 4px 0;
  color: var(--muted);
}

.product-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.product-facts-bottom {
  margin-top: 6px;
}

.product-facts span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
}

.product-fact-discount {
  color: #15803d;
  border-color: #22c55e;
  background: #dcfce7;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(22, 163, 74, 0.25);
}

.message-menu {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.message-menu-title {
  margin-bottom: 0;
  align-items: center;
}

.message-menu-title > div:first-child {
  display: grid;
  gap: 2px;
}

.message-box {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: clamp(220px, 38vh, 280px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.message-menu-title small,
.empty-message,
.chat-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.message-log {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 12px;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background: #f8fafc;
}

.chat-line {
  display: grid;
  gap: 3px;
  justify-self: start;
  max-width: min(78%, 620px);
  border: 1px solid #dbe4ef;
  border-radius: 14px 14px 14px 4px;
  padding: 8px 11px;
  background: #fff;
}

.chat-line.own {
  justify-self: end;
  border-color: #99d7ca;
  border-radius: 14px 14px 4px 14px;
  background: #e6fffa;
}

.chat-line p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chat-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 8px;
  background: #fff;
}

.chat-compose textarea {
  min-height: 42px;
  max-height: 96px;
  border-radius: 999px;
  padding: 10px 14px;
  resize: vertical;
}

.chat-send {
  min-width: 72px;
  min-height: 42px;
  border-radius: 999px;
  padding: 0 16px;
}

.qty-input {
  text-align: right;
  font-weight: 800;
}

.qty-field {
  align-self: start;
}

.qty-field-label {
  display: none;
}

.bill-actions {
  margin-top: 12px;
}

.save-success {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid #8fd8b4;
  border-radius: 999px;
  padding: 0 14px;
  background: #ecfdf3;
  color: #067647;
  font-weight: 800;
  animation: save-pop 1.8s ease both;
}

@keyframes save-pop {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(.96);
  }
  18% {
    opacity: 1;
    transform: translateY(0) scale(1.02);
  }
  35% {
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

pre {
  overflow-x: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #0f172a;
  color: #e5e7eb;
  font-size: 13px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.timeline { margin: 0; padding-left: 22px; }
.timeline li { margin: 8px 0; }

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

  .topbar {
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
  }

  .brand {
    min-height: 40px;
    padding: 5px 9px;
  }

  .brand-logo {
    height: 26px;
    max-width: 150px;
  }

  .topbar .actions {
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 8px;
  }

  .topbar .actions > button:not(.icon-button) {
    min-height: 38px;
    padding: 0 10px;
  }

  .user-chip {
    max-width: 116px;
    min-height: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .shell {
    width: min(100% - 20px, 520px);
    padding: 18px 0 34px;
  }

  .heading {
    margin-bottom: 14px;
  }

  h1 {
    font-size: 26px;
    line-height: 1.14;
  }

  h2 {
    font-size: 18px;
  }

  .panel,
  .notice,
  .empty,
  .bill {
    padding: 14px;
  }

  button,
  .button,
  input,
  textarea {
    min-height: 44px;
  }

  .tabs button,
  .filters button,
  .actions button {
    flex: 1 1 auto;
  }

  .icon-button {
    flex: 0 0 40px;
    min-height: 40px;
  }

  .notification-popover {
    right: -6px;
    max-width: calc(100vw - 24px);
    white-space: normal;
  }

  .request-row,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .request-row {
    padding: 14px;
  }

  .request-row > span:last-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .two,
  .product-line,
  .copy-row {
    grid-template-columns: 1fr;
  }

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

  .summary-card {
    padding: 12px;
  }

  .summary-card strong {
    font-size: 22px;
  }

  .product-table {
    overflow-x: visible;
  }

  .product-table-head {
    display: none;
  }

  .product-table-row {
    display: grid;
    grid-template-columns: 1fr;
    min-width: 0;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
  }

  .compact-field {
    font-size: 13px;
  }

  .bill-header, .bill-product-head { grid-template-columns: 1fr; }

  .bill-header {
    gap: 12px;
    padding-bottom: 12px;
  }

  .bill-header h1 {
    font-size: 24px;
    line-height: 1.16;
    overflow-wrap: anywhere;
  }

  .bill-products {
    margin-top: 12px;
  }

  .bill-product-head {
    display: none;
  }

  .bill-product-row {
    grid-template-columns: minmax(0, 1fr) 82px;
    gap: 10px;
  }

  .product-facts {
    gap: 5px;
  }

  .product-facts span {
    border-radius: 6px;
    padding: 4px 6px;
  }

  .message-menu {
    padding: 12px;
  }

  .message-box {
    height: 240px;
  }

  .message-menu-title {
    align-items: stretch;
  }

  .chat-compose {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .qty-input {
    min-height: 38px;
    padding: 6px 8px;
    text-align: center;
  }

  .qty-field-label {
    display: block;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    text-align: center;
    text-transform: uppercase;
  }

  .bill-top-actions { justify-content: flex-start; }
  .bill-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .save-success {
    grid-column: 1 / -1;
    justify-content: center;
  }
}

@media (max-width: 420px) {
  .brand-logo {
    max-width: 118px;
  }

  .topbar .actions {
    gap: 6px;
  }

  .topbar .actions > button:not(.icon-button) {
    padding: 0 8px;
  }

  .user-chip {
    display: none;
  }

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

@media print {
  .no-print, .topbar, .filters, .message-menu { display: none !important; }
  body { background: #fff; }
  .shell { width: 100%; padding: 0; }
  .panel { break-inside: avoid; }
}
