:root {
  --bg: #0c0e12;
  --surface: #15181e;
  --surface-hover: #1c2028;
  --border: #262a33;
  --border-active: #3f4553;
  --text: #f3f5f8;
  --text-muted: #8e97a4;
  --accent: #d4af37;
  --accent-glow: rgba(212, 175, 55, 0.15);
  --danger: #ef476f;
  --danger-bg: rgba(239, 71, 111, 0.12);
  --success: #06d6a0;
  --success-bg: rgba(6, 214, 160, 0.12);
  --warning: #ffd166;
  --warning-bg: rgba(255, 209, 102, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 76px; /* For mobile bottom bar */
  min-height: 100vh;
}

/* ---------------- Layout & Header ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(21, 24, 30, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
}

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

.brand-logo {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 1.5px;
  color: var(--accent);
  text-transform: uppercase;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
  padding-left: 8px;
}

.branch-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--accent);
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.container {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* ---------------- Bottom Navigation ---------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100vw;
  background: rgba(21, 24, 30, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 6px 2px;
  z-index: 100;
  box-sizing: border-box;
}

.bottom-nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
  min-width: 40px;
  flex: 1 1 0;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.nav-item .icon {
  font-size: 17px;
}

.nav-item.active {
  color: var(--accent);
}

/* ---------------- Loading, Empty & Error States (B6) ---------------- */
.state-loading, .state-empty, .state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 12px 0;
  width: 100%;
  box-sizing: border-box;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(212, 175, 55, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-icon, .error-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.empty-title, .error-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.empty-title {
  color: var(--text);
}

.error-title {
  color: var(--danger);
}

.empty-text, .error-msg {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 300px;
  margin-bottom: 16px;
}

.error-msg {
  color: #ff859e;
}

/* ---------------- Views ---------------- */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* ---------------- Cards & Panels ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.headline-card {
  background: linear-gradient(145deg, #181b22, #13161c);
  border: 1px solid #2d3340;
  position: relative;
  overflow: hidden;
}

.headline-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--danger);
}

.headline-meta {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.headline-number {
  font-size: 38px;
  font-weight: 800;
  color: var(--danger);
  line-height: 1.1;
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

.headline-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------------- Grid & Metric Counters ---------------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.metric-box {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono);
}

.metric-value.danger { color: var(--danger); }
.metric-value.success { color: var(--success); }
.metric-value.warning { color: var(--warning); }

/* ---------------- Tables & Lists ---------------- */
.table-responsive {
  overflow-x: auto;
}

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

th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
.badge-neutral { background: var(--surface-hover); color: var(--text-muted); border: 1px solid var(--border); }

/* ---------------- Forms & Buttons ---------------- */
.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #000;
}

.btn-primary:hover {
  background: #e2be4c;
}

.btn-secondary {
  background: var(--surface-hover);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--border-active);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-block {
  width: 100%;
}

/* ---------------- Recipe / Ingredient Line Editor ---------------- */
.line-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  background: var(--surface-hover);
  padding: 8px;
  border-radius: var(--radius-sm);
}

.line-row select {
  flex: 2;
}

.line-row input {
  flex: 1;
}

/* ---------------- Alerts / Flags ---------------- */
.alert-flag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 8px;
  background: var(--warning-bg);
  color: var(--warning);
  border-left: 4px solid var(--warning);
}

/* ---------------- Modal ---------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

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

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

/* ---------------- Utility & Component Classes (CSP Strict No Inline Styles) ---------------- */
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.mb-16 { margin-bottom: 16px; }
.mt-2 { margin-top: 2px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.my-16 { margin: 16px 0; }
.ml-4 { margin-left: 4px; }
.ml-6 { margin-left: 6px; }
.ml-12 { margin-left: 12px; }
.mr-4 { margin-right: 4px; }

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-normal { color: var(--text); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-italic { font-style: italic; }
.font-mono { font-family: var(--font-mono); }

.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.fs-14 { font-size: 14px; }
.fs-16 { font-size: 16px; }
.fs-18 { font-size: 18px; }
.fs-20 { font-size: 20px; }
.fs-22 { font-size: 22px; }

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.flex-between-start {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.flex-end {
  display: flex;
  justify-content: flex-end;
}
.flex-row {
  display: flex;
  align-items: center;
}
.flex-wrap {
  flex-wrap: wrap;
}
.flex-1 {
  flex: 1;
}
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-sm {
  width: 18px;
  height: 18px;
}
.checkbox-md {
  width: 20px;
  height: 20px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
}
.btn-xs-12 {
  padding: 4px 8px;
  font-size: 12px;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}
.btn-sm-12 {
  padding: 6px 12px;
  font-size: 12px;
}
.btn-plain-danger {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
}

.auth-code-input {
  font-size: 24px;
  text-align: center;
  letter-spacing: 6px;
  font-family: var(--font-mono);
}
.pos-count-input {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.tickets-filter-card {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.tickets-date-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 160px;
}
.lib-search-input {
  flex: 1;
  min-width: 180px;
}
.lib-gate-card {
  text-align: center;
  padding: 24px;
}
.lib-footer-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 14px 8px;
}

.alert-flag-danger {
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}
.alert-banner-warning {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.4);
  color: #facc15;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.alert-banner-link {
  color: #facc15;
  font-weight: 700;
  text-decoration: underline;
  margin-left: 12px;
}

.flavour-waste-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.device-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.table-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--surface-hover);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.card-border-warning {
  border-color: var(--warning);
}
.card-border-accent {
  border-color: var(--accent);
}
.plan-list {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-muted);
}
.plan-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.plan-row-last {
  padding: 8px 0;
}

.provision-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.provision-qr-svg {
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border: 1px dashed #ccc;
  border-radius: 8px;
}
.provision-qr-json {
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
}
#provisionQrImg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* ---------------- Responsive Desktop Enhancement ---------------- */
@media (min-width: 768px) {
  body {
    padding-bottom: 0;
  }
  .app-header {
    padding: 16px 24px;
  }
  .bottom-nav {
    position: static;
    border-top: none;
    background: transparent;
    padding: 0;
    gap: 4px;
  }
  .nav-item {
    flex-direction: row;
    padding: 6px 12px;
    font-size: 13px;
  }
  .nav-item .icon {
    font-size: 16px;
  }
}
