/* ==========================================================================
   Forge3D - Stylesheet
   Dark-themed UI for AI 3D model generation
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  --bg-darkest:   #0a0a0f;
  --bg-panel:     #12121a;
  --bg-card:      #1a1a2e;
  --bg-input:     #1e1e30;
  --bg-hover:     #252540;

  --accent:       #7c3aed;
  --accent-light: #a855f7;
  --accent-glow:  rgba(124, 58, 237, 0.25);

  --success:      #10b981;
  --error:        #ef4444;
  --warning:      #f59e0b;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --border:       #2a2a40;
  --border-focus:  #7c3aed;

  --radius-card:  8px;
  --radius-input: 6px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --panel-left-width: 350px;
  --history-height: 120px;
  --header-height: 56px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-darkest);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------- App Layout (CSS Grid) ---------- */
.app-layout {
  display: grid;
  grid-template-columns: var(--panel-left-width) 1fr;
  grid-template-rows: var(--header-height) 1fr var(--history-height);
  grid-template-areas:
    "header  header"
    "left    viewer"
    "history history";
  height: 100vh;
  width: 100%;
}

/* ---------- Header ---------- */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

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

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

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

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

/* GPU Status Indicator */
.gpu-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 20px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.status-dot.offline {
  background: var(--error);
}

.status-dot.busy {
  background: var(--warning);
}

/* ---------- Left Panel ---------- */
.panel-left {
  grid-area: left;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Tab Toggle ---------- */
.tab-toggle {
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius-input);
  padding: 3px;
  gap: 3px;
}

.tab-btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--accent);
  color: var(--text-primary);
}

.tab-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ---------- Tab Content ---------- */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ---------- Form Elements ---------- */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field-group {
  display: flex;
  flex-direction: column;
}

.prompt-input {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s;
}

.prompt-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.prompt-input::placeholder {
  color: var(--text-muted);
}

/* Prompt Tips */
.prompt-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

.tips-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tip-chip {
  font-family: var(--font);
  font-size: 11px;
  color: var(--accent-light);
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 12px;
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tip-chip:hover {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--accent);
}

/* Select Inputs */
.select-input {
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.2s;
}

.select-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Provider Toggle */
.provider-toggle {
  display: flex;
  gap: 4px;
}

.provider-btn {
  flex: 1;
  padding: 7px 8px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: all 0.2s;
}

.provider-btn.active {
  color: var(--text-primary);
  background: var(--accent);
  border-color: var(--accent);
}

.provider-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Range Input */
.range-input {
  width: 100%;
  height: 4px;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  margin: 8px 0 4px;
}

.range-input::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 4px var(--accent-glow);
}

.range-input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--bg-panel);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-top: 10px;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkmark {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------- Accordion ---------- */
.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: none;
  cursor: pointer;
  transition: color 0.2s;
}

.accordion-header:hover {
  color: var(--text-primary);
}

.accordion-arrow {
  transition: transform 0.3s;
}

.accordion.open .accordion-arrow {
  transform: rotate(180deg);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.accordion.open .accordion-body {
  max-height: 400px;
  padding: 14px;
}

/* ---------- Generate Button ---------- */
.generate-btn {
  width: 100%;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.generate-btn:active {
  transform: translateY(0);
}

.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.cancel-btn {
  width: 100%;
  padding: 10px 16px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: all 0.2s;
}

.cancel-btn:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* ---------- Progress Bar ---------- */
.progress-container {
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.progress-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.progress-percent {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ---------- Drop Zone ---------- */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius-card);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  overflow: hidden;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.05);
}

.drop-zone.drag-over {
  animation: dropPulse 1.5s ease infinite;
}

@keyframes dropPulse {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: var(--accent-light); }
}

.drop-zone-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}

.drop-zone-placeholder p {
  font-size: 14px;
  color: var(--text-secondary);
}

.drop-hint {
  font-size: 12px;
}

.image-preview {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.image-preview img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 4px;
}

.remove-image {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  background: var(--error);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s;
}

.remove-image:hover {
  transform: scale(1.1);
}

/* ---------- 3D Viewer Panel ---------- */
.panel-viewer {
  grid-area: viewer;
  background: var(--bg-darkest);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.viewer-placeholder h2 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary);
}

.viewer-placeholder p {
  font-size: 14px;
  max-width: 300px;
}

model-viewer {
  width: 100%;
  flex: 1;
  background: var(--bg-darkest);
  --poster-color: var(--bg-darkest);
}

/* Model Info & Download */
.model-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.model-info {
  display: flex;
  gap: 20px;
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.info-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.download-buttons {
  display: flex;
  gap: 6px;
}

.download-btn {
  padding: 6px 14px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.download-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

/* ---------- History Panel ---------- */
.panel-history {
  grid-area: history;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  flex-shrink: 0;
}

.history-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.2s;
}

.refresh-btn:hover {
  color: var(--text-primary);
}

.history-scroll {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 0 16px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: stretch;
}

.history-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font-size: 13px;
  color: var(--text-muted);
}

.history-item {
  flex-shrink: 0;
  width: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  cursor: pointer;
  overflow: hidden;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
}

.history-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.history-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.history-thumb {
  width: 100%;
  height: 56px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-thumb svg {
  color: var(--text-muted);
  opacity: 0.4;
}

.history-meta {
  padding: 6px 8px;
  flex: 1;
}

.history-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 10px;
  color: var(--text-muted);
}

.history-status {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.history-status.completed { background: var(--success); }
.history-status.failed    { background: var(--error); }
.history-status.running   { background: var(--warning); }
.history-status.pending   { background: var(--text-muted); }

/* ---------- Backend Banner ---------- */
.backend-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(239, 68, 68, 0.15);
  border-bottom: 1px solid rgba(239, 68, 68, 0.3);
  backdrop-filter: blur(8px);
}

.backend-banner-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: #fca5a5;
}

.backend-banner-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.banner-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: #fca5a5;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

/* ---------- Notifications (Toast) ---------- */
.notifications {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.notification {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  min-width: 280px;
  max-width: 420px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  animation: slideIn 0.3s ease;
  border-left: 3px solid var(--text-muted);
}

.notification.success { border-left-color: var(--success); }
.notification.error   { border-left-color: var(--error); }
.notification.warning { border-left-color: var(--warning); }
.notification.info    { border-left-color: var(--accent); }

.notification.fade-out {
  animation: slideOut 0.3s ease forwards;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

/* ---------- Utility Classes ---------- */
.hidden {
  display: none !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root {
    --panel-left-width: 280px;
  }
}

@media (max-width: 700px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) auto 1fr var(--history-height);
    grid-template-areas:
      "header"
      "left"
      "viewer"
      "history";
  }

  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }

  .subtitle {
    display: none;
  }

  .model-actions {
    flex-direction: column;
    align-items: flex-start;
  }
}
