@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=DM+Sans:wght@300;400;500;600&display=swap');

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

:root {
  /* ── BACKGROUNDS ── */
  --bg0:     #eef1f6;
  --bg1:     #ffffff;
  --bg2:     #f6f8fc;
  --bg3:     #edf0f7;
  --bg4:     #e4e8f0;
  --inset:   #f2f4f8;

  /* ── BORDERS ── */
  --border:  #dde2ec;
  --border2: #c5cdd9;
  --border3: #a8b2c4;

  /* ── TEXT ── */
  --t1: #0d1321;
  --t2: #3d4a5c;
  --t3: #8899aa;
  --t4: #c5cdd9;

  /* ── STATUS ── */
  --green:    #16a34a; --green-bg: #f0fdf4; --green-bdr:#bbf7d0; --green-dim:#dcfce7;
  --red:      #dc2626; --red-bg:   #fef2f2; --red-bdr:  #fecaca; --red-dim:  #fee2e2;
  --amber:    #d97706; --amber-bg: #fffbeb; --amber-bdr:#fde68a; --amber-dim:#fef3c7;
  --blue:     #2563eb; --blue-bg:  #eff6ff; --blue-bdr: #bfdbfe; --blue-dim: #dbeafe;
  --teal:     #0d9488; --teal-bg:  #f0fdfa; --teal-bdr: #99f6e4;
  --slate:    #64748b; --slate-bg: #f8fafc; --slate-bdr:#e2e8f0;
  --purple:   #8b5cf6; --purple-bg:#f5f3ff; --purple-bdr:#ddd6fe;

  /* ── TYPOGRAPHY ── */
  --mono: 'JetBrains Mono', monospace;
  --sans: 'DM Sans', sans-serif;

  /* ── SHADOWS ── */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);

  /* ── RADIUS ── */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
}

html, body {
  height: 100%; background: var(--bg0); color: var(--t1);
  font-family: var(--sans); overflow-x: hidden; -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg0); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border3); }

/* ── TOPBAR ── */
.topbar {
  position: sticky; top: 0; z-index: 200;
  background: var(--bg1); border-bottom: 1px solid var(--border);
  height: 52px; display: flex; align-items: center;
  padding: 0 20px; gap: 16px; box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; }
.brand-icon {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--teal) 0%, #0f766e 100%);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: #fff;
  box-shadow: 0 2px 6px rgba(13,148,136,0.35); flex-shrink: 0;
}
.brand-name { font-size: 14px; font-weight: 600; color: var(--t1); letter-spacing: 0.5px; }
.brand-sep { width: 1px; height: 18px; background: var(--border); }
.brand-sub { font-size: 11px; color: var(--t3); letter-spacing: 0.5px; font-weight: 500; }
.nav { display: flex; gap: 2px; }
.nav-btn {
  padding: 5px 13px; font-size: 12px; font-weight: 500; letter-spacing: 0.3px;
  font-family: var(--sans); border-radius: var(--r-sm);
  color: var(--t3); background: none; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; display: block; transition: all 0.13s;
}
.nav-btn:hover  { background: var(--bg3); color: var(--t2); }
.nav-btn.active { background: var(--bg3); color: var(--t1); border-color: var(--border); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* ── TOPBAR USER ── */
.topbar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--bg2);
  font-size: 12px; color: var(--t2); font-weight: 500;
}
.topbar-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--teal) 0%, #0f766e 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.topbar-logout {
  padding: 4px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: none;
  font-size: 11px; font-weight: 500; color: var(--t3);
  cursor: pointer; font-family: var(--sans); transition: all 0.12s;
}
.topbar-logout:hover { background: var(--red-bg); border-color: var(--red-bdr); color: var(--red); }

/* ── ALARM BADGE ── */
.alarm-badge {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-sm);
  font-size: 11px; font-weight: 600; cursor: pointer; border: none;
  font-family: var(--sans); transition: all 0.13s;
}
.alarm-badge.has-alarm { background: var(--red-bg);   border: 1px solid var(--red-bdr);   color: var(--red);   }
.alarm-badge.no-alarm  { background: var(--green-bg); border: 1px solid var(--green-bdr); color: var(--green); }
.alarm-badge .adot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.alarm-badge.has-alarm .adot { background: var(--red);   animation: pulse-dot 1s infinite; }
.alarm-badge.no-alarm  .adot { background: var(--green); }

/* ── SHIFT + CLOCK ── */
.shift-pill { padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; font-family: var(--mono); }
.shift-M { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bdr); }
.shift-A { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.shift-N { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-bdr);  }
.clock { font-family: var(--mono); font-size: 13px; color: var(--t2); min-width: 70px; text-align: right; font-weight: 500; }

/* ── KPI STRIP ── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.kpi-cell { padding: 11px 18px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; }
.kpi-cell:last-child { border-right: none; }
.kpi-label { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.9px; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 600; font-family: var(--mono); line-height: 1; color: var(--t1); }
.kpi-hint  { font-size: 10px; color: var(--t3); }

/* ── SECTION HEADER ── */
.sec-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px 6px; }
.sec-title { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600; }
.sec-actions { display: flex; gap: 6px; }

/* ── FILTER CHIPS ── */
.filter-btn {
  padding: 3px 12px; border-radius: 20px; font-size: 11px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg1); color: var(--t3);
  transition: all 0.12s; font-family: var(--sans); font-weight: 500;
}
.filter-btn:hover  { border-color: var(--border2); color: var(--t2); background: var(--bg3); }
.filter-btn.active { background: var(--bg3); border-color: var(--border2); color: var(--t1); font-weight: 600; }

/* ── MACHINE GRID ── */
.machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(182px, 1fr)); gap: 10px; padding: 10px 20px 80px; }
@media (min-width: 1600px) { .machine-grid { grid-template-columns: repeat(6,1fr); } }

.loading-msg { grid-column:1/-1; display:flex; align-items:center; justify-content:center; padding:60px; color:var(--t3); font-size:13px; font-family:var(--mono); letter-spacing:1px; gap:3px; }
.ld { animation:pulse-dot 0.8s infinite; }
.ld:nth-child(2){animation-delay:0.2s;} .ld:nth-child(3){animation-delay:0.4s;}

