:root {
  --bg: #eef3f8;
  --panel: #fff;
  --text: #071426;
  --muted: #5d6f88;
  --border: #cbd8e6;
  --green: #17a34a;
  --teal: #0f766e;
  --blue: #2563eb;
  --amber: #b45309;
  --slate: #475569;
  --red: #dc2626;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-weight: 650;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; border-radius: 8px; padding: 13px 22px; font-weight: 800; }
.hidden { display: none !important; }
.primary { background: var(--green); color: #fff; }
.teal { background: var(--teal); color: #fff; }
.blue { background: var(--blue); color: #fff; }
.amber { background: var(--amber); color: #fff; }
.slate { background: var(--slate); color: #fff; }
.danger { background: var(--red); color: #fff; }
.wide { width: 100%; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(520px, 100%);
  background: #fff;
  border: 1px solid #94a3b8;
  padding: 30px 34px;
}
.login-logo { display: block; width: 300px; max-width: 90%; margin: 0 auto 18px; }
.login-card h1 { text-align: center; margin: 6px 0 28px; font-size: 28px; }
label { display: block; margin: 12px 0; }
input, select, textarea {
  width: 100%;
  border: 1px solid transparent;
  background: #f6f8fb;
  padding: 12px;
  margin-top: 7px;
  min-height: 42px;
}
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--green);
}
textarea { resize: vertical; min-height: 64px; }
.check-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: auto;
  margin: 18px 0 6px;
  cursor: pointer;
}
.check-line span { line-height: 1; }
.fill-check {
  margin: 2px 0 14px;
  font-size: 16px;
}
.fill-check input {
  margin-top: 1px;
}
.status { text-align: center; color: var(--green); min-height: 48px; white-space: pre-line; }
.home-view {
  min-height: 100vh;
  background: var(--bg);
}
.home-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  min-height: 92px;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.home-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.home-brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}
.home-brand h1 {
  margin: 0 0 3px;
  font-size: 32px;
}
.home-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}
.home-account {
  display: flex;
  align-items: center;
  gap: 18px;
}
.module-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 58px 28px;
}
.module-shell h2 {
  margin-bottom: 22px;
  font-size: 29px;
}
.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(250px, 1fr));
  gap: 18px;
}
.module-card {
  height: 188px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 28px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.module-card:hover {
  border-color: #94a3b8;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .08);
}
.module-card strong {
  color: var(--text);
  font-size: 27px;
}
.module-card span {
  color: var(--muted);
  font-weight: 600;
}
.lactose-module { border-top: 5px solid var(--green); }
.laboratory-module { border-top: 5px solid var(--teal); }
.users-module { border-top: 5px solid var(--slate); }
.app {
  min-height: 100vh;
  overflow-x: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: 8px; }
.brand img { width: 52px; height: 52px; object-fit: contain; }
.brand h1 { font-size: 34px; margin: 0; white-space: nowrap; }
nav { display: flex; gap: 16px; }
.clock { margin-left: auto; font-size: 20px; white-space: nowrap; }
.shift-banner {
  width: calc(100% - 36px);
  margin: 14px 18px 0;
  background: #dc2626;
  color: #fff;
  animation: blink 1s infinite;
  font-size: 24px;
}
.shift-banner.saved { background: #16a34a; animation: none; }
@keyframes blink { 50% { opacity: .45; } }
.top-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  width: 100%;
  min-width: 0;
}
.top-grid > div { min-width: 0; }
h2 { margin: 0 0 12px; font-size: 24px; }
.process-tanks { display: grid; gap: 10px; }
.process-card, .empty-card, .tank-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}
.process-card {
  padding: 12px 14px;
  height: 164px;
  overflow: hidden;
}
.process-card h3, .empty-card h3, .tank-card h3 { text-align: center; margin: 0 0 10px; font-size: 19px; }
.process-card input {
  text-align: center;
  color: var(--green);
  font-size: 20px;
  min-height: 46px;
  padding: 8px;
  margin-top: 0;
}
.process-card textarea {
  height: 56px;
  min-height: 56px;
  padding: 7px 8px;
  margin-top: 8px;
  overflow: auto;
  resize: none;
}
.empty-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 152px);
  grid-auto-columns: 184px;
  gap: 12px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  touch-action: pan-x pan-y;
}
.empty-card {
  padding: 12px 16px;
  height: 140px;
  display: flex;
  flex-direction: column;
}
.tank-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 6px 0 12px;
  min-height: 30px;
}
.tank-icon {
  width: 34px;
  height: 34px;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}
