:root {
  --navy: #1e3a5f;
  --navy-dark: #16243f;
  --blue: #2563eb;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --sidebar-w: 260px;
  --sidebar-w-mini: 72px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  overflow-x: hidden;
}

body.sidebar-open {
  overflow: hidden;
}

img, canvas, svg { max-width: 100%; height: auto; }

/* Login — 3D scene */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #1e4a8a 0%, var(--navy-dark) 45%, #0c1222 100%);
  padding: 20px;
  position: relative;
  overflow: hidden;
  perspective: 1200px;
}

.login-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.scene-3d {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  perspective: 900px;
}

.grid-floor {
  position: absolute;
  left: -20%;
  right: -20%;
  bottom: -30%;
  height: 70%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: rotateX(72deg) translateZ(-80px);
  transform-origin: center bottom;
  opacity: 0.55;
  animation: gridPulse 8s ease-in-out infinite;
}

.shape-3d {
  position: absolute;
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
  transform-style: preserve-3d;
}

.shape-a {
  width: 120px;
  height: 120px;
  top: 12%;
  left: 8%;
  animation: float3dA 22s ease-in-out infinite;
}

.shape-b {
  width: 90px;
  height: 90px;
  top: 20%;
  right: 10%;
  border-radius: 50%;
  animation: float3dB 18s ease-in-out infinite;
}

.shape-c {
  width: 160px;
  height: 70px;
  bottom: 22%;
  left: 12%;
  animation: float3dC 26s ease-in-out infinite;
}

.shape-d {
  width: 70px;
  height: 140px;
  bottom: 18%;
  right: 15%;
  animation: float3dD 20s ease-in-out infinite;
}

@keyframes float3dA {
  0%, 100% { transform: translate3d(0, 0, 40px) rotateX(25deg) rotateY(-35deg); }
  50% { transform: translate3d(30px, -25px, 80px) rotateX(35deg) rotateY(15deg); }
}

@keyframes float3dB {
  0%, 100% { transform: translate3d(0, 0, 60px) rotateY(0deg); }
  50% { transform: translate3d(-20px, 20px, 100px) rotateY(180deg); }
}

@keyframes float3dC {
  0%, 100% { transform: translate3d(0, 0, 20px) rotateX(45deg) rotateZ(0deg); }
  50% { transform: translate3d(40px, -15px, 50px) rotateX(55deg) rotateZ(8deg); }
}

@keyframes float3dD {
  0%, 100% { transform: translate3d(0, 0, 30px) rotateY(25deg); }
  50% { transform: translate3d(-25px, -30px, 70px) rotateY(-25deg); }
}

@keyframes gridPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.7; }
}

.login-card {
  background: rgba(255, 255, 255, 0.97);
  border-radius: 20px;
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow:
    0 32px 64px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.15);
  position: relative;
  z-index: 2;
  backdrop-filter: blur(12px);
}

.login-card .logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--blue), var(--navy));
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 12px 28px rgba(37, 99, 235, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: perspective(400px) rotateX(8deg) rotateY(-12deg);
  animation: logoFloat 4s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: perspective(400px) rotateX(8deg) rotateY(-12deg) translateY(0); }
  50% { transform: perspective(400px) rotateX(12deg) rotateY(8deg) translateY(-6px); }
}

.login-card .logo h1 {
  font-size: 22px;
  color: var(--navy);
}

.login-card .logo p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.login-card .tagline {
  font-style: italic;
  font-size: 12px;
  color: var(--blue);
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--navy);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  background: #fff;
  min-height: 44px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
  border-color: var(--red);
  background: #fffafb;
}

.form-group.has-error input:focus,
.form-group.has-error select:focus,
.form-group.has-error textarea:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.field-error {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--red);
  font-weight: 500;
}

.form-validation-summary {
  margin-bottom: 16px;
}

.form-validation-summary.is-visible {
  display: block !important;
}

#production-form.shake {
  animation: formShake 0.45s ease;
}

@keyframes formShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-height: 44px;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--blue), #1d4ed8);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  background: #e2e8f0;
  color: var(--ink);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

