:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #687386;
  --line: #dce2ea;
  --primary: #146c94;
  --primary-dark: #0f5879;
  --accent: #f3b23b;
  --danger: #b42318;
  --ok: #237a4b;
  --shadow: 0 16px 40px rgba(24, 32, 43, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

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

.topbar h1,
.dialog-head h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-actions,
.dialog-actions,
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

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

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

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

.icon-button {
  width: 40px;
  padding: 0;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #e8f2f6;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.auth-panel,
.metrics {
  display: grid;
  gap: 12px;
}

.auth-panel {
  grid-template-columns: 1fr 2fr;
  align-items: center;
  margin-bottom: 16px;
  padding: 14px;
}

.auth-panel h2 {
  margin: 0;
  font-size: 20px;
}

.auth-fields {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 10px;
}

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

.auth-panel,
.metrics article,
.dashboard-grid article,
.toolbar,
.table-wrap,
.order-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metrics strong {
  font-size: clamp(22px, 3vw, 30px);
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.quick-filter {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.quick-filter.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 190px 190px;
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-grid article {
  padding: 14px;
}

.insight-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.insight-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

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

label span,
.toolbar span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

.table-wrap {
  overflow: auto;
}

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

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

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

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f9fbfd;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  background: #eef3f8;
  color: #334155;
}

.pill.warn {
  background: #fff1d6;
  color: #7a4a00;
}

.pill.ok {
  background: #dff6e9;
  color: #14532d;
}

.pill.danger {
  background: #fee4e2;
  color: var(--danger);
}

.money-cell {
  white-space: nowrap;
  font-weight: 700;
}

.profit-cell {
  color: var(--ok);
}

.profit-cell.negative {
  color: var(--danger);
}

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

dialog {
  width: min(980px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.order-form {
  padding: 18px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

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

fieldset {
  margin: 16px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

legend {
  padding: 0 8px;
  color: var(--muted);
  font-weight: 700;
}

.hidden {
  display: none;
}

.items-section,
.files-section,
.notes-field {
  display: block;
  margin-top: 18px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title h3 {
  margin: 0;
  font-size: 17px;
}

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

.item-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 70px 110px 120px 110px 120px 110px 120px 40px;
  gap: 8px;
  align-items: end;
}

.item-row button {
  min-height: 40px;
}

.item-row input[readonly] {
  background: #f3f6f9;
  color: var(--muted);
  font-weight: 700;
}

.totals,
.files-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.totals span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcfe;
}

.files-list {
  padding: 0;
  list-style: none;
}

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

.file-open-button {
  min-height: 32px;
  padding: 0 10px;
}

.customer-history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
  color: var(--muted);
  font-size: 13px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 24px;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.check-row span {
  margin: 0;
  color: var(--ink);
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

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

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button,
  .dialog-actions button {
    flex: 1;
  }

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

  .auth-panel,
  .auth-fields,
  .dashboard-grid,
  .toolbar,
  .form-grid,
  .item-row {
    grid-template-columns: 1fr;
  }

  .item-row {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }
}
