:root {
  color-scheme: light;
  --bg: #eef4f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d7e0ea;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --soft: #f4f8fb;
  --soft-strong: #eaf1f7;
  --success: #138a5b;
  --success-bg: #dcfce7;
  --success-line: #9ce3bd;
  --warn: #a15c07;
  --warn-bg: #fff4d8;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --shadow: 0 18px 48px rgba(31, 44, 71, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.version-badge {
  margin-bottom: 3px;
  padding: 5px 8px;
  border: 1px solid #b7d3ff;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 950;
  line-height: 1;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1;
}

h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.status-pill {
  min-width: 96px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.status-pill.ok {
  border-color: var(--success-line);
  background: var(--success-bg);
  color: var(--success);
}

.status-pill.error {
  border-color: #f3b5af;
  background: var(--danger-bg);
  color: var(--danger);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}

.search-row input,
.request-form input,
.request-form select,
.request-form textarea,
.production-form input,
.production-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

.search-row input {
  min-height: 46px;
  padding: 0 14px;
}

.search-row button,
.primary-button,
.ghost-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 850;
}

.search-row button,
.primary-button {
  background: var(--accent);
  color: white;
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.search-row button {
  padding: 0 16px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.4fr);
  gap: 14px;
}

.requests-panel {
  margin-bottom: 14px;
}

.requests-panel > .panel-head {
  padding-bottom: 12px;
}

.request-form {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(220px, 1.6fr) minmax(110px, 0.6fr) minmax(120px, 0.7fr) minmax(140px, 0.8fr);
  gap: 10px;
  padding: 0 16px 14px;
  align-items: end;
}

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

.request-form input,
.request-form select,
.request-form textarea {
  min-height: 46px;
  padding: 9px 11px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 750;
}

.request-form select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 16px) 19px, calc(100% - 11px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.request-comment-field {
  grid-column: 1 / 5;
}

.request-materials-preview {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.request-materials-preview .section-head {
  margin-bottom: 8px;
}

.request-materials-list {
  display: grid;
  gap: 7px;
}

.request-material {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.request-material strong,
.request-material span {
  display: block;
}

.request-material > div:first-child strong {
  overflow-wrap: anywhere;
}

.request-material > div:first-child span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.request-material-quantity {
  min-width: 128px;
  text-align: right;
}

.request-material-quantity strong {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 950;
}

.request-material-quantity span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.request-material.short {
  border-color: #f0bd6c;
  background: var(--warn-bg);
}

.request-material.short .request-material-quantity strong,
.request-material.short .request-material-quantity span {
  color: var(--warn);
}

.request-form .primary-button {
  min-height: 46px;
  font-size: 15px;
  font-weight: 900;
}

.requests-panel .notice {
  margin: 0 16px 14px;
}

.requests-list {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
}

.request-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.production-mode .request-card:not(.done):not(.cancelled) {
  cursor: pointer;
}

.production-mode .request-card:not(.done):not(.cancelled):hover,
.request-card.active {
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
}

.production-mode .request-card.active {
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 72%);
}

.request-card.in_progress {
  border-color: var(--success-line);
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 68%);
}

.office-mode .request-card.in_progress {
  border-left: 5px solid var(--success);
  background: linear-gradient(135deg, #dcfce7 0%, #ffffff 70%);
}

.production-mode .request-card.in_progress.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 72%);
}

.request-card.done {
  border-color: #b7d3ff;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 70%);
}

.office-mode .request-card.done {
  border-left: 5px solid var(--accent);
  background: linear-gradient(135deg, #dbeafe 0%, #ffffff 72%);
}

.request-card.cancelled {
  opacity: 0.68;
}

.office-mode .request-card.cancelled {
  border-left: 5px solid #98a2b3;
}

.request-main {
  display: grid;
  gap: 6px;
}

.request-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.request-title strong {
  overflow-wrap: anywhere;
}

.request-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.request-comment {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}

.request-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.request-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--soft-strong);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.request-badge.urgent {
  background: #e11d48;
  color: #ffffff;
}

.request-badge.high {
  background: var(--warn-bg);
  color: var(--warn);
}

.request-badge.due {
  background: #e0f2fe;
  color: #075985;
}

.request-card.in_progress .request-badge {
  background: var(--success-bg);
  color: var(--success);
}

.request-card.in_progress .request-badge.urgent {
  background: #e11d48;
  color: #ffffff;
}

.request-result {
  width: fit-content;
  max-width: 100%;
  padding: 7px 9px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  font-weight: 900;
}

.request-actions {
  display: grid;
  gap: 6px;
  align-content: start;
  min-width: 150px;
}

.request-actions button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

.requests-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 16px 16px;
}

.requests-pagination span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.requests-pagination button {
  min-height: 36px;
}

.panel {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head {
  padding: 16px 16px 10px;
}

.panel-head h2 {
  margin-bottom: 2px;
}

.panel-head span,
.section-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.plans-toggle {
  min-height: 36px;
  padding: 0 12px;
}

.plans-list {
  display: grid;
  gap: 12px;
  padding: 0 10px 10px;
}

.plans-panel.collapsed .plans-list {
  display: none;
}

.plan-category {
  display: grid;
  gap: 8px;
}

.plan-category-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  text-align: left;
}

.plan-category-head:hover {
  border-color: #abc4e5;
  background: var(--soft-strong);
}

