/* shadcn-style library with additions */
:root {
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 222.2 84% 4.9%;
  --radius: 0.5rem;
  --star-color: hsl(47.9, 95.8%, 53.1%); /* Gold color for the star */
}

* {
  box-sizing: border-box;
  border-width: 0;
  border-style: solid;
  border-color: hsl(var(--border));
}

html {
  -webkit-text-size-adjust: 100%;
  font-feature-settings: normal;
  font-variation-settings: normal;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  background-color: hsl(var(--secondary));
  color: hsl(var(--foreground));
  line-height: 1.5;
  margin: 0;
}

.p-4 { padding: 1rem; }
.p-8 { padding: 2rem; }
.md\:p-8 { padding: 2rem; }
.space-x-2 > :not([hidden]) ~ :not([hidden]) { margin-left: 0.5rem; }
.space-x-4 > :not([hidden]) ~ :not([hidden]) { margin-left: 1rem; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.max-w-7xl { max-width: 80rem; }

/* Card Component */
.card {
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border-radius: var(--radius);
  border-width: 1px;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}
.card-header { padding: 1.5rem; border-bottom-width: 1px; }
.card-header .card-title { font-size: 1.25rem; font-weight: 600; }
.card-content { padding: 1.5rem; }
.card-footer { padding: 1.5rem; border-top-width: 1px; display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Button Component */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  height: 2.5rem;
  padding: 0 1rem;
  transition: all 150ms;
  cursor: pointer;
  border-width: 1px;
  outline: none;
}
.btn:focus-visible { outline: 2px solid transparent; outline-offset: 2px; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring)); }

.btn-primary { background-color: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background-color: hsl(var(--primary) / 0.9); }

.btn-secondary { background-color: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); border-color: hsl(var(--border)); }
.btn-secondary:hover { background-color: hsl(var(--secondary) / 0.8); }

.btn-destructive { background-color: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-destructive:hover { background-color: hsl(var(--destructive) / 0.9); }

.btn-ghost { background-color: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background-color: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-success { background-color: hsl(142.1, 76.2%, 36.3%); color: hsl(var(--primary-foreground)); }
.btn-success:hover { background-color: hsl(142.1, 76.2%, 36.3% / 0.9); }

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.75rem; }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; }
.btn-icon svg { height: 1rem; width: 1rem; }


/* Input Component */
.input {
  display: block;
  width: 100%;
  border-radius: calc(var(--radius) - 2px);
  border-width: 1px;
  border-color: hsl(var(--input));
  background-color: hsl(var(--background));
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: border-color 150ms;
}
.input:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / 0.1); }
textarea.input { min-height: 80px; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

/* Label Component */
.label { font-size: 0.875rem; font-weight: 500; color: hsl(var(--foreground)); margin-bottom: 0.5rem; display: block; }

/* Form Group */
.form-group { margin-bottom: 1.5rem; }

/* Table Component */
.table { width: 100%; border-collapse: collapse; }
.table thead tr { border-bottom-width: 1px; }
.table th { padding: 0.75rem; text-align: left; font-size: 0.75rem; font-weight: 500; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.05em; }
.table td { padding: 0.75rem; font-size: 0.875rem; vertical-align: middle; }
.table tbody tr { border-bottom-width: 1px; }
.table tbody tr:last-child { border-bottom-width: 0; }
.table tbody tr:hover { background-color: hsl(var(--muted) / 0.5); }

/* Modal/Dialog Component */
.dialog-overlay { position: fixed; inset: 0; background-color: rgb(0 0 0 / 0.5); backdrop-filter: blur(4px); z-index: 50; }
.dialog-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: hsl(var(--background));
    border-radius: var(--radius);
    border-width: 1px;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    width: 90vw;
    max-width: 48rem;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.dialog-header { padding: 1rem 1.5rem; border-bottom-width: 1px; display: flex; justify-content: space-between; align-items: center; }
.dialog-title { font-size: 1.125rem; font-weight: 600; color: hsl(var(--foreground)); }
.dialog-close-btn { font-size: 1.5rem; background: none; border: none; cursor: pointer; color: hsl(var(--muted-foreground)); line-height: 1; }
.dialog-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.dialog-footer { padding: 1rem 1.5rem; border-top-width: 1px; display: flex; justify-content: flex-end; gap: 0.75rem; }

/* Badge */
.badge { display: inline-flex; align-items: center; border-radius: 9999px; padding: 0.125rem 0.625rem; font-size: 0.75rem; font-weight: 500; }
.badge-success { background-color: hsl(142.1 76.2% 36.3% / 0.1); color: hsl(142.1 76.2% 36.3%); }
.badge-destructive { background-color: hsl(var(--destructive) / 0.1); color: hsl(var(--destructive)); }

/* Loading Spinner */
.spinner {
    border: 3px solid hsl(var(--border));
    border-radius: 50%;
    border-top: 3px solid hsl(var(--primary));
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.loader-container { position: absolute; inset: 0; background: hsl(var(--background) / 0.8); display: flex; align-items: center; justify-content: center; z-index: 10; }

/* Image Grid */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1rem; }
.image-preview {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: calc(var(--radius) - 2px);
    border-width: 1px;
    background-color: hsl(var(--muted));
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview-actions {
    position: absolute;
    inset: 0;
    background-color: rgb(0 0 0 / 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 150ms;
}
.image-preview:hover .image-preview-actions { opacity: 1; }

.image-preview.is-main {
    box-shadow: 0 0 0 3px var(--star-color);
}
.btn-star {
    color: white;
    background-color: transparent;
    border: none;
}
.btn-star.is-main svg {
    fill: var(--star-color);
    stroke: var(--star-color);
}

/* MODIFICATION: Fix for modal scrolling */
#edit-modal .dialog-content form {
    flex: 1; /* Make the form grow to fill available space */
    display: flex; /* Make it a flex container for its children */
    flex-direction: column;
    min-height: 0; /* Important for flex children to not overflow */
}

/* ADDED: Styles for Drag and Drop */
.drag-handle {
  color: hsl(var(--muted-foreground));
  opacity: 0.4;
  transition: opacity 150ms;
  cursor: move;
}
tr:hover .drag-handle {
  opacity: 1;
}
tr.dragging {
  opacity: 0.5;
  background: hsl(var(--accent));
}
tr.dragging .btn {
    visibility: hidden;
}

/* Helper classes */
.hidden { display: none; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-destructive { color: hsl(var(--destructive)); }
.font-bold { font-weight: 700; }
.mb-4 { margin-bottom: 1rem; }
.mb-8 { margin-bottom: 2rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.w-full { width: 100%; }
.text-sm { font-size: 0.875rem; }
.rounded-md { border-radius: var(--radius); }
.rounded-full { border-radius: 9999px; }
.border { border-width: 1px; }
.bg-destructive\/10 { background-color: hsl(var(--destructive) / 0.1); }
.border-destructive { border-color: hsl(var(--destructive)); }
.p-3 { padding: 0.75rem; }
.font-medium { font-weight: 500; }
.hover\:underline:hover { text-decoration: underline; }
.text-primary { color: hsl(var(--primary)); }
