:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #172033;
  --muted: #687386;
  --line: #d9e1ec;
  --line-soft: #e8edf4;
  --brand: #2357d9;
  --brand-dark: #173ea6;
  --success: #008f7a;
  --danger: #c43d4d;
  --warning: #b7791f;
  --shadow: 0 16px 38px rgba(22, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  padding: 18px;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-header,
.app-shell {
  width: min(1220px, 100%);
  margin: 0 auto;
}

.app-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 8px 0 18px;
}

.back-link,
.btn,
.clear-search,
.qty-btn {
  border: 0;
  cursor: pointer;
  text-decoration: none;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(22, 32, 51, 0.06);
}

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-block img {
  width: 76px;
  height: auto;
  flex: 0 0 auto;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  color: var(--ink);
  letter-spacing: 0;
}

h1 {
  margin-top: 3px;
  font-size: 1.8rem;
  line-height: 1.08;
}

h2 {
  margin-top: 2px;
  font-size: 1.35rem;
  line-height: 1.15;
}

.header-stat {
  display: grid;
  gap: 4px;
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: right;
  box-shadow: 0 8px 22px rgba(22, 32, 51, 0.06);
}

.header-stat strong {
  color: var(--brand);
  font-size: 1.02rem;
}

.command-panel {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.search-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(35, 87, 217, 0.12);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
}

.search-box input::placeholder {
  color: #8a95a6;
}

.clear-search {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #e9eef6;
  color: var(--muted);
}

.order-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: max-content;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.94rem;
  font-weight: 800;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.btn:hover:not(:disabled),
.back-link:hover,
.clear-search:hover,
.qty-btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.btn-primary {
  background: var(--brand);
  box-shadow: 0 10px 18px rgba(35, 87, 217, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-dark);
}

.btn-secondary {
  background: var(--danger);
  box-shadow: 0 10px 18px rgba(196, 61, 77, 0.16);
}

.feedback {
  min-height: 28px;
  padding: 9px 2px 3px;
  color: var(--danger);
  font-size: 0.94rem;
  font-weight: 800;
  text-align: center;
}

.feedback.success {
  color: var(--success);
}

.content-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 14px;
}

.catalogue-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.subject-card {
  --accent: var(--brand);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(22, 32, 51, 0.06);
}

.subject-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-top: 4px solid var(--accent);
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfe;
  cursor: pointer;
  outline: 0;
}

.subject-header:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(35, 87, 217, 0.16);
}

.subject-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 900;
}

.subject-title {
  min-width: 0;
}

.subject-title h3 {
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.subject-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.subject-total {
  min-width: 76px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 26%, white);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent);
  text-align: center;
}

.subject-total small,
.subject-total strong {
  display: block;
}

.subject-total small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.subject-total strong {
  margin-top: 1px;
  font-size: 1rem;
}

.subject-progress {
  height: 4px;
  background: #edf1f7;
}

.subject-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.18s ease;
}

.subject-chevron {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--muted);
  transition: transform 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.subject-card.is-open .subject-chevron {
  transform: rotate(180deg);
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: var(--accent);
}

.subject-card.is-collapsed .manual-list {
  display: none;
}

.manual-list {
  display: grid;
}

.manual-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
}

.manual-row:last-child {
  border-bottom: 0;
}

.manual-row.is-selected {
  background: color-mix(in srgb, var(--success) 7%, white);
}

.manual-main {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
}

.manual-number {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 28px;
  padding: 0 6px;
  border-radius: 8px;
  background: #eef2f7;
  color: #516070;
  font-size: 0.82rem;
  font-weight: 850;
}

.manual-name {
  min-width: 0;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}

.manual-name[dir="rtl"] {
  text-align: right;
}

.qty-control {
  display: grid;
  grid-template-columns: 34px 54px 34px;
  align-items: center;
  width: 122px;
  height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.qty-btn {
  display: grid;
  place-items: center;
  height: 100%;
  background: #f1f5f9;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 900;
}

.qty-btn:active {
  transform: translateY(0);
}

.qty-input {
  width: 100%;
  height: 100%;
  border: 0;
  border-inline: 1px solid var(--line);
  outline: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  text-align: center;
}

.qty-control:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(35, 87, 217, 0.12);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 28px 18px;
  border: 1px dashed #bdc7d6;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 1.08rem;
}

[hidden] {
  display: none !important;
}

@supports not (background: color-mix(in srgb, #000 10%, white)) {
  .subject-mark {
    background: #eef4ff;
  }

  .subject-total {
    border-color: var(--line);
  }

  .manual-row.is-selected {
    background: #effaf7;
  }
}

@media (min-width: 980px) {
  .catalogue-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
}

@media (max-width: 760px) {
  body {
    padding: 12px;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 12px;
    padding-bottom: 12px;
  }

  .back-link {
    justify-self: start;
  }

  .brand-block {
    gap: 10px;
  }

  .brand-block img {
    width: 64px;
  }

  h1 {
    font-size: 1.48rem;
  }

  .header-stat {
    width: 100%;
    grid-template-columns: 1fr 1fr;
    text-align: left;
  }

  .command-panel {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .order-strip {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .btn {
    width: 100%;
    min-width: 0;
    padding: 0 10px;
  }
}

@media (max-width: 430px) {
  .command-panel {
    gap: 7px;
  }

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

  .subject-chevron {
    grid-column: 3;
    grid-row: 1;
  }

  .subject-total {
    display: flex;
    grid-column: 2 / 4;
    grid-row: 2;
    align-items: center;
    justify-content: space-between;
    min-width: 0;
    text-align: left;
  }

  .manual-row {
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 11px 12px;
  }

  .qty-control {
    justify-self: end;
  }
}

@media (max-width: 350px) {
  body {
    padding: 8px;
  }

  .brand-block img {
    width: 56px;
  }

  .manual-main {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
  }

  .manual-number {
    min-width: 32px;
    height: 26px;
    font-size: 0.76rem;
  }

  .qty-control {
    width: 116px;
    grid-template-columns: 32px 52px 32px;
  }
}
