:root {
  --bg: #000000;
  --panel: #ffffff;
  --ink: #1f2d2a;
  --muted: #60706b;
  --line: #dbe5e0;
  --accent: #2f6b55;
  --accent-strong: #214e3f;
  --soft: #e8f1ed;
  --warn: #8a3b28;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input,
select {
  font: inherit;
}

input[type="date"],
input[type="datetime-local"],
input[type="month"],
select,
textarea {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfc 100%);
  box-shadow: inset 0 1px 2px rgba(31, 45, 42, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="month"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 107, 85, 0.14);
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.8;
  filter: invert(29%) sepia(17%) saturate(725%) hue-rotate(101deg) brightness(88%) contrast(90%);
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
}

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

button.secondary {
  background: var(--soft);
  color: var(--accent-strong);
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 7px;
  background: var(--soft);
  color: var(--accent-strong);
  font-weight: 800;
  padding: 0 14px;
  text-decoration: none;
}

.nav-button:hover {
  background: #d8e8e1;
}

button.secondary:hover {
  background: #d8e8e1;
}

button.danger {
  background: #f4dfd8;
  color: var(--warn);
}

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

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

main {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto 40px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  width: min(1500px, calc(100% - 32px));
  margin: 24px auto;
}

.topbar h1,
.panel h2,
.items-heading h3 {
  margin: 0;
}

.topbar h1 {
  font-size: 34px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

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

.summary-grid article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(31, 45, 42, 0.05);
}

.summary-grid article {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.summary-grid span,
.table-total {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-grid strong {
  font-size: 28px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(420px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

#dealSection:empty {
  display: none;
}

.customer-panel {
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
}

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

.customer-sort-control {
  min-width: 220px;
}

.product-panel,
.customer-form-panel {
  position: fixed;
  top: 24px;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: min(720px, calc(100vw - 48px));
  overflow: auto;
  box-shadow: 0 18px 50px rgba(31, 45, 42, 0.22);
}

.customer-form-panel {
  width: min(900px, calc(100vw - 48px));
}

.form-grid {
  display: grid;
  grid-template-columns: 160px minmax(240px, 1fr) 160px;
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.items-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 0 12px;
}

.items {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 90px 150px 40px;
  align-items: end;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.icon-button {
  min-width: 40px;
  padding: 0;
  background: #eef3f0;
  color: var(--ink);
  font-size: 22px;
}

.form-total {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.form-total span {
  color: var(--muted);
  font-weight: 700;
}

.form-total strong {
  color: var(--ink);
}

.product-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 100px 72px;
  gap: 8px;
  margin-bottom: 12px;
}

.product-form #productName {
  grid-column: 1 / -1;
}

.product-margin-output,
.product-margin {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
  color: var(--ink);
  font-weight: 800;
  padding: 10px;
}

.customer-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 130px 150px minmax(150px, 1fr) minmax(140px, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  align-items: end;
}

.compact-field {
  min-width: 0;
}

.customer-form button {
  grid-column: span 1;
}

#customerName {
  grid-column: 1 / 3;
}

#customerBusinessId {
  grid-column: 3;
}

#customerPhone {
  grid-column: 4;
}

#customerEmail {
  grid-column: 5;
}

#customerAddress {
  grid-column: 1 / 4;
}

.compact-button {
  min-height: 40px;
  white-space: nowrap;
}

.status-field {
  grid-column: 5;
}

#customerExtra {
  grid-column: 1 / 5;
}

.customer-form button[type="submit"] {
  grid-column: 5;
}

.customer-delete-panel-button {
  margin-top: 10px;
}

.import-form {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.import-form input {
  width: 260px;
}

.customer-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.customer-table {
  min-width: 1260px;
}

.link-button {
  min-height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent-strong);
  text-align: left;
}

.link-button:hover {
  background: transparent;
  text-decoration: underline;
}

.status-select {
  min-width: 150px;
}

.recall-controls {
  min-width: 220px;
}

.recall-display,
.recall-edit {
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-recall-date {
  min-width: 140px;
}

.table-recall-time {
  min-width: 100px;
}

.recall-value {
  display: inline-block;
  min-width: 100%;
  padding: 7px 9px;
  border-radius: 7px;
}

.recall-value:empty {
  padding: 0;
}

.recall-overdue {
  color: #8f1d1d;
  background: #f8d7d7;
  box-shadow: inset 0 0 0 1px #efb7b7;
  font-weight: 800;
}

.selected-row {
  background: var(--soft);
}

.customer-history-row td {
  padding: 0 8px 14px;
  background: var(--soft);
}

.customer-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
  padding: 14px;
  min-width: 0;
}

.customer-workspace .panel,
.customer-workspace .history-panel {
  min-width: 0;
}

.customer-workspace .deal-panel .form-grid {
  grid-template-columns: minmax(130px, 0.45fr) minmax(220px, 1fr) minmax(130px, 0.45fr);
}

.customer-workspace .deal-panel .item-row {
  grid-template-columns: minmax(180px, 1fr) 72px minmax(110px, 0.5fr) 40px;
}

.customer-workspace .deal-panel input,
.customer-workspace .deal-panel select {
  min-width: 0;
}

