/* ============================================================
   DGX Model Manager — Nostromo Industrial Dark
   Design system aligned with Homepage dashboard
   ============================================================ */

/* === Variables === */
:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --border: #334155;
  --border-hover: #475569;
  --accent-cyan: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.3);
  --accent-dim: rgba(6, 182, 212, 0.06);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-dim: #475569;
  --emerald: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Subtle grid texture */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 24px 24px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.hidden { display: none !important; }

/* === Header === */
.header {
  position: relative;
  height: 40px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.header__scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255, 255, 255, 0.03) 2px,
    rgba(255, 255, 255, 0.03) 3px
  );
  opacity: 0.12;
}

.header__inner {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.header__title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent-cyan);
}

.header__status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* === Status Dot === */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background var(--transition);
  flex-shrink: 0;
}
.status-dot.healthy {
  background: var(--emerald);
  box-shadow: 0 0 6px var(--emerald);
}
.status-dot.down {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}
.status-dot.loading {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
}

/* -- GPU Memory Bar -- */
.header__gpu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header__gpu-label {
  color: #94a3b8;
  font-weight: 600;
}

.header__gpu-track {
  width: 120px;
  height: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  position: relative;
  overflow: hidden;
}

.header__gpu-fill {
  height: 100%;
  background: #06b6d4;
  width: 0%;
  transition: width 0.5s ease;
}

.header__gpu-text {
  color: #06b6d4;
  min-width: 100px;
}

/* === Container === */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}

/* === Section Headings === */
.section-heading {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

/* === Card Base === */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.5rem 0.75rem;
}

.card__heading {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

/* === Badges === */
.badge {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  padding: 0.1rem 0.4rem;
  border-radius: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  display: inline-block;
  line-height: 1.4;
}
.badge--loaded { background: var(--accent-dim); color: var(--accent-cyan); }
.badge--available { background: rgba(16, 185, 129, 0.1); color: var(--emerald); }
.badge--idle { background: rgba(51, 65, 85, 0.5); color: var(--text-secondary); }
.badge--slot {
  background: var(--accent-dim);
  color: var(--accent-cyan);
  font-size: 0.55rem;
  margin-left: 0.25rem;
  border: 1px solid rgba(6, 182, 212, 0.2);
}

/* === Slot Grid — Compact Rows === */
.slot-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.slot-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: border-color var(--transition);
  position: relative;
}

/* Corner brackets on active slots */
.slot-card--active {
  border-color: var(--accent-cyan);
}
.slot-card--active::before,
.slot-card--active::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  pointer-events: none;
}
.slot-card--active::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--accent-cyan);
  border-left: 2px solid var(--accent-cyan);
}
.slot-card--active::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--accent-cyan);
  border-right: 2px solid var(--accent-cyan);
}

.slot-card__name {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: 0.08em;
  white-space: nowrap;
  min-width: 120px;
}

.slot-card__status {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 90px;
}

.slot-card__model {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.slot-card__model--empty {
  color: var(--text-dim);
  font-weight: 400;
  font-style: italic;
}

.slot-card__port {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.slot-card__controls {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-shrink: 0;
}

/* -- Autorun Toggle -- */
.autorun-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.autorun-toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 28px;
  height: 14px;
  background: #1e293b;
  border: 1px solid #334155;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.autorun-toggle input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 10px;
  height: 10px;
  background: #64748b;
  transition: transform 0.2s, background 0.2s;
}

.autorun-toggle input[type="checkbox"]:checked {
  background: rgba(6, 182, 212, 0.2);
  border-color: #06b6d4;
}

.autorun-toggle input[type="checkbox"]:checked::after {
  transform: translateX(14px);
  background: #06b6d4;
}

.autorun-label {
  color: #64748b;
}

.autorun-toggle input[type="checkbox"]:checked + .autorun-label {
  color: #06b6d4;
}

/* Slot card header (unused in compact row but kept for compat) */
.slot-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* === Select Dropdown === */
.select {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.3rem 1.4rem 0.3rem 0.5rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  max-width: 200px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  transition: border-color var(--transition);
}
.select:focus { border-color: var(--accent-cyan); }

/* === Model Grid — Compact List === */
.model-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.model-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: border-color var(--transition), background var(--transition);
  margin-top: -1px; /* collapse borders */
}
.model-card:first-child { margin-top: 0; }
.model-card:hover {
  border-color: var(--border-hover);
  background: rgba(30, 41, 59, 0.8);
}

.model-card__info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.model-card__name {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-card__org {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.model-card__size {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 55px;
  text-align: right;
}

.model-card__badges {
  display: flex;
  gap: 0.2rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.model-card__actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Legacy compat */
.model-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.placeholder {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.5rem 0;
}

/* === Buttons === */
.btn {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--text-secondary); }
.btn:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 1px; }
.btn:disabled { opacity: 0.3; cursor: not-allowed; }
.btn--accent {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.btn--accent:hover:not(:disabled) {
  background: var(--accent-dim);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.15);
}
.btn--danger { border-color: var(--red); color: var(--red); }
.btn--danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.08); }
.btn--sm {
  font-size: 0.6rem;
  padding: 0.2rem 0.45rem;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Download Form === */
.card--download { padding: 0.5rem 0.75rem; }

.dl-form {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.dl-form__input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
  transition: border-color var(--transition);
}
.dl-form__input:focus { border-color: var(--accent-cyan); }
.dl-form__input::placeholder { color: var(--text-dim); }

.dl-progress {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.progress-bar {
  flex: 1;
  height: 14px;
  background: var(--border);
  border-radius: 0;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent-cyan);
  transition: width 0.3s;
  box-shadow: 0 0 8px var(--accent-glow);
}

.dl-progress__text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  min-width: 2.5rem;
  text-align: right;
}

/* === Toast === */
.toast-container {
  position: fixed;
  bottom: 0.75rem;
  right: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 100;
  pointer-events: none;
}

.toast {
  padding: 0.45rem 0.75rem;
  border-radius: 0;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  animation: slideIn 0.2s ease;
  pointer-events: auto;
  max-width: 320px;
  letter-spacing: 0.02em;
}
.toast--error { border-color: var(--red); color: var(--red); }
.toast--success { border-color: var(--emerald); color: var(--emerald); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* === Footer === */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  height: 30px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.footer__toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  color: var(--text-secondary);
}
.footer__toggle input { accent-color: var(--accent-cyan); width: 12px; height: 12px; }

/* === Responsive === */
@media (max-width: 768px) {
  .slot-card {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .slot-card__name { min-width: auto; }
  .slot-card__model { width: 100%; order: 5; }
  .slot-card__controls { width: 100%; order: 6; }
  .select { max-width: none; flex: 1; }
  .model-card { flex-wrap: wrap; }
  .model-card__info { width: 100%; }
  .dl-form { flex-direction: column; }
  .dl-form__input { width: 100%; }
  .container { padding: 0.5rem; }
}

@media (max-width: 480px) {
  .header__inner { padding: 0 0.5rem; }
  .header__title { font-size: 0.7rem; letter-spacing: 0.1em; }
}
