/* =========================================================
   Depot IT Asset Tool — Design System
   ========================================================= */

/* ----- Tokens ----- */
:root {
  --color-primary:        #1565C0;
  --color-primary-hover:  #0D47A1;
  --color-primary-light:  #E3F2FD;
  --color-primary-rgb:    21, 101, 192;

  --color-success:        #2E7D32;
  --color-success-light:  #E8F5E9;
  --color-warning:        #B45309;
  --color-warning-light:  #FEF3C7;
  --color-error:          #B91C1C;
  --color-error-light:    #FEE2E2;
  --color-info:           #0277BD;
  --color-info-light:     #E1F5FE;
  --color-orange:         #C2410C;
  --color-orange-light:   #FED7AA;

  --neutral-0:   #FFFFFF;
  --neutral-50:  #F8FAFC;
  --neutral-100: #F1F5F9;
  --neutral-200: #E2E8F0;
  --neutral-300: #CBD5E1;
  --neutral-400: #94A3B8;
  --neutral-500: #64748B;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1E293B;
  --neutral-900: #0F172A;

  --color-bg:             #EFF3F8;
  --color-surface:        #FFFFFF;
  --color-border:         #E2E8F0;
  --color-border-light:   #F1F5F9;

  --color-text:           #0F172A;
  --color-text-secondary: #475569;
  --color-text-tertiary:  #94A3B8;

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  --font-normal:   400;
  --font-medium:   500;
  --font-semibold: 600;
  --font-bold:     700;

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-pill: 9999px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg:  0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
}

/* ----- Reset ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
input, select { font-family: inherit; }

/* ----- Layout ----- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-bold);
  font-size: var(--text-sm);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
.logo-text {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}
.logo-sub {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-left: auto;
}

.page-content {
  max-width: 1160px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ----- Stepper ----- */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 32px;
}
.step {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  flex-shrink: 0;
  border: 2px solid var(--neutral-300);
  color: var(--neutral-400);
  background: var(--color-surface);
}
.step-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--neutral-400);
  white-space: nowrap;
}
.step.active .step-num {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}
.step.active .step-label { color: var(--color-primary); font-weight: var(--font-semibold); }
.step.done .step-num {
  background: var(--color-success-light);
  border-color: var(--color-success);
  color: var(--color-success);
}
.step.done .step-label { color: var(--color-success); }
.step-line {
  flex: 1;
  height: 2px;
  background: var(--neutral-200);
  margin: 0 8px;
}
.step-line.done { background: var(--color-success); }

/* ----- Cards ----- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}
.card-body { padding: 24px; }

/* ----- Upload Card ----- */
.upload-card {
  max-width: 640px;
  margin: 0 auto;
}
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
  margin-bottom: 6px;
}
.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
.form-select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--neutral-300);
  border-radius: var(--radius-md);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  background: var(--neutral-50);
  position: relative;
}
.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.drop-zone-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  color: var(--neutral-400);
}
.drop-zone-icon.has-file { color: var(--color-success); }
.drop-zone-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.drop-zone-text strong { color: var(--color-primary); }
.drop-zone-hint {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-top: 4px;
}
.drop-zone-filename {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-success);
  margin-top: 8px;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  min-height: 44px;
}
@media (prefers-reduced-motion: no-preference) {
  .btn { transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease; }
}
.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--color-primary-rgb), 0.35);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-success {
  background: var(--color-success);
  color: white;
}
.btn-success:hover:not(:disabled) {
  background: #1B5E20;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(46,125,50,0.35);
}
.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--neutral-100);
  color: var(--color-text);
}
.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
  min-height: 32px;
  gap: 4px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-full { width: 100%; }

