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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --success-dark: #059669;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

  /* Theme colors */
  --bg-body: var(--gray-100);
  --bg-card: white;
  --bg-input: white;
  --bg-hover: var(--gray-50);
  --text-primary: var(--gray-800);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-500);
  --border-color: var(--gray-200);
  --border-light: var(--gray-100);
}

[data-theme="dark"] {
  --bg-body: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-input: #252525;
  --bg-hover: #252525;
  --text-primary: #f5f5f5;
  --text-secondary: #d4d4d4;
  --text-muted: #a3a3a3;
  --border-color: #333333;
  --border-light: #252525;
  --gray-50: #1a1a1a;
  --gray-100: #252525;
  --gray-200: #333333;
  --gray-300: #525252;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--gray-300);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: var(--success-dark);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-dark);
}

.btn-text {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem;
}

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

.btn-small {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-group small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
  width: auto;
}

/* Checkbox list for multi-select categories */
.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: normal;
  cursor: pointer;
  transition: all 0.15s ease;
}

.checkbox-item:hover {
  border-color: var(--primary);
}

.checkbox-item:has(input:checked) {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--primary);
  color: var(--primary);
}

.checkbox-item input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Alerts */
.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #ecfdf5;
  color: var(--success);
  border: 1px solid #a7f3d0;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--gray-800) 0%, var(--gray-900) 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* Error Page */
.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.error-container {
  text-align: center;
  padding: 1rem;
}

.error-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 3rem;
  box-shadow: var(--shadow-lg);
}

.error-card h1 {
  font-size: 3rem;
  color: var(--danger);
  margin-bottom: 1rem;
}

.error-message {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

/* Admin Header */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
}

.back-link:hover {
  color: var(--primary);
}

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

.username {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Admin Navigation */
.admin-nav {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

.nav-link {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-link.active {
  color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
}

/* Admin Main */
.admin-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Dashboard */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.dashboard-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dashboard-actions {
  display: flex;
  gap: 0.75rem;
}

/* Build Panel */
.build-panel {
  background: var(--gray-800);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  overflow: hidden;
}

.build-panel.hidden {
  display: none;
}

.build-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--gray-900);
}

.build-header h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-300);
}

.build-header #buildStatus {
  color: white;
  font-weight: 600;
}

.build-header #buildStatus.building {
  color: var(--warning);
}

.build-header #buildStatus.success {
  color: var(--success);
}

.build-header #buildStatus.error {
  color: var(--danger);
}

.build-log {
  padding: 1rem 1.25rem;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--gray-300);
}

.build-log p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.build-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--gray-700);
}

.build-actions .hidden {
  display: none;
}

/* Projects Table */
.projects-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.empty-state {
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state a {
  color: var(--primary);
}

.projects-table {
  width: 100%;
  border-collapse: collapse;
}

.projects-table th,
.projects-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.projects-table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-hover);
}

.projects-table tr:last-child td {
  border-bottom: none;
}

.projects-table tr:hover {
  background: var(--bg-hover);
}

.reorder-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-hover);
}

.drag-handle-header {
  width: 40px;
}

.drag-handle-cell {
  width: 40px;
  text-align: center;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.25rem;
  user-select: none;
  padding: 0.25rem;
}

.drag-handle:hover {
  color: var(--text-primary);
}

.drag-handle:active {
  cursor: grabbing;
}

.projects-table tr.dragging {
  opacity: 0.5;
  background: var(--gray-100);
}

.projects-table tr.drag-over {
  border-top: 2px solid var(--primary);
}

.projects-table tr.drag-over-bottom {
  border-bottom: 2px solid var(--primary);
}

.thumb-cell {
  width: 80px;
}

.thumb-img {
  width: 60px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--gray-200);
}

.slug {
  color: var(--gray-400);
  font-family: monospace;
}

.category-badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-hover);
  color: var(--text-primary);
}

.category-building {
  background: #dbeafe;
  color: #1e40af;
}

.category-rich-media {
  background: #fce7f3;
  color: #9d174d;
}

.category-motion {
  background: #d1fae5;
  color: #065f46;
}

.category-websites {
  background: #fef3c7;
  color: #92400e;
}

.featured-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--warning);
  background: #fffbeb;
  border-radius: var(--radius-sm);
}

.actions-cell {
  display: flex;
  gap: 0.5rem;
}

.inline-form {
  display: inline;
}

/* Project Form */
.project-form {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  padding: 2rem;
}

@media (max-width: 1024px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-section {
  margin-bottom: 2rem;
}

.form-section:last-child {
  margin-bottom: 0;
}

.form-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.section-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.input-with-upload {
  display: flex;
  gap: 0.5rem;
}

.input-with-upload input {
  flex: 1;
}

.thumbnail-preview {
  margin-top: 0.75rem;
  width: 200px;
  height: 133px;
  background: var(--bg-hover);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.thumbnail-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-preview {
  margin-top: 0.75rem;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1920/800;
  background: var(--bg-hover);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.hero-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-upload {
  margin-bottom: 1rem;
}

.gallery-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.5rem;
}

.gallery-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.5rem 2rem;
  background: var(--bg-hover);
  border-top: 1px solid var(--border-color);
}

/* Placeholder SVG */
.placeholder-svg {
  width: 100%;
  height: 100%;
  background: var(--gray-200);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* Form Header */
.form-header {
  margin-bottom: 1.5rem;
}

.form-header .back-link {
  display: inline-block;
  margin-bottom: 0.75rem;
}

.form-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Category Form */
.category-form {
  max-width: 500px;
  padding: 2rem;
}

.category-form .form-group input[readonly] {
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: not-allowed;
}

.categories-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.categories-table code {
  background: var(--bg-hover);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.theme-toggle:hover {
  background: var(--gray-200);
  color: var(--text-primary);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Tech Icons Grid */
.tech-icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.tech-icon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.tech-icon-item:hover {
  border-color: var(--primary);
}

.tech-icon-item:has(input:checked) {
  background: rgba(37, 99, 235, 0.1);
  border-color: var(--primary);
}

.tech-icon-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.tech-icon-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.tech-icon-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.2;
}

.tech-icon-item:has(input:checked) .tech-icon-label {
  color: var(--primary);
}

/* Tech Order List (Drag & Drop) */
.tech-order-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 50px;
}

.tech-order-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: grab;
  transition: all 0.15s ease;
}

.tech-order-item:hover {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.tech-order-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.tech-order-item.drag-over {
  border-color: var(--primary);
  border-style: dashed;
  background: rgba(37, 99, 235, 0.1);
}

.tech-order-item .drag-handle {
  color: var(--text-muted);
  font-size: 1rem;
  cursor: grab;
  user-select: none;
}

.tech-order-item .tech-order-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.tech-order-item .tech-order-label {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.tech-order-item .tech-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.tech-order-item .tech-remove-btn:hover {
  color: var(--danger);
}

.tech-order-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  background: var(--bg-hover);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
}

.input-with-button {
  display: flex;
  gap: 0.5rem;
}

.input-with-button input {
  flex: 1;
}
