/* ===== 1NINE Parts Request App — Light Professional Theme ===== */
:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f1f3;
  --border: #d8dbe0;
  --text: #1a1d21;
  --text-muted: #5c6370;
  --text-dim: #8b929c;
  --accent: #e10600; /* 1NINE red */
  --accent-hover: #c40500;
  --accent-dim: rgba(225, 6, 0, 0.10);
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --header-h: 56px;
  --search-h: 52px;
  --tabs-h: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, textarea { font-family: inherit; }

/* ===== Splash ===== */
.splash {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  gap: 20px;
}
.splash-logo { width: min(280px, 80vw); height: auto; }
.splash-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.splash p { color: var(--text-muted); font-size: 14px; }

/* ===== Utilities ===== */
.hidden { display: none !important; }
.req { color: var(--accent); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 20px;
  border: none; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  cursor: pointer; transition: all 0.15s ease;
  text-decoration: none; color: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover, .btn-primary:focus { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; }
.btn-icon {
  background: transparent; border: none; color: var(--text);
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer;
}
.btn-icon:hover { background: var(--bg-hover); }
.btn-icon svg { pointer-events: none; }

/* ===== Modal Overlay ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Gate Modal */
.gate-modal {
  padding: 32px 24px;
  text-align: center;
}
.modal-logo { width: 180px; margin-bottom: 16px; }
.gate-modal h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }

.form-group { margin-bottom: 16px; text-align: left; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em;
}
.form-group input, .form-group textarea {
  width: 100%; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; /* prevents iOS zoom */
  outline: none; transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus {
  border-color: var(--accent);
}
.form-group input[readonly] {
  color: var(--text-muted); background: #eef0f3;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== App Shell ===== */
#app {
  display: flex; flex-direction: column;
  height: 100%; min-height: 100dvh;
}

.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 12px;
  padding-top: env(safe-area-inset-top, 0);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-icon { width: 32px; height: 32px; border-radius: 6px; }
.header-title { font-weight: 700; font-size: 16px; display: block; }
.header-meta { font-size: 11px; color: var(--text-muted); }
.header-right { display: flex; align-items: center; }

.cart-btn { position: relative; }
.cart-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* Search */
.search-bar {
  padding: 8px 12px;
  background: var(--bg);
  position: sticky; top: var(--header-h); z-index: 90;
}
.search-input-wrap {
  position: relative; display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 12px; color: var(--text-dim); pointer-events: none;
}
#search-input {
  width: 100%; padding: 11px 40px 11px 40px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 24px; color: var(--text); font-size: 15px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
.clear-btn {
  position: absolute; right: 10px;
  background: var(--border); border: none; color: var(--text);
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* Category Tabs */
.category-tabs {
  display: flex; gap: 6px;
  padding: 6px 12px 10px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg);
  position: sticky; top: calc(var(--header-h) + var(--search-h) - 8px); z-index: 80;
  border-bottom: 1px solid var(--border);
}
.category-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0; padding: 7px 14px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text-muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
}
.tab:hover { color: var(--text); border-color: #b0b5bc; }
.tab.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* Parts Main */
.parts-main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px; padding-bottom: calc(24px + var(--safe-bottom));
}

