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

:root {
  --brand-dark: #1a1a2e;
  --brand-accent: #16213e;
  --brand-blue: #0f3460;
  --brand-highlight: #e94560;
  --text: #1a1a2e;
  --text-light: #666;
  --text-muted: #999;
  --bg: #f5f6fa;
  --card: #fff;
  --border: #e0e0e0;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

input, select, button, textarea { font-family: inherit; font-size: 14px; }

/* ============ LOGIN ============ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand-accent) 50%, var(--brand-blue) 100%);
}

.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 48px 40px;
  width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo { height: 48px; margin-bottom: 24px; }
.login-card h2 { font-size: 22px; font-weight: 600; color: var(--brand-dark); margin-bottom: 4px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--bg);
  transition: border-color 0.2s;
}
.login-card input:focus { outline: none; border-color: var(--brand-blue); }

.error-msg { color: var(--brand-highlight); font-size: 13px; margin-top: 12px; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary { background: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--brand-blue); color: var(--brand-blue); }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }

/* ============ HEADER ============ */
.app-header {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 60px;
  background: var(--brand-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.header-left { display: flex; align-items: center; }
.header-logo { height: 32px; }
.header-nav { display: flex; gap: 4px; margin-left: 40px; }
.nav-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.2s;
}
.nav-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: #fff; background: var(--brand-blue); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: rgba(255,255,255,0.7); }
.header-right .btn-outline { border-color: rgba(255,255,255,0.3); color: rgba(255,255,255,0.8); }
.header-right .btn-outline:hover { border-color: #fff; color: #fff; }

/* ============ TABS ============ */
.tab-content { padding: 24px; max-width: 1400px; margin: 0 auto; }
.tab-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.tab-toolbar h2 { font-size: 20px; font-weight: 600; }
.boq-main > .tab-toolbar { position: sticky; top: 60px; z-index: 90; background: var(--bg); padding: 12px 0; border-bottom: 1px solid var(--border); }
.toolbar-actions { display: flex; gap: 10px; align-items: center; }

.input-search, .input-select {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.input-search { width: 240px; }
.input-search:focus, .input-select:focus { outline: none; border-color: var(--brand-blue); }

/* ============ PRODUCT GRID (CATALOG) ============ */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.12); }

.product-card-img {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f9f9fb;
  padding: 12px;
}
.product-card-img img { max-height: 100%; max-width: 100%; object-fit: contain; }
.product-card-img .no-img { font-size: 48px; color: #ddd; }

.product-card-body { padding: 14px 16px; }
.product-card-code { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.product-card-name { font-size: 13px; font-weight: 500; margin: 4px 0 8px; line-height: 1.4; min-height: 36px; }
.product-card-meta { display: flex; gap: 8px; font-size: 11px; color: var(--text-light); margin-bottom: 8px; }
.product-card-meta span { background: var(--bg); padding: 2px 8px; border-radius: 4px; }
.product-card-prices { display: flex; justify-content: space-between; align-items: center; }
.product-card-price { font-weight: 600; color: var(--brand-blue); }
.product-card-di { font-size: 11px; color: var(--text-muted); }
.product-card-tiers { font-size: 11px; color: var(--text-muted); }
.product-card-cat { display: inline-block; font-size: 10px; background: var(--brand-blue); color: #fff; padding: 2px 8px; border-radius: 10px; margin-bottom: 6px; }

/* ============ BOQ BUILDER ============ */
.boq-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.boq-main { min-width: 0; }

.boq-header-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.boq-header-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 11px; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; }
.field-group input, .field-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  transition: border-color 0.2s;
}
.field-group input:focus, .field-group select:focus { outline: none; border-color: var(--brand-blue); background: #fff; }

/* Global Discount Bar */
.global-discount-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 12px;
}
.global-discount-bar label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
}
.global-discount-bar input {
  width: 80px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}
.global-discount-bar input:focus { outline: none; border-color: var(--brand-blue); }
.global-discount-note {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  margin-left: auto;
}

/* BOQ Items List */
.boq-items-list { display: flex; flex-direction: column; gap: 2px; }

.boq-section-row {
  background: var(--brand-blue);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  cursor: grab;
}
.boq-section-row .section-name { font-weight: 600; font-size: 14px; }
.boq-section-row .section-subtotal { font-size: 13px; opacity: 0.8; }
.boq-section-row .section-actions { display: flex; gap: 6px; }
.boq-section-row .section-actions button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.boq-section-row .section-actions button:hover { background: rgba(255,255,255,0.35); }
.section-add-btn { background: rgba(255,255,255,0.15) !important; border-color: rgba(255,255,255,0.3) !important; color: #fff !important; font-size: 11px !important; }
.section-add-btn:hover { background: rgba(255,255,255,0.25) !important; border-color: rgba(255,255,255,0.5) !important; }

.ep-image-row { display: flex; align-items: center; gap: 12px; }
.ep-image-preview { width: 60px; height: 60px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); background: #fafafa; }
.ep-image-name { font-size: 11px; color: var(--text-muted); }

.linked-checkbox { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--brand-blue); cursor: pointer; margin-top: 4px; }
.linked-checkbox input { cursor: pointer; }
.linked-sub-item { background: #f0f4ff !important; border-left: 3px solid var(--brand-blue) !important; margin-left: 24px; }

.boq-product-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 50px 1fr 80px 80px 80px 80px 36px;
  gap: 10px;
  align-items: center;
  cursor: grab;
  transition: box-shadow 0.2s;
}
.boq-product-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.boq-product-row .prod-img {
  width: 50px;
  height: 50px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--bg);
}
.boq-product-row .prod-info { min-width: 0; }
.boq-product-row .prod-code { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.boq-product-row .prod-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.boq-product-row .prod-field input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 13px;
}
.boq-product-row .prod-field input:focus { outline: none; border-color: var(--brand-blue); }
.boq-product-row .prod-field label { font-size: 10px; color: var(--text-muted); text-align: center; display: block; }
.boq-product-row .prod-total { font-weight: 600; font-size: 13px; color: var(--brand-blue); text-align: right; }
.boq-product-row .prod-remove {
  background: none;
  border: none;
  color: #ccc;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.boq-product-row .prod-remove:hover { color: var(--brand-highlight); background: #fff0f0; }

.boq-product-row.has-variants { border-left: 3px solid var(--brand-blue); }
.boq-product-row.volume-priced { border-left: 3px solid #f0ad4e; }
.boq-product-row .volume-tag {
  display: inline-block;
  font-size: 9px;
  background: #fff3cd;
  color: #856404;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

.prod-variants { display: flex; gap: 6px; margin-top: 4px; }
.variant-select {
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.variant-select:focus { outline: none; border-color: var(--brand-blue); }

.engraving-tag {
  display: inline-block;
  font-size: 9px;
  background: #f8d7da;
  color: #721c24;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

.boq-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  background: var(--card);
  border-radius: var(--radius);
  border: 2px dashed var(--border);
}
.boq-empty p { font-size: 15px; margin-bottom: 8px; }
.boq-empty small { font-size: 12px; }

.driver-info {
  background: #fff3cd;
  border: 1px solid #f0ad4e;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #856404;
}
.driver-info-icon { font-size: 18px; }

/* ============ BOQ SIDEBAR ============ */
.boq-sidebar { position: sticky; top: 84px; }

.sidebar-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.sidebar-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--brand-dark); }

.totals-card .totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.totals-card .totals-row.grand { border-top: 2px solid var(--brand-dark); margin-top: 8px; padding-top: 10px; font-size: 16px; font-weight: 700; color: var(--brand-dark); }
.totals-card .totals-row.di-total-row { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 6px; font-size: 12px; color: var(--text-muted); }
.totals-card .totals-row.di-total-row .value { font-weight: 500; color: var(--text-muted); }
.totals-card .totals-row .label { color: var(--text-light); }
.totals-card .totals-row .value { font-weight: 600; }

.di-card { background: #fafafa; border: 1px dashed var(--border); }
.di-card h3 { color: var(--text-muted); }
.di-rows .di-row { display: flex; justify-content: space-between; font-size: 12px; padding: 3px 0; color: var(--text-light); }

#exportBtn { margin-bottom: 12px; }

/* ============ PICKER MODAL ============ */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}

.picker-item {
  display: flex;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  align-items: center;
}
.picker-item:hover { border-color: var(--brand-blue); background: #f0f4ff; }

.picker-item img { width: 48px; height: 48px; object-fit: contain; border-radius: 4px; background: var(--bg); }
.picker-item .no-img { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 4px; color: #ddd; font-size: 24px; }
.picker-item-info { flex: 1; min-width: 0; }
.picker-item-code { font-size: 10px; color: var(--text-muted); font-weight: 600; }
.picker-item-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-item-price { font-size: 11px; color: var(--brand-blue); font-weight: 600; }

/* ============ MODALS ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}
.modal-content {
  background: var(--card);
  border-radius: 12px;
  width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-lg { width: 800px; }
.modal-sm { width: 380px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.modal-toolbar .input-search { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.form-grid .full-width { grid-column: 1 / -1; }

/* ============ DATA TABLE ============ */
.data-table {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-collapse: collapse;
  overflow: hidden;
}
.data-table th {
  background: var(--brand-dark);
  color: #fff;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:hover td { background: #f8f9ff; }
.data-table .actions { display: flex; gap: 6px; }

/* ============ DRAGGING ============ */
.dragging { opacity: 0.5; }
.drag-over { border-top: 3px solid var(--brand-blue) !important; }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .boq-layout { grid-template-columns: 1fr; }
  .boq-sidebar { position: static; }
  .boq-product-row { grid-template-columns: 40px 1fr 60px 60px 60px 60px 30px; gap: 6px; padding: 8px 10px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 600px) {
  .app-header { padding: 0 12px; }
  .header-nav { margin-left: 12px; }
  .nav-btn { padding: 6px 10px; font-size: 11px; }
  .tab-content { padding: 12px; }
  .boq-product-row { grid-template-columns: 1fr; gap: 8px; }
}