/* Loading spinner inside button */
.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ----- Stat Cards ----- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
}
@media (prefers-reduced-motion: no-preference) {
  .stat-card { transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.stat-card.active {
  border-width: 2px;
  box-shadow: var(--shadow-md);
}
.stat-card .stat-label {
  font-size: 11px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  line-height: 1;
}
.stat-card.ready     .stat-value { color: var(--color-success); }
.stat-card.ready.active          { border-color: var(--color-success); }
.stat-card.no-dep    .stat-value { color: var(--color-info); }
.stat-card.no-dep.active         { border-color: var(--color-info); }
.stat-card.errors    .stat-value { color: var(--color-error); }
.stat-card.errors.active         { border-color: var(--color-error); }
.stat-card.out       .stat-value { color: var(--color-orange); }
.stat-card.out.active            { border-color: var(--color-orange); }
.stat-card.success   .stat-value { color: var(--color-success); }

/* ----- Results Section ----- */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.results-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ----- Table ----- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  position: relative;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--neutral-100);
  border-bottom: 2px solid var(--color-border);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  white-space: nowrap;
}
tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  color: var(--color-text);
  line-height: 1.3;
}
tbody tr:last-child td { border-bottom: none; }
/* State-tinted row backgrounds */
tbody tr                              { background: var(--color-surface); }
tbody tr:nth-child(even)              { background: var(--neutral-50); }
tbody tr[data-state="READY"]          { background: #F0FFF0; }
tbody tr[data-state="READY_NO_DEP"]   { background: #F0F9FF; }
tbody tr[data-state="ALREADY_CHECKED_OUT"] { background: #FFF7ED; }
tbody tr[data-state="NOT_FOUND"]      { background: #FFF5F5; }
tbody tr[data-state="TYPE_MISMATCH"]  { background: #FFFBEB; }
tbody tr[data-state="DUPLICATE"]      { background: #FFF5F5; }
tbody tr[data-state="FAILED"]         { background: #FFF5F5; }
tbody tr[data-state="SUCCESS"]        { background: #F0FFF0; }
tbody tr:hover                        { background: var(--color-primary-light) !important; }
/* Filtered-out rows */
tbody tr.row-filtered                 { display: none; }
/* Key columns emphasized */
.td-serial { font-weight: var(--font-semibold); color: var(--color-text); }
.td-name   { font-weight: var(--font-medium); color: var(--color-text); }
/* Dim reference columns */
.td-dim    { color: var(--neutral-400); font-size: 11px; }
/* Row checkbox column */
.td-check { width: 36px; text-align: center; }
.td-check input[type="checkbox"] {
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--color-primary);
  margin: 0;
}
.th-check { width: 36px; text-align: center; }
.th-check input[type="checkbox"] {
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--color-primary);
  margin: 0;
}
.mono { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 11px; }
.td-muted { color: var(--color-text-secondary); }
.td-em { font-weight: var(--font-medium); }
/* Compact row number */
.td-rownum { color: var(--neutral-400); font-size: 11px; width: 30px; }

/* ----- Loading Overlay ----- */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  border-radius: var(--radius-lg);
}
.loading-overlay.section-hidden { display: none; }
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--neutral-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 12px;
}
.loading-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
}
.loading-subtext {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-top: 4px;
}

/* Override button for errors */
.btn-override {
  background: transparent;
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: var(--font-medium);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  min-height: 0;
  margin-top: 4px;
}
.btn-override:hover {
  background: var(--color-warning-light);
}

/* Selected row count */
.selected-count {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--font-medium);
}

/* ----- Badges ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.badge-ready           { background: var(--color-success-light); color: var(--color-success); }
.badge-ready-no-dep    { background: var(--color-info-light);    color: var(--color-info); }
.badge-not-found       { background: var(--color-error-light);   color: var(--color-error); }
.badge-duplicate       { background: var(--color-error-light);   color: var(--color-error); }
.badge-ambiguous       { background: var(--color-error-light);   color: var(--color-error); }
.badge-checked-out     { background: var(--color-orange-light);  color: var(--color-orange); }
.badge-type-mismatch   { background: var(--color-warning-light); color: var(--color-warning); }
.badge-checking-out    { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success         { background: var(--color-success-light); color: var(--color-success); }
.badge-failed          { background: var(--color-error-light);   color: var(--color-error); }
.badge-pending         { background: var(--neutral-100);         color: var(--neutral-500); }
.badge-api-error       { background: var(--color-error-light);   color: var(--color-error); }

/* Spinner inside badge */
.badge-spinner {
  width: 10px; height: 10px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

/* Confirm checkbox for NO_DEP */
.confirm-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.confirm-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--color-info); }
.confirm-row label { font-size: var(--text-xs); color: var(--color-info); cursor: pointer; }

/* Reason text — compact inline */
.reason-text {
  font-size: 10px;
  color: var(--color-text-tertiary);
  margin-top: 2px;
  display: block;
  max-width: 200px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reason-text.error { color: var(--color-error); }
.reason-text.orange { color: var(--color-orange); }
/* Tooltip on hover for full reason */
.state-cell { position: relative; }
.state-cell:hover .reason-text {
  white-space: normal;
  overflow: visible;
  position: absolute;
  z-index: 10;
  background: var(--neutral-900);
  color: white;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  max-width: 280px;
  box-shadow: var(--shadow-lg);
  left: 0;
  top: 100%;
  margin-top: 4px;
  font-size: 11px;
}

/* ----- Progress Bar ----- */
.progress-wrap {
  margin: 16px 0;
  display: none;
}
.progress-wrap.visible { display: block; }
.progress-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}
.progress-bar-track {
  height: 6px;
  background: var(--neutral-200);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-pill);
  width: 0%;
}
@media (prefers-reduced-motion: no-preference) {
  .progress-bar-fill { transition: width 0.3s ease; }
}
.progress-bar-fill.indeterminate {
  width: 40%;
  animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes indeterminate {
  0%   { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* ----- Summary Card (Step 3) ----- */
.summary-card {
  background: var(--color-success-light);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  margin-bottom: 24px;
}
.summary-card h2 {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-success);
  margin-bottom: 8px;
}
.summary-card p { color: var(--color-text-secondary); font-size: var(--text-sm); }
.summary-card.has-errors {
  background: var(--color-warning-light);
  border-color: var(--color-warning);
}
.summary-card.has-errors h2 { color: var(--color-warning); }

/* ----- Toasts ----- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--neutral-900);
  color: white;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  max-width: 360px;
  pointer-events: all;
  border-left: 4px solid transparent;
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: slideUp 0.3s ease-out; }
  .toast.removing { animation: slideDown 0.25s ease-in forwards; }
}
.toast-success { border-left-color: var(--color-success); }
.toast-error   { border-left-color: var(--color-error); }
.toast-info    { border-left-color: var(--color-info); }
.toast-body { flex: 1; line-height: 1.4; }
.toast-title { font-weight: var(--font-semibold); margin-bottom: 2px; }
.toast-msg { font-size: var(--text-xs); color: var(--neutral-300); }
.toast-close {
  background: none;
  border: none;
  color: var(--neutral-400);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  font-size: 18px;
}
.toast-close:hover { color: white; }

/* ----- Inline spinner ----- */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--neutral-300);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* ----- Empty State ----- */
.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--color-text-secondary);
}
.empty-state svg {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  color: var(--neutral-300);
  display: block;
}
.empty-state p { font-size: var(--text-sm); }

/* ----- Error Alert ----- */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error {
  background: var(--color-error-light);
  color: var(--color-error);
  border: 1px solid #FECACA;
}
.alert-info {
  background: var(--color-info-light);
  color: var(--color-info);
  border: 1px solid #BAE6FD;
}

/* ----- Animations ----- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes slideDown {
  from { transform: translateY(0);    opacity: 1; }
  to   { transform: translateY(16px); opacity: 0; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ----- Section visibility ----- */
.section-hidden { display: none !important; }

/* ----- Responsive ----- */
@media (max-width: 768px) {
  .page-content { padding: 16px 16px 48px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .results-header { flex-direction: column; align-items: flex-start; }
  .stepper .step-label { display: none; }
}