/* ── MACHINE CARD ── */
.mcard {
  background: var(--bg1); border-radius: var(--r-md);
  border: 1px solid var(--border); overflow: hidden;
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
  display: flex; flex-direction: column; box-shadow: var(--shadow-sm);
}
.mcard:hover { border-color: var(--border2); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.mcard.blink-card { animation: cardBlink 1.1s infinite; }
@keyframes cardBlink {
  0%,100%{ border-color: var(--red-bdr); box-shadow: 0 0 0 2px var(--red-dim); }
  50%{ border-color: var(--border); box-shadow: none; }
}
.mcard-head { padding: 9px 11px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; }
.st-running   .mcard-head { background: var(--green-dim); border-bottom-color: var(--green-bdr); }
.st-breakdown .mcard-head { background: var(--red-dim);   border-bottom-color: var(--red-bdr);   }
.st-idle      .mcard-head { background: var(--amber-dim); border-bottom-color: var(--amber-bdr); }
.st-endorder  .mcard-head { background: var(--blue-dim);  border-bottom-color: var(--blue-bdr);  }
.st-disc      .mcard-head { background: var(--bg3);       border-bottom-color: var(--border);    }
/* mcard as direct status wrapper (index.html renders card.className="mcard st-xxx") */
.mcard.st-running   .mcard-head { background: var(--green-dim); border-bottom-color: var(--green-bdr); }
.mcard.st-breakdown .mcard-head { background: var(--red-dim);   border-bottom-color: var(--red-bdr);   }
.mcard.st-idle      .mcard-head { background: var(--amber-dim); border-bottom-color: var(--amber-bdr); }
.mcard.st-endorder  .mcard-head { background: var(--blue-dim);  border-bottom-color: var(--blue-bdr);  }
.mcard.st-disc      .mcard-head { background: var(--bg3);       border-bottom-color: var(--border);    }
.mcard.st-running   .sdot { background: var(--green); }
.mcard.st-breakdown .sdot { background: var(--red);   animation: pulse-dot 0.8s infinite; }
.mcard.st-idle      .sdot { background: var(--amber); }
.mcard.st-endorder  .sdot { background: var(--blue);  }
.mcard.st-disc      .sdot { background: var(--slate); }
.mcard.st-running   .slabel { color: var(--green); }
.mcard.st-breakdown .slabel { color: var(--red);   }
.mcard.st-idle      .slabel { color: var(--amber); }
.mcard.st-endorder  .slabel { color: var(--blue);  }
.mcard.st-disc      .slabel { color: var(--slate); }
.mcard.st-breakdown { animation: cardBlink 1.1s infinite; }

.mcard-name { font-size: 12px; font-weight: 600; margin-bottom: 3px; color: var(--t1); }
.mcard-status { display: flex; align-items: center; gap: 5px; }
.sdot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.st-running   .sdot { background: var(--green); }
.st-breakdown .sdot { background: var(--red);   animation: pulse-dot 0.8s infinite; }
.st-idle      .sdot { background: var(--amber); }
.st-endorder  .sdot { background: var(--blue);  }
.st-disc      .sdot { background: var(--slate); }
.slabel {
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  line-height: 1;
  color: var(--t3);
}
.perf-tag { font-size: 10px; margin-left: 3px; font-style: italic; color: var(--t3); }
.perf-tag.col-green { color: var(--green); }
.mes-table .chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.mes-table .chip .chip-dot { width: 8px; height: 8px; }
.mes-table td.col-green, .mes-table td.col-amber, .mes-table td.col-red { font-weight: 700; }
.table-view .mes-table { max-width: 1400px; margin: 0 auto; }
.perf-tag.col-amber { color: var(--amber); }
.perf-tag.col-red   { color: var(--red);   }
.mcard-timer { font-family: var(--mono); font-size: 10px; color: var(--t3); background: rgba(0,0,0,0.06); padding: 2px 7px; border-radius: 4px; flex-shrink: 0; }
.mcard-oee { padding: 10px 11px 7px; }
.oee-row { display: flex; align-items: baseline; gap: 5px; margin-bottom: 7px; }
.oee-num { font-family: var(--mono); font-size: 28px; font-weight: 600; line-height: 1; }
.oee-unit { font-size: 10px; color: var(--t3); }
.oee-bar-track { height: 4px; background: var(--border); border-radius: 2px; }
.oee-bar-fill  { height: 4px; border-radius: 2px; transition: width 0.6s ease; }
.apq-row { display: grid; grid-template-columns: 1fr 1fr 1fr; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.apq-cell { padding: 5px 4px; text-align: center; }
.apq-cell:not(:last-child) { border-right: 1px solid var(--border); }
.apq-val { font-size: 12px; font-weight: 600; font-family: var(--mono); color: var(--t2); }
.apq-lbl { font-size: 9px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.6px; margin-top: 1px; }
.mcard-foot { padding: 7px 11px; display: flex; justify-content: space-between; align-items: flex-end; }
.mf-group { display: flex; flex-direction: column; gap: 1px; }
.mf-lbl { font-size: 9px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.5px; }
.mf-val { font-size: 12px; font-weight: 600; font-family: var(--mono); color: var(--t2); }
.order-track { height: 2px; background: var(--border); border-radius: 1px; margin-top: 3px; width: 55px; }
.order-fill  { height: 2px; border-radius: 1px; background: var(--teal); }

/* ── PANELS ── */
.panel { background: var(--bg1); border-radius: var(--r-md); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.panel-head { padding: 11px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel-title { font-size: 11px; font-weight: 600; color: var(--t2); text-transform: uppercase; letter-spacing: 0.9px; }
.panel-body { padding: 14px; }

/* ── STATUS CHIPS ── */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; }
.chip-run  { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bdr); }
.chip-down { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-bdr);   }
.chip-idle { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.chip-end  { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-bdr);  }
.chip-disc { background: var(--slate-bg); color: var(--slate); border: 1px solid var(--slate-bdr); }
.chip-dot  { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.chip-run  .chip-dot { background: var(--green); }
.chip-down .chip-dot { background: var(--red);   animation: pulse-dot 0.8s infinite; }
.chip-idle .chip-dot { background: var(--amber); }
.chip-end  .chip-dot { background: var(--blue);  }
.chip-disc .chip-dot { background: var(--slate); }

/* ── TABLES ── */

.table-view {
  width: 100%;
  overflow-x: auto;
  padding: 10px;
}

.mes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg2);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

/* HEADER */
.mes-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(90deg, #0f172a, #111c2e);
  color: #fff;
  text-align: left;
  padding: 12px 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border-bottom: 2px solid rgba(255,255,255,0.08);
  white-space: nowrap;
}

/* BODY */
.mes-table tbody td {
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: var(--t2);
  white-space: nowrap;
}

/* STRIPED */
.mes-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}

/* HOVER EFFECT */
.mes-table tbody tr:hover {
  background: rgba(13, 148, 136, 0.08);
  transition: 0.2s ease;
  transform: scale(1.002);
}

/* STATUS COLORS */
.st-running {
  color: #22c55e;
  font-weight: 600;
}

.st-breakdown {
  color: #ef4444;
  font-weight: 700;
}

.st-idle {
  color: #f59e0b;
  font-weight: 600;
}

.st-endorder {
  color: #38bdf8;
  font-weight: 600;
}

/* MACHINE NAME EMPHASIS */
.mes-table td:first-child {
  font-weight: 600;
  color: var(--t1);
}

/* OEE highlight column (4th column) */
.mes-table td:nth-child(4) {
  font-weight: 700;
}

/* RESPONSIVE */
@media (max-width: 1200px) {
  .mes-table {
    font-size: 12px;
  }

  .mes-table th,
  .mes-table td {
    padding: 8px;
  }
}

/* ── STAT CELL ── */
.stat-cell { background: var(--bg2); border-radius: 8px; padding: 10px 14px; border: 1px solid var(--border); }
.stat-label { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 4px; font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 600; font-family: var(--mono); line-height: 1; color: var(--t1); }
.stat-sub   { font-size: 10px; color: var(--t3); margin-top: 3px; }

/* ── PROGRESS BARS ── */
.prog-track { height: 4px; background: var(--border); border-radius: 2px; }
.prog-fill  { height: 4px; border-radius: 2px; background: var(--teal); transition: width 0.5s ease; }

/* ── BUTTONS ── */
.btn {
  padding: 6px 14px; border-radius: var(--r-sm); font-size: 12px;
  cursor: pointer; font-family: var(--sans); font-weight: 500;
  border: 1px solid var(--border); background: var(--bg1); color: var(--t2);
  transition: all 0.12s; white-space: nowrap;
}
.btn:hover { background: var(--bg3); border-color: var(--border2); color: var(--t1); }
.btn.primary { background: linear-gradient(135deg, var(--teal) 0%, #0f766e 100%); border-color: transparent; color: #fff; box-shadow: 0 2px 8px rgba(13,148,136,0.30); }
.btn.primary:hover { box-shadow: 0 4px 14px rgba(13,148,136,0.40); transform: translateY(-1px); }
.btn.danger  { background: var(--red-bg); border-color: var(--red-bdr); color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── MODAL ── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.40); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg1); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 22px; width: 380px; max-width: 95%; box-shadow: var(--shadow-lg); animation: modalIn 0.18s ease; }
@keyframes modalIn { from { opacity:0; transform:scale(0.95) translateY(-8px); } to { opacity:1; transform:none; } }
.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 18px; color: var(--t1); }
.modal input, .modal select { width: 100%; background: var(--inset); border: 1px solid var(--border); color: var(--t1); padding: 9px 12px; border-radius: var(--r-sm); font-size: 13px; margin-bottom: 10px; font-family: var(--sans); transition: border-color 0.12s; }
.modal input:focus, .modal select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,0.1); }
.modal label { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.8px; display: block; margin-bottom: 4px; font-weight: 600; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ── STATUS BAR ── */
.statusbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: var(--bg1); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 5px 20px; font-size: 10px; color: var(--t3); font-family: var(--mono); box-shadow: 0 -1px 4px rgba(0,0,0,0.04); }
.st-ok  { color: var(--green); font-weight: 500; }
.st-err { color: var(--red);   font-weight: 500; }

