:root {
  --bg-0: #02060f;
  --bg-1: #07142c;
  --surface: #081226;
  --surface-2: #0c1b36;
  --surface-3: #102446;
  --line: rgba(56, 176, 255, .28);
  --line-soft: rgba(56, 176, 255, .14);
  --text: #eaf2fb;
  --muted: #8fa6c2;
  --faint: #5d7595;
  --cyan: #34d7ff;
  --cyan-strong: #12bce9;
  --green: #2fd968;
  --yellow: #f8c84e;
  --red: #ff6868;
  --radius: 16px;
  --shadow: 0 22px 60px rgba(0, 0, 0, .38);
  --font: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg-0); }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 580px at 92% -10%, rgba(18, 73, 150, .38), transparent 62%),
    radial-gradient(600px 420px at -10% 100%, rgba(0, 125, 178, .18), transparent 65%),
    var(--bg-0);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a, select, input, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.cyan { color: var(--cyan); }
.green { color: var(--green); }
.yellow { color: var(--yellow); }
.red { color: var(--red); }
.mono { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 3px solid rgba(52, 215, 255, .45);
  outline-offset: 2px;
}

.login-page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(380px, .9fr);
}

.login-showcase {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: clamp(28px, 5vw, 72px);
  border-right: 1px solid var(--line-soft);
  background:
    radial-gradient(circle at 26% 28%, rgba(52, 215, 255, .19), transparent 26%),
    linear-gradient(145deg, rgba(10, 34, 76, .8), rgba(2, 6, 15, .92));
}

.login-showcase::before {
  position: absolute;
  width: 520px;
  height: 520px;
  right: -180px;
  bottom: -180px;
  border: 1px solid rgba(52, 215, 255, .2);
  border-radius: 50%;
  box-shadow:
    0 0 0 70px rgba(52, 215, 255, .025),
    0 0 0 140px rgba(52, 215, 255, .018);
  content: "";
}

.showcase-brand { width: min(250px, 65%); position: relative; }
.showcase-copy { position: relative; max-width: 620px; }
.showcase-copy h1 {
  max-width: 680px;
  margin: 0 0 18px;
  font-size: clamp(36px, 5vw, 68px);
  line-height: 1.02;
  letter-spacing: -.04em;
}
.showcase-copy p {
  max-width: 580px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.6;
}
.showcase-points {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 34px;
}
.showcase-points span {
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: #bad0e7;
  background: rgba(7, 19, 42, .62);
  font-size: 13px;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 28px;
}
.login-card {
  width: min(430px, 100%);
  padding: clamp(24px, 4vw, 38px);
  border: 1px solid var(--line-soft);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(12, 27, 54, .95), rgba(7, 18, 38, .96));
  box-shadow: var(--shadow);
}
.login-card .symbol {
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
}
.login-card h2 { margin: 0 0 8px; font-size: 28px; letter-spacing: -.02em; }
.login-card > p { margin: 0 0 26px; color: var(--muted); line-height: 1.5; }
.demo-note {
  margin-top: 18px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(52, 215, 255, .04);
  font-size: 13px;
  line-height: 1.5;
}