.customer-workspace .deal-panel .items,
.customer-workspace .deal-panel .form-grid,
.customer-workspace .deal-panel .item-row {
  max-width: 100%;
}

.history-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfc;
  max-width: none;
}

.history-panel h3 {
  margin: 0;
}

.history-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-close-button {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 50%;
  color: #829089;
  background: transparent;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  opacity: 0.72;
}

.history-close-button:hover,
.history-close-button:focus-visible {
  color: var(--accent-strong);
  background: var(--soft);
  opacity: 1;
}

.history-form {
  display: grid;
  gap: 8px;
}

.history-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.history-action-row button {
  width: 100%;
}

.deal-form-mount {
  display: grid;
  min-width: 0;
}

.deal-form-mount:empty {
  display: none;
}

.deal-form-mount .deal-panel {
  margin: 0;
}

.history-recall-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef6f2;
  padding: 12px;
}

.history-recall-panel h4 {
  margin: 0;
}

.history-recall-fields {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(120px, 0.8fr);
  gap: 8px;
}

.history-recall-fields button {
  align-self: end;
}

.date-select {
  display: grid;
  grid-template-columns: minmax(72px, 0.8fr) minmax(96px, 1fr) minmax(92px, 0.9fr);
  gap: 6px;
}

.date-select select {
  min-width: 0;
  padding-left: 10px;
  padding-right: 10px;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  resize: vertical;
  font: inherit;
}

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

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

.call-history-column {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f8f5;
  padding: 10px;
}

.history-column-heading {
  min-height: 20px;
}

.history-column-heading p,
.history-section-heading p {
  margin: 0;
}

.order-history {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.order-history-section {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f8f5;
  padding: 10px;
}

.history-section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.history-section-heading strong {
  color: var(--ink);
}

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

.order-history-entry {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.order-history-entry p {
  margin: 0;
  line-height: 1.45;
}

.order-product-list {
  display: grid;
  gap: 6px;
}

.order-product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 7px 8px;
  border-radius: 6px;
  background: var(--soft);
}

.order-product-name {
  min-width: 0;
  font-weight: 600;
  line-height: 1.35;
}

.order-product-amount {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.order-product-amount small {
  color: var(--muted);
}

.order-history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.order-history-note {
  color: var(--muted);
  font-size: 13px;
}

.history-entry {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.history-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-entry-head input {
  max-width: 160px;
}

.icon-text-button {
  min-height: 30px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--accent-strong);
  font-size: 12px;
  padding: 0 10px;
}

.icon-text-button:hover {
  background: #d8e8e1;
}

.history-entry p {
  margin: 4px 0 0;
  color: var(--ink);
  line-height: 1.45;
}

.history-entry button {
  justify-self: start;
}

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

.product-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 92px 40px;
  align-items: center;
  gap: 8px;
}

.visible-product-row {
  grid-template-columns: repeat(3, minmax(0, 1fr)) 92px 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  align-items: end;
}

.visible-product-row .product-name {
  grid-column: 1 / 5;
}

.visible-product-row .icon-button {
  grid-column: 5;
  grid-row: 1;
}

.visible-product-row label {
  min-width: 0;
}

.visible-product-row label:nth-of-type(1),
.visible-product-row label:nth-of-type(2),
.visible-product-row label:nth-of-type(3),
.visible-product-row .product-margin {
  grid-row: 2;
  width: auto;
  justify-self: stretch;
}

.visible-product-row label:nth-of-type(1) {
  grid-column: 1;
}

.visible-product-row label:nth-of-type(2) {
  grid-column: 2;
}

.visible-product-row label:nth-of-type(3) {
  grid-column: 3;
}

.visible-product-row .product-margin {
  grid-column: 4;
  display: grid;
  gap: 2px;
}

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

.product-name {
  display: grid;
  gap: 2px;
}

.product-name strong {
  color: var(--ink);
  font-size: 15px;
}

.product-name span,
.empty-inline {
  color: var(--muted);
  font-size: 13px;
}

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

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

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

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

td.numeric {
  text-align: right;
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  padding: 20px 8px;
}

@media (max-width: 980px) {
  .topbar,
  .layout,
  .summary-grid,
  .form-grid,
  .item-row,
  .product-form,
  .visible-product-row,
  .customer-form,
  .customer-layout,
  .customer-workspace,
  .history-columns,
  .history-recall-fields,
  .date-select {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .summary-grid {
    display: grid;
  }

  #customerName,
  #customerBusinessId,
  #customerPhone,
  #customerEmail,
  #customerAddress,
  .status-field,
  #customerExtra,
  .customer-form button[type="submit"] {
    grid-column: 1;
  }
}

@media (max-width: 1250px) {
  .customer-workspace {
    grid-template-columns: 1fr;
  }
}
body.auth-pending > .topbar,
body.auth-pending > main {
  visibility: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #f4f0e7, #e5eadf);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 18px;
  padding: 36px;
  border: 1px solid rgba(41, 55, 42, 0.14);
  border-radius: 24px;
  background: #fffdf8;
  box-shadow: 0 24px 70px rgba(41, 55, 42, 0.16);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.login-help {
  color: #5f685e;
  line-height: 1.5;
}

.login-error {
  padding: 10px 12px;
  border-radius: 10px;
  color: #8b1e1e;
  background: #fbe9e7;
}
