:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17212b;
  background: #f3f6f8;
  font-synthesis: none;
  --blue: #1e4f77;
  --blue-light: #e5f0f8;
  --green: #2f7a43;
  --green-light: #dcefd9;
  --beige: #fff2d5;
  --red: #a52a2a;
  --red-light: #f9dada;
  --gray: #e9eef2;
  --shadow: 0 2px 12px rgb(23 33 43 / 8%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #f3f6f8;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }

.registration {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.registration-card { max-width: 480px; width: 100%; }
.registration-card h1 { margin-top: 0; color: var(--blue); }

label {
  display: grid;
  gap: 7px;
  margin: 16px 0;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #b8c4cc;
  border-radius: 10px;
  background: white;
  padding: 10px 12px;
  color: #17212b;
}

input:focus {
  outline: 3px solid rgb(30 79 119 / 18%);
  border-color: var(--blue);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 68px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--blue);
  color: white;
  box-shadow: var(--shadow);
}

.topbar strong { display: block; font-size: 1.1rem; }
.topbar small { display: block; opacity: .85; }
.badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.badge { border-radius: 999px; padding: 5px 8px; background: rgb(255 255 255 / 16%); font-size: .76rem; }
.badge.offline, .badge.warning { background: #805c14; }

main { max-width: 900px; margin: 0 auto; padding: 14px; }
.view { display: grid; gap: 14px; }
.card { background: white; border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.card h2, .section-header h2 { margin: 0 0 12px; font-size: 1.05rem; color: var(--blue); }

.choice-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.choice-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice-button {
  min-height: 52px;
  border: 1px solid #c7d2da;
  border-radius: 11px;
  background: #f7f9fa;
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  color: #243442;
}
.choice-button.selected { background: var(--beige); border: 2px solid var(--green); color: #1d542d; }
.choice-button.selected::before { content: "✓ "; color: var(--green); }

.chip-list { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.client-chip { border: 1px solid #bdcbd5; border-radius: 999px; padding: 8px 11px; background: #f6f9fb; }
.client-chip.selected { background: var(--beige); border-color: var(--green); }
.client-suggestions { margin-top: 8px; max-height: 310px; overflow: auto; border-radius: 10px; }
.client-row { display: grid; grid-template-columns: 1fr 48px; border-bottom: 1px solid #e4e9ed; background: white; }
.client-row.selected { background: var(--beige); }
.client-name, .favorite-button { min-height: 48px; border: 0; background: transparent; }
.client-name { text-align: left; padding: 8px 10px; }
.favorite-button { font-size: 1.4rem; color: #b27600; }

.quantity-input { font-size: 1.35rem; text-align: center; margin-bottom: 12px; }
.primary-button, .secondary-button, .danger-button {
  border-radius: 10px;
  min-height: 46px;
  padding: 10px 14px;
  font-weight: 800;
}
.primary-button { width: 100%; border: 0; background: var(--green); color: white; }
.secondary-button { border: 1px solid #b8c7d2; background: white; color: var(--blue); }
.danger-button { border: 1px solid #d9a4a4; background: #fff5f5; color: var(--red); }

.form-status { min-height: 24px; margin: 12px 0 0; font-weight: 700; }
.form-status.success { color: var(--green); }
.form-status.error, .inline-error { color: var(--red); }
.form-status.pending { color: #805c14; }

.section-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-header h2 { margin: 0; }
.section-header > div { display: flex; gap: 7px; }
.recent-list { display: grid; gap: 10px; }
.operation-card { background: white; border-left: 5px solid #7890a1; border-radius: 12px; padding: 13px; box-shadow: var(--shadow); }
.operation-card.status-CANCELLED { border-left-color: var(--red); background: #fff9f9; }
.operation-card.status-pending, .operation-card.status-sending { border-left-color: #b47b17; }
.operation-card.status-error, .operation-card.status-needs_fix { border-left-color: var(--red); }
.operation-card h3 { margin: 0 0 8px; font-size: 1rem; }
.operation-details { display: grid; gap: 3px; color: #4c5d69; }
.operation-status { margin-top: 8px; font-weight: 800; color: var(--green); }
.status-CANCELLED .operation-status, .status-error .operation-status, .status-needs_fix .operation-status { color: var(--red); }
.operation-card .danger-button { margin-top: 10px; }

.table-wrap { overflow: auto; background: white; border-radius: 12px; box-shadow: var(--shadow); }
table { width: max-content; min-width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid #dfe6eb; padding: 10px; text-align: center; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--blue); color: white; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 2; background: white; text-align: left; }
th:first-child { background: var(--blue); z-index: 3; }
td.negative { background: var(--red-light); color: #7b1111; font-weight: 800; }
td.zero { color: #76848e; }

.profile-name { font-size: 1.2rem; font-weight: 800; margin-bottom: 4px; }
.muted { color: #637481; font-size: .9rem; }
.privacy-note, .info-box { font-size: .9rem; color: #50616d; background: var(--blue-light); border-radius: 10px; padding: 10px; }
.info-box { margin: 12px 0; }
.empty-state { text-align: center; color: #71818c; padding: 28px 10px; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 7px calc(7px + env(safe-area-inset-bottom));
  background: white;
  border-top: 1px solid #d5dee4;
  box-shadow: 0 -3px 15px rgb(23 33 43 / 9%);
}
.bottom-nav button { min-height: 48px; border: 0; background: transparent; color: #60717c; font-weight: 700; }
.bottom-nav button.active { color: var(--blue); background: var(--blue-light); border-radius: 10px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  max-width: min(90vw, 520px);
  transform: translate(-50%, 30px);
  opacity: 0;
  pointer-events: none;
  background: #26343e;
  color: white;
  border-radius: 11px;
  padding: 12px 15px;
  transition: .2s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: #245d35; }
.toast.warning { background: #745213; }
.toast.error { background: #862525; }

[hidden] { display: none !important; }

@media (min-width: 700px) {
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
