/* ─── Page Header ───────────────────────────────────────────────────────── */
.page-header {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
}
.page-header h1 { margin: 0; }
.page-header p { margin: 0; color: var(--text-secondary); font-size: 1.05rem; }

/* ─── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.badge-accent { background: rgba(56,189,248,0.12); color: var(--accent); border-color: rgba(56,189,248,0.25); }
.badge-success { background: rgba(34,197,94,0.12); color: var(--success); border-color: rgba(34,197,94,0.25); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); border-color: rgba(245,158,11,0.25); }
.badge-danger  { background: rgba(239,68,68,0.12); color: var(--danger); border-color: rgba(239,68,68,0.25); }

/* ─── Status Bar ────────────────────────────────────────────────────────── */
.api-status {
  padding: 14px 20px;
  border-radius: var(--radius);
  background: rgba(56,189,248,0.08);
  border: 1px solid rgba(56,189,248,0.2);
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.9rem;
  font-family: var(--font-mono);
}

/* ─── API Grid / Cards ──────────────────────────────────────────────────── */
.api-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.api-card {
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.api-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.api-header h2 { font-size: 1.05rem; }
.api-card p { font-size: 0.9rem; flex: 1; }
.api-output, .ai-output, .webgpu-output {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
}

/* ─── Forms ─────────────────────────────────────────────────────────────── */
.form-panel {
  max-width: 520px;
  display: grid;
  gap: 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field span, .form-field label { font-size: 0.88rem; font-weight: 600; color: var(--text-secondary); }
.checkbox-field { flex-direction: row; align-items: center; gap: 10px; }
.checkbox-field input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.form-feedback { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.9rem; min-height: 1.5em; }
.form-feedback-success { background: rgba(34,197,94,0.12); color: var(--success); border: 1px solid rgba(34,197,94,0.25); }
.form-feedback-danger  { background: rgba(239,68,68,0.12); color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.table-panel { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.table-toolbar { display: flex; gap: 12px; padding: 16px 20px; background: var(--bg-surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.table-toolbar input { flex: 1; min-width: 180px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead { background: var(--bg-surface); }
th { padding: 12px 16px; text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; cursor: pointer; user-select: none; }
th:hover { color: var(--text-primary); }
th[data-sort="asc"]::after  { content: ' ↑'; }
th[data-sort="desc"]::after { content: ' ↓'; }
td { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--text-secondary); }
tr:hover td { background: var(--bg-muted); color: var(--text-primary); }
.table-pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--text-secondary); }

/* ─── Gallery ───────────────────────────────────────────────────────────── */
.gallery-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.gallery-item { border-radius: var(--radius-lg); overflow: hidden; cursor: pointer; position: relative; aspect-ratio: 4/3; background: var(--bg-surface); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.35s ease; }
.gallery-item:hover img { transform: scale(1.06); }
.gallery-item figcaption { position: absolute; bottom: 0; left: 0; right: 0; padding: 10px 14px; background: linear-gradient(to top, rgba(0,0,0,0.65), transparent); color: #fff; font-size: 0.85rem; font-weight: 600; opacity: 0; transition: opacity 0.25s; }
.gallery-item:hover figcaption { opacity: 1; }
.gallery-lightbox { max-width: min(92vw, 960px); border: none; border-radius: var(--radius-xl); background: var(--bg-secondary); padding: 0; overflow: hidden; }
.gallery-lightbox::backdrop { background: rgba(0,0,0,0.8); backdrop-filter: blur(12px); }
.gallery-lightbox img { width: 100%; max-height: 70vh; object-fit: contain; display: block; }
.gallery-lightbox-footer { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; }

/* ─── Media ─────────────────────────────────────────────────────────────── */
.media-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.media-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.media-card h2 { font-size: 1.05rem; }
video, audio { width: 100%; border-radius: var(--radius-sm); background: #000; }
audio { accent-color: var(--accent); }
#audio-visualizer { width: 100%; height: 80px; border-radius: var(--radius-sm); background: var(--bg-surface); }

/* ─── Maps ──────────────────────────────────────────────────────────────── */
.map-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
#map-container { height: 420px; width: 100%; background: var(--bg-surface); }
.map-toolbar { padding: 16px 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); }
#location-output { padding: 12px 20px; font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-secondary); }

/* ─── PDF ───────────────────────────────────────────────────────────────── */
.pdf-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.pdf-toolbar { padding: 16px 20px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; background: var(--bg-surface); border-bottom: 1px solid var(--border); }
#pdf-canvas-wrap { overflow-y: auto; max-height: 600px; display: flex; justify-content: center; background: #525659; padding: 20px; }
#pdf-canvas { max-width: 100%; box-shadow: var(--shadow-lg); }
.pdf-link { padding: 10px 20px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-weight: 600; }

/* ─── Upload ────────────────────────────────────────────────────────────── */
.upload-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; display: grid; gap: 20px; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: 48px 24px; text-align: center; color: var(--text-secondary); cursor: pointer; transition: border-color var(--transition), background var(--transition); font-size: 0.95rem; }
.dropzone:hover, .dropzone.drag-over { border-color: var(--accent); background: rgba(56,189,248,0.06); color: var(--text-primary); }
.upload-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.upload-item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; background: var(--bg-surface); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.88rem; }
.upload-item-preview { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.upload-item-icon { width: 48px; height: 48px; background: var(--bg-muted); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 1.4rem; }
.upload-progress { height: 4px; background: var(--bg-muted); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.upload-progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; }

/* ─── Markdown ──────────────────────────────────────────────────────────── */
.markdown-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; height: 540px; }
.markdown-grid textarea { height: 100%; resize: none; font-family: var(--font-mono); font-size: 0.9rem; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.preview-pane { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; overflow-y: auto; }
.preview-pane h1,.preview-pane h2,.preview-pane h3 { margin: 1.2em 0 0.5em; }
.preview-pane p { margin: 0.75em 0; }
.preview-pane code { background: var(--bg-surface); padding: 2px 6px; border-radius: 4px; }
.preview-pane pre { background: var(--bg-surface); padding: 16px; border-radius: var(--radius-sm); overflow-x: auto; margin: 1em 0; }
.preview-pane ul,.preview-pane ol { margin: 0.75em 0; }
.preview-pane blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 1em 0; color: var(--text-secondary); }
@media (max-width: 700px) { .markdown-grid { grid-template-columns: 1fr; height: auto; } .markdown-grid textarea { height: 300px; } }

/* ─── AI ─────────────────────────────────────────────────────────────────── */
.ai-grid { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 24px; }
.ai-panel { display: grid; gap: 14px; }
.ai-panel img { border-radius: var(--radius-lg); max-height: 380px; width: 100%; object-fit: cover; }
#ai-webcam { border-radius: var(--radius-lg); max-height: 380px; width: 100%; object-fit: cover; background: #000; }
.ai-model-list { display: grid; gap: 10px; }
.ai-model-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--bg-surface); border-radius: var(--radius-sm); border: 1px solid var(--border); gap: 12px; }
.ai-model-item span { font-size: 0.88rem; flex: 1; }
.model-progress { height: 4px; background: var(--bg-muted); border-radius: 2px; overflow: hidden; flex: 1; }
.model-progress-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; }
@media (max-width: 760px) { .ai-grid { grid-template-columns: 1fr; } }