/* ── PARETO ── */
.pareto-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.pareto-head { display: flex; justify-content: space-between; font-size: 12px; }
.pareto-lbl  { font-family: var(--sans); color: var(--t2); font-weight: 500; }
.pareto-time { font-family: var(--mono); font-weight: 600; color: var(--amber); }
.pareto-track { height: 7px; background: var(--border); border-radius: 4px; }
.pareto-fill  { height: 7px; border-radius: 4px; background: linear-gradient(90deg, var(--amber) 0%, #f59e0b 100%); transition: width 0.5s; }

/* ════════════════════════════════════════
   LOGIN PAGE
════════════════════════════════════════ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg0); position: relative; overflow: hidden;
}
.login-page::before {
  content: ''; position: absolute; inset: 0;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px; opacity: 0.55;
}
.login-page::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 50%, rgba(13,148,136,0.07) 0%, transparent 70%);
}
.login-box {
  position: relative; z-index: 1;
  background: var(--bg1); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 36px 40px; width: 380px; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-brand-icon {
  width: 54px; height: 54px; border-radius: 14px;
  background: linear-gradient(135deg, var(--teal) 0%, #0f766e 100%);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 20px; font-weight: 700; color: #fff;
  box-shadow: 0 6px 20px rgba(13,148,136,0.30);
}
.login-brand-name { font-family: var(--mono); font-size: 18px; font-weight: 600; color: var(--t1); letter-spacing: 2px; }
.login-brand-sub { font-size: 11px; color: var(--t3); font-weight: 500; letter-spacing: 0.5px; margin-top: -4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-label { font-size: 10px; color: var(--t3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.9px; }
.login-input {
  background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 10px 14px; font-size: 14px; font-family: var(--sans); color: var(--t1);
  transition: border-color 0.12s, box-shadow 0.12s; width: 100%;
}
.login-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,0.12); background: var(--bg1); }
.login-input::placeholder { color: var(--t4); }
.login-error {
  background: var(--red-bg); border: 1px solid var(--red-bdr); color: var(--red);
  border-radius: var(--r-sm); padding: 9px 12px; font-size: 12px; font-weight: 500;
  display: none; align-items: center; gap: 8px;
}
.login-error.show { display: flex; }
.login-btn {
  width: 100%; padding: 12px;
  background: linear-gradient(135deg, var(--teal) 0%, #0f766e 100%);
  color: #fff; border: none; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; font-family: var(--sans);
  cursor: pointer; transition: all 0.15s;
  box-shadow: 0 3px 10px rgba(13,148,136,0.30); letter-spacing: 0.3px;
}
.login-btn:hover { box-shadow: 0 5px 18px rgba(13,148,136,0.40); transform: translateY(-1px); }
.login-btn:active { transform: translateY(0); }
.login-btn:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }
.login-footer { margin-top: 20px; text-align: center; font-size: 11px; color: var(--t4); }
.login-dashboard-link{
  display:inline-block;
  margin-top:8px;
  color:var(--teal);
  text-decoration:none;
  font-size:12px;
  font-weight:600;
  transition:.2s;
}
.login-dashboard-link:hover{
  opacity:.8;
  text-decoration:underline;
}
.login-logo {
  width: 120px;
  height: auto;
  display: block;
  margin: 0 auto 12px auto;
}

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

.brand-logo {
  height: 28px;
  width: auto;
}

.brand-logo {
  height: 32px;
  background: white;
  padding: 4px 6px;
  border-radius: 6px;
}
/* ── ANIMATIONS ── */
@keyframes pulse-dot { 0%,100%{opacity:1;} 50%{opacity:0.25;} }
@keyframes fadeIn { from{opacity:0;transform:translateY(4px);} to{opacity:1;transform:none;} }
@keyframes modalIn { from { opacity:0; transform:scale(0.95) translateY(-8px); } to { opacity:1; transform:none; } }

/* ── UTILITY ── */
.pb80 { padding-bottom: 80px; }
.col-green { color: var(--green) !important; }
.col-amber { color: var(--amber) !important; }
.col-red   { color: var(--red)   !important; }
.col-blue  { color: var(--blue)  !important; }
.col-teal  { color: var(--teal)  !important; }
.col-muted { color: var(--t3)    !important; }
.mono      { font-family: var(--mono) !important; }
.fw5       { font-weight: 500 !important; }
.fw6       { font-weight: 600 !important; }

/* ── RESPONSIVE ── */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; align-items: flex-start; gap: 10px; }
  .nav { width: 100%; overflow-x: auto; padding-bottom: 6px; }
  .nav-btn { flex: 0 0 auto; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .sec-header { flex-wrap: wrap; gap: 12px; }
  .kpi-strip { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .summary-strip, .report-strip, .alarm-strip, .plan-strip, .order-detail-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .gantt { min-width: 720px; }
  .gantt-header { grid-template-columns: 120px 1fr; }
  .gantt-lbl-col { width: 120px; }
  .gantt-row { grid-template-columns: 120px 1fr; }
  .gmach { width: 120px; padding: 10px; }
  .gtrack { min-height: 54px; }
  .gblock { top: 8px; height: calc(100% - 16px); padding: 0 8px; }
  .gblock-order { font-size: 10px; }
  .gblock-part { font-size: 9px; }
  .panel { border-radius: var(--r-lg); }
  .panel-body { padding: 12px; }
  .chart-wrap { min-height: 220px; }
  .statusbar { flex-wrap: wrap; gap: 8px; }
  .mes-table { font-size: 11px; }
  .mes-table th, .mes-table td { padding: 8px 10px; }
  .search-bar { width: 100%; max-width: 100%; }
}
@media (max-width: 768px) {
  .topbar { height: auto; padding: 12px 14px; }
  .brand { width: 100%; justify-content: space-between; }
  .brand-sub { display: none; }
  .nav-btn { padding: 7px 10px; font-size: 11px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .page-body { padding: 14px 12px 100px; }
  .kpi-strip { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .kpi-cell { padding: 10px; }
  .summary-strip, .report-strip, .alarm-strip, .plan-strip { grid-template-columns: 1fr; }
  .ps-cell, .sum-cell, .asum-cell, .rs-cell { padding: 14px 14px; }
  .sec-header { padding-top: 8px; }
  .zoom-btns { flex-wrap: wrap; }
  .zoom-btn { flex: 1 1 auto; min-width: 90px; }
  .order-row { grid-template-columns: 60px 1fr; gap: 10px; padding: 12px 14px; }
  .order-row > div:nth-child(3) { text-align: left; }
  .chart-wrap { min-height: 180px; }
  .hero { flex-direction: column; align-items: stretch; }
  .hero-name { font-size: 18px; }
  .hero-meta { font-size: 11px; }
  .oee-big-num { font-size: 44px; }
  .oee-big-lbl { font-size: 10px; }
  .gauge-wrap { gap: 8px; }
  .rank-table th, .rank-table td { padding: 8px 10px; font-size: 11px; }
  .oee-mini-grid { gap: 6px; }
  .oee-mini-cell { padding: 10px; }
}

@media (max-width: 520px) {
  .nav-btn { padding: 7px 10px; font-size: 10px; }
  .shift-pill { padding: 4px 10px; }
  .clock { font-size: 11px; }
  .brand-name { font-size: 13px; }
  .brand-sep { display: none; }
  .btn { width: 100%; }
  .panel-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .panel-head button { width: 100%; }
  .chart-tabs { flex-wrap: wrap; }
  .chart-tab { flex: 1 1 auto; }
  .order-row { grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
  .order-row > div { width: 100%; }
  .summary-strip, .report-strip, .alarm-strip, .plan-strip { grid-template-columns: 1fr; }
  .page-body { padding: 12px 10px 110px; }
  .modal { width: calc(100% - 20px); }
  .statusbar { padding: 8px 12px; font-size: 9px; }
}

/* ══════════════════════════════════════
   PAGE LAYOUT — shared across all pages
══════════════════════════════════════ */
.page-body {
  padding: 16px 20px 80px;
  display: flex; flex-direction: column; gap: 12px;
}

/* ── SUMMARY / KPI STRIPS ── */
.summary-strip,
.alarm-strip,
.report-strip,
.plan-strip {
  display: grid;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.summary-strip { grid-template-columns: repeat(4,1fr); }
.alarm-strip   { grid-template-columns: repeat(4,1fr); }
.report-strip  { grid-template-columns: repeat(6,1fr); }
.plan-strip    { grid-template-columns: repeat(5,1fr); }

/* Strip cells */
.sum-cell, .asum-cell, .rs-cell, .ps-cell {
  padding: 12px 18px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 3px;
}
.sum-cell:last-child,
.asum-cell:last-child,
.rs-cell:last-child,
.ps-cell:last-child { border-right: none; }

.sum-lbl, .asum-lbl, .rs-lbl, .ps-lbl {
  font-size: 10px; color: var(--t3);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 2px; font-weight: 600;
}
.sum-val, .asum-val, .rs-val, .ps-val {
  font-size: 24px; font-weight: 600;
  font-family: var(--mono); line-height: 1;
}
.rs-sub, .ps-sub { font-size: 10px; color: var(--t3); margin-top: 1px; }

/* ── SEARCH BAR ── */
.search-bar {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--t1); padding: 6px 12px; border-radius: var(--r-sm);
  font-size: 13px; font-family: var(--sans); width: 240px;
  transition: border-color 0.12s;
}
.search-bar:focus { outline: none; border-color: var(--teal); }

/* ── LAYOUT GRIDS ── */
.two-col   { display: grid; grid-template-columns: 1fr 1fr;     gap: 12px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.two-col-wide { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; }
@media(max-width:900px) { .two-col,.three-col,.two-col-wide { grid-template-columns: 1fr; } }

/* ── PROGRESS (orders table) ── */
.prog-cell { display: flex; align-items: center; gap: 6px; }
.prog-track-sm { flex: 1; min-width: 50px; height: 4px; background: var(--border); border-radius: 2px; }
.prog-fill-sm  { height: 4px; border-radius: 2px; background: var(--teal); }
.prog-pct { min-width: 34px; text-align: right; font-family: var(--mono); font-size: 12px; font-weight: 600; }

/* ── ORDER BADGES ── */
.ob { display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; }
.ob-run  { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bdr); }
.ob-done { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-bdr);  }
.ob-idle { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.ob-down { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-bdr);   }
.ob-disc { background: var(--slate-bg); color: var(--slate); border: 1px solid var(--slate-bdr); }

/* ── TABLE HELPERS ── */
.empty-row td { color: var(--t3); text-align: center; padding: 30px !important; font-family: var(--sans); font-size: 12px; }
.stop-wrap { max-height: 280px; overflow-y: auto; }

/* ── ALARM CARDS ── */
.alarm-card {
  background: var(--red-bg); border: 1px solid var(--red-bdr);
  border-radius: var(--r-md); padding: 14px 18px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  animation: alarmPulse 1.5s infinite; cursor: pointer;
}
@keyframes alarmPulse { 0%,100%{border-color:var(--red-bdr);} 50%{border-color:var(--red);} }
.alarm-card:hover { animation: none; border-color: var(--red); box-shadow: 0 4px 12px rgba(220,38,38,0.12); }
.alarm-machine { font-size: 14px; font-weight: 600; margin-bottom: 3px; color: var(--t1); }
.alarm-reason  { font-size: 12px; color: var(--amber); font-weight: 600; margin-bottom: 2px; }
.alarm-meta    { font-size: 11px; color: var(--t3); font-family: var(--mono); }
.alarm-duration{ font-family: var(--mono); font-size: 28px; font-weight: 600; color: var(--red); line-height: 1; }
.alarm-dur-lbl { font-size: 10px; color: var(--t3); margin-top: 3px; }

.no-alarms { background: var(--green-bg); border: 1px solid var(--green-bdr); border-radius: var(--r-md); padding: 30px; text-align: center; }
.no-alarms-icon { font-size: 28px; margin-bottom: 6px; color: var(--green); font-family: var(--mono); }
.no-alarms-txt  { font-size: 12px; color: var(--green); font-weight: 600; }

/* ── REPORT / RANKING TABLE ── */
.rank-table { width: 100%; border-collapse: collapse; }
.rank-table th { padding: 8px 14px; text-align: left; color: var(--t3); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.rank-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); color: var(--t2); font-family: var(--mono); font-size: 12px; }
.rank-table tr:last-child td { border-bottom: none; }
.rank-table tr:hover td { background: var(--bg3); cursor: pointer; }
.rank-table td.primary { color: var(--t1); font-family: var(--sans); font-weight: 600; }

.rank-num { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; font-family: var(--mono); }
.rn-1 { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.rn-2 { background: var(--bg3);      color: var(--t2);   border: 1px solid var(--border2);   }
.rn-3 { background: #fef3c7;         color: #92400e;     border: 1px solid #fde68a;           }

/* ── MACHINE HERO (machine.html) ── */
.hero { background: var(--bg1); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; box-shadow: var(--shadow-sm); }
.hero-icon { width: 48px; height: 48px; border-radius: 10px; background: var(--bg3); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--t3); flex-shrink: 0; }
.hero-name { font-size: 20px; font-weight: 600; line-height: 1; margin-bottom: 4px; color: var(--t1); }
.hero-meta { font-size: 12px; color: var(--t3); font-family: var(--mono); }

/* ── OEE BLOCK ── */
.oee-big-wrap { text-align: center; padding: 20px 14px; }
.oee-big-num  { font-family: var(--mono); font-size: 52px; font-weight: 600; line-height: 1; }
.oee-big-lbl  { font-size: 11px; color: var(--t3); text-transform: uppercase; letter-spacing: 1px; margin-top: 6px; }
.oee-big-bar  { height: 6px; background: var(--border); border-radius: 3px; margin: 12px 0; }
.oee-big-fill { height: 6px; border-radius: 3px; transition: width 0.6s; }
.apq-big { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.apq-big-cell { background: var(--bg2); border-radius: 8px; padding: 10px; text-align: center; border: 1px solid var(--border); }
.apq-big-val  { font-family: var(--mono); font-size: 18px; font-weight: 600; color: var(--t2); }
.apq-big-lbl  { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.7px; margin-top: 3px; }

/* ── GAUGE ROWS (machine.html) ── */
.gauge-wrap { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.gauge-row  { display: flex; flex-direction: column; gap: 4px; }
.gauge-head { display: flex; justify-content: space-between; font-size: 12px; }
.gauge-lbl  { color: var(--t3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; font-weight: 600; }
.gauge-val  { font-family: var(--mono); font-weight: 600; color: var(--t1); }
.gauge-track { height: 5px; background: var(--border); border-radius: 3px; }
.gauge-fill  { height: 5px; border-radius: 3px; transition: width 0.5s; }

/* ── JOB GRID (machine.html) ── */
.job-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px; }
.job-field { background: var(--bg2); border-radius: 8px; padding: 8px 12px; border: 1px solid var(--border); }
.job-lbl   { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 3px; font-weight: 600; }
.job-val   { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-full  { grid-column: 1/-1; }

/* ── CHART TABS ── */
.chart-tabs { display: flex; gap: 4px; padding: 10px 14px 0; }
.chart-tab  { padding: 4px 12px; border-radius: 20px; font-size: 11px; cursor: pointer; font-weight: 500; border: 1px solid var(--border); background: none; color: var(--t3); font-family: var(--sans); transition: all 0.12s; }
.chart-tab:hover  { color: var(--t2); border-color: var(--border2); }
.chart-tab.active { background: var(--bg3); color: var(--t1); border-color: var(--border2); font-weight: 600; }
.chart-panels { padding: 10px 14px 14px; }
.chart-panel  { display: none; }
.chart-panel.active { display: block; }
.chart-wrap { position: relative; height: 220px; }

/* ── BREAKDOWN BANNER ── */
.breakdown-banner {
  display: none; background: var(--red-bg); border: 2px solid var(--red-bdr);
  border-radius: var(--r-md); padding: 14px 18px;
  align-items: center; justify-content: space-between; gap: 14px;
  animation: bannerPulse 1.8s infinite; box-shadow: 0 0 0 4px var(--red-dim);
}
.breakdown-banner.show { display: flex; }
@keyframes bannerPulse { 0%,100%{box-shadow:0 0 0 4px var(--red-dim);} 50%{box-shadow:0 0 0 8px transparent;} }
.bb-left  { display: flex; align-items: center; gap: 14px; }
.bb-icon  { font-size: 28px; line-height: 1; }
.bb-title { font-size: 14px; font-weight: 700; color: var(--red); margin-bottom: 3px; }
.bb-sub   { font-size: 12px; color: var(--t2); }
.bb-alarm { font-size: 11px; font-family: var(--mono); color: var(--amber); font-weight: 600; margin-top: 4px; background: var(--amber-bg); padding: 2px 8px; border-radius: 4px; display: inline-block; }
.bb-timer { font-family: var(--mono); font-size: 32px; font-weight: 700; color: var(--red); text-align: right; line-height: 1; }
.bb-timer-lbl { font-size: 10px; color: var(--t3); text-align: right; margin-top: 2px; }
.btn-declare { background: var(--red); color: #fff; border: none; border-radius: var(--r-sm); padding: 10px 20px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: var(--sans); transition: all 0.15s; box-shadow: 0 3px 10px rgba(220,38,38,0.35); white-space: nowrap; }
.btn-declare:hover { background: #b91c1c; box-shadow: 0 5px 16px rgba(220,38,38,0.45); transform: translateY(-1px); }

/* ── STOP REASON MODAL ── */
.sr-modal { width: 520px; max-width: 95vw; }
.sr-modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.sr-subtitle { font-size: 12px; color: var(--t3); margin-bottom: 18px; }
.sr-alarm-box { background: var(--amber-bg); border: 1px solid var(--amber-bdr); border-radius: var(--r-sm); padding: 8px 12px; margin-bottom: 16px; font-size: 12px; font-family: var(--mono); color: var(--amber); display: none; }
.sr-alarm-box.show { display: block; }
.cat-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; margin-bottom: 16px; }
.cat-btn { padding: 8px 6px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--bg2); cursor: pointer; text-align: center; font-family: var(--sans); transition: all 0.12s; }
.cat-btn:hover { border-color: var(--border2); background: var(--bg3); }
.cat-btn.active { border-color: var(--teal); background: var(--teal-bg); }
.cat-btn .cat-code  { font-size: 11px; font-weight: 700; font-family: var(--mono); color: var(--t2); }
.cat-btn .cat-label { font-size: 9px; color: var(--t3); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }
.cat-btn.active .cat-code, .cat-btn.active .cat-label { color: var(--teal); }
.reason-list { border: 1px solid var(--border); border-radius: var(--r-sm); max-height: 200px; overflow-y: auto; margin-bottom: 14px; }
.reason-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.reason-item:last-child { border-bottom: none; }
.reason-item:hover { background: var(--bg3); }
.reason-item.selected { background: var(--teal-bg); }
.ri-radio { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border2); flex-shrink: 0; transition: all 0.12s; }
.reason-item.selected .ri-radio { border-color: var(--teal); background: var(--teal); box-shadow: 0 0 0 3px var(--teal-bg); }
.ri-code  { font-size: 10px; font-weight: 700; font-family: var(--mono); color: var(--t3); min-width: 44px; }
.reason-item.selected .ri-code { color: var(--teal); }
.ri-label { font-size: 12px; color: var(--t1); font-weight: 500; }
.sr-comment { width: 100%; background: var(--inset); border: 1px solid var(--border); color: var(--t1); padding: 8px 12px; border-radius: var(--r-sm); font-size: 12px; font-family: var(--sans); resize: none; height: 60px; transition: border-color 0.12s; }
.sr-comment:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,0.1); }
.sr-save-btn { background: linear-gradient(135deg,var(--teal) 0%,#0f766e 100%); color: #fff; border: none; border-radius: var(--r-sm); padding: 10px 22px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--sans); box-shadow: 0 2px 8px rgba(13,148,136,0.30); transition: all 0.15s; }
.sr-save-btn:hover { box-shadow: 0 4px 14px rgba(13,148,136,0.40); transform: translateY(-1px); }
.sr-save-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ── DOWNTIME LOG BADGES ── */
.dl-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; font-size: 10px; font-weight: 600; }
.dl-badge-ME { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-bdr);   }
.dl-badge-EL { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.dl-badge-MO { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-bdr); }
.dl-badge-MA { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-bdr);  }
.dl-badge-PR { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-bdr);  }
.dl-badge-OR { background: var(--slate-bg); color: var(--slate); border: 1px solid var(--slate-bdr); }
.dl-badge-PL { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-bdr); }
.dl-badge-OT { background: var(--slate-bg); color: var(--slate); border: 1px solid var(--slate-bdr); }
.btn-declare-sm { padding: 3px 10px; border-radius: var(--r-sm); font-size: 10px; font-weight: 600; cursor: pointer; font-family: var(--sans); background: var(--red-bg); border: 1px solid var(--red-bdr); color: var(--red); transition: all 0.12s; white-space: nowrap; }
.btn-declare-sm:hover { background: var(--red); color: #fff; border-color: var(--red); }
.unknown-row td { background: var(--red-dim) !important; }

/* ── PLANNING-SPECIFIC ── */
.gantt-shell {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.gantt-header {
  display: grid;
  grid-template-columns: 160px 1fr;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h, 52px);
  z-index: 10;
  overflow: hidden;
}
.gantt-lbl-col { padding: 8px 16px; font-size: 10px; font-weight: 600; color: var(--t3); text-transform: uppercase; letter-spacing: 0.8px; border-right: 1px solid var(--border); width: 160px; min-width: 160px; flex-shrink: 0; display: flex; align-items: center; }
.gantt-ruler { overflow: hidden; position: relative; height: 32px; flex: 1; min-width: 0; display: flex; align-items: stretch; }
.gantt-body  { overflow-x: auto; overflow-y: auto; max-height: 480px; }
.gantt { min-width: 900px; }
.gantt-row { display: flex; border-bottom: 1px solid var(--border); }
.gantt-row:last-child { border-bottom: none; }
.gantt-row > .gtrack { flex: 1; min-width: 0; position: relative; }
.gmach { width: 160px; padding: 12px 16px; border-right: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.gmach-name { font-size: 12px; font-weight: 600; color: var(--t1); }
.gmach-type { font-size: 10px; color: var(--t3); font-family: var(--mono); }
.gtrack { position: relative; min-height: 60px; background: var(--bg1); }
.gblock { position: absolute; top: 10px; height: calc(100% - 20px); border-radius: var(--r-sm); display: flex; flex-direction: column; justify-content: center; padding: 0 10px; overflow: hidden; cursor: pointer; transition: opacity 0.12s, box-shadow 0.12s; min-width: 30px; }
.gblock:hover { opacity: 0.88; box-shadow: var(--shadow-md); }
.gblock-order { font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gblock-part  { font-size: 10px; color: rgba(255,255,255,0.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gnow { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--teal); z-index: 5; }
.gnow::before { content: ''; position: absolute; top: 4px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--teal); }
.ghr-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); }
.ghr-lbl  { position: absolute; top: 6px; font-size: 9px; color: var(--t3); font-family: var(--mono); transform: translateX(-50%); }
.zoom-btns { display: flex; gap: 4px; }
.zoom-btn { padding: 4px 12px; border-radius: 20px; font-size: 11px; cursor: pointer; font-weight: 500; border: 1px solid var(--border); background: none; color: var(--t3); font-family: var(--sans); transition: all 0.12s; }
.zoom-btn:hover  { color: var(--t2); border-color: var(--border2); }
.zoom-btn.active { background: var(--bg3); color: var(--t1); border-color: var(--border2); font-weight: 600; }
.legend { display: flex; align-items: center; gap: 12px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--t3); font-weight: 500; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.order-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); align-items: center; }
.order-row:last-child { border-bottom: none; }
.order-row:hover { background: var(--bg3); }
.oee-mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 8px; padding: 14px; }
.oee-mini-cell { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px; cursor: pointer; transition: all 0.12s; }
.oee-mini-cell:hover { border-color: var(--border2); box-shadow: var(--shadow-sm); }
.oee-mini-name { font-size: 12px; font-weight: 600; color: var(--t1); margin-bottom: 6px; }
.oee-mini-val  { font-family: var(--mono); font-size: 22px; font-weight: 600; }
.oee-mini-bar  { height: 3px; background: var(--border); border-radius: 2px; margin-top: 6px; }
.oee-mini-fill { height: 3px; border-radius: 2px; }