.field { display: grid; gap: 7px; margin-bottom: 15px; min-width: 0; }
.field label, .field-label {
  color: #b8cae0;
  font-size: 13px;
  font-weight: 650;
}
.field input, .field select, .field textarea, .control {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: rgba(4, 14, 32, .72);
  padding: 10px 12px;
}
.field textarea { min-height: 92px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.field input:disabled, .field select:disabled { opacity: .6; cursor: not-allowed; }
.field-error { min-height: 18px; margin: -5px 0 8px; color: var(--red); font-size: 13px; }

.btn {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 15px;
  color: var(--cyan);
  background: rgba(12, 30, 58, .74);
  font-weight: 700;
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.btn:hover { border-color: rgba(52, 215, 255, .55); background: rgba(17, 45, 82, .82); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-primary {
  border-color: transparent;
  color: #eafff1;
  background: linear-gradient(180deg, #23b954, #13853a);
  box-shadow: 0 0 16px rgba(47, 217, 104, .25);
}
.btn-primary:hover { border-color: transparent; background: linear-gradient(180deg, #2ac860, #159344); }
.btn-danger { border-color: rgba(255, 104, 104, .42); color: var(--red); background: rgba(255, 104, 104, .06); }
.btn-quiet { border-color: transparent; color: var(--muted); background: transparent; }
.btn-sm { min-height: 34px; padding: 6px 11px; font-size: 13px; }

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

.sidebar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  border-right: 1px solid var(--line-soft);
  background: rgba(6, 16, 35, .96);
  padding: 20px 14px;
}
.side-logo { width: 190px; margin: 2px auto 24px; }
.side-context {
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  background: rgba(12, 30, 58, .44);
}
.side-context .field { margin-bottom: 10px; }
.side-context .field:last-child { margin-bottom: 0; }
.side-context select { min-height: 38px; padding: 7px 9px; font-size: 13px; }
.nav { display: grid; gap: 5px; }
.nav a {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 11px;
  border-radius: 10px;
  padding: 10px 13px;
  color: #92b7e2;
  font-weight: 680;
  text-decoration: none;
}
.nav a:hover { color: var(--text); background: rgba(20, 50, 90, .4); }
.nav a.active {
  color: var(--cyan);
  background: linear-gradient(90deg, rgba(20, 60, 110, .72), rgba(20, 60, 110, .18));
}
.nav-icon { width: 21px; color: currentColor; text-align: center; }
.sidebar-footer {
  margin-top: 24px;
  padding: 13px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
}
.user-name { display: block; margin-bottom: 3px; color: var(--text); font-weight: 700; }
.sidebar-footer .btn { margin-top: 12px; }

.main { min-width: 0; }
.topbar {
  position: sticky;
  z-index: 15;
  top: 0;
  display: flex;
  min-height: 68px;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(2, 8, 20, .86);
  backdrop-filter: blur(12px);
  padding: 10px clamp(16px, 3vw, 34px);
}
.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cyan);
  background: rgba(12, 30, 58, .6);
  font-size: 21px;
}
.topbar-info { min-width: 0; flex: 1; }
.crumb { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.controller-title { overflow: hidden; margin-top: 2px; font-weight: 760; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.status-pill, .tag {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  background: rgba(8, 24, 47, .7);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.status-pill::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  content: "";
}
.status-pill.online { border-color: rgba(47, 217, 104, .35); color: var(--green); }
.status-pill.online::before { background: var(--green); box-shadow: 0 0 9px rgba(47, 217, 104, .65); }
.status-pill.offline { border-color: rgba(255, 104, 104, .35); color: var(--red); }
.status-pill.offline::before { background: var(--red); }
.tag { min-height: 24px; padding: 3px 8px; }
.tag.green { border-color: rgba(47, 217, 104, .35); color: var(--green); }
.tag.yellow { border-color: rgba(248, 200, 78, .38); color: var(--yellow); }
.tag.red { border-color: rgba(255, 104, 104, .38); color: var(--red); }
.tag.cyan { border-color: rgba(52, 215, 255, .38); color: var(--cyan); }

.content {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px);
}
.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0 0 5px; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.03em; }
.page-head p { margin: 0; color: var(--muted); line-height: 1.5; }
.page-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; }

.grid { display: grid; gap: 14px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1.5fr) minmax(280px, .8fr); }
.card {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 33, 62, .75), rgba(9, 22, 46, .78));
  box-shadow: 0 12px 35px rgba(0, 0, 0, .12);
  padding: 17px;
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title h2, .card-title h3 { margin: 0; font-size: 15px; color: var(--cyan); text-transform: uppercase; letter-spacing: .03em; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { margin-top: 7px; font-size: clamp(21px, 3vw, 28px); font-weight: 800; letter-spacing: -.025em; }
.stat-detail { margin-top: 5px; color: var(--faint); font-size: 12px; }

.machine-state {
  display: flex;
  min-height: 124px;
  align-items: center;
  gap: 18px;
}
.machine-mark {
  position: relative;
  display: grid;
  width: 82px;
  height: 82px;
  flex: none;
  place-items: center;
  border: 2px solid rgba(52, 215, 255, .4);
  border-radius: 50%;
  background: rgba(52, 215, 255, .05);
}
.machine-mark img { width: 58px; height: 58px; object-fit: contain; }
.machine-mark.active { border-color: var(--green); box-shadow: 0 0 22px rgba(47, 217, 104, .18); }
.machine-state h2 { margin: 0 0 5px; font-size: 25px; }
.machine-state p { margin: 0; color: var(--muted); }

.progress-native {
  width: 100%;
  height: 8px;
  overflow: hidden;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: rgba(45, 75, 110, .5);
}
.progress-native::-webkit-progress-bar { border-radius: 999px; background: rgba(45, 75, 110, .5); }
.progress-native::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan-strong), var(--green));
}
.progress-native::-moz-progress-bar { border-radius: 999px; background: linear-gradient(90deg, var(--cyan-strong), var(--green)); }

.list { display: grid; gap: 9px; }
.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}
.list-row:last-child { border-bottom: 0; }
.list-row b { display: block; overflow-wrap: anywhere; }
.list-row small { display: block; margin-top: 3px; color: var(--muted); }

