/* ERP Inventory — Main Stylesheet */
/* Mobile-first, Bootstrap-free, clean blue/white theme matching reference UI */

:root {
  --primary: #1976D2;
  --primary-dark: #1256A3;
  --primary-light: #E3F2FD;
  --accent: #0288D1;
  --success: #2E7D32;
  --danger: #C62828;
  --warning: #F57F17;
  --info: #0277BD;
  --text: #212121;
  --text-muted: #757575;
  --border: #E0E0E0;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);

  /* Layout Enhancement (Task 7) */
  --sidebar-w-desktop : 220px;
  --sidebar-w-tablet  : 64px;
  --topbar-h          : 56px;
  --bottomnav-h       : 64px;
  --content-max-w     : 100%;   /* full-width — no global cap */
  --form-max-w        : 100%;   /* forms use full available width */

  /* Spacing scale */
  --space-xs  : 4px;
  --space-sm  : 8px;
  --space-md  : 16px;
  --space-lg  : 24px;
  --space-xl  : 32px;

  /* Elevation */
  --shadow-sm : 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg : 0 8px 32px rgba(0,0,0,0.16);

  /* Sidebar colors */
  --sidebar-bg       : #0D47A1;
  --sidebar-text     : rgba(255,255,255,0.85);
  --sidebar-active   : #ffffff;
  --sidebar-active-bg: rgba(255,255,255,0.15);
  --sidebar-hover-bg : rgba(255,255,255,0.08);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }
body {
  font-family: 'Inter', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.lang-zh { font-family: 'Noto Sans SC', 'Inter', sans-serif; }
a { text-decoration: none; color: var(--primary); }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── Sidebar Overlay ── */
.sb-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,.4);
}
.sb-overlay.open { display: block; }