.plan-category-title {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.plan-category-title strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.plan-category-title small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.plan-category-chevron {
  width: 9px;
  height: 9px;
  margin-right: 3px;
  flex: 0 0 auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.plan-category.expanded .plan-category-chevron {
  transform: rotate(225deg) translate(-2px, -2px);
}

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

.plan-category-list.is-collapsed {
  display: none;
}

.plan-button {
  width: 100%;
  min-height: 78px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 12px;
}

.plan-button strong,
.line-title {
  display: block;
  overflow-wrap: anywhere;
}

.plan-button p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.plan-button.active,
.plan-button:hover {
  border-color: var(--accent);
  background: #eff6ff;
}

.detail-panel {
  padding: 18px;
}

.empty-state {
  display: grid;
  min-height: 380px;
  align-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--ink);
}

.hidden {
  display: none;
}

.office-mode .production-only,
.production-mode .office-only {
  display: none;
}

.muted {
  color: var(--muted);
  line-height: 1.45;
}

.instructions-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.instructions-panel .muted {
  margin: 8px 0 0;
}

.instructions-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.instruction-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.instruction-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--panel-strong);
  font-size: 13px;
  font-weight: 900;
}

.instruction-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.instruction-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.instruction-extras {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.instruction-extra {
  display: grid;
  grid-template-columns: minmax(80px, auto) 1fr;
  gap: 8px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--accent-strong);
}

.instruction-extra span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.instruction-extra strong {
  font-size: 16px;
  font-weight: 950;
}

.production-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.65fr) minmax(240px, 1.35fr);
  gap: 12px;
  align-items: start;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.production-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  font-weight: 850;
}

.production-form input,
.production-form textarea {
  min-height: 48px;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 750;
}

.production-form textarea {
  resize: vertical;
}

.primary-button {
  padding: 0 20px;
}

.form-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(150px, 0.65fr) minmax(240px, 1.35fr);
  gap: 12px;
  align-items: stretch;
}

.form-actions .ghost-button,
.form-actions .primary-button {
  min-height: 48px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 900;
  white-space: nowrap;
}

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

.line-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.line-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.loading-row {
  opacity: 0.72;
}

.line-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.line-extras {
  display: grid;
  grid-column: 1 / -1;
  gap: 6px;
  margin-top: 2px;
}

.line-extra {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
  width: 100%;
  max-width: 100%;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-strong);
}

.line-extra-value {
  display: grid;
  gap: 3px;
}

.line-extra span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.line-extra strong {
  overflow-x: auto;
  max-width: 100%;
  white-space: nowrap;
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 950;
  line-height: 1.15;
  scrollbar-width: thin;
}

.barcode-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.barcode-actions button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--panel-strong);
  font-size: 12px;
  font-weight: 900;
}

.quantity {
  display: grid;
  gap: 2px;
  min-width: 72px;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-strong);
  text-align: right;
  font-weight: 900;
}

.quantity strong,
.quantity span {
  display: block;
}

.quantity span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.quantity.short {
  background: var(--warn-bg);
  color: var(--warn);
}

.quantity.short span {
  color: var(--warn);
}

.notice {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #e5d4b9;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
  font-weight: 750;
}

.notice-ok {
  border-color: var(--success-line);
  background: var(--success-bg);
  color: var(--success);
}

.notice-error {
  border-color: #f3b5af;
  background: var(--danger-bg);
  color: var(--danger);
}

.notice-pending {
  border-color: var(--line);
  background: var(--soft);
  color: var(--muted);
}

.notice a {
  color: var(--ink);
  font-weight: 950;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
}

.modal-panel {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  margin-bottom: 8px;
  font-size: 24px;
}

.modal-text {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  font-weight: 800;
}

.modal-actions {
  display: grid;
  grid-template-columns: 0.7fr 1.3fr;
  gap: 10px;
  margin-top: 18px;
}

.primary-link-button {
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.modal-overlay.hidden {
  display: none;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(8px);
}

.login-panel {
  display: grid;
  gap: 12px;
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel input {
  min-height: 48px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
  font-size: 20px;
  font-weight: 850;
  letter-spacing: 0;
  text-align: center;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: #8f1d12;
  font-size: 13px;
  font-weight: 800;
}

.login-overlay.hidden {
  display: none;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .layout,
  .split,
  .production-form,
  .request-form {
    grid-template-columns: 1fr;
  }

  .plans-panel {
    min-height: unset;
  }

  .plans-panel.collapsed {
    min-height: unset;
  }

  .plans-panel.collapsed .panel-head {
    padding-bottom: 16px;
  }

  .detail-panel {
    padding: 14px;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .search-row button,
  .primary-button {
    width: 100%;
  }

  .request-comment-field {
    grid-column: auto;
  }

  .request-materials-preview {
    grid-column: auto;
  }

  .request-material {
    grid-template-columns: 1fr;
  }

  .request-material-quantity {
    min-width: 0;
    text-align: left;
  }

  .request-card {
    grid-template-columns: 1fr;
  }

  .request-actions {
    grid-template-columns: 1fr 1fr;
    min-width: 0;
  }

  .requests-pagination {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .requests-pagination span {
    text-align: center;
  }

  .form-actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .form-actions .ghost-button,
  .form-actions .primary-button {
    white-space: normal;
  }

  .line-item {
    grid-template-columns: 1fr;
  }

  .line-extra {
    padding: 10px;
  }

  .quantity {
    width: fit-content;
    justify-self: start;
    text-align: left;
  }

  .barcode-actions button {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .request-actions {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    padding: 18px;
  }
}
