/* =============================
   Design Tokens / Theme
   ============================= */
:root {
  --brand-50: #eff8fd;
  --brand-100: #d9f0fb;
  --brand-200: #bfe6f7;
  --brand-400: #60a5fa;
  --brand-500: #a78bfa;
  --brand-600: #06b6d4;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --text-900: #0f172a;
  --text-700: #334155;
  --text-600: #475569;
  --muted: #94a3b8;
  --border: #e5e7eb;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --accent: #06b6d4;

  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;

  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.10);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
}

/* Dark mode */
[data-theme="dark"] {
  --bg: #000000;
  --surface: #111827;
  --text-900: #e5e7eb;
  --text-700: #cbd5e1;
  --text-600: #94a3b8;
  --muted: #64748b;
  --border: #1f2937;

  --shadow-sm: 0 2px 8px rgba(2, 6, 23, 0.45);
  --shadow-md: 0 10px 30px rgba(2, 6, 23, 0.5);
  --shadow-lg: 0 25px 60px rgba(2, 6, 23, 0.55);
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* =============================
   Base & Layout
   ============================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Floating Ghost Companion */
.companion-container {
  position: fixed;
  top: calc(50% - 75px);
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  pointer-events: none;
}

.floating-character {
  width: 400px;
  animation: floaty 3s ease-in-out infinite;
}

@keyframes floaty {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
  100% {
    transform: translateY(0px);
  }
}

.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-8);
  position: relative;
  z-index: 1;
}

/* =============================
   Header
   ============================= */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(8px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.65));
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .header {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.7), rgba(15, 23, 42, 0.6));
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  height: 72px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-8);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35), 0 6px 14px rgba(167, 139, 250, 0.35);
}

.brand-name {
  color: var(--text-900);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-700);
  background: var(--surface);
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
  text-decoration: none;
  display: inline-block;
}

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

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
}

.btn-primary:hover {
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background: transparent;
  color: var(--text-700);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.08);
}

/* =============================
   Page Title / Toolbar
   ============================= */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin: var(--space-8) 0 var(--space-6);
}

.title {
  font-size: clamp(22px, 2.2vw, 28px);
  font-weight: 700;
  letter-spacing: 0.2px;
  background: linear-gradient(135deg, var(--text-900), var(--text-600));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* =============================
   Products Grid
   ============================= */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
  align-items: stretch;
}

.card {
  border-radius: var(--radius-lg);
  background: var(--surface);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s ease, transform 0.18s ease, border-color 0.2s ease;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px) scale(1.01);
  border-color: rgba(6, 182, 212, 0.35);
  cursor: pointer;
}

.card:active {
  transform: translateY(-1px) scale(0.995);
}

[data-theme="dark"] .card {
  background: rgba(15, 23, 42, 0.75);
}

.card-media {
  height: 120px;
  width: 100%;
  opacity: 0.9;
}

.card-body {
  padding: var(--space-3);
  flex: 1;
}

.card-body h3 {
  margin: 0 0 var(--space-1) 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.card-body p.muted {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.card-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.inline-note {
  font-size: 0.85rem;
  color: var(--muted);
}

.card-actions {
  margin-top: var(--space-2);
}

.card-actions button {
  width: 100%;
}

/* =============================
   Modal
   ============================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  place-items: center;
  padding: var(--space-6);
  overflow-y: auto;
}

.modal.show {
  display: grid;
  animation: backdropIn 0.25s ease;
}

@keyframes backdropIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 1400px;
  width: 95%;
  max-height: 98vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.dialog.animate-in {
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dialog-header {
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-header h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--muted);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-900);
  transform: translateY(-1px);
}

.dialog-body {
  padding: var(--space-2);
  overflow-y: auto;
  flex: 1;
}

.dialog-footer {
  padding: var(--space-2);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* =============================
   Forms
   ============================= */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1) var(--space-3);
}

.form-grid .wide {
  grid-column: span 4;
}

.form-grid .half {
  grid-column: span 2;
}

/* Section containers for multi-column layout */
.form-section-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  grid-column: 1 / -1;
}

.form-section-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-section-column .form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-1) var(--space-2);
}

