/* ================================================
   PURCHASE REQUEST SYSTEM - Main Stylesheet
   ================================================ */

/* ---- CSS Variables ---- */
:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --accent:        #0ea5e9;
  --success:       #10b981;
  --danger:        #ef4444;
  --warning:       #f59e0b;
  --bg:            #0f172a;
  --bg-card:       #1e293b;
  --bg-card2:      #263347;
  --bg-input:      #0f172a;
  --border:        rgba(99,120,156,0.25);
  --border-light:  rgba(99,120,156,0.15);
  --text:          #e2e8f0;
  --text-muted:    #94a3b8;
  --text-dim:      #64748b;
  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     16px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:     0 2px 8px rgba(0,0,0,0.25);
  --transition:    0.2s cubic-bezier(0.4,0,0.2,1);
  --nav-h:         64px;
  --sidebar-w:     300px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', 'Noto Sans SC', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ================================================
   TOP NAV
   ================================================ */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(15,23,42,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 24px;
  z-index: 1000;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.nav-logo {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: white;
  letter-spacing: 0.5px;
}

.nav-title { display: flex; flex-direction: column; }
.nav-title-main { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; }
.nav-title-sub  { font-size: 11px; color: var(--text-muted); }

.nav-tabs {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.nav-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.nav-tab svg { width: 16px; height: 16px; }
.nav-tab:hover { background: var(--bg-card); color: var(--text); }
.nav-tab.active {
  background: var(--primary);
  color: white;
}

.btn-print {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-print svg { width: 16px; height: 16px; }
.btn-print:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(37,99,235,0.35);
}

/* ================================================
   MAIN CONTENT
   ================================================ */
.main-content {
  margin-top: var(--nav-h);
  min-height: calc(100vh - var(--nav-h));
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ================================================
   PANEL: NEW REQUEST
   ================================================ */
.panel-layout {
  display: flex;
  height: calc(100vh - var(--nav-h));
  overflow: hidden;
}

/* ---- Sidebar ---- */
.form-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-header { margin-bottom: 24px; }
.sidebar-header h2 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.sidebar-header p  { font-size: 12px; color: var(--text-muted); }

.form-section { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.form-input::placeholder { color: var(--text-dim); }
.form-textarea { resize: vertical; min-height: 72px; }
.form-select { cursor: pointer; }
.mt-8 { margin-top: 8px; }
.input-row { display: flex; gap: 8px; }
.input-row .form-input { flex: 1; }

.sidebar-actions {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Shared button base */
.btn-save, .btn-new, .btn-add-item, .btn-add-product, .btn-save-product, .btn-cancel {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.btn-save svg, .btn-new svg, .btn-add-item svg, .btn-add-product svg, .btn-save-product svg { width: 16px; height: 16px; }

.btn-save {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}
.btn-save:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.4); }

.btn-new {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-new:hover { color: var(--text); border-color: var(--text-dim); }

/* ---- Items Section ---- */
.items-section {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.items-header h3 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.item-count {
  font-size: 11px; font-weight: 600;
  background: var(--primary);
  color: white;
  padding: 2px 10px;
  border-radius: 20px;
}

.btn-add-item {
  background: var(--success);
  color: white;
  padding: 8px 16px;
}
.btn-add-item:hover { opacity: 0.9; transform: translateY(-1px); }

/* ---- Product Search ---- */
.product-search-bar { position: relative; }
.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  gap: 10px;
  transition: var(--transition);
}
.search-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.search-icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.product-search-input {
  flex: 1;
  padding: 10px 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.product-search-input::placeholder { color: var(--text-dim); }

.product-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 280px;
  overflow-y: auto;
}
.product-dropdown.open { display: block; animation: fadeDown 0.15s ease; }

.product-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid var(--border-light);
}
.product-option:last-child { border-bottom: none; }
.product-option:hover { background: var(--bg-card2); }
.product-option-img {
  width: 40px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.product-option-img-placeholder {
  width: 40px; height: 40px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 16px;
}
.product-option-info { display: flex; flex-direction: column; gap: 2px; }
.product-option-cn  { font-size: 14px; font-weight: 600; color: var(--text); }
.product-option-en  { font-size: 12px; color: var(--text-muted); }
.product-option-unit { font-size: 11px; color: var(--text-dim); background: var(--bg); padding: 2px 6px; border-radius: 4px; margin-left: auto; }

/* ---- Items Table ---- */
.table-wrapper { overflow-x: auto; flex: 1; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.items-table thead tr { background: var(--bg-card2); }
.items-table th {
  padding: 12px 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.items-table th small { display: block; font-size: 10px; text-transform: none; letter-spacing: 0; color: var(--text-dim); font-weight: 400; }

.items-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.items-table tbody tr:hover { background: var(--bg-card2); }
.items-table tbody tr:last-child { border-bottom: none; }

.items-table td {
  padding: 8px 6px;
  text-align: center;
  vertical-align: middle;
}

.col-no    { width: 44px; }
.col-img   { width: 60px; }
.col-cn    { min-width: 90px; }
.col-en    { min-width: 120px; }
.col-spec  { min-width: 100px; }
.col-unit  { width: 70px; }
.col-qty   { width: 70px; }
.col-notes { min-width: 90px; }
.col-date  { min-width: 120px; }
.col-action{ width: 40px; }

.row-no {
  width: 28px; height: 28px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  margin: auto;
}

.item-img-thumb {
  width: 44px; height: 44px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
  margin: auto;
}
.item-img-empty {
  width: 44px; height: 44px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  margin: auto;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: var(--transition);
}
.item-img-empty:hover { border-color: var(--primary); color: var(--primary); }

.table-cell-input {
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  text-align: center;
  transition: var(--transition);
  outline: none;
}
.table-cell-input:hover { border-color: var(--border); background: var(--bg-input); }
.table-cell-input:focus { border-color: var(--primary); background: var(--bg-input); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }

.btn-delete-row {
  width: 28px; height: 28px;
  border: none; background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.btn-delete-row:hover { background: rgba(239,68,68,0.1); color: var(--danger); }
.btn-delete-row svg { width: 14px; height: 14px; }

.empty-table {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 60px 24px;
  color: var(--text-dim); text-align: center;
}
.empty-table svg { width: 48px; height: 48px; opacity: 0.4; }
.empty-table p { font-size: 13px; max-width: 280px; line-height: 1.6; }

/* ================================================
   PANEL: HISTORY
   ================================================ */
.history-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}
.history-header { margin-bottom: 24px; }
.history-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.history-header p  { color: var(--text-muted); font-size: 13px; }

.history-list { display: flex; flex-direction: column; gap: 12px; }

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  transition: var(--transition);
}
.history-card:hover { border-color: var(--primary); transform: translateX(4px); }

.history-card-left { display: flex; flex-direction: column; gap: 4px; }
.history-req-no { font-size: 15px; font-weight: 700; color: var(--primary); }
.history-project { font-size: 13px; color: var(--text); }
.history-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 16px; }

.history-card-actions { display: flex; gap: 8px; }
.btn-history-load, .btn-history-delete {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
  font-family: inherit;
}
.btn-history-load svg, .btn-history-delete svg { width: 14px; height: 14px; }
.btn-history-load:hover { background: var(--primary); border-color: var(--primary); color: white; }
.btn-history-delete:hover { background: rgba(239,68,68,0.1); border-color: var(--danger); color: var(--danger); }

/* ================================================
   PANEL: PRODUCTS
   ================================================ */
.products-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}
.products-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}
.products-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.products-header p  { color: var(--text-muted); font-size: 13px; }

.btn-add-product {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-add-product:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.3); }

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
}
.product-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 8px 32px rgba(37,99,235,0.15); }