/* ─── Three.js ──────────────────────────────────────────────────────────── */
.three-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.three-root { width: 100%; height: 460px; display: block; }
.three-toolbar { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Physics ───────────────────────────────────────────────────────────── */
.physics-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
#physics-canvas { display: block; width: 100%; height: 400px; cursor: crosshair; }
.physics-toolbar { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Canvas ────────────────────────────────────────────────────────────── */
.canvas-demo { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.canvas-toolbar { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.canvas-toolbar label { font-size: 0.85rem; color: var(--text-secondary); }
#painting-canvas { display: block; width: 100%; cursor: crosshair; background: #0f172a; }
.color-swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }

/* ─── Settings ──────────────────────────────────────────────────────────── */
.settings-grid { display: grid; gap: 28px; max-width: 640px; }
.settings-section { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; display: grid; gap: 18px; }
.settings-section h2 { font-size: 1rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.theme-btn { background: var(--bg-surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 12px 8px; font-size: 0.82rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; text-align: center; transition: all var(--transition); }
.theme-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.theme-btn.active { border-color: var(--accent); background: rgba(56,189,248,0.1); color: var(--accent); }
.settings-note { font-size: 0.85rem; color: var(--text-muted); }
.stats-list { display: grid; gap: 8px; }
.stats-list dt { font-size: 0.82rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stats-list dd { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ─── About ─────────────────────────────────────────────────────────────── */
.about-content { max-width: 800px; display: grid; gap: 24px; }
.about-content ul { display: grid; gap: 8px; }
.about-content li { color: var(--text-secondary); }
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tech-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; font-size: 0.85rem; color: var(--text-secondary); }
.tech-card strong { display: block; color: var(--text-primary); margin-bottom: 4px; }

/* ─── 404 ────────────────────────────────────────────────────────────────── */
.not-found { text-align: center; padding: 80px 24px; }
.not-found .error-code { font-size: 8rem; font-weight: 900; color: var(--accent); opacity: 0.15; letter-spacing: -0.05em; line-height: 1; }
.not-found h1 { font-size: 2rem; margin-top: -1.5rem; }

/* ─── Home ──────────────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 60px 24px 40px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.5rem); background: linear-gradient(135deg, var(--text-primary), var(--accent)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.hero p { font-size: clamp(1rem, 2vw, 1.2rem); max-width: 600px; margin: 12px auto 28px; }
.hero-stats { display: flex; gap: 32px; justify-content: center; flex-wrap: wrap; margin-bottom: 40px; }
.hero-stat { text-align: center; }
.hero-stat strong { display: block; font-size: clamp(1.8rem, 3vw, 2.5rem); font-weight: 800; color: var(--accent); letter-spacing: -0.04em; }
.hero-stat span { font-size: 0.82rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.feature-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; display: flex; flex-direction: column; gap: 10px; transition: border-color var(--transition), box-shadow var(--transition); text-decoration: none; }
.feature-card:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.feature-card .card-icon { font-size: 2rem; line-height: 1; }
.feature-card h2 { font-size: 1rem; margin: 0; }
.feature-card p { font-size: 0.88rem; color: var(--text-secondary); flex: 1; }
.feature-card .card-link { font-size: 0.82rem; color: var(--accent); font-weight: 600; margin-top: auto; }

/* ─── WebGPU ─────────────────────────────────────────────────────────────── */
.webgpu-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; display: grid; gap: 18px; max-width: 760px; }
#webgpu-status { padding: 10px 16px; border-radius: var(--radius-sm); background: var(--bg-surface); font-family: var(--font-mono); font-size: 0.85rem; color: var(--text-secondary); border: 1px solid var(--border); }

/* ─── Command Palette ────────────────────────────────────────────────────── */
#command-palette-root dialog {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 560px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  padding: 0;
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#command-palette-root dialog::backdrop { background: rgba(0,0,0,0.5); backdrop-filter: blur(8px); }
.palette-search { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.palette-search svg { flex-shrink: 0; color: var(--text-muted); }
.palette-search input { border: none; background: transparent; font-size: 1rem; width: 100%; color: var(--text-primary); padding: 0; }
.palette-search input:focus { outline: none; box-shadow: none; }
.palette-results { overflow-y: auto; padding: 8px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-secondary); font-size: 0.9rem; }
.palette-item:hover, .palette-item.focused { background: var(--bg-muted); color: var(--text-primary); }
.palette-item .pi-icon { font-size: 1.2em; width: 28px; text-align: center; }
.palette-item .pi-label { flex: 1; }
.palette-item .pi-hint { font-size: 0.78rem; color: var(--text-muted); }
.palette-empty { padding: 32px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* ─── QR & Barcode ──────────────────────────────────────────────────────── */
.qr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.qr-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; display: grid; gap: 14px; }
#qr-output, #barcode-output { display: flex; justify-content: center; padding: 20px; background: var(--bg-surface); border-radius: var(--radius); min-height: 150px; align-items: center; }
#barcode-output svg { max-width: 100%; }