/* ══════════════════════════════════════
   PLANNING — GANTT TIMELINE (v2 classes)
══════════════════════════════════════ */

/* ── Gantt ruler hourly ticks ── */
.gantt-ruler {
  display: flex;
  align-items: stretch;
  height: 32px;
  overflow: hidden;
  position: relative;
}
.gantt-hour {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 0 4px 4px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t3);
  border-left: 1px solid var(--border);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}
.gantt-hour.is-now {
  color: var(--teal);
  font-weight: 700;
  border-left-color: var(--teal);
}
.gantt-hour.is-day-start {
  border-left: 2px solid var(--border2);
}
.day-label {
  display: block;
  font-size: 8px;
  font-weight: 600;
  color: var(--t2);
  margin-bottom: 1px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Gantt track (scrollable rows) ── */
.gtrack {
  position: relative;
  min-height: 68px;
  background: var(--bg1);
  flex: 1;
}

/* ── Machine label cell ── */
.gmach {
  width: 160px;
  min-width: 160px;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
  justify-content: center;
}
.gmach-meta {
  display: flex;
  align-items: center;
  gap: 5px;
}
.gdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.gmach-status {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
}
.gmach-order {
  font-size: 9px;
  color: var(--t3);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Gantt blocks ── */
.gblock {
  position: absolute;
  top: 8px;
  height: calc(100% - 16px);
  border-radius: var(--r-sm);
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.12s, box-shadow 0.12s, transform 0.12s;
  min-width: 4px;
  z-index: 2;
}
.gblock[draggable] {
  cursor: grab;
}
.gblock[draggable]:active {
  cursor: grabbing;
  transform: scale(1.02);
}
.gblock:hover {
  opacity: 0.85;
  box-shadow: var(--shadow-md);
  z-index: 3;
}
.gb-current {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  box-shadow: 0 2px 6px rgba(22,163,74,0.30);
}
.gb-planned {
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
  border: 1px solid #cbd5e1;
}
.gblock-inner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  padding: 0 8px;
  gap: 1px;
}
.gblock-order {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.gb-planned .gblock-order {
  color: var(--t2);
}
.gblock-part {
  font-size: 9px;
  color: rgba(255,255,255,0.80);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.gb-planned .gblock-part {
  color: var(--t3);
}
.gblock-end {
  font-size: 8px;
  color: rgba(255,255,255,0.65);
  font-family: var(--mono);
  white-space: nowrap;
  margin-top: 1px;
}
.gb-planned .gblock-end {
  color: var(--t4);
}

/* Progress bar inside current block */
.gblock-prog {
  height: 3px;
  background: rgba(255,255,255,0.25);
  border-radius: 2px;
  margin-top: 3px;
  overflow: hidden;
}
.gblock-prog-fill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transition: width 0.4s;
}

/* ── Now line ── */
.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--teal);
  z-index: 5;
  pointer-events: none;
}
.now-line::before {
  content: '';
  position: absolute;
  top: 0;
  left: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
}
.now-line-head {
  position: absolute;
  top: 0;
  left: 4px;
  font-size: 8px;
  font-weight: 700;
  color: var(--teal);
  font-family: var(--mono);
  background: var(--bg1);
  padding: 1px 3px;
  border-radius: 3px;
  border: 1px solid var(--teal-bdr);
  white-space: nowrap;
  line-height: 1.4;
}

