:root {
  --navy: #0c1f3d;
  --navy-light: #163261;
  --navy-soft: #1f4277;
  --navy-hover: #132746;
  --sidebar-w: 230px;
  --orange: #f37021;
  --orange-dark: #d95e13;
  --orange-light: #fff2ea;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --yellow: #f59e0b;
  --yellow-light: #fef3c7;
  --purple: #8b5cf6;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 16px rgba(12, 31, 61, 0.07);
  --shadow-lg: 0 10px 30px rgba(12, 31, 61, 0.12);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.erp-shell { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ================= TOPBAR ================= */
.topbar {
  background: var(--navy);
  color: #fff;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 120;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; }
.brand:hover { text-decoration: none; }
.logo { height: 34px; width: auto; object-fit: contain; flex-shrink: 0; }
.brand-title { font-size: 15px; font-weight: 800; color: #fff; white-space: nowrap; }
.brand-sub { font-size: 11px; color: #9fb3cc; white-space: nowrap; }

.topbar-search {
  position: relative;
  flex: 1;
  max-width: 480px;
}
.search-box {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 0 10px;
  height: 38px;
  gap: 8px;
}
.search-box:focus-within { background: rgba(255,255,255,0.22); border-color: var(--orange); }
.search-icon { font-size: 13px; opacity: 0.8; }
.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 13px;
  font-family: inherit;
}
.search-box input::placeholder { color: #a9bed7; }
.search-clear { background: transparent; border: none; color: #cbd7e6; font-size: 12px; cursor: pointer; padding: 2px 4px; }
.search-dropdown {
  position: absolute;
  top: 44px;
  left: 0;
  right: 0;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}
.search-dropdown.open { display: block; }
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  font-size: 12.5px;
}
.search-item:hover { background: #f8fafc; }
.search-tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; }
.search-empty { padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center; }

.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.live-clock { font-family: monospace; font-size: 12px; color: #b8cbe0; white-space: nowrap; margin-left: 6px; }

/* ================= BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
  min-height: 38px;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); color: #fff; }
.btn-outline { background: transparent; border-color: rgba(255,255,255,0.3); color: #fff; }
.btn-outline:hover { background: rgba(255,255,255,0.12); color: #fff; }
.btn-orange-outline { background: transparent; border-color: var(--orange); color: var(--orange); }
.btn-orange-outline:hover { background: var(--orange); color: #fff; }
.btn-whatsapp { background: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1eb857; color: #fff; }
.btn-gdrive { background: rgba(255,255,255,0.14); color: #fff; }
.btn-gdrive:hover { background: rgba(255,255,255,0.24); color: #fff; }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #eef2f7; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: #b91c1c; color: #fff; }
.btn-sm { font-size: 12px; padding: 5px 10px; min-height: 32px; border-radius: 7px; }
.btn-xs { font-size: 11px; padding: 3px 8px; min-height: 26px; border-radius: 6px; }

/* ================= SHELL ================= */
.erp-body { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: var(--sidebar-w);
  background: #091830;
  color: #c4d4ea;
  padding: 12px 8px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.06);
  z-index: 90;
}
.sidebar-section-title {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #7f99ba;
  padding: 12px 10px 4px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.snav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #c4d4ea;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 40px;
}
.snav:hover { background: rgba(255,255,255,0.07); color: #fff; }
.snav.active { background: var(--orange); color: #fff; }
.snav-icon { font-size: 16px; width: 20px; text-align: center; }
.snav-label { flex: 1; }
.snav-badge {
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.snav-badge.orange { background: var(--orange); }
.snav-badge.red { background: var(--red); }
.snav-badge.yellow { background: var(--yellow); }
.sidebar-footer { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 11px; color: #8fa7c5; }
.role-desc { font-size: 10.5px; color: #6e88aa; margin-top: 2px; }
.sidebar-backdrop { display: none; }

.erp-main { flex: 1; min-width: 0; padding: 16px 20px 24px; }

/* ================= MODULES ================= */
.module { display: none; animation: modFade 0.12s ease; }
.module.active { display: block; }
@keyframes modFade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.mod-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.mod-head h1 { font-size: 22px; font-weight: 900; color: var(--navy); }
.mod-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { font-size: 12.5px; color: var(--muted); }

/* ================= CARDS & KPI ================= */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.card-head h2 { font-size: 16px; font-weight: 800; color: var(--navy); }
.link-btn { background: none; border: none; color: var(--orange); font-size: 12.5px; font-weight: 700; cursor: pointer; font-family: inherit; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-top: 3px solid var(--navy);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-card:active { transform: scale(0.98); }
.kpi-card.kpi-orange { border-top-color: var(--orange); }
.kpi-card.kpi-red { border-top-color: var(--red); }
.kpi-card.kpi-yellow { border-top-color: var(--yellow); }
.kpi-icon { font-size: 21px; margin-bottom: 2px; }
.kpi-num { font-size: 22px; font-weight: 900; color: var(--navy); line-height: 1.1; margin-bottom: 2px; }
.kpi-label { font-size: 12px; font-weight: 700; color: #475569; margin-bottom: 3px; }
.kpi-sub { font-size: 11px; color: var(--muted); }

/* Quick actions row */
.quick-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: thin; }
.quick-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--navy);
  border-radius: 99px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 36px;
}
.quick-btn:hover { border-color: var(--orange); color: var(--orange); transform: translateY(-1px); }
.qb-icon { font-size: 14px; }
.qb-text { font-size: 12.5px; }

/* Alert ribbon */
.alert-ribbon { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.alert-item.red { background: var(--red-light); color: var(--red); border-left: 4px solid var(--red); }
.alert-item.yellow { background: var(--yellow-light); color: #b45309; border-left: 4px solid var(--yellow); }
.alert-item.blue { background: var(--blue-light); color: var(--blue); border-left: 4px solid var(--blue); }
.alert-action { font-size: 12px; text-decoration: underline; }

/* Dashboard 2 columns */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.eq-status-bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.eq-bar-row { font-size: 12.5px; }
.eq-bar-label { display: flex; justify-content: space-between; margin-bottom: 3px; font-weight: 600; }
.eq-bar-track { height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; }
.eq-bar-fill { height: 100%; border-radius: 99px; transition: width 0.3s; }
.idle-model-list { display: flex; flex-direction: column; gap: 6px; border-top: 1px dashed var(--border); padding-top: 10px; font-size: 12.5px; }
.idle-model-row { display: flex; justify-content: space-between; color: #475569; }

.mini-jobs { display: flex; flex-direction: column; gap: 8px; }

/* Sheet cards grid */
.sheet-cards-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.scard {
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  transition: all 0.15s;
}
.scard:hover { border-color: var(--orange); transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.sc-icon { font-size: 26px; }
.sc-t { font-size: 13.5px; font-weight: 800; color: var(--navy); }
.sc-s { font-size: 11px; color: var(--muted); }
.sc-ar { font-size: 14px; color: var(--orange); margin-left: auto; font-weight: 800; }

/* ================= TABLES ================= */
.table-card { padding: 0; overflow: hidden; }
.data-table-wrap { overflow-x: auto; scrollbar-width: thin; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  background: #f1f5f9;
  color: #334155;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  white-space: nowrap;
}
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}
.data-table tr:hover td { background: #fafcff; }

/* Filter row */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.select-filter, .search-input-inline {
  padding: 7px 11px;
  font-size: 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  outline: none;
}
.search-input-inline { flex: 1; min-width: 200px; }
.search-input-inline:focus, .select-filter:focus { border-color: var(--orange); }
.chips-group { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; }
.chip {
  background: #fff;
  border: 1.5px solid var(--border);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 32px;
}
.chip:hover { border-color: var(--orange); color: var(--orange); }
.chip.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.filter-count { font-size: 12px; color: var(--muted); margin-left: auto; }

/* Badges */
.badge-st {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-st.green { background: var(--green-light); color: var(--green); }
.badge-st.blue { background: var(--blue-light); color: var(--blue); }
.badge-st.red { background: var(--red-light); color: var(--red); }
.badge-st.orange { background: var(--orange-light); color: var(--orange-dark); }
.badge-st.yellow { background: var(--yellow-light); color: #b45309; }
.badge-st.gray { background: #eef2f7; color: var(--muted); }
.badge-code { background: #eef2f7; color: var(--navy); padding: 2px 7px; border-radius: 4px; font-weight: 800; font-size: 11px; font-family: monospace; }
.status-select { font-size: 11.5px; border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; font-family: inherit; background: #fff; }

/* ================= ORDERS ================= */
.order-pipeline { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: thin; }
.pipe-tab {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: #334155;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 40px;
}
.pipe-tab:hover { border-color: var(--orange); color: var(--orange); }
.pipe-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.order-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ocard {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.ocard-top { display: flex; justify-content: space-between; align-items: center; }
.ocard-id { font-size: 11.5px; font-weight: 800; color: var(--muted); font-family: monospace; }
.ocard-title { font-weight: 800; color: var(--navy); font-size: 14px; }
.ocard-sub { color: #475569; font-size: 12px; }
.ocard-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.ocard-actions { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

/* ================= DISPATCH ================= */
.day-chip-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.day-chip-label { font-size: 13px; font-weight: 800; color: var(--navy); }
.day-chip-list { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; scrollbar-width: thin; }
.dispatch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.job-item {
  background: var(--card);
  border-radius: 10px;
  padding: 13px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  font-size: 13px;
  margin-bottom: 10px;
}
.job-item.in { border-left-color: var(--red); }
.job-item.out { border-left-color: var(--green); }
.job-badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; margin-bottom: 4px; }
.job-badge.in { background: var(--red-light); color: var(--red); }
.job-badge.out { background: var(--green-light); color: var(--green); }
.job-model { font-weight: 800; font-size: 14px; color: var(--navy); margin-bottom: 2px; }
.job-addr { color: #475569; font-size: 12px; margin-bottom: 4px; }
.job-owner { color: var(--muted); font-size: 11px; }
.job-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* ================= MAINTENANCE ================= */
.repeat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.repeat-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
}
.repeat-num { font-size: 20px; font-weight: 900; color: var(--orange-dark); }
.repeat-label { font-size: 12px; font-weight: 800; color: var(--navy); }
.repeat-sub { font-size: 11px; color: var(--muted); }

/* ================= INVENTORY ================= */
.inv-list { display: flex; flex-direction: column; gap: 12px; }
.inv-item { font-size: 13px; }
.inv-row1 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.inv-name { font-weight: 800; color: var(--navy); }
.inv-sku { font-size: 11.5px; color: var(--muted); font-family: monospace; }
.inv-bar-wrap { height: 10px; background: #eef2f7; border-radius: 99px; overflow: hidden; position: relative; }
.inv-bar-fill { height: 100%; border-radius: 99px; transition: width 0.3s; }
.inv-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.memo-box { background: var(--orange-light); border-left: 4px solid var(--orange); padding: 12px 14px; border-radius: 8px; font-size: 13px; color: #7c2d12; line-height: 1.6; }

/* ================= CUSTOMERS ================= */
.cust-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.ccard {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ccard-name { font-weight: 900; color: var(--navy); font-size: 14px; }
.ccard-sub { color: #475569; font-size: 12px; }
.ccard-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ================= SHEETS HUB ================= */
.sheet-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: thin; }
.sheet-tab {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: #334155;
  font-size: 13.5px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 44px;
}
.sheet-tab:hover { border-color: var(--orange); color: var(--orange); }
.sheet-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.sheet-info-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.sheet-title-full { font-size: 16px; font-weight: 900; color: var(--navy); }
.sheet-hint { font-size: 12px; color: var(--muted); }
.subtabs-bar {
  background: #eef2f7;
  border: 1px solid var(--border);
  border-top: none;
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.subtab {
  background: #fff;
  border: 1px solid var(--border);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 32px;
}
.subtab:hover { color: var(--orange); border-color: var(--orange); }
.subtab.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.iframe-container {
  position: relative;
  width: 100%;
  height: 76vh;
  min-height: 480px;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  overflow: hidden;
}
.iframe-container iframe { width: 100%; height: 100%; border: 0; display: block; }
.iframe-container.fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  border: none;
}
.frame-loader {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 2;
  transition: opacity 0.25s;
  font-size: 14px;
  color: #334155;
  padding: 20px;
  text-align: center;
}
.frame-loader.hidden { opacity: 0; pointer-events: none; }
.frame-loader .spinner {
  width: 38px;
  height: 38px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loader-sub { font-size: 12px; color: var(--muted); max-width: 520px; }
@keyframes spin { to { transform: rotate(360deg); } }
.view-mode-bar {
  background: #eef2f7;
  border: 1px solid var(--border);
  border-top: none;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  border-radius: 0 0 var(--radius) var(--radius);
}
.view-chip {
  background: #fff;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  min-height: 30px;
}
.view-chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.snapshot-panel {
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.snapshot-head {
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: #f8fafc;
  user-select: none;
}
.snapshot-title { font-size: 14.5px; font-weight: 800; color: var(--navy); }
.snapshot-toggle { font-size: 12px; color: var(--muted); }
.snapshot-body { display: none; padding: 14px 16px; }
.snapshot-body.open { display: block; }

/* ================= AI ================= */
.ai-hero {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.ai-hero-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ai-icon { font-size: 32px; }
.ai-search-row { display: flex; gap: 10px; margin-bottom: 12px; }
.ai-search-row input {
  flex: 1;
  padding: 12px 14px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  outline: none;
  font-family: inherit;
}
.ai-search-row input:focus { border-color: var(--orange); }
.ai-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.ai-result {
  display: none;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.65;
}
.ai-sources { font-size: 11px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 10px; }
.ai-examples { margin-top: 18px; border-top: 1px dashed var(--border); padding-top: 14px; font-size: 12px; color: var(--muted); }
.ai-ex-title { font-weight: 800; color: var(--navy); margin-bottom: 6px; }
.ai-examples ul { padding-left: 18px; line-height: 1.7; }
.ai-examples code { background: #eef2f7; padding: 1px 6px; border-radius: 4px; font-size: 11.5px; }

/* ================= SETTINGS ================= */
.ref-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 20px; }
.ref-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.ref-card h3 { font-size: 15px; font-weight: 900; color: var(--navy); margin-bottom: 10px; }
.ref-card ul { padding-left: 18px; font-size: 13px; color: #475569; }
.ref-card li { margin-bottom: 6px; }
.settings-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ================= FOOTER ================= */
.site-footer {
  background: var(--navy);
  color: #9fb3cc;
  padding: 16px 20px;
  font-size: 12px;
  margin-top: auto;
}
.footer-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.footer-links { display: flex; gap: 14px; flex-wrap: wrap; }
.footer-links a { color: #d0e0f5; }

/* ================= MOBILE BOTTOM NAV ================= */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: #091830;
  border-top: 1px solid rgba(255,255,255,0.1);
  justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,0.25);
}
.bnav {
  flex: 1;
  background: transparent;
  border: none;
  color: #9fb3cc;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  min-height: 48px;
}
.bnav:active { transform: scale(0.92); }
.bnav.active { color: var(--orange); }
.bnav-icon { font-size: 18px; line-height: 1; }

/* ================= MORE SHEET ================= */
.more-sheet { display: none; position: fixed; inset: 0; z-index: 220; }
.more-sheet.open { display: block; }
.more-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.more-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 12px 16px calc(14px + var(--safe-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,0.25);
  animation: sheetUp 0.18s ease;
  max-height: 80vh;
  overflow-y: auto;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.more-drag { width: 36px; height: 4px; background: #cbd5e1; border-radius: 99px; margin: 0 auto 12px; }
.more-title { font-size: 14px; font-weight: 900; color: var(--navy); margin-bottom: 12px; }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.more-btn {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
  color: var(--navy);
  cursor: pointer;
  font-family: inherit;
  position: relative;
  min-height: 62px;
}
.more-btn:active { background: #eef2f7; }
.mb-i { font-size: 20px; }
.mb-bdg { position: absolute; top: 6px; right: 8px; font-size: 10px; font-weight: 900; padding: 1px 6px; border-radius: 99px; color: #fff; }
.mb-bdg.red { background: var(--red); }
.more-cta-row { display: flex; gap: 8px; }

/* ================= MODALS ================= */
.modal { display: none; position: fixed; inset: 0; z-index: 230; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal::before { content: ''; position: absolute; inset: 0; background: rgba(12,31,61,0.55); }
.modal-card {
  position: relative;
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  padding: 20px;
  z-index: 1;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { font-size: 17px; font-weight: 900; color: var(--navy); }
.modal-close { background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { font-size: 12px; font-weight: 700; color: #475569; display: flex; flex-direction: column; gap: 4px; }
.form-full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 8px 10px;
  font-size: 13px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  outline: none;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--orange); }
textarea { resize: vertical; }

/* ================= DRAWER ================= */
.drawer { display: none; position: fixed; inset: 0; z-index: 240; }
.drawer.open { display: block; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(12,31,61,0.5); }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: #fff;
  box-shadow: -10px 0 30px rgba(0,0,0,0.25);
  padding: 20px;
  overflow-y: auto;
  animation: drawerIn 0.18s ease;
}
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

/* ================= TOAST ================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================= RESPONSIVE ================= */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .sheet-cards-grid { grid-template-columns: repeat(3, 1fr); }
  .order-grid { grid-template-columns: 1fr 1fr; }
  .cust-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 991px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: -230px;
    bottom: 0;
    transition: left 0.2s ease;
    z-index: 130;
    height: auto;
  }
  .sidebar.open { left: 0; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 56px 0 0 0;
    background: rgba(12,31,61,0.5);
    z-index: 125;
  }
  .sidebar.open ~ .sidebar-backdrop { display: block; }
  .erp-main { padding: 14px 14px 20px; }
  .dashboard-grid, .dispatch-grid { grid-template-columns: 1fr; }
  .kpi-grid-3 { grid-template-columns: 1fr 1fr; }
  .repeat-grid { grid-template-columns: 1fr 1fr; }
  .cust-grid { grid-template-columns: 1fr 1fr; }
  .sheet-cards-grid { grid-template-columns: 1fr 1fr; }
  .bottom-nav { display: flex; }
  .erp-main { padding-bottom: calc(78px + var(--safe-bottom)); }
  .toast { bottom: calc(76px + var(--safe-bottom)); }
  .hide-mobile { display: none !important; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-search { display: none; }
  .brand-sub { display: none; }
  .brand-title { font-size: 13.5px; }
  .logo { height: 26px; }
  .top-cta { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .kpi-num { font-size: 20px; }
  .quick-btn { padding: 6px 11px; font-size: 12px; }
  .order-grid { grid-template-columns: 1fr; }
  .repeat-grid, .cust-grid, .sheet-cards-grid, .kpi-grid-3, .ref-grid { grid-template-columns: 1fr; }
  .mod-head h1 { font-size: 19px; }
  .iframe-container { height: 64vh; min-height: 360px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .icon-only-mobile { padding: 5px 7px; min-height: 30px; }
}

/* Mobile topbar polish */
@media (max-width: 900px) {
  .live-clock { display: none !important; }
}
@media (max-width: 640px) {
  .topbar { height: 50px; }
  .topbar-left { gap: 6px; }
  .logo { height: 24px; }
  .brand-title { font-size: 12.5px; }
  .topbar-right { gap: 4px; }
  .topbar-right .btn { padding: 4px 6px; min-height: 28px; font-size: 11.5px; }
}
@media (max-width: 380px) {
  .btn-gdrive { display: none !important; }
}
