/* ============================================================
   CSS VARIABLES — Dark glass/industrial theme
   ============================================================ */
:root {
  --bg-primary:    #0f1117;
  --bg-secondary:  #1a1d27;
  --bg-tertiary:   #232637;
  --bg-hover:      #2a2e42;
  --accent-blue:   #3b82f6;
  --accent-blue-h: #2563eb;
  --accent-cyan:   #06b6d4;
  --accent-green:  #22c55e;
  --accent-yellow: #f59e0b;
  --accent-orange: #f97316;
  --accent-red:    #ef4444;
  --accent-red-h:  #dc2626;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --border:        #2d3148;
  --border-light:  #3d4160;
  --radius:        8px;
  --radius-sm:     4px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   HEADER
   ============================================================ */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 58px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon {
  font-size: 20px;
  opacity: 0.7;
}

#app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-primary);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-blue-h); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: var(--accent-red);
  color: #fff;
}
.btn-danger:hover { background: var(--accent-red-h); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: color 0.15s, background 0.15s;
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 8px;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s;
}
.btn-clear:hover { color: var(--text-primary); }

/* ============================================================
   SEARCH SECTION
   ============================================================ */
#search-section {
  padding: 14px 20px 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-row { margin-bottom: 10px; }

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: border-color 0.15s;
}
.search-input-wrap:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.search-icon { color: var(--text-muted); font-size: 15px; margin-right: 8px; }

#search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  padding: 10px 0;
}
#search-input::placeholder { color: var(--text-muted); }

.filters-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filters-row select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  min-width: 160px;
}
.filters-row select:focus { border-color: var(--accent-blue); }
.filters-row select option { background: var(--bg-secondary); }

.results-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================================
   RESULTS TABLE
   ============================================================ */
#results-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}

/* Custom scrollbar */
.table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg-primary); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

#results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

#results-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

#results-table th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#results-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}

#results-table tbody tr {
  transition: background 0.12s;
}
#results-table tbody tr:hover {
  background: var(--bg-hover);
}

.loading-cell, .empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
  font-size: 15px;
}

/* Name cell */
.cell-name { min-width: 180px; }
.name-main { font-weight: 500; }
.name-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Size cell */
.size-tag {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  color: var(--accent-cyan);
  white-space: nowrap;
}

/* Type tag */
.type-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: rgba(59,130,246,0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(59,130,246,0.3);
}

/* Corner cell */
.corner-cell {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--text-secondary);
}

/* SKU & ML ID */
.sku-cell, .mlid-cell {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Match-type badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-right: 5px;
  vertical-align: middle;
}
.badge-fuzzy {
  background: rgba(245,158,11,0.2);
  color: var(--accent-yellow);
  border: 1px solid rgba(245,158,11,0.35);
}
.badge-fuzzy_reversed {
  background: rgba(249,115,22,0.2);
  color: var(--accent-orange);
  border: 1px solid rgba(249,115,22,0.35);
}

/* Links */
.drive-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-cyan);
  text-decoration: none;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(6,182,212,0.3);
  transition: background 0.15s;
}
.drive-link:hover { background: rgba(6,182,212,0.1); }

.img-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
  margin-left: 4px;
}
.img-link:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Action buttons */
.actions-cell {
  white-space: nowrap;
}
.btn-edit-row {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  margin-right: 4px;
}
.btn-edit-row:hover {
  background: rgba(59,130,246,0.15);
  color: var(--accent-blue);
  border-color: rgba(59,130,246,0.4);
}
.btn-delete-row {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-delete-row:hover {
  background: rgba(239,68,68,0.15);
  color: var(--accent-red);
  border-color: rgba(239,68,68,0.4);
}

/* ============================================================
   MODAL
   ============================================================ */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

#modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 600px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

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

.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
}

#glass-form {
  overflow-y: auto;
  padding: 20px;
  flex: 1;
}
#glass-form::-webkit-scrollbar { width: 5px; }
#glass-form::-webkit-scrollbar-track { background: transparent; }
#glass-form::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group--full { grid-column: 1 / -1; }

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.required { color: var(--accent-red); margin-left: 2px; }

.form-group input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.form-group input::placeholder { color: var(--text-muted); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* ============================================================
   IMAGE MODAL
   ============================================================ */
#img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

#img-box {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

#img-preview {
  display: block;
  max-width: 85vw;
  max-height: 85vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  object-fit: contain;
}

.img-close-btn {
  position: absolute;
  top: -12px;
  right: -12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 10;
}

/* Header right */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.auth-email {
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Login modal */
#login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
#login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 360px;
  max-width: calc(100vw - 32px);
  padding: 0;
  box-shadow: var(--shadow);
}
#login-box .modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
#login-box form {
  padding: 20px;
}
.login-error {
  font-size: 12px;
  color: var(--accent-red);
  min-height: 16px;
  margin-bottom: 4px;
}

/* File upload row */
.file-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.file-input-row input[type="text"] {
  flex: 1;
}
.btn-upload-label {
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
}
.upload-status {
  font-size: 11px;
  margin-top: 4px;
  min-height: 16px;
  display: block;
}
.upload-status.uploading { color: var(--accent-yellow); }
.upload-status.success   { color: var(--accent-green); }
.upload-status.error     { color: var(--accent-red); }

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

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  #app-header h1 { font-size: 14px; }

  .filters-row { gap: 8px; }
  .filters-row select { min-width: 130px; flex: 1; }

  .form-grid { grid-template-columns: 1fr; }
  .form-group--full { grid-column: 1; }

  /* Hide less important columns on small screens */
  #results-table th:nth-child(5),
  #results-table td:nth-child(5),
  #results-table th:nth-child(6),
  #results-table td:nth-child(6) {
    display: none;
  }
}