@media (max-width: 1200px) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid .wide {
    grid-column: span 2;
  }
  .form-section-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .wide,
  .form-grid .half {
    grid-column: span 1;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.label {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-700);
}

.control {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-900);
  font-family: inherit;
  font-size: 0.8rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.1);
  transform: translateY(-1px);
}

select.control {
  padding: 4px 6px;
}

.invalid-feedback {
  display: none;
  font-size: 0.85rem;
  color: var(--danger);
  margin-top: var(--space-1);
}

.field.invalid .control {
  border-color: var(--danger);
}

.field.invalid .invalid-feedback {
  display: block;
}

/* =============================
   Toast Notification
   ============================= */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text-900);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  font-weight: 600;
  z-index: 200;
  display: none;
  animation: toast-in 0.3s ease;
}

.toast.show {
  display: block;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* =============================
   Submissions Table
   ============================= */
.submissions-table {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

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

.submissions-table th {
  text-align: left;
  padding: 16px 12px;
  background: var(--bg);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-700);
  border-bottom: 1px solid var(--border);
}

.submissions-table td {
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-900);
  font-size: 1rem;
}

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

.submissions-table tr:hover {
  background: rgba(148, 163, 184, 0.05);
}

.submission-actions {
  display: flex;
  gap: var(--space-2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

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

.btn-danger:hover {
  background: #dc2626;
}

.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-6);
  color: var(--muted);
}

.empty-state p {
  margin: var(--space-3) 0;
  font-size: 1.1rem;
}

/* =============================
   Responsive - Mobile First
   ============================= */

/* Tablet styles */
@media (max-width: 768px) {
  .container {
    padding: var(--space-6);
  }

  .header-inner {
    padding: 0 var(--space-6);
    height: 64px;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .chip {
    font-size: 0.85rem;
    padding: 6px 10px;
  }

  .grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-4);
  }
}

/* Mobile styles */
@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .header-inner {
    padding: 0 var(--space-4);
    height: 60px;
    gap: var(--space-3);
  }

  .container {
    padding: var(--space-4);
  }

  .brand {
    gap: var(--space-2);
  }

  .brand-mark {
    width: 24px;
    height: 24px;
  }

  .brand-name {
    font-size: 0.9rem;
  }

  .header-actions {
    gap: var(--space-2);
  }

  .chip {
    font-size: 0.8rem;
    padding: 6px 8px;
    gap: 6px;
  }

  /* Make buttons more touch-friendly */
  .btn {
    padding: 12px 18px;
    font-size: 0.95rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn-primary {
    width: 100%;
  }

  /* Card improvements for mobile */
  .card {
    padding: var(--space-5);
  }

  .card-body h3 {
    font-size: 1.1rem;
  }

  .card-footer {
    gap: var(--space-3);
  }

  .card-actions {
    width: 100%;
  }

  .card-actions .btn {
    width: 100%;
  }

  /* Modal improvements for mobile */
  .dialog {
    margin: var(--space-4);
    max-width: calc(100% - 32px);
    max-height: calc(100dvh - 32px);
  }

  .dialog-body {
    max-height: calc(100dvh - 200px);
  }

  /* Form improvements for mobile */
  .form-group label {
    font-size: 0.9rem;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px;
  }

  /* Hide avatar images on very small screens to save space */
  .header-actions .chip img {
    display: none;
  }

  /* Adjust admin panel on mobile */
  .admin-panel-buttons {
    flex-direction: column;
    width: 100%;
  }

  .admin-panel-buttons .btn {
    width: 100%;
  }

  /* Make submission action buttons (Edit/Delete) more visible and touch-friendly */
  .submission-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .submission-actions .btn-sm {
    padding: 10px 16px;
    font-size: 0.95rem;
    min-height: 44px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
  }

  /* Make tables horizontally scrollable on mobile */
  .submissions-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .submissions-table table {
    min-width: 700px;
  }
}

/* Extra small mobile */
@media (max-width: 375px) {
  .container {
    padding: var(--space-3);
  }

  .header-inner {
    padding: 0 var(--space-3);
  }

  .brand-name {
    font-size: 0.85rem;
  }

  .title {
    font-size: 1.3rem;
  }

  .card {
    padding: var(--space-4);
  }
}
