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

:root {
  /* Catppuccin Mocha */
  --bg: #1e1e2e;
  --surface: #313244;
  --surface-hover: #45475a;
  --border: #45475a;
  --border-subtle: #313244;
  --accent: #89b4fa;
  --accent-hover: #b4d0fb;
  --text: #cdd6f4;
  --text-muted: #a6adc8;
  --text-faint: #6c7086;
  --danger: #f38ba8;
  --warning: #f9e2af;
  --success: #a6e3a1;
  --crust: #11111b;
  --mantle: #181825;
  --lavender: #b4befe;
  --mauve: #cba6f7;
  --peach: #fab387;
  --radius: 8px;
  --radius-sm: 6px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--crust);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code {
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 48px;
  background: var(--mantle);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.topbar__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}

.topbar__counter {
  color: var(--text-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
}

.topbar__sep {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 0 4px;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.badge--subtle {
  background: transparent;
  color: var(--text-faint);
  border-color: transparent;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible,
.tab:focus-visible,
.tab__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  color: var(--crust);
  border-color: transparent;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Tab Bar ── */
.tab-bar {
  display: flex;
  overflow-x: auto;
  gap: 1px;
  padding: 0 20px;
  background: var(--mantle);
  border-bottom: 1px solid var(--border-subtle);
  scrollbar-width: none;
  flex-shrink: 0;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-bar:empty {
  display: none;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: color 0.15s ease;
}

.tab:hover {
  color: var(--text-muted);
}

.tab--active {
  color: var(--text);
}

.tab--active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

.tab__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s ease;
}

.tab:hover .tab__close {
  opacity: 1;
}

.tab__close:hover {
  background: var(--danger);
  color: var(--crust);
  opacity: 1;
}

/* ── Viewport ── */
.viewport {
  flex: 1;
  padding: 0;
  overflow: hidden;
  min-height: 0;
  background: var(--crust);
}

.viewport--grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 2px;
  padding: 2px;
  overflow: auto;
  background: var(--mantle);
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-faint);
}

.empty-state__icon {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
}

.empty-state__desc {
  max-width: 400px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-faint);
}

.empty-state__btn {
  margin-top: 8px;
  padding: 8px 20px;
  font-size: 13px;
}

/* ── Terminal Container ── */
.terminal {
  position: relative;
  background: #000;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.terminal--hidden {
  display: none;
}

.terminal__screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
  min-height: 0;
}

.terminal__screen div {
  display: inline;
  white-space: pre;
  font: 14px ui-monospace, monospace;
  line-height: 1;
}

.terminal__screen canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  background: #000;
}

/* ── Loading Overlay ── */
.terminal__loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 10;
  gap: 16px;
}

.terminal__loading--hidden {
  display: none;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--surface);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.terminal__loading-text {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
}

.terminal__progress {
  width: 160px;
  height: 3px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}

.terminal__progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

/* ── Grid label ── */
.terminal__label {
  display: none;
  padding: 6px 12px;
  background: var(--mantle);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.viewport--grid .terminal__label {
  display: block;
}

.viewport--grid .terminal {
  min-height: 300px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  color: var(--text);
  font-size: 12px;
  max-width: 340px;
  animation: toast-in 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.toast--warning { border-left: 3px solid var(--warning); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--success { border-left: 3px solid var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Drag & Drop ── */
.terminal--dragover::after {
  content: 'Drop file to upload';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(137, 180, 250, 0.1);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  z-index: 20;
  pointer-events: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar__meta { display: none; }
  .viewport--grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar__counter { display: none; }
  .topbar__sep { display: none; }
}
