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

/* ===== GLOBAL UTILITY ===== */
.hidden { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ===== VIEWS ===== */
.view { display: none; }
.view.active { display: flex; }
.view.hidden { display: none; }

/* ===== LOGIN VIEW ===== */
#view-login {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

/* ===== FORM FIELDS ===== */
.field {
  margin-bottom: 1.1rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 0.4rem;
}

.field input,
.field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  font-size: 0.95rem;
  background: #fafafa;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: #0f3460;
  background: #fff;
}

.required-star { color: #c0392b; margin-left: 2px; }
.unit-hint { font-weight: 400; color: #888; font-size: 0.8rem; }

/* ===== BUTTONS ===== */
button {
  cursor: pointer;
  border: none;
  border-radius: 7px;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1.25rem;
  transition: background 0.2s, opacity 0.2s;
}

#login-btn, .btn-primary {
  width: 100%;
  background: #0f3460;
  color: #fff;
  margin-top: 0.5rem;
}

#login-btn:hover:not(:disabled), .btn-primary:hover:not(:disabled) {
  background: #16213e;
}

#login-btn:disabled, .btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.btn-secondary:hover { background: rgba(255,255,255,0.1); }

.btn-admin {
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 7px;
}

.btn-admin:hover { background: rgba(255,255,255,0.25); }

/* ===== ERROR / SUCCESS MESSAGES ===== */
.error-msg {
  font-size: 0.85rem;
  color: #c0392b;
  margin-bottom: 0.75rem;
}
.error-msg.hidden { display: none; }

.success-msg {
  font-size: 0.85rem;
  color: #27ae60;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #eafaf1;
  border-radius: 6px;
  border: 1px solid #a9dfbf;
}
.success-msg.hidden { display: none; }

/* ===== APP HEADER ===== */
.app-header {
  background: #0f3460;
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  font-size: 0.82rem;
  opacity: 0.8;
}

/* ===== SELECTOR VIEW ===== */
#view-selector {
  flex-direction: column;
  min-height: 100vh;
}

.selector-main {
  max-width: 560px;
  width: 100%;
  margin: 3rem auto;
  padding: 0 1rem;
}

.selector-main h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.4rem;
}

.hint {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

.hint.hidden { display: none; }

#start-request-btn {
  margin-top: 1.5rem;
}

/* ===== REQUEST FORM VIEW ===== */
#view-request {
  flex-direction: column;
  min-height: 100vh;
}

.form-main {
  max-width: 640px;
  width: 100%;
  margin: 2.5rem auto;
  padding: 0 1rem;
}

.form-main h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.4rem;
}

.meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

@media (max-width: 480px) {
  .meta-fields { grid-template-columns: 1fr; }
}

.form-divider {
  border: none;
  border-top: 1.5px solid #e5e5e5;
  margin: 1.25rem 0 1.5rem;
}

#request-submit-btn { margin-top: 1.5rem; }

/* ===== RESULTS VIEW ===== */
#view-results {
  flex-direction: column;
  min-height: 100vh;
}

.results-main {
  max-width: 900px;
  width: 100%;
  margin: 2.5rem auto;
  padding: 0 1rem;
}

.results-main h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.35rem;
}

#results-table-wrap.hidden { display: none; }

.results-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  margin-top: 1rem;
}

.results-table th {
  background: #0f3460;
  color: #fff;
  text-align: left;
  padding: 0.65rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.results-table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
  vertical-align: middle;
}

.results-table tr:last-child td { border-bottom: none; }
.results-table tr:hover td { background: #f8f9ff; }

.rank-cell {
  font-weight: 700;
  color: #0f3460;
  width: 2rem;
  text-align: center;
}

.priority-cell {
  text-align: center;
  color: #888;
}

.mono { font-family: monospace; font-size: 0.85rem; }

.miss-cell {
  font-size: 0.8rem;
  color: #999;
  max-width: 220px;
  word-break: break-word;
}

.score-label {
  font-weight: 700;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 3px;
}

.score-bar-wrap {
  background: #eee;
  border-radius: 4px;
  height: 6px;
  width: 100px;
  overflow: hidden;
}

.score-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s;
}

