:root {
  --ink: #172326;
  --muted: #667477;
  --line: #d9e2df;
  --panel: #ffffff;
  --page: #eef3f1;
  --green: #18634f;
  --green-2: #0f4b3d;
  --gold: #c7922f;
  --red: #b64b3c;
  --blue: #335c81;
  --shadow: 0 16px 40px rgba(22, 35, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

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

.hidden {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  padding: 28px;
  background: #e5ece9;
}

.login-card {
  width: min(760px, 100%);
  padding: 34px 34px 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-brand {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 12px;
  margin-bottom: 26px;
}

.login-brand img {
  width: min(312px, 86%);
  max-height: 124px;
  object-fit: contain;
}

.login-brand h1 {
  margin: 0;
  color: #244146;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-brand h1::after {
  content: "";
  display: block;
  width: 86px;
  height: 3px;
  margin: 12px auto 0;
  border-radius: 999px;
  background: var(--green);
}

.login-footer {
  align-self: end;
  padding-top: 18px;
  text-align: center;
}

.powered-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}

.powered-link img {
  width: 58px;
  max-height: 20px;
  object-fit: contain;
  opacity: 0.78;
}

.powered-link:hover {
  color: var(--green-2);
}

.powered-link:hover img {
  opacity: 1;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  max-width: 420px;
  margin: 0 auto;
}

.form-error {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.quick-logins {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 420px;
  margin: 18px auto 0;
  justify-content: center;
}

.quick-logins button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #cbd9d5;
  border-radius: 999px;
  color: var(--green-2);
  background: #f7faf9;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding: 24px;
  color: #ffffff;
  background: #173238;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
}

.brand img {
  width: 88px;
  max-height: 42px;
  object-fit: contain;
  padding: 6px;
  background: #ffffff;
  border-radius: 6px;
}

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

.brand strong {
  font-size: 17px;
}

.brand span {
  margin-top: 3px;
  color: #d8e2df;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #eaf1ee;
  background: transparent;
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
}

.nav-icon {
  display: inline-grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 16px;
}

.session-box {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.session-role {
  color: #bad2ca;
  font-size: 12px;
  text-transform: uppercase;
}

.session-user {
  margin: 4px 0 12px;
  font-weight: 700;
}

.main {
  grid-column: 2;
  min-width: 0;
  padding: 28px;
}

.app-footer {
  grid-column: 2;
  padding: 0 28px 18px;
  text-align: right;
}

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

.topbar h1 {
  margin: 3px 0 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.1;
  letter-spacing: 0;
}

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

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

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.scan-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #0f4b3d;
  border-radius: 6px;
  color: #ffffff;
  background: var(--green);
  font-weight: 800;
}

.scan-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 74px;
  margin-bottom: 18px;
  border: 2px solid #0f4b3d;
  border-radius: 8px;
  color: #ffffff;
  background: #173238;
  box-shadow: var(--shadow);
}

.scan-hero span {
  font-size: 28px;
}

.scan-hero strong {
  font-size: 18px;
}

.primary-button {
  padding: 0 16px;
  color: #ffffff;
  background: var(--green);
}

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

.secondary-button {
  padding: 0 14px;
  color: var(--green-2);
  border-color: #bdd3ce;
  background: #f7faf9;
}

.ghost-button {
  width: 100%;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.22);
  background: transparent;
}

.icon-button {
  width: 44px;
  padding: 0;
  color: var(--green-2);
  border-color: #bdd3ce;
  background: #ffffff;
  font-size: 18px;
}

.link-button {
  width: fit-content;
  min-height: 30px;
  margin: -4px auto 0;
  padding: 0;
  border: 0;
  color: var(--green-2);
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
}