/* ══════════════════════════════════════
   PLANNING — KPI STRIP (planning names)
══════════════════════════════════════ */
/* Legacy alias names used in planning.html — map to the standard tokens */
.kpi-lbl  { font-size: 10px; color: var(--t3); text-transform: uppercase; letter-spacing: 0.9px; font-weight: 600; }
.kpi-val  { font-size: 22px; font-weight: 600; font-family: var(--mono); line-height: 1; color: var(--t1); }
.kpi-sub  { font-size: 10px; color: var(--t3); }

/* KPI cell color accents */
.kpi-cell.c-green .kpi-val,
.kpi-cell.c-green .kpi-value { color: var(--green); }
.kpi-cell.c-blue  .kpi-val,
.kpi-cell.c-blue  .kpi-value { color: var(--blue);  }
.kpi-cell.c-teal  .kpi-val,
.kpi-cell.c-teal  .kpi-value { color: var(--teal);  }
.kpi-cell.c-amber .kpi-val,
.kpi-cell.c-amber .kpi-value { color: var(--amber); }
.kpi-cell.c-violet .kpi-val,
.kpi-cell.c-violet .kpi-value { color: var(--teal); }

/* ══════════════════════════════════════
   PLANNING — ORDER QUEUE GRID
══════════════════════════════════════ */
.order-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