/* ===== ADMIN VIEWS ===== */
#view-admin-vendors,
#view-admin-brands,
#view-admin-pt,
#view-admin-priority,
#view-admin-catalog,
#view-admin-specs,
#view-admin-upload {
  flex-direction: column;
  min-height: 100vh;
}

.admin-main {
  max-width: 1100px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
}

.admin-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.admin-filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.admin-filter-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #444;
}

.admin-filter-group select {
  padding: 0.5rem 0.75rem;
  border: 1.5px solid #ddd;
  border-radius: 7px;
  font-size: 0.9rem;
  background: #fff;
  min-width: 180px;
  -webkit-appearance: none;
  appearance: none;
}

.btn-action {
  background: #0f3460;
  color: #fff;
  padding: 0.5rem 1.1rem;
  font-size: 0.9rem;
  border-radius: 7px;
  margin-left: auto;
}

.btn-action:hover { background: #16213e; }

/* Admin table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  font-size: 0.88rem;
}

.admin-table th {
  background: #0f3460;
  color: #fff;
  text-align: left;
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.admin-table td {
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f8f9ff; }

.admin-table tr.inactive-row td { opacity: 0.45; }

.col-order { width: 80px; text-align: center; }
.col-actions { width: 140px; text-align: center; white-space: nowrap; }

.desc-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  color: #555;
}

/* Order arrows */
.order-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.order-num {
  font-weight: 700;
  color: #0f3460;
  min-width: 20px;
  text-align: center;
  font-size: 0.85rem;
}

.btn-arrow {
  background: #e8edf5;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
  color: #0f3460;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s;
}

.btn-arrow:hover:not(:disabled) { background: #c8d4e8; }
.btn-arrow:disabled { opacity: 0.25; cursor: default; }

/* Action buttons in table */
.btn-edit {
  background: #e8f4fd;
  color: #1a6fa8;
  border: none;
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-right: 4px;
}
.btn-edit:hover { background: #cce5f7; }

.btn-deactivate {
  background: #fdf0e8;
  color: #c0392b;
  border: none;
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-deactivate:hover { background: #f9d5c8; }

.btn-activate {
  background: #eafaf1;
  color: #27ae60;
  border: none;
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-activate:hover { background: #c8f0d8; }

.badge-match {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-exact    { background: #e8f4fd; color: #1a6fa8; }
.badge-range    { background: #fef9e7; color: #b7770d; }
.badge-nearest  { background: #eafaf1; color: #27ae60; }

.badge-req {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-yes { background: #fde8e8; color: #c0392b; }
.badge-no  { background: #f0f0f0; color: #888; }

.badge-active {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-on  { background: #eafaf1; color: #27ae60; }
.badge-off { background: #f0f0f0; color: #aaa; }

/* pt group header row */
.pt-group-row td {
  background: #eef1f8;
  font-weight: 700;
  font-size: 0.82rem;
  color: #0f3460;
  padding: 0.4rem 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-bottom: 1px solid #d8dff0;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-height: 90vh;
  overflow-y: auto;
}

/* Wider modal for catalog items (many spec fields) */
.catalog-modal-card {
  max-width: 700px;
}

.modal-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 1.25rem;
}

.modal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #444;
  cursor: pointer;
  padding-top: 0.3rem;
}

.checkbox-field input[type=checkbox] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn-modal-cancel {
  background: #f0f2f5;
  color: #444;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
}
.btn-modal-cancel:hover { background: #dde1e8; }

.btn-modal-save {
  background: #0f3460;
  color: #fff;
  padding: 0.55rem 1.3rem;
  font-size: 0.9rem;
}
.btn-modal-save:hover { background: #16213e; }

/* Catalog item spec fields grid */
.catalog-specs-header {
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.75rem;
}

.catalog-specs-hint {
  font-size: 0.78rem;
  font-weight: 400;
  color: #888;
  margin-left: 6px;
}

.catalog-specs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

@media (max-width: 560px) {
  .catalog-specs-grid { grid-template-columns: 1fr; }
  .catalog-modal-card  { max-width: 100%; }
}

/* ===== CATALOG UPLOAD VIEW ===== */
.upload-intro h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 0.35rem;
}

.upload-section {
  margin-top: 2rem;
}

.upload-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0f3460;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #e5e5e5;
}

/* Template download cards */
.template-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .template-cards { grid-template-columns: 1fr; }
}

.template-card {
  background: #fff;
  border: 1.5px solid #e0e4ed;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.04);
}

.template-card-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.template-card-body {
  flex: 1;
}

.template-card-body strong {
  display: block;
  font-size: 0.9rem;
  color: #1a1a2e;
  margin-bottom: 0.35rem;
}

.template-card-body p {
  font-size: 0.8rem;
  color: #666;
  line-height: 1.5;
}

.template-card-body code {
  background: #f0f2f5;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.78rem;
  color: #0f3460;
}

.btn-dl {
  background: #eef1f8;
  color: #0f3460;
  border: 1.5px solid #c8d4e8;
  border-radius: 7px;
  padding: 0.4rem 0.8rem;
  font-size: 0.83rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: center;
}
.btn-dl:hover { background: #c8d4e8; }

/* Upload panels */
.upload-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 700px) {
  .upload-panels { grid-template-columns: 1fr; }
}

.upload-panel {
  background: #fff;
  border: 1.5px solid #e0e4ed;
  border-radius: 10px;
  padding: 1.1rem 1.1rem 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.04);
}

.upload-panel-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.upload-panel-num {
  background: #0f3460;
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.upload-panel-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1a1a2e;
  flex: 1;
}

.upload-file-status {
  font-size: 0.78rem;
  color: #27ae60;
  font-weight: 600;
}

.file-drop-zone {
  display: block;
  border: 2px dashed #c8d4e8;
  border-radius: 8px;
  padding: 1.1rem;
  text-align: center;
  font-size: 0.85rem;
  color: #888;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  user-select: none;
}

.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: #0f3460;
  background: #f0f4fc;
  color: #0f3460;
}

.hidden-file-input {
  display: none;
}

/* Preview table */
.preview-wrap {
  margin-top: 0.85rem;
}
.preview-wrap.hidden { display: none; }

.preview-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #666;
  margin-bottom: 0.4rem;
}

.preview-scroll {
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid #e0e4ed;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.preview-table th {
  background: #eef1f8;
  color: #0f3460;
  padding: 0.4rem 0.6rem;
  text-align: left;
  font-weight: 700;
  white-space: nowrap;
}

.preview-table td {
  padding: 0.35rem 0.6rem;
  border-top: 1px solid #f0f0f0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Validation message */
.upload-validate-msg {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  border-radius: 5px;
  padding: 0.4rem 0.65rem;
}
.upload-validate-msg.hidden { display: none; }
.upload-validate-msg.success { background: #eafaf1; color: #27ae60; border: 1px solid #a9dfbf; }
.upload-validate-msg.error   { background: #fdf0e8; color: #c0392b; border: 1px solid #f5c6b0; }

/* Run upload button row */
.upload-action-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
}

.upload-run-btn {
  width: auto;
  padding: 0.65rem 2rem;
  font-size: 1rem;
}

/* Upload log */
.upload-log {
  background: #1a1a2e;
  color: #c8f7c5;
  border-radius: 8px;
  padding: 1rem 1.1rem;
  font-family: monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  max-height: 320px;
  overflow-y: auto;
}

.upload-log p { margin: 0; }
.log-ok    { color: #2ecc71; }
.log-warn  { color: #f39c12; }
.log-error { color: #e74c3c; }