.product-card-img {
  width: 100%; height: 140px;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.product-card-img-placeholder {
  width: 100%; height: 140px;
  background: linear-gradient(135deg, var(--bg), var(--bg-card2));
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}
.product-card-body { padding: 14px; }
.product-card-cn { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.product-card-en { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.product-card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.product-tag {
  font-size: 10px; font-weight: 500;
  background: var(--bg);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.product-card-actions {
  display: flex;
  border-top: 1px solid var(--border);
}
.btn-pc-action {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-family: inherit;
}
.btn-pc-action svg { width: 13px; height: 13px; }
.btn-pc-action:first-child { border-right: 1px solid var(--border); }
.btn-pc-action:hover { background: var(--bg-card2); color: var(--text); }
.btn-pc-delete:hover { background: rgba(239,68,68,0.1) !important; color: var(--danger) !important; }

/* ================================================
   MODAL
   ================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s cubic-bezier(0.4,0,0.2,1);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--bg);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: rgba(239,68,68,0.1); color: var(--danger); }

.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 4px; }

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  position: sticky; bottom: 0;
  background: var(--bg-card);
}

.btn-cancel {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-cancel:hover { color: var(--text); border-color: var(--text-dim); }

.btn-save-product {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
}
.btn-save-product:hover { opacity: 0.9; transform: translateY(-1px); }

/* Image Upload */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  height: 160px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
  position: relative;
}
.image-upload-area:hover { border-color: var(--primary); background: rgba(37,99,235,0.04); }

#modalImagePreview {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.upload-placeholder {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; color: var(--text-dim);
  text-align: center;
}
.upload-placeholder svg    { width: 36px; height: 36px; }
.upload-placeholder p      { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.upload-placeholder small  { font-size: 11px; }

/* ================================================
   TOAST
   ================================================ */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slideInRight 0.3s ease;
  min-width: 220px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }
.toast.info    { border-left: 3px solid var(--primary); }
.toast-icon    { font-size: 16px; }
.toast-out     { animation: slideOutRight 0.3s ease forwards; }

/* ================================================
   LOADING
   ================================================ */
.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 60px; color: var(--text-dim);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ================================================
   PRINT AREA (HIDDEN UNTIL PRINT)
   ================================================ */
.print-area { display: none; }

/* ================================================
   KEYFRAMES
   ================================================ */
@keyframes fadeIn    { from { opacity: 0; }           to { opacity: 1; }           }
@keyframes fadeDown  { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes slideUp   { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes slideInRight  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes slideOutRight { to { opacity: 0; transform: translateX(20px); } }
@keyframes spin      { to { transform: rotate(360deg); } }