.modal {
  width: min(520px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(23, 50, 56, 0.36);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 22px;
}

.contact-box {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf9;
}

.contact-box span {
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  min-height: 104px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(22, 35, 38, 0.06);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 14px;
  font-size: 34px;
  line-height: 1;
}

.metric.warn strong {
  color: var(--gold);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
  gap: 18px;
}

.line-layout {
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel.wide {
  min-height: 320px;
}

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

.panel-header h2 {
  margin: 3px 0 0;
  font-size: 21px;
  letter-spacing: 0;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid #e5ece9;
  border-radius: 6px;
  background: #fbfdfc;
}

.timeline-date {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.timeline-title {
  margin: 0 0 4px;
  font-weight: 700;
}

.timeline-text {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.timeline-meta {
  margin: 6px 0 0;
  color: #405256;
  font-size: 12px;
  font-weight: 700;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--green-2);
  background: #e5f1ed;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.hse {
  color: #ffffff;
  background: var(--red);
}

.badge.order {
  color: #2f2712;
  background: #f4ddaa;
}

.active-status {
  color: #ffffff;
  background: var(--green);
}

.qr-demo {
  display: grid;
  grid-template-columns: repeat(5, 28px);
  grid-template-rows: repeat(5, 28px);
  gap: 5px;
  width: max-content;
  margin: 8px auto 16px;
  padding: 14px;
  border: 8px solid #ffffff;
  outline: 1px solid var(--line);
  background: #ffffff;
}

.qr-demo span {
  background: #14272b;
}

.qr-demo span:nth-child(2),
.qr-demo span:nth-child(8),
.qr-demo span:nth-child(11),
.qr-demo span:nth-child(14),
.qr-demo span:nth-child(18),
.qr-demo span:nth-child(21),
.qr-demo span:nth-child(24) {
  background: #ffffff;
}

.qr-caption {
  display: grid;
  gap: 4px;
  text-align: center;
}

.qr-caption span {
  color: var(--muted);
  font-size: 13px;
}

.equipment-list,
.document-list,
.line-list {
  display: grid;
  gap: 10px;
}

.equipment-item,
.document-item,
.line-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid #e5ece9;
  border-radius: 6px;
  background: #fbfdfc;
}

.equipment-item {
  cursor: pointer;
}

.equipment-item:hover {
  border-color: #bdd3ce;
  background: #f4faf7;
}

.equipment-item strong,
.document-item strong {
  display: block;
  margin-bottom: 4px;
}

.equipment-item span,
.document-item span {
  color: var(--muted);
  font-size: 13px;
}

.line-title {
  margin: 16px 0 8px;
  color: var(--green-2);
  font-size: 15px;
  font-weight: 800;
}

.machine-detail {
  display: grid;
  gap: 12px;
}

.machine-detail img {
  width: 160px;
  height: 160px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.machine-parts {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
}

.machine-parts div {
  padding: 10px;
  border: 1px solid #e5ece9;
  border-radius: 6px;
  background: #fbfdfc;
  font-size: 13px;
}

.scan-modal video {
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  background: #111;
}

.scan-help {
  color: var(--muted);
  font-size: 13px;
}

.form-panel {
  max-width: 980px;
}

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

label {
  display: grid;
  gap: 7px;
  color: #314246;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd9d5;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

input,
select {
  min-height: 42px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

.full-field {
  margin-top: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-weight: 400;
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.search-input {
  max-width: 280px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid #e5ece9;
  text-align: left;
  vertical-align: top;
}

th {
  color: #314246;
  background: #f2f7f5;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

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

.admin-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5ece9;
}

.admin-list span {
  color: var(--muted);
}

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

.role-grid div {
  min-height: 94px;
  padding: 14px;
  border: 1px solid #e5ece9;
  border-radius: 6px;
  background: #fbfdfc;
}

.role-grid strong,
.role-grid span {
  display: block;
}

.role-grid span {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #173238;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .login-brand {
    justify-items: center;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    inset: auto;
    width: auto;
    height: auto;
    max-height: none;
    overflow: visible;
    top: 0;
    z-index: 10;
    padding: 14px;
  }

  .brand {
    min-height: 44px;
  }

  .brand img {
    width: 72px;
  }

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-tab {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 52px;
    padding: 6px;
    text-align: center;
    font-size: 11px;
  }

  .session-box {
    display: none;
  }

  .main {
    grid-column: 1;
    padding: 18px;
  }

  .app-footer {
    grid-column: 1;
    padding: 0 18px 18px;
    text-align: center;
  }

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

  .metrics-grid,
  .content-grid,
  .form-grid,
  .role-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .nav-tab span:last-child {
    display: none;
  }

  .topbar-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  .panel {
    padding: 15px;
  }
}