/* Order machine card */
.ocard {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.ocard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.ocard-machine {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ocard-mname {
  font-size: 13px;
  font-weight: 600;
  color: var(--t1);
}
.ocard-count {
  font-size: 10px;
  color: var(--t3);
  font-weight: 600;
  font-family: var(--mono);
  background: var(--bg3);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Order rows inside card */
.order-rows {
  display: flex;
  flex-direction: column;
}
.orow {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
  transition: background 0.1s;
}
.orow:last-of-type {
  border-bottom: none;
}
.orow:hover {
  background: var(--bg3);
}
.orow.is-current {
  background: var(--green-dim);
  border-left: 3px solid var(--green);
}
.orow.is-current:hover {
  background: var(--green-bg);
}

/* Sequence badge + duration */
.or-seq-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding-top: 2px;
}
.or-seq-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  flex-shrink: 0;
}
.is-now {
  background: linear-gradient(135deg, var(--green) 0%, #15803d 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(22,163,74,0.30);
}
.is-plan {
  background: var(--bg3);
  color: var(--t2);
  border: 1px solid var(--border2);
}
.or-dur {
  font-size: 9px;
  color: var(--t3);
  font-family: var(--mono);
  text-align: center;
}

/* Order text info */
.or-order {
  font-size: 12px;
  font-weight: 600;
  color: var(--t1);
  font-family: var(--mono);
  line-height: 1.2;
}
.or-part {
  font-size: 11px;
  color: var(--t2);
  margin-top: 2px;
}
.or-mould {
  font-size: 10px;
  color: var(--t3);
  font-family: var(--mono);
  margin-top: 2px;
}

/* Right side — status + qty */
.or-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.or-status {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}
.s-running {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-bdr);
}
.s-planned {
  background: var(--slate-bg);
  color: var(--slate);
  border: 1px solid var(--slate-bdr);
}
.or-qty {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--t3);
  font-weight: 500;
}

/* Order card progress bar */
.orow-prog {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  padding: 0 14px 10px;
  align-items: center;
  margin-top: -6px;
  border-bottom: 1px solid var(--border);
}
.orow-prog-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.orow-prog-fill {
  height: 4px;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.5s;
}
.orow-prog-pct {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--green);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--t3);
  font-size: 13px;
  text-align: center;
  grid-column: 1 / -1;
}
.empty-icon {
  font-size: 32px;
  opacity: 0.6;
}

/* ══════════════════════════════════════
   PLANNING — MODAL (mfield form style)
══════════════════════════════════════ */
.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--t1);
  margin-bottom: 16px;
}
.mfield {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.mfield label {
  font-size: 10px;
  color: var(--t3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.mfield input,
.mfield select {
  background: var(--inset);
  border: 1px solid var(--border);
  color: var(--t1);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: var(--sans);
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
  margin-bottom: 0;
}
.mfield input:focus,
.mfield select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,0.10);
}
.mfield-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mfield-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  margin-top: 2px;
}
.mfield-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0 10px;
}

/* ── Statusbar meta span ── */
.st-meta {
  color: var(--t3);
  font-family: var(--mono);
  font-size: 10px;
}
/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE OVERRIDES — Mobile-first additions for Android/Chrome/WebView
   Breakpoints: 1200px · 992px · 768px · 576px
   Strategy: Augment existing rules — do NOT break desktop layout.
   All touch targets: minimum 44×44px (WCAG 2.5.5 / Android HIG)
══════════════════════════════════════════════════════════════════════════ */

/* ── Responsive utility classes ── */
.hide-mobile  { display: initial !important; }
.show-mobile  { display: none   !important; }
.hide-tablet  { display: initial !important; }
.show-tablet  { display: none   !important; }
.no-wrap      { white-space: nowrap; }
.scroll-x     { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Smooth scroll + tap highlight fix for Android ── */
html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  touch-action: manipulation;
}

/* ── Prevent iOS/Android font size inflation ── */
body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── Safe-area insets for notched phones ── */
.statusbar {
  padding-bottom: calc(5px + env(safe-area-inset-bottom));
  padding-left:  calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}
.topbar {
  padding-left:  calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}

/* ══════════════════════════════
   ≤ 1200px  (large tablet / small laptop)
══════════════════════════════ */
@media (max-width: 1200px) {
  /* KPI strip: 3 cols on first wrap */
  .kpi-strip { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

  /* Machine grid: slightly smaller min */
  .machine-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; padding: 10px 16px 80px; }

  /* Report/planning strips */
  .report-strip { grid-template-columns: repeat(3, 1fr); }
  .plan-strip   { grid-template-columns: repeat(3, 1fr); }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .alarm-strip   { grid-template-columns: repeat(2, 1fr); }

  /* Two-col wide collapses to equal cols */
  .two-col-wide { grid-template-columns: 1fr 1.2fr; }

  /* Order grid */
  .order-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

  /* Gantt */
  .gantt { min-width: 800px; }
  .gantt-header { grid-template-columns: 140px 1fr; }
  .gmach { width: 140px; min-width: 140px; }
  .gantt-row { }
}