.io-grid { display: grid; grid-template-columns: repeat(8, minmax(34px, 1fr)); gap: 6px; }
.io-pill {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px 3px;
  color: var(--faint);
  text-align: center;
  font-size: 12px;
}
.io-pill.on { border-color: rgba(47, 217, 104, .55); color: #eafff1; background: rgba(47, 217, 104, .13); }

.section-gap { margin-top: 14px; }
.sync-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.sync-versions { display: flex; flex-wrap: wrap; gap: 20px; }
.sync-versions span { display: block; color: var(--muted); font-size: 12px; }
.sync-versions b { display: block; margin-top: 3px; font-size: 18px; }
.notice {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: #b9d9ef;
  background: rgba(52, 215, 255, .055);
  line-height: 1.5;
  font-size: 13px;
}
.notice.warning { border-color: rgba(248, 200, 78, .32); color: #efdda7; background: rgba(248, 200, 78, .055); }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.products-editor { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.product-editor {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(3, 13, 31, .45);
  padding: 13px;
}
.product-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}
.product-editor-head b { overflow-wrap: anywhere; }
.product-fields { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(90px, .6fr)); gap: 9px; }
.product-fields .field { margin: 0; }

.toggle {
  position: relative;
  display: inline-flex;
  width: 46px;
  height: 26px;
  flex: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  width: 100%;
  height: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(40, 60, 90, .45);
}
.toggle span::after {
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #6b7e98;
  content: "";
  transition: transform .16s ease, background .16s ease;
}
.toggle input:checked + span { border-color: rgba(47, 217, 104, .5); background: rgba(47, 217, 104, .12); }
.toggle input:checked + span::after { background: var(--green); transform: translateX(20px); }

.table-wrap { max-width: 100%; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th {
  padding: 10px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: .04em;
  text-align: left;
  text-transform: uppercase;
}
.data-table td {
  padding: 12px 10px;
  border-top: 1px solid var(--line-soft);
  color: #c7d7e9;
  font-size: 13px;
  overflow-wrap: anywhere;
  vertical-align: top;
}
.data-table td b { color: var(--text); }
.audit-detail { color: var(--muted); line-height: 1.45; }
.filters { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; margin-bottom: 14px; }
.filters .field { margin: 0; }

.empty {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 30px;
}
.loading {
  display: flex;
  min-height: 220px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.spinner {
  width: 26px;
  height: 26px;
  margin-right: 12px;
  border: 3px solid rgba(52, 215, 255, .16);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 28px);
  padding: 12px 18px;
  border: 1px solid rgba(47, 217, 104, .42);
  border-radius: 12px;
  color: #eafff1;
  background: linear-gradient(180deg, #123a22, #0c2a18);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 130%);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 104, 104, .5); background: linear-gradient(180deg, #3a1212, #2a0c0c); }

.modal-backdrop {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 4, 12, .74);
  backdrop-filter: blur(7px);
}
.modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h2 { margin: 0 0 9px; }
.modal p { margin: 0 0 16px; color: var(--muted); line-height: 1.55; }
.modal-actions { display: flex; justify-content: end; gap: 8px; margin-top: 18px; }

.drawer-backdrop { display: none; }

@media (max-width: 1120px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .product-fields { grid-template-columns: minmax(0, 1fr) repeat(2, minmax(78px, .55fr)); }
}

@media (max-width: 860px) {
  .login-page { grid-template-columns: 1fr; }
  .login-showcase { display: none; }
  .login-panel { min-height: 100dvh; }

  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(310px, 87vw);
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-backdrop {
    position: fixed;
    z-index: 19;
    inset: 0;
    background: rgba(0, 4, 12, .62);
  }
  .drawer-backdrop.open { display: block; }
  .menu-button { display: inline-grid; place-items: center; flex: none; }
  .products-editor { grid-template-columns: 1fr; }
}

@media (max-width: 660px) {
  .topbar { min-height: 60px; padding: 8px 12px; }
  .top-actions .role-pill { display: none; }
  .content { padding: 16px 12px 28px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions { justify-content: stretch; }
  .page-actions .btn { flex: 1; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .card { padding: 14px; border-radius: 13px; }
  .stat-value { font-size: 20px; }
  .machine-state { min-height: 106px; }
  .machine-mark { width: 68px; height: 68px; }
  .machine-mark img { width: 48px; height: 48px; }
  .io-grid { grid-template-columns: repeat(4, minmax(34px, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .product-fields { grid-template-columns: 1fr 1fr; }
  .product-fields .field:first-child { grid-column: 1 / -1; }
  .sync-card { align-items: stretch; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .filters .btn { width: 100%; }

  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tr {
    margin-bottom: 10px;
    border: 1px solid var(--line-soft);
    border-radius: 11px;
    background: rgba(3, 13, 31, .38);
    padding: 9px;
  }
  .data-table td {
    display: grid;
    grid-template-columns: minmax(92px, .45fr) minmax(0, 1fr);
    gap: 10px;
    border: 0;
    padding: 6px;
  }
  .data-table td::before {
    color: var(--faint);
    content: attr(data-label);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

@media (max-width: 390px) {
  .stats-grid { grid-template-columns: 1fr; }
  .machine-state { align-items: flex-start; }
  .status-pill { padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