.parts-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 640px) {
  .parts-list { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .parts-list { grid-template-columns: 1fr 1fr 1fr; }
  .parts-main { padding: 16px 24px; }
}

/* Part Card */
.part-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; gap: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.part-card:hover { border-color: #b0b5bc; background: var(--bg-hover); }
.part-qr {
  flex-shrink: 0; width: 64px; height: 64px;
  background: #fff; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.part-qr canvas, .part-qr img { width: 58px !important; height: 58px !important; }
.part-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.part-number {
  font-weight: 700; font-size: 13px; color: var(--accent);
  word-break: break-all;
}
.part-desc {
  font-size: 13px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.part-meta {
  font-size: 11px; color: var(--text-dim);
  margin-top: auto;
}
.part-actions {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.qty-input {
  width: 56px; padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; text-align: center; outline: none;
}
.qty-input:focus { border-color: var(--accent); }
.btn-add {
  flex: 1; padding: 7px 12px; font-size: 13px;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-add:hover { background: var(--accent); color: #fff; }
.btn-add.added { background: var(--success); color: #fff; border-color: var(--success); }

.no-results {
  text-align: center; padding: 48px 16px; color: var(--text-muted);
}
.loading-more { text-align: center; padding: 16px; color: var(--text-dim); }

/* ===== Drawer (Cart) ===== */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(400px, 100vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  padding-top: env(safe-area-inset-top, 0);
}
.drawer.open { transform: translateX(0); }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 199; opacity: 0; transition: opacity 0.28s;
  pointer-events: none;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.drawer-header h2 { font-size: 18px; }
.cart-items {
  flex: 1; overflow-y: auto; padding: 12px;
}
.cart-item {
  display: flex; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item-qr { width: 48px; height: 48px; background: #fff; border-radius: 4px; flex-shrink: 0; }
.cart-item-qr canvas { width: 44px !important; height: 44px !important; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-pn { font-weight: 700; font-size: 12px; color: var(--accent); }
.cart-item-desc { font-size: 12px; color: var(--text-muted); margin: 2px 0; }
.cart-item-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.cart-item-actions .qty-input { width: 52px; padding: 6px 4px; font-size: 14px; text-align: center; }
.btn-qty-minus, .btn-qty-plus {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface, #fff); color: var(--text); font-size: 18px; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.btn-qty-minus:hover, .btn-qty-plus:hover { border-color: var(--accent); color: var(--accent); }
.btn-remove {
  background: none; border: none; color: var(--text-dim);
  font-size: 12px; cursor: pointer; padding: 4px 8px;
}
.btn-remove:hover { color: var(--accent); }
.cart-empty {
  text-align: center; padding: 40px 16px; color: var(--text-muted);
}
.cart-footer {
  padding: 16px; border-top: 1px solid var(--border);
  padding-bottom: calc(16px + var(--safe-bottom));
}
.cart-summary { margin-bottom: 12px; font-weight: 600; color: var(--text-muted); }

/* Side Menu */
.side-menu {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: min(300px, 85vw);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  z-index: 200;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  padding-top: env(safe-area-inset-top, 0);
}
.side-menu.open { transform: translateX(0); }
.side-menu-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.side-logo { width: 120px; }
.side-nav { flex: 1; padding: 12px 0; }
.side-link {
  display: block; width: 100%; text-align: left;
  padding: 14px 20px; background: none; border: none;
  color: var(--text); font-size: 15px; font-weight: 500;
  cursor: pointer;
}
.side-link:hover { background: var(--bg-hover); color: var(--accent); }
.side-nav hr { border: none; border-top: 1px solid var(--border); margin: 8px 16px; }
.side-footer {
  padding: 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); text-align: center;
}
.version { margin-top: 4px; }

/* Checkout Modal */
.checkout-modal { max-width: 560px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; }
.checkout-body { padding: 16px 20px; max-height: 50vh; overflow-y: auto; }
.checkout-meta {
  background: var(--bg); border-radius: var(--radius-sm);
  padding: 12px; margin-bottom: 16px; font-size: 13px;
}
.checkout-meta strong { color: var(--accent); }
.checkout-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.checkout-item-pn { font-weight: 600; color: var(--accent); }
.checkout-item-qty { font-weight: 700; white-space: nowrap; }
.modal-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}

/* Success */
.success-modal { text-align: center; padding: 32px 24px; }
.success-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--success); color: #fff;
  font-size: 32px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.success-actions { display: flex; flex-direction: column; gap: 10px; margin: 24px 0 16px; }
.success-note { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* Admin */
.admin-modal { max-width: 560px; }
.admin-note { font-size: 12px; color: var(--text-muted); padding: 0 20px 12px; }
.admin-list { padding: 0 20px 16px; max-height: 50vh; overflow-y: auto; }
.admin-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px;
}
.admin-card.approved { border-color: var(--success); }
.admin-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.admin-card-id { font-weight: 700; font-size: 13px; }
.admin-status {
  font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 10px; text-transform: uppercase;
}
.admin-status.pending { background: var(--warning); color: #000; }
.admin-status.approved { background: var(--success); color: #fff; }
.admin-card-meta { font-size: 12px; color: var(--text-muted); margin: 6px 0; }
.admin-card-actions { display: flex; gap: 8px; margin-top: 8px; }
.admin-pin { flex: 1; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); }

/* Fulfillment */
.fulfill-modal { max-width: 640px; }
.fulfill-body { padding: 16px 20px; max-height: 55vh; overflow-y: auto; }
.fulfill-items { display: flex; flex-direction: column; gap: 10px; }
.fulfill-row {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.fulfill-qr {
  width: 56px; height: 56px; background: #fff; border-radius: 4px;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.fulfill-qr canvas { width: 52px !important; height: 52px !important; }
.fulfill-info { flex: 1; min-width: 0; }
.fulfill-pn { font-weight: 700; font-size: 13px; color: var(--accent); }
.fulfill-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.fulfill-qty {
  font-weight: 700; font-size: 16px; color: var(--text);
  min-width: 40px; text-align: right;
}

/* Toast */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 500; z-index: 3000;
  box-shadow: var(--shadow); opacity: 0; transition: all 0.25s;
  pointer-events: none; white-space: nowrap; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--accent); }

/* Print Area */
.print-area {
  position: absolute; left: -9999px; top: 0;
  width: 800px; background: #fff; color: #000;
  padding: 24px; font-family: Arial, sans-serif;
}

/* Desktop refinements */
@media (min-width: 768px) {
  .gate-modal, .checkout-modal, .success-modal, .admin-modal, .fulfill-modal {
    max-width: 560px;
  }
  .app-header { padding-left: 20px; padding-right: 16px; }
  .search-bar { padding: 10px 20px; }
  .category-tabs { padding-left: 20px; padding-right: 20px; }
}