/* ══════════════════════════════
   ≤ 992px  (tablet portrait / large phone landscape)
══════════════════════════════ */
@media (max-width: 992px) {
  /* Topbar: 2-row layout */
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 16px 4px;
    gap: 8px;
  }
  .brand { flex-shrink: 0; }
  .topbar-right { margin-left: auto; gap: 8px; }

  /* Nav: scrollable single row below brand */
  .nav {
    order: 10; /* push nav to second row */
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    gap: 2px;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn {
    flex: 0 0 auto;
    padding: 7px 14px;
    font-size: 12px;
    min-height: 34px;
  }

  /* KPI strip */
  .kpi-strip { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .kpi-value { font-size: 18px; }

  /* Strips */
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .alarm-strip   { grid-template-columns: repeat(2, 1fr); }
  .report-strip  { grid-template-columns: repeat(3, 1fr); }
  .plan-strip    { grid-template-columns: repeat(3, 1fr); }

  /* Layout grids */
  .two-col, .two-col-wide, .three-col { grid-template-columns: 1fr; }

  /* Machine grid */
  .machine-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); padding: 10px 14px 80px; }

  /* Tables: allow horizontal scroll */
  .table-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: inherit;
  }
  .mes-table { min-width: 600px; }
  .rank-table { min-width: 500px; }

  /* Gantt */
  .gantt-body { max-height: 360px; }
  .gantt { min-width: 700px; }

  /* Modals */
  .modal { width: calc(100% - 32px); max-width: 500px; padding: 20px; }

  /* Page body */
  .page-body { padding: 12px 14px 80px; }

  /* Sec header */
  .sec-header { padding: 10px 14px 6px; }

  /* Order grid */
  .order-grid { grid-template-columns: 1fr; }

  /* Panels */
  .panel-head { flex-wrap: wrap; gap: 8px; }

  /* Search bar full width */
  .search-bar { width: 200px; }

  /* Users strip */
  .usr-strip { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════
   ≤ 768px  (phone landscape / small tablet)
══════════════════════════════ */
@media (max-width: 768px) {
  /* Topbar tightened */
  .topbar { padding: 8px 12px 4px; gap: 6px; }
  .brand-sub { display: none; }
  .brand-sep { display: none; }
  .brand-name { font-size: 13px; }
  .brand-icon { width: 28px; height: 28px; font-size: 10px; }

  /* Topbar right — hide label text, keep chips */
  .topbar-user span { display: none; }
  .topbar-user { padding: 4px 8px; }
  .topbar-logout { padding: 4px 8px; font-size: 10px; }
  .shift-pill { padding: 4px 10px; font-size: 10px; }
  .clock { font-size: 11px; min-width: 58px; }

  /* Nav buttons larger tap targets */
  .nav-btn { padding: 8px 11px; font-size: 11px; min-height: 36px; }

  /* KPI strip: 3 per row */
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .kpi-cell  { padding: 9px 10px; }
  .kpi-label { font-size: 9px; letter-spacing: 0.5px; }
  .kpi-value { font-size: 16px; }
  .kpi-hint  { font-size: 9px; }

  /* Strips — 2 per row */
  .summary-strip,
  .alarm-strip   { grid-template-columns: repeat(2, 1fr); }
  .report-strip  { grid-template-columns: repeat(2, 1fr); }
  .plan-strip    { grid-template-columns: repeat(2, 1fr); }

  .sum-val, .asum-val, .rs-val, .ps-val { font-size: 20px; }
  .sum-cell, .asum-cell, .rs-cell, .ps-cell { padding: 10px 12px; }

  /* Machine grid: 2 cards per row */
  .machine-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 8px 12px 80px; }
  .oee-num { font-size: 24px; }

  /* Page body */
  .page-body { padding: 10px 12px 80px; gap: 10px; }

  /* Section header */
  .sec-header { padding: 8px 12px 4px; flex-wrap: wrap; gap: 8px; }
  .sec-actions { flex-wrap: wrap; gap: 4px; }

  /* Filter buttons — compact */
  .filter-btn { padding: 5px 10px; font-size: 11px; min-height: 32px; }

  /* Tables in scroll wrappers */
  .mes-table { min-width: 520px; font-size: 11px; }
  .mes-table th { padding: 8px 10px; }
  .mes-table td { padding: 8px 10px; }

  /* Panels */
  .panel-head { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .panel-body { padding: 12px; }
  .panel-title { font-size: 10px; }

  /* Modals — full width with margin */
  .modal { width: calc(100% - 24px); padding: 18px 16px; border-radius: var(--r-md); }
  .modal h3 { font-size: 14px; margin-bottom: 14px; }
  .modal-footer { flex-direction: column-reverse; gap: 8px; }
  .modal-footer .btn { width: 100%; min-height: 44px; justify-content: center; }
  .mfield-row { grid-template-columns: 1fr; } /* stack form rows */
  .mfield input, .mfield select { min-height: 42px; font-size: 15px; } /* prevent iOS zoom */

  /* Btn standard size */
  .btn { min-height: 36px; padding: 7px 14px; font-size: 12px; }
  .btn.primary { min-height: 40px; }

  /* Search bar */
  .search-bar { width: 100%; min-height: 38px; font-size: 15px; } /* 15px stops iOS zoom */

  /* Hero section */
  .hero { padding: 12px; flex-direction: column; align-items: flex-start; gap: 10px; }
  .hero-name { font-size: 17px; }
  .hero-meta { font-size: 11px; }
  .hero > div:last-child { width: 100%; justify-content: flex-start; flex-wrap: wrap; }

  /* Breakdown banner */
  .breakdown-banner {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    padding: 14px;
  }
  .breakdown-banner > div:last-child { width: 100%; justify-content: space-between; }
  .bb-timer { font-size: 28px; }

  /* OEE big panel */
  .oee-big-num { font-size: 48px; }
  .apq-big { gap: 0; }

  /* Alarm cards */
  .alarm-card { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
  .alarm-card > div:last-child { width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .alarm-duration { font-size: 24px; }

  /* Gantt: horizontal scroll */
  .gantt-shell { overflow: hidden; }
  .gantt { min-width: 620px; }
  .gantt-body { max-height: 300px; }
  .gantt-header { grid-template-columns: 120px 1fr; }
  .gmach { width: 120px; min-width: 120px; padding: 8px 10px; }
  .gmach-name { font-size: 11px; }

  /* Zoom buttons wrap */
  .zoom-btns { flex-wrap: wrap; gap: 4px; }
  .zoom-btn { padding: 5px 10px; min-height: 32px; }

  /* Planning order queue */
  .order-grid { grid-template-columns: 1fr; }
  .orow { grid-template-columns: 44px 1fr auto; gap: 8px; padding: 8px 10px; }

  /* Legend items */
  .legend { flex-wrap: wrap; gap: 8px; }

  /* Status bar */
  .statusbar { flex-direction: column; align-items: flex-start; gap: 3px; padding: 6px 12px; font-size: 9px; }
  .statusbar > span:last-child { display: none; } /* hide API endpoint on mobile */

  /* Users strip */
  .usr-strip { grid-template-columns: repeat(2, 1fr); }

  /* Reports chart */
  .chart-wrap { min-height: 200px; }

  /* Chart tabs */
  .chart-tabs { flex-wrap: wrap; gap: 4px; }
  .chart-tab  { flex: 1 1 auto; text-align: center; min-height: 34px; }

  /* OEE mini grid */
  .oee-mini-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 10px; }

  /* Rank table */
  .rank-table { min-width: 460px; font-size: 11px; }
  .rank-table th, .rank-table td { padding: 7px 10px; }

  /* Declare button */
  .btn-declare { width: 100%; min-height: 42px; }
  .btn-declare-sm { min-height: 30px; padding: 4px 10px; }

  /* Stop/reason panel */
  .reason-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Show/hide helpers activate */
  .hide-mobile { display: none !important; }
  .show-mobile { display: initial !important; }
}

/* ══════════════════════════════
   ≤ 576px  (phone portrait — primary mobile target)
══════════════════════════════ */
@media (max-width: 576px) {
  /* Topbar: brand row + right, then nav row */
  .topbar { padding: 7px 12px 0; }

  /* Nav: full width scrollable row */
  .nav { padding-bottom: 7px; }
  .nav-btn { padding: 8px 12px; font-size: 11px; }

  /* KPI strip: 2 per row (most critical KPIs) */
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .kpi-cell  { padding: 8px 10px; border-right: 1px solid var(--border); }
  .kpi-cell:nth-child(2n) { border-right: none; }
  .kpi-value { font-size: 15px; }
  .kpi-label { font-size: 9px; }

  /* Strips — single column */
  .summary-strip,
  .alarm-strip   { grid-template-columns: repeat(2, 1fr); }
  .report-strip  { grid-template-columns: repeat(2, 1fr); }
  .plan-strip    { grid-template-columns: repeat(2, 1fr); }
  .sum-val, .asum-val, .rs-val, .ps-val { font-size: 18px; }

  /* Machine grid: 1 card per row on very small phones, 2 on normal */
  .machine-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 8px 10px 80px; }
  .mcard-name   { font-size: 11px; }
  .oee-num      { font-size: 22px; }
  .mcard-oee    { padding: 8px 10px 6px; }
  .mcard-head   { padding: 8px 10px; }
  .mcard-foot   { padding: 6px 10px; gap: 2px; flex-wrap: wrap; }
  .mf-val       { font-size: 11px; }
  .apq-val      { font-size: 11px; }
  .apq-lbl      { font-size: 8px; }

  /* Page body */
  .page-body { padding: 8px 10px 80px; gap: 8px; }

  /* Panel head: stack vertically */
  .panel-head { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 12px; }
  .panel-head .btn,
  .panel-head button { width: 100%; min-height: 44px; }
  .panel-head > div:last-child { width: 100%; flex-direction: column; gap: 6px; }
  .panel-head .search-bar { width: 100%; }

  /* Section header */
  .sec-header { padding: 8px 10px 4px; gap: 6px; }
  .sec-actions { width: 100%; }
  .filter-btn  { flex: 1 1 auto; text-align: center; min-height: 36px; }

  /* Tables */
  .mes-table { min-width: 480px; font-size: 11px; }
  .mes-table th, .mes-table td { padding: 7px 8px; }

  /* Buttons — full width in stacked contexts */
  .btn { font-size: 13px; }
  .btn-declare { font-size: 12px; }

  /* Modals */
  .modal { width: calc(100% - 16px); padding: 16px 14px; }
  .modal-backdrop { align-items: flex-end; } /* slide up from bottom on phones */
  .modal { border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 90vh; overflow-y: auto; }
  .modal h3 { font-size: 13px; }
  .mfield label { font-size: 9px; }
  .mfield input, .mfield select { min-height: 44px; font-size: 16px; } /* 16px critical — prevents iOS zoom */

  /* Login page */
  .login-box { padding: 28px 20px; }
  .login-brand-icon { width: 46px; height: 46px; font-size: 17px; }
  .login-brand-name { font-size: 15px; }
  .login-input { font-size: 16px; min-height: 44px; } /* 16px — stops iOS/Android zoom */
  .login-btn   { min-height: 48px; font-size: 15px; }

  /* Hero */
  .hero { padding: 10px 12px; }
  .hero-name { font-size: 15px; }
  .hero-meta { font-size: 10px; }

  /* Breakdown banner */
  .bb-title { font-size: 13px; }
  .bb-sub   { font-size: 11px; }
  .bb-timer { font-size: 26px; }

  /* OEE panel big number */
  .oee-big-num { font-size: 42px; }
  .oee-big-lbl { font-size: 10px; }

  /* Order detail grid */
  .order-detail-grid { grid-template-columns: 1fr 1fr !important; }

  /* Alarm cards */
  .alarm-machine { font-size: 13px; }
  .alarm-reason  { font-size: 11px; }
  .alarm-meta    { font-size: 10px; }

  /* Stop reason grid */
  .reason-grid { grid-template-columns: 1fr !important; }
  .reason-item { padding: 10px 12px; min-height: 44px; }

  /* Pareto */
  .pareto-head { font-size: 11px; }

  /* Alarm summary strip values */
  .asum-val { font-size: 20px; }

  /* Plan strip / report strip */
  .ps-val, .rs-val { font-size: 18px; }

  /* Users strip */
  .usr-strip { grid-template-columns: repeat(2, 1fr); }
  .usc-val   { font-size: 18px; }

  /* OEE mini: 2 per row */
  .oee-mini-grid { grid-template-columns: repeat(2, 1fr); padding: 8px; }
  .oee-mini-val  { font-size: 18px; }

  /* Chart */
  .chart-wrap { min-height: 180px; }

  /* Gantt */
  .gantt-body { max-height: 260px; }
  .gmach { width: 100px; min-width: 100px; }
  .gmach-name { font-size: 10px; }
  .gmach-type { font-size: 9px; }

  /* Planning order row */
  .order-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 12px; }
  .order-row > div { width: 100%; }

  /* Status bar */
  .statusbar { padding: 6px 10px; font-size: 9px; }

  /* Show tablet helpers */
  .hide-tablet { display: none !important; }
  .show-tablet { display: initial !important; }
}