/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w-desktop);
  min-height: 100vh;
  background: linear-gradient(160deg, #1976D2 0%, #0d47a1 100%);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .25s ease, transform .25s ease;
}
.sb-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  display: flex; align-items: center; gap: 10px;
}
.sb-logo-icon {
  width: 34px; height: 34px;
  background: rgba(255,255,255,.2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff; flex-shrink: 0;
}
.sb-logo-text { font-size: 13px; font-weight: 700; color: #fff; line-height: 1.25; }
.sb-logo-sub  { font-size: 10px; color: rgba(255,255,255,.55); font-weight: 400; }

.sb-section-lbl {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: rgba(255,255,255,.5);
  padding: 18px 18px 6px;
  white-space: nowrap; overflow: hidden;
}
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,.65);
  transition: all .15s; cursor: pointer; text-decoration: none;
}
.sb-item:hover   { color: #fff; background: rgba(255,255,255,.13); text-decoration: none; }
.sb-item.active  { color: #fff; background: rgba(255,255,255,.2); border-right: 3px solid #fff; }
.sb-item i { width: 16px; text-align: center; font-size: 12px; opacity: .8; flex-shrink: 0; }
.sb-item span { white-space: nowrap; overflow: hidden; }
.sb-bottom {
  margin-top: auto; padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.18);
}
.sb-user { display: flex; align-items: center; gap: 10px; }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sb-user-name { font-size: 12px; font-weight: 600; color: #fff; }
.sb-user-role { font-size: 10px; color: rgba(255,255,255,.55); }

/* ═══════════════════════════════════════════════════════════════════
   MAIN WRAPPER
═══════════════════════════════════════════════════════════════════ */
.main {
  margin-left: var(--sidebar-w-desktop);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 8px rgba(25,118,210,.3);
}
.topbar-hamburger {
  display: none;
  width: 36px; height: 36px;
  border-radius: 8px; background: rgba(255,255,255,.15);
  border: none; cursor: pointer;
  align-items: center; justify-content: center;
  font-size: 15px; color: #fff; flex-shrink: 0;
}
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.topbar-btn {
  width: 34px; height: 34px;
  border-radius: 8px; background: rgba(255,255,255,.15);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff; transition: background .15s;
}
.topbar-btn:hover { background: rgba(255,255,255,.25); }
.lang-pill {
  display: flex; align-items: center;
  background: rgba(255,255,255,.15);
  border-radius: 20px; overflow: hidden;
  font-size: 11px; font-weight: 600; color: rgba(255,255,255,.6);
  cursor: pointer; text-decoration: none;
}
.lang-pill:hover { text-decoration: none; }
.lang-pill span { padding: 4px 10px; color: inherit; }
.lang-pill span.active { background: rgba(255,255,255,.3); color: #fff; }

/* ── Bottom Nav ── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--bottomnav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.bn-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; color: var(--text-muted);
  font-size: 10px; font-weight: 500; cursor: pointer;
  transition: color .2s; text-decoration: none;
}
.bn-item i { font-size: 20px; }
.bn-item.active, .bn-item:hover { color: var(--primary); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE SHELL
═══════════════════════════════════════════════════════════════════ */
/* Tablet: icon-only sidebar */
@media (min-width: 768px) and (max-width: 1199px) {
  .sidebar { width: var(--sidebar-w-tablet); }
  .sb-logo { padding: 16px 0; justify-content: center; }
  .sb-logo > div { display: none; }
  .sb-section-lbl { display: none; }
  .sb-item { padding: 12px 0; justify-content: center; gap: 0; }
  .sb-item i { width: auto; font-size: 18px; }
  .sb-item span { display: none; }
  .sb-bottom { padding: 10px 0; display: flex; justify-content: center; }
  .sb-user-name, .sb-user-role { display: none; }
  .main { margin-left: var(--sidebar-w-tablet); }
}

/* Mobile: slide-in sidebar + fixed topbar + bottom nav */
@media (max-width: 767px) {
  body { display: block; }
  .sidebar { width: var(--sidebar-w-desktop); transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar { position: fixed; top: 0; left: 0; right: 0; }
  .topbar-hamburger { display: flex; }
  .bottom-nav { display: flex; }
}

/* Section headers on dashboard */
.section-label {
  font-size: 13px; color: var(--text-muted); font-weight: 500;
  padding: 14px 16px 6px;
  letter-spacing: 0.2px;
}

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 12px 12px;
  overflow: hidden; /* mobile: clips border-radius */
}
.card-body { padding: 14px; }
.card-header {
  padding: 12px 14px;
  font-weight: 600; font-size: 15px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

/* Stats row (入库统计 / 出库统计) */
.stats-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 0 12px 4px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.stat-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.stat-icon.danger { background: #E53935; }
.stat-icon.success { background: #43A047; }
.stat-icon.warning { background: #FB8C00; }
.stat-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }

/* Icon Grid (管理, 单据, etc.) */
.icon-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
}
.icon-grid-item {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px 6px;
  gap: 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none; color: var(--text);
}
.icon-grid-item:nth-child(4n) { border-right: none; }
.icon-grid-item:nth-last-child(-n+4) { border-bottom: none; }
.icon-grid-item:active, .icon-grid-item:hover { background: var(--primary-light); }
.icon-grid-icon {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.icon-grid-label { font-size: 12px; font-weight: 500; color: var(--text); text-align: center; }

/* 3-col grid (Other section) */
.icon-grid-3 { grid-template-columns: repeat(3, 1fr); }
.icon-grid-3 .icon-grid-item:nth-child(3n) { border-right: none; }
.icon-grid-3 .icon-grid-item:nth-child(4n) { border-right: 1px solid var(--border); }

/* Pull to refresh hint */
.pull-hint {
  text-align: center; color: var(--text-muted);
  font-size: 12px; padding: 12px 0 4px;
}

/* Flash Messages */
.flash {
  position: fixed; top: calc(var(--topbar-h) + 8px);
  left: 50%; transform: translateX(-50%);
  z-index: 999; background: var(--success); color: #fff;
  padding: 10px 20px; border-radius: 24px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap;
  animation: slideDown 0.3s ease;
}
.flash-error { background: var(--danger); }
.flash-warning { background: var(--warning); }
.flash-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  margin-left: 8px;
  transition: background 0.2s;
}
.flash-close:hover { background: rgba(255,255,255,0.35); }
@keyframes slideDown { from { opacity:0; transform: translateX(-50%) translateY(-10px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }

/* Page header (for sub-pages) */
.page-header {
  background: var(--card); padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.page-header h2 { font-size: 16px; font-weight: 600; }

/* Page toolbar — mobile/tablet: compact bar */
.page-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: #fff;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.page-toolbar-title { font-size: 16px; font-weight: 700; }
.page-toolbar-actions { display: flex; align-items: center; gap: 8px; }
/* Hide the inline search box on mobile (use the dedicated search-bar below) */
.search-bar-inline { display: none; }
/* On mobile, the standalone .search-bar is shown instead */

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--primary-light); color: var(--primary-dark); font-weight: 600;
  font-size: 12px; padding: 10px 12px; text-align: left; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFAFA; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
}
.badge-draft    { background: #F5F5F5; color: #616161; }
.badge-confirmed{ background: #E8F5E9; color: #2E7D32; }
.badge-cancelled{ background: #FFEBEE; color: #C62828; }
.badge-warning  { background: #FFF8E1; color: #F57F17; }
.badge-info     { background: #E3F2FD; color: #1565C0; }
.badge-completed{ background: #E8F5E9; color: #2E7D32; }
.badge-in_progress{ background: #E3F2FD; color: #1565C0; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--text-muted); }
.form-control {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text);
  transition: border-color 0.2s;
  font-size: 14px;
}
.form-control:focus { outline: none; border-color: var(--primary); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; border: none; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: #43A047; color: #fff; }
.btn-success:hover { background: #388E3C; color: #fff; }
.btn-danger  { background: #E53935; color: #fff; }
.btn-danger:hover  { background: #C62828; color: #fff; }
.btn-secondary { background: #EEEEEE; color: var(--text); }
.btn-secondary:hover { background: #E0E0E0; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-outline {
  background: transparent; border: 1.5px solid var(--primary); color: var(--primary);
}
.btn-divider {
  width: 1px; align-self: stretch; background: rgba(0,0,0,.12); margin: 0 2px;
}

/* FAB */
.fab {
  position: fixed; bottom: calc(var(--bottomnav-h) + 16px); right: 16px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: var(--shadow-md);
  border: none; cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  z-index: 80;
}
.fab:hover { background: var(--primary-dark); transform: scale(1.05); }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; margin: 10px 12px;
}
.search-bar input { flex: 1; border: none; outline: none; font-size: 14px; background: transparent; }
.search-bar i { color: var(--text-muted); }

/* List items */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: #fff;
}
.list-item:last-child { border-bottom: none; }
.list-item-info { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-item-right { text-align: right; flex-shrink: 0; padding-left: 10px; }

/* Alert strip */
.alert-strip {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; display: flex; align-items: center; gap: 8px;
  margin: 0 12px 8px;
}
.alert-strip-danger  { background: #FFEBEE; color: #C62828; border-left: 3px solid #E53935; }
.alert-strip-warning { background: #FFF8E1; color: #F57F17; border-left: 3px solid #FB8C00; }
.alert-strip-info    { background: #E3F2FD; color: #1565C0; border-left: 3px solid #1976D2; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 40px 20px; color: var(--text-muted);
  gap: 10px;
}
.empty-state i { font-size: 48px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* Login page */
.login-page {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--primary) 0%, #0d47a1 100%);
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 32px 24px;
  width: 100%; max-width: 360px; box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}
.login-logo {
  text-align: center; margin-bottom: 24px;
}
.login-logo i { font-size: 48px; color: var(--primary); }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); margin-top: 8px; }
.login-logo p { font-size: 13px; color: var(--text-muted); }

/* Items table in orders */
.items-table th, .items-table td { font-size: 12px; padding: 8px; }
.items-table input { padding: 6px 8px; font-size: 12px; }

/* Utility */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-primary{ color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-warning{ color: var(--warning); }
.fw-600 { font-weight: 600; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.p-12  { padding: 12px; }
.p-16  { padding: 16px; }
.d-flex{ display: flex; }
.gap-8 { gap: 8px; }
.flex-1{ flex: 1; }
.w-100 { width: 100%; }

/* Form action footer — mobile: equal-width full buttons */
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 20;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  margin: 0 0 var(--bottomnav-h);
}
.form-actions .btn {
  flex: 1;                 /* equal width on mobile */
  justify-content: center;
}

/* ===================== SIDEBAR (Legacy override) ===================== */
.sidebar {
  display: none; /* hidden on mobile */
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w-desktop);
  background: var(--sidebar-bg);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 90;
  flex-direction: column;
  transition: width 0.3s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px;
  color: #fff;
  font-size: 15px; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap; overflow: hidden;
}
.sidebar-brand i { font-size: 20px; flex-shrink: 0; }

.sidebar-nav { flex: 1; padding: 8px 0; }

.sidebar-group-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  padding: 12px 16px 4px;
}

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.sidebar-item i { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.sidebar-item span { opacity: 1; transition: opacity 0.2s; }
.sidebar-item:hover { background: var(--sidebar-hover-bg); color: #fff; }
.sidebar-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  border-left-color: #fff;
}

/* Sub-items: indented, smaller, lighter */
.sidebar-item-sub {
  padding-left: 40px;
  font-size: 12px;
  opacity: 0.85;
}
.sidebar-item-sub i { font-size: 12px; width: 14px; }
.sidebar-item-sub.active { opacity: 1; }

/* Dashboard stat card highlight variant */
.stat-card-warning { border-color: #f6ad55 !important; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 8px 0 4px;
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  overflow: hidden;
}
.sidebar-user i { font-size: 22px; color: rgba(255,255,255,0.6); flex-shrink: 0; }
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name { font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,0.5); }
.sidebar-logout { color: rgba(255,100,100,0.9); }
.sidebar-logout:hover { background: rgba(200,0,0,0.2); color: #ff8080; }

/* Collapsed sidebar (Task 10) */
.sidebar-collapsed { width: var(--sidebar-w-tablet) !important; }
.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-item span,
.sidebar-collapsed .sidebar-group-label,
.sidebar-collapsed .sidebar-user-info { display: none !important; }

/* TOPBAR ENHANCEMENTS (Task 11) */
.lang-pill {
  display: flex; background: rgba(255,255,255,0.15);
  border-radius: 20px; overflow: hidden; font-size: 12px; font-weight: 700;
}
.lang-pill span { padding: 4px 10px; color: rgba(255,255,255,0.6); cursor: pointer; }
.lang-pill span.active { background: rgba(255,255,255,0.25); color: #fff; }
.lang-pill:hover { background: rgba(255,255,255,0.2); }
.topbar-breadcrumb { font-size: 13px; color: rgba(255,255,255,0.8); display: flex; align-items: center; gap: 6px; margin-left: 8px; }
.topbar-breadcrumb a { color: rgba(255,255,255,0.7); text-decoration: none; }
.topbar-breadcrumb a:hover { color: #fff; }
.topbar-username { font-size: 13px; color: rgba(255,255,255,0.85); font-weight: 500; }

/* Responsive display helpers */
.d-none-mobile   { display: none !important; }
.d-none-tablet   { display: flex !important; }
.d-desktop-only  { display: none !important; }
.d-none-desktop  { display: flex !important; }  /* shown on mobile/tablet, hidden on desktop */

/* Pagination (Task 10) */
.pagination-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
}

/* ===================== TABLET (601–1024px) ===================== */
@media (min-width: 601px) {
  .sidebar {
    display: flex;
    width: var(--sidebar-w-tablet);
  }
  .sidebar-brand-text,
  .sidebar-item span,
  .sidebar-group-label,
  .sidebar-user-info { display: none; }
  .sidebar-brand { justify-content: center; padding: 16px 0; }
  .sidebar-item { justify-content: center; padding: 12px 0; border-left: none; border-right: 3px solid transparent; }
  .sidebar-item.active { border-right-color: #fff; border-left: none; }
  .sidebar-user { justify-content: center; padding: 12px 0; }

  .main-content {
    margin-left: var(--sidebar-w-tablet);
    margin-bottom: 0; /* no bottom nav on tablet+ */
  }
  .bottom-nav { display: none; }
  .fab { right: 24px; bottom: 24px; }

  /* Tooltip for icon-only sidebar */
  .sidebar-item { position: relative; }
  .sidebar-item[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute; left: calc(var(--sidebar-w-tablet) + 8px);
    background: rgba(0,0,0,0.85); color: #fff;
    font-size: 12px; padding: 4px 10px; border-radius: 6px;
    white-space: nowrap; z-index: 200; pointer-events: none;
  }

  /* Responsive Display Helpers */
  .d-none-mobile  { display: flex !important; }
  .d-none-tablet  { display: none !important; }
}

/* ===================== DESKTOP (1025px+) ===================== */
@media (min-width: 1025px) {
  .sidebar {
    width: var(--sidebar-w-desktop);
  }
  .sidebar-brand-text,
  .sidebar-item span,
  .sidebar-group-label,
  .sidebar-user-info { display: block; }
  .sidebar-brand { justify-content: flex-start; padding: 16px 14px; }
  .sidebar-item { justify-content: flex-start; padding: 10px 16px; border-left: 3px solid transparent; border-right: none; }
  .sidebar-item.active { border-left-color: #fff; border-right: none; }
  .sidebar-user { justify-content: flex-start; padding: 10px 16px; }

  .main-content {
    margin-left: var(--sidebar-w-desktop);
    margin-top: var(--topbar-h);
    margin-bottom: 0;
    min-width: 0;
    /* No max-width — content fills the space beside the sidebar */
  }
  .topbar { padding: 0 24px; }
  .fab { display: none; } /* use inline Add buttons instead */

  /* Responsive Display Helpers */
  .d-desktop-only { display: flex !important; }

  /* Card layout improvements */
  .card { margin: 0 20px 16px; }
  .section-label { padding: 16px 20px 8px; }
  .stats-row { gap: 16px; padding: 0 20px 8px; }

  /* Table improvements */
  th, td { padding: 12px 16px; }
  .search-bar { margin: 10px 20px; }

  /* Desktop page toolbar (Task 3) */
  .page-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; background: #fff;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .page-toolbar-title { font-size: 18px; font-weight: 700; }
  .page-toolbar-actions { display: flex; align-items: stretch; gap: 10px; height: 40px; }
  .page-toolbar-actions .btn { height: auto; padding-top: 0; padding-bottom: 0; }
  .search-bar-inline {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); padding: 0 12px;
    width: 280px; height: auto;
  }
  .search-bar-inline input { flex: 1; border: none; outline: none; background: transparent; font-size: 13px; height: 100%; }

  /* Hide mobile search bar on desktop (only show inline toolbar search) */
  .d-none-desktop { display: none !important; }

  /* ── Form pages — full-width, fluid, responsive ── */
  .form-card-wrapper {
    max-width: 100%;
    margin: 20px 0 0;
  }

  /* 2-column row — default across all screen sizes on desktop */
  .form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

  /* 3-column row utility */
  .form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

  /* 4-column row utility (tight fields: qty, price, etc.) */
  .form-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

  /* Mixed ratio rows */
  .form-row-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
  .form-row-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 14px; }

  /* Side-by-side card sections — arrange multiple .card blocks in columns */
  .form-section-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 20px;
    align-items: start;
  }
  .form-section-grid > .card { margin-left: 0; margin-right: 0; }

  /* Action footer — save/cancel bar */
  .form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;   /* buttons cluster to the right on desktop */
    gap: 10px;
    padding: 14px 20px;
    background: #fff;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 20;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    margin: 0 0 16px;
  }
  /* All action buttons: equal fixed width, no flex-grow */
  .form-actions .btn {
    flex: none;
    min-width: 140px;
    justify-content: center;
  }

  /* Order view (Task 5) */
  .order-view-grid {
    display: grid; grid-template-columns: minmax(300px, 360px) 1fr;
    gap: 20px; padding: 20px; align-items: start;
  }

  /* Dashboard grid (Task 2) */
  .dashboard-panels-row {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 16px; padding: 0 20px;
  }
  .stats-row { grid-template-columns: repeat(4, 1fr); }
  .stat-card { padding: 20px 16px; }

  /* Sticky table header - disabled: causes rendering issues with overflow:hidden */
  /* thead th { position: sticky; top: var(--topbar-h); z-index: 10; } */
}

/* ===================== TEXTILE ERP STYLES ===================== */

/* Status badges for textile modules */
.badge-ordered    { background: #E3F2FD; color: #1565C0; }
.badge-partial_received { background: #FFF3E0; color: #E65100; }
.badge-received   { background: #E8F5E9; color: #2E7D32; }
.badge-in_production { background: #EDE7F6; color: #4527A0; }
.badge-ready      { background: #E0F7FA; color: #00695C; }
.badge-delivered  { background: #E8F5E9; color: #1B5E20; }
.badge-issued     { background: #E3F2FD; color: #1565C0; }
.badge-returned   { background: #E8F5E9; color: #2E7D32; }
.badge-rejected   { background: #FFEBEE; color: #C62828; }
.badge-approved   { background: #E8F5E9; color: #2E7D32; }
.badge-obsolete   { background: #F5F5F5; color: #9E9E9E; }
.badge-available  { background: #E8F5E9; color: #2E7D32; }
.badge-reserved   { background: #FFF8E1; color: #F57F17; }
.badge-depleted   { background: #F5F5F5; color: #9E9E9E; }
.badge-packed     { background: #E0F7FA; color: #00695C; }
.badge-packing    { background: #FFF3E0; color: #E65100; }
.badge-dispatched { background: #E3F2FD; color: #1565C0; }
.badge-unpaid     { background: #FFEBEE; color: #C62828; }
.badge-partial    { background: #FFF3E0; color: #E65100; }
.badge-paid       { background: #E8F5E9; color: #2E7D32; }
.badge-overdue    { background: #FFEBEE; color: #B71C1C; }

/* SO Timeline Tracker */
.timeline-tracker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px;
  overflow-x: auto;
}
.timeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  flex: 1;
  min-width: 80px;
}
.timeline-step::after {
  content: '';
  position: absolute;
  top: 16px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.timeline-step:last-child::after { display: none; }
.timeline-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  z-index: 1;
  transition: all 0.3s;
}
.timeline-step.completed .timeline-dot {
  background: var(--success);
  color: #fff;
}
.timeline-step.completed::after {
  background: var(--success);
}
.timeline-step.active .timeline-dot {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 0 4px var(--primary-light);
}
.timeline-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
}
.timeline-step.completed .timeline-label,
.timeline-step.active .timeline-label {
  color: var(--text);
  font-weight: 600;
}
a.timeline-step-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.timeline-step-link:hover .timeline-dot {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--primary-light);
}
a.timeline-step-link.completed:hover .timeline-dot {
  background: var(--success-dark, #1a7a3c);
  box-shadow: 0 0 0 4px rgba(40,167,69,0.2);
}
a.timeline-step-link:hover .timeline-label {
  color: var(--primary);
}

/* Recipe Table */
.recipe-table { width: 100%; border-collapse: collapse; }
.recipe-table th {
  background: #F5F5F5;
  font-size: 12px;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
}
.recipe-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.recipe-table .component-row { background: #FAFAFA; }
.recipe-table .auxiliary-row { background: #F5F9FF; }

/* Packing auto-calc display */
.packing-calc {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  margin: 12px 0;
}
.packing-calc-item {
  text-align: center;
}
.packing-calc-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.packing-calc-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Label preview */
.label-preview {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 12px 0;
  background: #fff;
  max-width: 320px;
  font-size: 12px;
}
.label-preview-header {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.label-preview-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.label-preview-barcode {
  text-align: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Report filter bar */
.report-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.report-filter-bar .form-group {
  margin-bottom: 0;
  min-width: 150px;
}
.report-filter-bar .form-label {
  margin-bottom: 3px;
  font-size: 11px;
}

/* Status filter tabs */
.status-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 2px solid var(--border);
  padding: 0 12px;
  background: #fff;
}
.status-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.status-tab:hover { color: var(--primary); }
.status-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.status-tab .tab-count {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 4px;
}

/* Linked records section */
.linked-records {
  margin-top: 16px;
}
.linked-record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: #FAFAFA;
}
.linked-record-item:hover { background: var(--primary-light); }
.linked-record-doc { font-weight: 600; font-size: 13px; }
.linked-record-info { font-size: 12px; color: var(--text-muted); }

/* Dashboard textile widgets */
.textile-widgets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 12px 12px;
}
.textile-widget {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.textile-widget-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}
.textile-widget-info { flex: 1; min-width: 0; }
.textile-widget-value { font-size: 20px; font-weight: 700; line-height: 1.2; }
.textile-widget-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }

/* Traceability tree */
.trace-tree { padding: 16px; }
.trace-node {
  padding: 10px 14px;
  border-left: 3px solid var(--primary);
  margin-left: 16px;
  margin-bottom: 8px;
  background: #FAFAFA;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.trace-node-title { font-weight: 600; font-size: 13px; }
.trace-node-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.trace-arrow {
  margin-left: 28px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 0;
}

/* Weight variance alert */
.weight-variance-ok { color: var(--success); }
.weight-variance-warn { color: var(--warning); font-weight: 600; }
.weight-variance-danger { color: var(--danger); font-weight: 700; }

/* Compare layout (recipe version diff) */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
}
.compare-highlight { background: #FFF9C4; }

/* Info grid for view pages */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  padding: 14px;
}
.info-item-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.info-item-value {
  font-size: 14px;
  font-weight: 500;
  word-break: break-word;
}

/* Desktop responsive adjustments for textile widgets */
@media (min-width: 1025px) {
  .textile-widgets { grid-template-columns: repeat(3, 1fr); padding: 0 20px 16px; }
  .packing-calc { grid-template-columns: repeat(4, 1fr); }
  .compare-grid { gap: 20px; padding: 20px; }
  .info-grid { grid-template-columns: 1fr 1fr 1fr; }
  .timeline-tracker { padding: 24px 32px; }
}

/* ── Wide screen: push to 3 cols on form rows, expand info grids ── */
@media (min-width: 1400px) {
  .form-row-2  { grid-template-columns: repeat(3, 1fr); gap: 16px; }
  .form-row-3  { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .form-row-4  { grid-template-columns: repeat(5, 1fr); gap: 16px; }
  .info-grid   { grid-template-columns: repeat(4, 1fr); gap: 10px 20px; }
  .textile-widgets { grid-template-columns: repeat(4, 1fr); }
  .order-view-grid { grid-template-columns: 380px 1fr; gap: 24px; }
  .compare-grid    { grid-template-columns: 1fr 1fr; gap: 24px; }
  .card            { margin: 0 24px 16px; }
  .form-card-wrapper .card { margin-left: 0; margin-right: 0; }
}

/* =====================================================================
   FORM DESIGN SYSTEM — ERP Inventory v1.0
   Append-only section. Never modify rules above.
   Covers: bilingual labels, validation states, toggle switch,
   barcode lookup, line-item tables, sticky action bar enhancements,
   form section dividers, readonly display, accessibility rings.
   ===================================================================== */

/* — New design tokens (extend :root via cascade) — */
:root {
  --color-label:        #424242;
  --color-hint:         #757575;
  --color-error:        #B71C1C;
  --color-error-border: #C62828;
  --color-error-bg:     #FFFAFA;
  --color-readonly-bg:  #F5F5F5;
  --focus-ring:         0 0 0 3px rgba(25,118,210,0.18);
  --input-height:       42px;
  --input-height-lg:    48px;
}

/* ── Bilingual label pattern ── */
.form-label {
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-label);
  margin-bottom: 5px;
  cursor: default;
}
.label-en {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-label);
}
.label-zh {
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 11px;
  font-weight: 400;
  color: #9E9E9E;
  letter-spacing: 0.3px;
}
.required-mark {
  color: var(--color-error-border);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  margin-left: 1px;
}

/* ── Input enhancements ── */
.form-control {
  height: var(--input-height);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control:hover { border-color: #BDBDBD; }
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.form-control:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.form-control:disabled {
  background: var(--color-readonly-bg);
  color: #9E9E9E;
  cursor: not-allowed;
  border-color: var(--border);
}
textarea.form-control { height: auto; }
select.form-control { height: var(--input-height); cursor: pointer; }

/* Readonly display — no border, styled like a field */
.form-control--readonly {
  background: var(--color-readonly-bg);
  font-weight: 600;
  color: var(--text);
  border-color: transparent;
  cursor: default;
  user-select: text;
}

/* Static display (status badge slot, calculated totals) */
.form-control-static {
  display: flex;
  align-items: center;
  min-height: var(--input-height);
  padding: 0 2px;
  font-size: 14px;
  font-weight: 500;
}

/* ── Hint & error messages ── */
.form-hint {
  display: block;
  font-size: 12px;
  color: var(--color-hint);
  margin-top: 4px;
  line-height: 1.4;
}
.form-error-msg {
  display: none;
  font-size: 12px;
  color: var(--color-error);
  font-weight: 500;
  margin-top: 4px;
  line-height: 1.4;
}
.form-error-msg::before {
  content: '\f06a  '; /* fa-circle-exclamation */
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  margin-right: 3px;
}

/* ── Validation error state ── */
.form-group--error .form-control {
  border-color: var(--color-error-border);
  background: var(--color-error-bg);
  box-shadow: 0 0 0 3px rgba(198,40,40,0.12);
}
.form-group--error .form-label,
.form-group--error .label-en { color: var(--color-error); }
.form-group--error .form-error-msg { display: block; }
.form-group--error .form-hint { display: none; }

/* ── Form section divider ── */
.form-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  padding: 12px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-title i {
  color: var(--primary);
  font-size: 13px;
  width: 16px;
  text-align: center;
}

/* ── Toggle switch ── */
.form-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  min-height: var(--input-height);
}
.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.toggle-slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background: #BDBDBD;
  border-radius: 24px;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.2s ease;
}
.toggle-input:checked + .toggle-slider { background: var(--primary); }
.toggle-input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle-input:focus-visible + .toggle-slider {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.toggle-label-text {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

/* ── Barcode lookup field ── */
.barcode-lookup-field { margin-bottom: 14px; }
.barcode-lookup-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.barcode-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
  z-index: 1;
}
.barcode-input {
  padding-left: 38px;
  height: var(--input-height-lg);
  font-size: 15px;
  letter-spacing: 0.5px;
}
.barcode-spinner {
  position: absolute;
  right: 12px;
  color: var(--primary);
  font-size: 14px;
}
.barcode-lookup-result {
  margin-top: 6px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.barcode-result-found {
  background: #E8F5E9;
  border-left: 3px solid var(--success);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.barcode-result-found .result-name { font-weight: 600; font-size: 13px; }
.barcode-result-found .result-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.barcode-result-notfound {
  background: #FFEBEE;
  border-left: 3px solid var(--danger);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Line item table ── */
.line-item-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.line-item-table thead th {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 600;
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.line-item-table tbody td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.line-item-table .form-control {
  height: 34px;
  padding: 5px 8px;
  font-size: 13px;
}
.line-item-table select.form-control { height: 34px; }
.line-item-table tfoot td {
  padding: 9px 10px;
  font-weight: 700;
  font-size: 13px;
  border-top: 2px solid var(--border);
  background: #FAFAFA;
}
.line-item-table .col-actions { width: 44px; text-align: center; }
.line-item-table .col-num    { width: 40px; color: var(--text-muted); font-size: 12px; text-align: center; }
.line-item-table .col-qty    { width: 100px; }
.line-item-table .col-price  { width: 120px; }
.line-item-table .col-total  { width: 120px; }
.line-item-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  cursor: pointer;
}

/* Line item table wrapper with horizontal scroll on mobile */
.line-item-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Mobile: line items as labeled cards */
@media (max-width: 767px) {
  .line-item-table thead { display: none; }
  .line-item-table, .line-item-table tbody,
  .line-item-table tr, .line-item-table td { display: block; width: 100%; }
  .line-item-table .line-item-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 10px;
    background: #fff;
    position: relative;
  }
  .line-item-table .line-item-row td {
    padding: 4px 0;
    border-bottom: none;
  }
  .line-item-table .line-item-row td::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }
  .line-item-table .col-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
  }
  .line-item-table .col-actions td::before { display: none; }
  .line-item-table tfoot { display: block; }
  .line-item-table tfoot td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 2px solid var(--border);
    margin-top: 4px;
    padding: 10px 4px;
  }
  .line-item-wrap { border: none; overflow-x: visible; }
}

/* ── Accessibility: focus-visible rings on all interactive elements ── */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.form-toggle:focus-within .toggle-slider {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Cursor pointer on all interactive non-link elements */
button, .btn, label.form-toggle, .status-tab,
.icon-grid-item, .list-item[onclick],
.line-item-add-btn, .linked-record-item[onclick] {
  cursor: pointer;
}

/* ── Form card spacing refinement ── */
.form-card-wrapper .card { margin-bottom: 12px; }
.form-card-wrapper .card:last-of-type { margin-bottom: 0; }

/* ── Inline total display (read-only calculated field) ── */
.total-display-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}
.total-display-row .total-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

/* ── Character / weight counter hint ── */
.form-counter {
  float: right;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}
.form-counter.near-limit { color: var(--warning); font-weight: 600; }
.form-counter.at-limit   { color: var(--danger);  font-weight: 700; }

/* ── Wastage / variance warning strip inside line tables ── */
.variance-strip {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  display: none;
}
.variance-strip.show { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.variance-strip-warn { background: #FFF8E1; color: var(--warning); border-left: 3px solid #FB8C00; }
.variance-strip-danger { background: #FFEBEE; color: var(--danger); border-left: 3px solid var(--danger); }

/* ── Tablet (768px+): activate multi-column form rows ── */
@media (min-width: 768px) {
  .barcode-input { font-size: 14px; }
  /* Bilingual side-by-side */
  .form-row-bilingual {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  /* 2-col and 3-col rows activate at tablet, not just desktop */
  .form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .form-row-3 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
}

/* ── Tablet-wide (900px+): 3-col rows get their actual 3 columns ── */
@media (min-width: 900px) {
  .form-row-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1800px) {
  .form-row-2 { grid-template-columns: repeat(4, 1fr); gap: 18px; }
  .form-row-3 { grid-template-columns: repeat(5, 1fr); gap: 18px; }
  .info-grid  { grid-template-columns: repeat(5, 1fr); }
  .card       { margin: 0 32px 16px; }
  .form-card-wrapper .card { margin-left: 0; margin-right: 0; }
}

/* ── Ensure form inputs never get uncomfortably wide ── */
@media (min-width: 1025px) {
  .form-control { max-width: 100%; }
  /* Full-width inputs inside single-col form-group stay readable */
  .form-group > .form-control,
  .form-group > textarea.form-control,
  .form-group > select.form-control { max-width: 100%; }
}

/* ===================== PRINT STYLES (Task 13) ===================== */
@media print {
  .topbar, .bottom-nav, .sidebar, .fab, .no-print,
  .page-toolbar-actions, .pagination-bar { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; margin: 0 0 12px !important; }
  body { font-size: 12px; }
  th, td { padding: 8px !important; }
  .order-view-grid { display: block !important; }
}

/* ── Form Design System v2 ───────────────────────── */

/* Page wrapper — max-width cap for ALL forms. */
.form-page-wrapper{max-width:1100px;margin:0 auto;width:100%}

/* Core 2-col grid */
.form-grid-2col{display:grid;grid-template-columns:1fr 1fr;gap:16px 20px}

/* Address row — sits BELOW the 2-col grid, not inside it.
   Two textareas side by side (billing + shipping, or address + notes).
   Use .single modifier when only one textarea exists. */
.form-addr-row{display:grid;grid-template-columns:1fr 1fr;gap:16px 20px;margin-top:16px}
.form-addr-row.single{grid-template-columns:1fr}

/* Table section — sits outside any grid, full width */
.form-table-section{margin-top:20px}

/* Section titles */
.form-section-title{font-size:11px;font-weight:600;color:#888;letter-spacing:.06em;
  text-transform:uppercase;margin:20px 0 14px;padding-bottom:8px;
  border-bottom:0.5px solid #eee}
.form-section-title:first-child{margin-top:0}

/* Form groups */
.form-group{display:flex;flex-direction:column;gap:5px}
.form-group--error .form-control{border-color:#d04040}
.form-group--error .form-control:focus{box-shadow:0 0 0 3px rgba(208,64,64,.1)}
.form-error-msg{font-size:11px;color:#d04040;display:flex;align-items:center;gap:4px}
.form-hint{font-size:11px;color:#999;margin-top:2px}

/* Labels */
.form-label{font-size:12px;font-weight:500;color:#555;display:flex;
  align-items:center;gap:4px;flex-wrap:wrap}
.label-zh{font-size:11px;color:#aaa;font-weight:400;margin-left:2px}
.required-star{color:#d04040;font-size:13px}
.required-note{font-size:11px;color:#999;margin-right:auto;display:flex;
  align-items:center;gap:4px}

/* Textareas */
textarea.form-control-addr{min-height:110px;resize:vertical}
textarea.form-control-notes{min-height:90px;resize:vertical}

/* Action bar */
.action-bar{display:flex;align-items:center;justify-content:flex-end;gap:10px;
  padding:14px 0 4px;border-top:0.5px solid #eee;margin-top:20px}

/* Line item table */
.line-item-table{width:100%;border-collapse:collapse;font-size:13px}
.line-item-table th{font-size:11px;font-weight:600;color:#888;
  text-transform:uppercase;letter-spacing:.04em;padding:8px 10px;
  border-bottom:1px solid #eee;text-align:left;white-space:nowrap}
.line-item-table td{padding:6px 8px;border-bottom:0.5px solid #f0f0f0;
  vertical-align:middle}
.line-item-table tr:last-child td{border-bottom:none}
.line-item-table .form-control{padding:5px 8px;font-size:12px}
.btn-row-add{background:none;border:1px dashed #bbb;color:#888;
  font-size:12px;padding:6px 12px;border-radius:6px;cursor:pointer;
  width:100%;margin-top:8px;transition:border-color .15s,color .15s}
.btn-row-add:hover{border-color:#1558b0;color:#1558b0}
.btn-row-remove{background:none;border:none;color:#ccc;cursor:pointer;
  font-size:14px;padding:4px;line-height:1;transition:color .15s}
.btn-row-remove:hover{color:#d04040}

/* Barcode lookup */
.barcode-field-wrap{position:relative}
.barcode-field-wrap .form-control{padding-right:38px}
.barcode-scan-btn{position:absolute;right:8px;top:50%;transform:translateY(-50%);
  background:none;border:none;color:#aaa;cursor:pointer;font-size:14px;
  padding:2px;transition:color .15s}
.barcode-scan-btn:hover{color:#1558b0}
.barcode-lookup-status{font-size:11px;margin-top:3px;min-height:14px}
.barcode-lookup-status.loading{color:#888}
.barcode-lookup-status.success{color:#3a7d44}
.barcode-lookup-status.error{color:#d04040}

/* Status badge (read-only in edit forms) */
.status-badge-display{display:inline-flex;align-items:center;gap:6px;
  font-size:12px;font-weight:500;padding:4px 10px;border-radius:20px}

/* Toggle switch */
.form-toggle-wrap{display:flex;align-items:center;gap:10px}
.form-toggle{position:relative;width:36px;height:20px;flex-shrink:0}
.form-toggle input{opacity:0;width:0;height:0;position:absolute}
.form-toggle-track{position:absolute;inset:0;background:#ddd;
  border-radius:10px;cursor:pointer;transition:background .2s}
.form-toggle input:checked+.form-toggle-track{background:#1558b0}
.form-toggle-track::after{content:'';position:absolute;top:2px;left:2px;
  width:16px;height:16px;background:#fff;border-radius:50%;
  transition:transform .2s}
.form-toggle input:checked+.form-toggle-track::after{transform:translateX(16px)}
.form-toggle-label{font-size:13px;color:#555;cursor:pointer}

/* Responsive */
@media(max-width:768px){
  .form-grid-2col{grid-template-columns:1fr}
  .form-addr-row{grid-template-columns:1fr}
}
@media(max-width:600px){
  .action-bar{position:sticky;bottom:0;z-index:10;background:#fff;
    border-top:1px solid #eee;padding:12px 16px;margin:0 -16px;
    box-shadow:0 -2px 8px rgba(0,0,0,.06)}
  .line-item-table{display:block;overflow-x:auto;-webkit-overflow-scrolling:touch}
}
/* ── End Form Design System v2 ──────────────────── */
