:root {
  --bg: #f3f6fa;
  --card: #ffffff;
  --border: #d8e1ec;
  --text: #14213d;
  --muted: #5c6b82;
  --primary: #145da0;
  --primary-hover: #0e467a;
  --success: #15803d;
  --success-hover: #116630;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --ok-bg: #dcfce7;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 28px rgba(20, 33, 61, 0.08);
}
.brand-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.subtitle { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.demo-hint {
  margin-top: 16px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Topbar */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.topbar-left, .topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.app-title { font-weight: 900; font-size: 18px; letter-spacing: 0.5px; }
.org-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.badge.org { background: rgba(255,255,255,0.2); }
.badge.wh { background: #0b3b66; }
.badge.prefix { background: #facc15; color: #14213d; }
.user-label { font-size: 13px; font-weight: 600; }

/* Layout */
.container {
  max-width: 1080px;
  margin: 18px auto;
  padding: 0 14px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(20, 33, 61, 0.04);
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-header h2 { margin: 0; font-size: 17px; }

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.printer-picker { display: flex; flex-direction: column; gap: 4px; min-width: 280px; }
.printer-picker label { font-size: 12px; font-weight: 700; color: var(--muted); }
.printer-row { display: flex; gap: 6px; }

/* Fields & Buttons */
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
}
input:focus, select:focus { outline: 2px solid rgba(20, 93, 160, 0.25); border-color: var(--primary); }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn.lg { padding: 13px 20px; font-size: 15px; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.full { width: 100%; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.success { background: var(--success); color: #fff; }
.btn.success:hover { background: var(--success-hover); }
.btn.ghost { background: #e8eef5; color: var(--text); }
.btn.ghost:hover { background: #dce5f0; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Quick Pick Products */
.quick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 8px;
}
.quick-chip {
  padding: 9px 13px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: #f8fafc;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.quick-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.qty-control { display: flex; gap: 6px; align-items: center; }
.qty-control input { text-align: center; font-size: 20px; font-weight: 800; }
.hint-pill {
  background: #e0f2fe;
  color: #0369a1;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.asi-preview {
  padding: 8px 10px;
  background: #f1f5f9;
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}
.field-error { color: var(--danger); font-size: 13px; font-weight: 700; }

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--success); }

/* Table */
.filter-row { display: flex; gap: 8px; align-items: center; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.data-table th { background: #f8fafc; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.code-pill {
  display: inline-block;
  background: #14213d;
  color: #fff;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 15px;
}
.empty { text-align: center !important; color: var(--muted); padding: 24px !important; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-dialog {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 820px;
  max-height: 95vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 12px;
  padding: 18px;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.modal-header h3 { margin: 0 0 4px; }
.a5-preview-frame-wrap {
  width: 100%;
  background: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}
#a5-iframe {
  width: 20cm;
  height: 15cm;
  border: none;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.print-controls {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 12px;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.modal-actions .btn { flex: 1; min-width: 200px; }