/* ══════════════════════════════
   Extra: very small phones (≤ 400px)
══════════════════════════════ */
@media (max-width: 400px) {
  .machine-grid { grid-template-columns: 1fr; }
  .kpi-strip    { grid-template-columns: repeat(2, 1fr); }
  .kpi-value    { font-size: 14px; }
  .nav-btn      { padding: 7px 10px; font-size: 10px; }
  .brand-name   { font-size: 12px; }
  .topbar-user  { display: none; } /* hide user chip on tiny screens */
}

/* ══════════════════════════════
   TV / Andon — responsive overrides
   (tv.html has its own internal CSS; these patch common elements)
══════════════════════════════ */
@media (max-width: 992px) {
  /* tv.html grid handled internally, but add safe-area */
  .tv-topbar {
    padding-left:  calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }
}

/* ══════════════════════════════
   Touch UX improvements
══════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices — avoids sticky hover states */
  .mcard:hover           { transform: none; box-shadow: var(--shadow-sm); }
  .btn:hover             { transform: none; }
  .btn.primary:hover     { transform: none; }
  .nav-btn:hover         { background: none; color: var(--t3); }
  .nav-btn.active:hover  { background: var(--bg3); color: var(--t1); }
  .filter-btn:hover      { background: var(--bg1); color: var(--t3); }
  .filter-btn.active:hover { background: var(--bg3); color: var(--t1); }

  /* Bigger tap targets for interactive rows */
  .mes-table td, .mes-table tr { height: auto; }
  .mes-table tr { min-height: 44px; }
  .rank-table tr { min-height: 44px; }

  /* Explicit active states for touch feedback */
  .btn:active         { opacity: 0.75; }
  .nav-btn:active     { background: var(--bg3); }
  .filter-btn:active  { background: var(--bg3); }
  .mcard:active       { opacity: 0.85; }
  .alarm-card:active  { opacity: 0.85; }
  .orow:active        { background: var(--bg3); }
}

/* ══════════════════════════════
   Scrollable table wrapper helper
   (Applied via JS on mobile — see responsive JS)
══════════════════════════════ */
.rsp-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: inherit;
  /* Subtle gradient hint that table scrolls */
  background:
    linear-gradient(to right, var(--bg1) 30%, rgba(255,255,255,0)),
    linear-gradient(to left,  var(--bg1) 30%, rgba(255,255,255,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%;
  background-attachment: local;
}

/* ══════════════════════════════
   Mobile nav hamburger (optional progressive enhancement)
   Classes added by responsive JS when screen < 576px
══════════════════════════════ */
.nav-hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--t2);
  min-width: 36px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-hamburger.active { background: var(--bg3); border-color: var(--border2); }

/* Mobile collapsible nav (when hamburger is active) */
.nav.nav-collapsed {
  display: none;
}
.nav.nav-expanded {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0 8px;
}
.nav.nav-expanded .nav-btn {
  width: 100%;
  padding: 10px 14px;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}
.nav.nav-expanded .nav-btn.active {
  border-color: var(--border);
  background: var(--bg3);
}

/* Inline flex for nav when not collapsing */
.nav:not(.nav-collapsed):not(.nav-expanded) {
  display: flex;
}

/* ══════════════════════════════
   Table: show scroll hint on mobile
══════════════════════════════ */
@media (max-width: 768px) {
  .rsp-table-wrap::after {
    content: '';
    display: block;
    height: 0;
  }

  /* Orders table: hide less important columns */
  .mes-table .col-hide-sm { display: none; }

  /* Make progress cells compact */
  .prog-cell { gap: 4px; }
  .prog-track-sm { min-width: 30px; }
  .prog-pct { font-size: 11px; min-width: 28px; }

  /* Stop-wrap table max-height increase for mobile */
  .stop-wrap { max-height: 360px; }
}

/* ══════════════════════════════
   Machine detail page mobile fixes
══════════════════════════════ */
@media (max-width: 768px) {
  /* Order detail stat grid */
  .order-detail-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; }

  /* Declare stop modal reason list */
  .sr-comment { font-size: 16px; } /* prevent iOS zoom */

  /* Downtime log */
  .dl-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ══════════════════════════════
   Planning page mobile fixes
══════════════════════════════ */
@media (max-width: 768px) {
  /* Planning modal full screen on mobile */
  .plan-modal .modal {
    width: calc(100% - 16px);
    max-height: 85vh;
    overflow-y: auto;
  }

  /* Gantt horizontal scroll hint text */
  .gantt-scroll-hint {
    display: block;
    font-size: 10px;
    color: var(--t3);
    text-align: center;
    padding: 4px;
    font-family: var(--mono);
  }
}
.gantt-scroll-hint { display: none; }

/* ══════════════════════════════
   Reports page mobile fixes
══════════════════════════════ */
@media (max-width: 768px) {
  /* Date range inputs stack */
  .report-date-row { flex-direction: column !important; gap: 8px !important; }
  .report-date-row input,
  .report-date-row select { width: 100%; min-height: 42px; font-size: 16px; }

  /* OEE gauge wrap */
  .gauge-wrap { gap: 6px; flex-wrap: wrap; justify-content: center; }
}

/* ══════════════════════════════
   Login page mobile
══════════════════════════════ */
@media (max-width: 576px) {
  .login-page::before { background-size: 24px 24px; }
  .login-box { border-radius: var(--r-md); margin: 16px; width: calc(100% - 32px); }
  .login-brand { margin-bottom: 20px; gap: 8px; }
  .login-form { gap: 12px; }
}

/* ══════════════════════════════
   Landscape phone — special case
   Shrink heights when viewport is wider than tall
══════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { height: auto; min-height: 44px; padding: 4px 12px; }
  .kpi-strip { grid-template-columns: repeat(5, 1fr); }
  .kpi-cell  { padding: 6px 8px; }
  .kpi-value { font-size: 14px; }
  .machine-grid { padding-bottom: 60px; }
  .page-body { padding: 6px 10px 60px; gap: 6px; }
  .statusbar { padding: 3px 12px; }
  .nav-btn   { padding: 5px 10px; }
}

/* ══════════════════════════════
   Language switcher (EN/FR)
══════════════════════════════ */
.mes-lang-switch {
  display: flex; align-items: center; gap: 2px;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 2px; flex-shrink: 0;
}
.mes-lang-btn {
  font-family: inherit; font-size: 11px; font-weight: 700;
  letter-spacing: .03em; color: #94a3b8; background: none; border: none;
  padding: 4px 9px; border-radius: 6px; cursor: pointer;
  transition: background .15s, color .15s;
}
.mes-lang-btn:hover { color: #3d4a5c; }
.mes-lang-btn.active { background: #0d9488; color: #fff; }

@media (max-width: 640px) {
  .mes-lang-btn { padding: 4px 7px; font-size: 10px; }
}