.amount-badge { background: #22c55e; color: #04130a; padding: 8px 14px; font-weight: 900; }
.empty-card button {
  width: 100%;
  padding: 10px;
  margin-top: auto;
  line-height: 1.1;
}
.section { padding: 0 18px 18px; }
.product-header { display: flex; align-items: center; gap: 18px; margin: 14px 0 10px; }
.product-header h2 { margin: 0; }
.product-total { font-size: 20px; }
.tank-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 250px;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  touch-action: pan-x pan-y;
}
.tank-card {
  min-height: 420px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  border-width: 2px;
  scroll-snap-align: start;
}
.tank-card.lab-card { min-height: 340px; }
.tank-card.ready { animation: borderPulse 1s infinite; }
@keyframes borderPulse { 50% { box-shadow: 0 0 0 4px rgba(34, 197, 94, .18); } }
.product-name { text-align: center; color: var(--green); font-size: 18px; margin-bottom: 10px; }
.date-line { text-align: center; color: var(--muted); margin-bottom: 12px; }
.countdown { text-align: center; color: var(--green); font-size: 24px; line-height: 1.35; margin: 10px 0; animation: blink 1.2s infinite; }
.ready-label { text-align: center; background: #22c55e; padding: 7px; color: #020617; margin: 3px 0 8px; }
.small-text { color: var(--muted); font-size: 13px; margin: 8px 0; }
.folder-icon {
  display: block;
  width: 68px;
  height: 68px;
  object-fit: contain;
}
.folder-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 10px;
  min-height: 68px;
}
.folder-button {
  padding: 0;
  border: 0;
  background: transparent;
  flex: 0 0 auto;
}
.folder-button:disabled {
  cursor: default;
}
.folder-button:not(:disabled):hover .folder-icon {
  transform: translateY(-1px);
}
.lab-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.lab-status.waiting {
  color: #b45309;
}
.lab-status.complete {
  color: var(--green);
}
.lab-record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.lab-record-box {
  border: 1px solid var(--border);
  background: #f8fafc;
  padding: 18px;
}
.lab-record-box h2 {
  font-size: 21px;
}
.lab-record-box h2 small {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.lab-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 12px;
}
.lab-fields input[readonly] {
  color: var(--muted);
  background: #e8eef5;
}
.readonly-note {
  margin: -5px 0 18px;
  padding: 11px 14px;
  background: #eef3f8;
  border: 1px solid var(--border);
  color: var(--muted);
}
.card-actions { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; }
.card-actions button { padding: 9px 8px; }
.filling-card {
  align-items: center;
  justify-content: center;
  min-height: 310px;
  max-height: 310px;
}
.clock-icon { color: var(--green); font-size: 64px; margin: 18px 0 8px; }
.modal-root {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .18);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}
.modal {
  background: #fff;
  border: 1px solid var(--border);
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .25);
}
.modal.large { width: min(1420px, 98vw); }
.modal h2 { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; }
.tabs { display: flex; gap: 10px; margin: 12px 0 18px; }
.tabs button.active { background: var(--green); color: #fff; }
.report-filter { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.report-body {
  border: 1px solid var(--border);
  padding: 16px;
  max-height: 66vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.location-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.report-box { border: 1px solid var(--border); padding: 14px; background: #f8fafc; min-height: 180px; }
.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td { padding: 8px; text-align: left; border-bottom: 1px solid #dbe4ef; }
.ledger-sheet {
  max-width: 860px;
}
.ledger-product {
  margin-bottom: 20px;
}
.ledger-product h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.ledger-table {
  table-layout: fixed;
  min-width: 760px;
}
.ledger-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #94a3b8 #e2e8f0;
}
.ledger-tank-col { width: 25%; }
.ledger-amount-col { width: 13%; }
.ledger-date-col { width: 18%; }
.ledger-time-col { width: 12%; }
.ledger-status-col { width: 32%; }
.ledger-table td:first-child,
.ledger-table th:first-child {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ledger-table tfoot th {
  background: #e8eef5;
  border-top: 2px solid var(--border);
}
.ledger-ready {
  color: var(--green);
}
.ledger-table-wrap::-webkit-scrollbar {
  height: 14px;
}
.ledger-table-wrap::-webkit-scrollbar-track {
  background: #e2e8f0;
  border-radius: 999px;
}
.ledger-table-wrap::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border: 3px solid #e2e8f0;
  border-radius: 999px;
}
.crystal-form-section {
  border: 1px solid var(--border);
  background: #f8fafc;
  padding: 16px;
  margin-bottom: 16px;
}
.crystal-form-section h2 small {
  margin-left: 8px;
  color: var(--muted);
  font-size: 14px;
}
.crystal-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #94a3b8 #e2e8f0;
}
.crystal-table {
  border-collapse: collapse;
  min-width: 2520px;
  width: 100%;
  background: #fff;
}
.crystal-table th,
.crystal-table td {
  border: 1px solid #dbe4ef;
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}
.crystal-table th {
  background: #e8eef5;
  color: #334155;
}
.crystal-table .crystal-group th {
  background: #d9e4ef;
  color: var(--text);
  font-size: 16px;
  text-align: center;
}
.crystal-table .system-tank-heading,
.crystal-table .system-tank-value {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 160px;
  background: #eef3f8;
  font-weight: 800;
}
.crystal-table .system-tank-heading {
  z-index: 2;
}
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.settings-grid.single { grid-template-columns: minmax(420px, 760px); }
.muted { color: var(--muted); }
.empty-grid,
.tank-row,
.report-body,
.modal {
  scrollbar-color: #94a3b8 #e2e8f0;
  scrollbar-width: auto;
}
.empty-grid::-webkit-scrollbar,
.tank-row::-webkit-scrollbar {
  height: 18px;
}
.report-body::-webkit-scrollbar,
.modal::-webkit-scrollbar {
  width: 18px;
  height: 18px;
}
.crystal-table-wrap::-webkit-scrollbar {
  height: 18px;
}
.empty-grid::-webkit-scrollbar-track,
.tank-row::-webkit-scrollbar-track,
.report-body::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track {
  background: #e2e8f0;
  border-radius: 999px;
}
.crystal-table-wrap::-webkit-scrollbar-track {
  background: #e2e8f0;
  border-radius: 999px;
}
.empty-grid::-webkit-scrollbar-thumb,
.tank-row::-webkit-scrollbar-thumb,
.report-body::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border: 4px solid #e2e8f0;
  border-radius: 999px;
}
.crystal-table-wrap::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border: 4px solid #e2e8f0;
  border-radius: 999px;
}
@media print {
  @page { size: A4 portrait; margin: 14mm; }
  body * {
    visibility: hidden;
  }
  .modal-root.printing,
  .modal-root.printing * {
    visibility: visible;
  }
  .modal-root.printing {
    position: absolute;
    display: block;
    inset: 0;
    background: #fff;
    padding: 0;
  }
  .modal-root.printing .modal {
    width: 100%;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    border: 0;
    padding: 0;
  }
  .modal-root.printing .no-print {
    display: none !important;
  }
  .modal-root.printing .ledger-sheet {
    max-width: none;
  }
  .modal-root.printing .ledger-table {
    min-width: 0;
  }
}
@media (max-width: 900px) {
  .module-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .top-grid, .location-grid, .settings-grid { grid-template-columns: 1fr; }
  .brand h1 { font-size: 26px; }
  nav { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  .topbar {
    gap: 10px;
    padding: 10px;
  }
  .brand {
    width: 100%;
    gap: 8px;
  }
  .brand img {
    width: 44px;
    height: 44px;
  }
  .brand h1 {
    font-size: 24px;
    white-space: normal;
  }
  nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .ledger-table {
    font-size: 13px;
  }
  nav button,
  #settingsOpen {
    padding: 11px 8px;
  }
  .clock {
    margin-left: 0;
    font-size: 16px;
  }
  .top-grid,
  .section {
    padding-left: 12px;
    padding-right: 12px;
  }
  .empty-grid {
    grid-template-rows: repeat(2, 152px);
    grid-auto-columns: minmax(158px, 46vw);
    padding-bottom: 24px;
    margin-bottom: 6px;
  }
  .tank-row {
    grid-auto-columns: calc(100vw - 36px);
    gap: 14px;
    padding: 0 4px 24px 0;
    margin-bottom: 10px;
  }
  .tank-card {
    width: calc(100vw - 36px);
    min-height: 0;
  }
  .card-actions {
    gap: 8px;
  }
  .card-actions button {
    padding: 12px 6px;
    min-width: 0;
  }
  .modal-root {
    align-items: start;
    padding: 10px;
  }
  .modal {
    width: 100%;
    max-height: 94vh;
    padding: 18px;
  }
  .form-row,
  .location-grid,
  .lab-record-grid,
  .lab-fields {
    grid-template-columns: 1fr;
  }
}
  .home-header {
    padding: 12px;
    display: block;
  }
  .home-brand img {
    width: 46px;
    height: 46px;
  }
  .home-brand h1 {
    font-size: 23px;
  }
  .home-account {
    margin-top: 16px;
    justify-content: space-between;
  }
  .module-shell {
    padding: 30px 12px;
  }
  .module-card {
    height: 144px;
    padding: 20px;
  }
  .module-card strong {
    font-size: 24px;
  }