.demo-roles {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.demo-roles p {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.demo-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.demo-btns .btn { flex: 1; min-width: 100px; font-size: 12px; padding: 8px; }

.brand-badge {
  display: inline-block;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
  color: var(--navy);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border: 1px solid #93c5fd;
}

.login-footer-note {
  margin-top: 16px;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  line-height: 1.5;
}

/* ─── Animations & 3D UI ─── */
.card-3d {
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.4s ease;
  transform-style: preserve-3d;
  will-change: transform;
}

.card-3d:hover {
  transform: translateY(-5px) rotateX(1.5deg) rotateY(-1.5deg);
  box-shadow: 0 20px 48px rgba(30, 58, 95, 0.14);
}

.float-in {
  animation: floatIn 0.85s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.fade-up {
  animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }

.kpi-enter {
  animation: kpiIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

@keyframes floatIn {
  from { opacity: 0; transform: translateY(28px) scale(0.96) rotateX(8deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotateX(0); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes kpiIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.view { display: none; }

.view.active {
  display: block;
  animation: viewIn 0.42s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.btn-glow {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.45);
  transition: transform 0.2s, box-shadow 0.3s, opacity 0.2s;
}

.btn-glow:hover {
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.55);
  transform: translateY(-1px);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
}

.topbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.sidebar {
  background: linear-gradient(180deg, #1a2f4d 0%, var(--navy-dark) 100%);
}

.nav-item {
  transition: background 0.2s, transform 0.2s, color 0.2s;
}

.nav-item:hover {
  transform: translateX(3px);
}

.nav-item.active {
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.machine-card {
  transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.35s;
}

.machine-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 28px rgba(30, 58, 95, 0.12);
}

.focus-box {
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 50%, #2d4a7c 100%);
  box-shadow: 0 16px 40px rgba(22, 36, 63, 0.35);
  transform: perspective(800px) rotateX(1deg);
}

.alert {
  animation: fadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.toast {
  animation: toastIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.show {
  animation: toastIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

  .card-3d:hover,
  .machine-card:hover {
    transform: none;
  }
}

/* App shell */
.app-shell { display: none; min-height: 100vh; }

.app-shell.active {
  display: flex;
  animation: appIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes appIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sidebar {
  width: var(--sidebar-w);
  max-width: 85vw;
  background: var(--navy-dark);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 200;
  transition: transform 0.28s ease, width 0.28s ease;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 150;
  opacity: 0;
  transition: opacity 0.28s ease;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

.sidebar-header {
  flex-shrink: 0;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 { font-size: 16px; font-weight: 700; }

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-logo-img, .brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-brand-text { min-width: 0; }

.sidebar-header small {
  display: block;
  font-size: 11px;
  opacity: 0.7;
  margin-top: 2px;
}

.nav-menu {
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.nav-menu::-webkit-scrollbar {
  width: 5px;
}

.nav-menu::-webkit-scrollbar-track {
  background: transparent;
}

.nav-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.nav-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.nav-item.active {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

.nav-item .icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }

.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sidebar states */
body.sidebar-mini .sidebar { width: var(--sidebar-w-mini); }
body.sidebar-mini .main-content {
  margin-left: var(--sidebar-w-mini);
  width: calc(100% - var(--sidebar-w-mini));
}
body.sidebar-mini .nav-label,
body.sidebar-mini .nav-section-label,
body.sidebar-mini .sidebar-brand-text,
body.sidebar-mini .sidebar-footer .user-chip > div:last-child,
body.sidebar-mini .sidebar-footer .btn { display: none; }
body.sidebar-mini .sidebar-header { padding: 16px 10px; }
body.sidebar-mini .sidebar-brand-row { justify-content: center; }
body.sidebar-mini .nav-item { justify-content: center; padding: 12px 8px; }
body.sidebar-mini .user-chip { justify-content: center; }
body.sidebar-mini .sidebar-footer { padding: 10px 8px; }

body.sidebar-hidden .sidebar { transform: translateX(-100%) !important; }
body.sidebar-hidden .main-content { margin-left: 0; width: 100%; }
body.sidebar-hidden .sidebar-float-open { display: flex; }

.sidebar-float-open {
  display: none;
  position: fixed;
  left: 12px;
  bottom: 24px;
  z-index: 210;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: none;
  background: var(--navy);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  align-items: center;
  justify-content: center;
}

.sidebar-float-open:hover { background: var(--blue); }

.nav-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.45;
  padding: 10px 14px 4px;
}

.nav-section-label:first-child {
  padding-top: 4px;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.user-chip .name { font-size: 13px; font-weight: 600; }

.user-chip .role {
  font-size: 11px;
  opacity: 0.65;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  min-height: 100dvh;
  width: calc(100% - var(--sidebar-w));
  max-width: 100%;
  transition: margin-left 0.28s ease, width 0.28s ease;
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar h1 {
  font-size: 18px;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-date {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 22px;
  cursor: pointer;
  color: var(--navy);
  flex-shrink: 0;
}

.page-content {
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

.view-intro {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.6;
}

/* Cards & KPIs */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }

.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.grid-charts { margin-top: 16px; }

.kpi .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.kpi .val {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
}

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

.val-green { color: var(--green); }
.val-amber { color: var(--amber); }
.val-red { color: var(--red); }
.val-blue { color: var(--blue); }

.section-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--navy);
  border-left: 4px solid var(--blue);
  padding-left: 10px;
  margin: 28px 0 14px;
}

.section-title:first-child { margin-top: 0; }

/* Pills & badges */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.pill-green { background: #dcfce7; color: #166534; }
.pill-amber { background: #fef3c7; color: #92400e; }
.pill-red { background: #fee2e2; color: #b91c1c; }
.pill-blue { background: #dbeafe; color: #1d4ed8; }
.pill-gray { background: #f1f5f9; color: #475569; }

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table-scroll-hint {
  display: none;
  font-size: 11px;
  color: var(--muted);
  padding: 0 0 8px;
  text-align: center;
}

.table-wrap table,
.table-wrap > table {
  width: 100%;
  min-width: 560px;
}

.table-wrap.table-wide > table { min-width: 900px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: var(--navy);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

tr:hover td { background: #f8fafc; }

/* Progress bar */
.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  min-width: 80px;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

/* Charts */
.chart-box {
  position: relative;
  height: clamp(200px, 40vw, 280px);
  width: 100%;
}

.chart-card h3 {
  font-size: 14px;
  color: var(--navy);
  margin-bottom: 12px;
}

/* Alerts */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-warning {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.alert-danger {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #7f1d1d;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
}

/* Machine grid (Welding) */
.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: 12px;
}

.machine-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}

.machine-card .mc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.machine-card .mc-code {
  font-weight: 700;
  font-size: 15px;
  color: var(--navy);
}

.machine-card .mc-body { font-size: 12px; color: var(--muted); }

.machine-card .mc-body strong { color: var(--ink); display: block; margin-top: 6px; }

.machine-card.critical { border-left: 4px solid var(--red); }
.machine-card.behind { border-left: 4px solid var(--amber); }
.machine-card.good { border-left: 4px solid var(--green); }

.records-meta { margin-bottom: 14px; }

/* Filters bar */
.filters-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  gap: 12px;
  margin-bottom: 16px;
  align-items: end;
}

.filters-bar .form-group { margin-bottom: 0; }

.filters-bar .btn { width: 100%; }

/* Form card */
.form-card { max-width: 900px; width: 100%; }

.form-card-title {
  font-size: 16px;
  color: var(--navy);
  margin-bottom: 8px;
}

.form-actions {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.form-actions .btn-primary { width: auto; padding: 12px 28px; flex: 1; min-width: 140px; }
.form-actions .btn-secondary { flex: 1; min-width: 100px; }

.calc-preview {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.calc-preview .calc-item label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.calc-preview .calc-item .num {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
}

.tab-btn.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

/* Master data */
.master-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 14px;
}

.master-card h4 {
  font-size: 14px;
  color: var(--navy);
  margin-bottom: 10px;
}

.master-card ul {
  list-style: none;
  font-size: 13px;
}

.master-card li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
}

/* Admin panels */
.admin-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.master-tabs, .settings-tabs {
  flex: 1;
  overflow-x: auto;
  padding-bottom: 4px;
}

.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.card-head-row h3 { font-size: 16px; color: var(--navy); }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  min-height: 32px;
}

.btn-danger {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}

.btn-danger:hover { background: #fee2e2; }

.pill-blue { background: #dbeafe; color: #1d4ed8; }

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

.role-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.role-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.role-item:hover { border-color: var(--blue); }

.role-item.active {
  border-color: var(--blue);
  background: #eff6ff;
  box-shadow: 0 0 0 1px var(--blue);
}

.role-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.role-item small { font-size: 12px; color: var(--muted); line-height: 1.4; }

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 10px;
  margin-top: 12px;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  background: #fafafa;
}

.perm-check input { width: 18px; height: 18px; accent-color: var(--blue); }

.perm-check:has(input:checked) {
  background: #eff6ff;
  border-color: #93c5fd;
}

.settings-grid { align-items: start; }

.settings-form-card h3,
.settings-preview-card h3 {
  font-size: 16px;
  color: var(--navy);
  margin-bottom: 8px;
}

.settings-save-row { margin-top: 16px; }

.brand-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: linear-gradient(135deg, var(--navy-dark), var(--navy));
  border-radius: 12px;
  color: #fff;
  margin-top: 12px;
}

.brand-preview-logo {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  overflow: hidden;
  flex-shrink: 0;
}

.brand-preview-logo img { width: 100%; height: 100%; object-fit: cover; }

.brand-preview-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.brand-preview-text strong { font-size: 17px; }
.brand-preview-text em { font-size: 13px; opacity: 0.85; font-style: normal; }
.brand-preview-text span { font-size: 12px; opacity: 0.7; }

.logo-upload-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.muted-hint { font-size: 12px; color: var(--muted); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s, visibility 0.25s;
  backdrop-filter: blur(3px);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 14px;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.25s;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 { font-size: 17px; color: var(--navy); }

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy);
  color: #fff;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  z-index: 1100;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

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

/* Focus box */
.focus-box {
  background: linear-gradient(120deg, var(--navy-dark), var(--navy));
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 20px;
}

.focus-box .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.75;
}

.focus-box .t { font-size: 17px; font-weight: 600; margin-top: 6px; line-height: 1.45; }

.focus-box-spaced { margin-top: 20px; }

.hidden-nav { display: none !important; }

/* Mobile card-style tables */
@media (max-width: 640px) {
  .table-cards table { min-width: 0 !important; }

  .table-cards thead { display: none; }

  .table-cards tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 0;
    background: #fff;
  }

  .table-cards tbody tr:hover td { background: transparent; }

  .table-cards td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    font-size: 13px;
  }

  .table-cards td:last-child { border-bottom: none; }

  .table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
    flex-shrink: 0;
    max-width: 45%;
  }

  .table-cards td .progress-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    min-width: 0;
  }

  .master-card li {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* ─── Responsive breakpoints ─── */

/* Large tablet */
@media (max-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .page-content { padding: 20px; }
  .kpi .val { font-size: 24px; }
}

/* Mobile landscape / small tablet */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  body.sidebar-mini .sidebar,
  body.sidebar-hidden .sidebar { transform: translateX(-100%); }
  body.sidebar-mini .main-content,
  body.sidebar-hidden .main-content { margin-left: 0; width: 100%; }

  .table-scroll-hint { display: block; }

  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* Mobile portrait */
@media (max-width: 640px) {
  .table-scroll-hint { display: none !important; }

  .login-card {
    padding: 28px 20px;
    border-radius: 14px;
  }

  .login-card .logo h1 { font-size: 19px; }

  .demo-btns { flex-direction: column; }

  .demo-btns .btn { width: 100%; min-width: 0; }

  .topbar {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .topbar h1 { font-size: 15px; max-width: 52vw; }

  .topbar-date { display: none; }

  .page-content {
    padding: 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

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

  .calc-preview { grid-template-columns: 1fr; }

  .card { padding: 14px; }

  .kpi .val { font-size: 22px; }

  .section-title {
    font-size: 13px;
    margin: 22px 0 12px;
  }

  .machine-grid { grid-template-columns: 1fr; }

  .focus-box { padding: 16px 18px; }

  .focus-box .t { font-size: 15px; }

  .toast {
    left: 14px;
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    text-align: center;
  }

  .form-actions { flex-direction: column; }

  .form-actions .btn { width: 100%; }

  .filters-bar { grid-template-columns: 1fr; }

  .nav-item { padding: 12px 14px; min-height: 44px; }

  .alert { font-size: 13px; padding: 12px 14px; }

  th, td { padding: 8px 10px; font-size: 12px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .topbar h1 { font-size: 14px; max-width: 46vw; }

  .tab-btn { padding: 8px 12px; font-size: 12px; }

  .pill { font-size: 10px; padding: 2px 8px; }
}

/* Desktop: sidebar always visible unless hidden */
@media (min-width: 901px) {
  body:not(.sidebar-hidden) .sidebar { transform: translateX(0) !important; }
  body.sidebar-mini:not(.sidebar-hidden) .sidebar { transform: translateX(0) !important; }

  .sidebar-overlay { display: none !important; }
}
