/* ==========================================================================
   BrandForge AI — stylesheet
   Ported from the original Tailwind + shadcn/ui build. The design tokens below
   are copied verbatim from app/globals.css; the component rules re-implement
   only the ~16 shadcn primitives the app actually used.
   No build step: this file is served as-is (the server has no Node).
   ========================================================================== */

/* --- Design tokens ------------------------------------------------------ */
:root {
    --background: 220 20% 97%;
    --foreground: 220 25% 10%;
    --card: 0 0% 100%;
    --card-foreground: 220 25% 10%;
    --popover: 0 0% 100%;
    --popover-foreground: 220 25% 10%;
    --primary: 220 70% 45%;
    --primary-foreground: 0 0% 100%;
    --secondary: 220 15% 94%;
    --secondary-foreground: 220 25% 20%;
    --muted: 220 15% 94%;
    --muted-foreground: 220 10% 50%;
    --accent: 200 80% 50%;
    --accent-foreground: 0 0% 100%;
    --destructive: 0 80% 55%;
    --destructive-foreground: 0 0% 100%;
    --border: 220 15% 88%;
    --input: 220 15% 92%;
    --ring: 220 70% 45%;
    --radius: 0.75rem;
    --sidebar: 220 25% 12%;
    --sidebar-foreground: 220 15% 85%;
    --sidebar-muted: 220 20% 20%;
    --sidebar-accent: 220 70% 55%;

    --success: 152 60% 40%;
    --warning: 38 92% 50%;

    --sidebar-width: 16rem;
    --header-height: 4.25rem;

    --shadow-sm: 0 1px 2px 0 hsl(220 25% 10% / 0.05);
    --shadow-md: 0 4px 12px -2px hsl(220 25% 10% / 0.08), 0 2px 4px -2px hsl(220 25% 10% / 0.04);
    --shadow-lg: 0 12px 32px -8px hsl(220 25% 10% / 0.16), 0 4px 8px -4px hsl(220 25% 10% / 0.06);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

.dark {
    --background: 220 25% 8%;
    --foreground: 220 15% 92%;
    --card: 220 22% 11%;
    --card-foreground: 220 15% 92%;
    --popover: 220 22% 11%;
    --popover-foreground: 220 15% 92%;
    --primary: 220 70% 60%;
    --primary-foreground: 0 0% 100%;
    --secondary: 220 20% 18%;
    --secondary-foreground: 220 15% 85%;
    --muted: 220 20% 18%;
    --muted-foreground: 220 10% 55%;
    --accent: 200 80% 55%;
    --accent-foreground: 0 0% 100%;
    --destructive: 0 70% 50%;
    --destructive-foreground: 0 0% 100%;
    --border: 220 20% 20%;
    --input: 220 20% 18%;
    --ring: 220 70% 60%;
    --sidebar: 220 28% 7%;
    --sidebar-foreground: 220 15% 80%;
    --sidebar-muted: 220 22% 14%;
    --sidebar-accent: 220 70% 60%;

    --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
    --shadow-md: 0 4px 12px -2px hsl(0 0% 0% / 0.4);
    --shadow-lg: 0 12px 32px -8px hsl(0 0% 0% / 0.55);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    line-height: 1.55;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "rlig" 1, "calt" 1;
}

img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; }
[x-cloak] { display: none !important; }
:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; border-radius: 4px; }

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

/* --- Ported utilities ---------------------------------------------------- */
.gradient-primary { background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 50%)); }
.text-gradient {
    background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 55%));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.dark .glass { background: rgba(20, 25, 40, 0.7); border: 1px solid rgba(255, 255, 255, 0.08); }

/* ==========================================================================
   Layout shell
   ========================================================================== */
.shell { display: flex; min-height: 100vh; }

.main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.page { padding: 1.5rem; max-width: 96rem; width: 100%; }

.sidebar {
    position: fixed;
    inset-block: 0;
    left: 0;
    width: var(--sidebar-width);
    background: hsl(var(--sidebar));
    color: hsl(var(--sidebar-foreground));
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 30;
    display: none;
}

.sidebar-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; padding: 1.125rem 1rem;
}

.brand-mark { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }

.brand-tile {
    width: 2rem; height: 2rem; flex: none;
    display: grid; place-items: center;
    border-radius: 0.625rem; color: #fff;
    background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 50%));
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 0.9375rem; color: #fff; letter-spacing: -0.01em; }
.brand-text small { font-size: 0.6875rem; color: hsl(var(--sidebar-foreground) / 0.6); }

.sidebar-close { display: none; color: hsl(var(--sidebar-foreground)); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem 0.625rem; display: flex; flex-direction: column; gap: 0.125rem; }

.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5625rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem; font-weight: 500;
    color: hsl(var(--sidebar-foreground) / 0.75);
    transition: background-color 0.15s, color 0.15s;
}
.nav-link:hover { background: hsl(var(--sidebar-muted) / 0.7); color: #fff; }
.nav-link.is-active { background: rgba(255, 255, 255, 0.1); color: #fff; }
.nav-link.is-active .nav-icon { color: hsl(var(--sidebar-accent)); }
.nav-icon { flex: none; }
.nav-chevron { margin-left: auto; opacity: 0.5; }

.sidebar-foot { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.75rem; border-top: 1px solid hsl(var(--sidebar-muted)); }

.theme-toggle {
    display: flex; align-items: center; gap: 0.5rem;
    width: 100%;
    padding: 0.4375rem 0.625rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem; font-weight: 500;
    color: hsl(var(--sidebar-foreground) / 0.75);
    transition: background-color 0.15s, color 0.15s;
}
.theme-toggle:hover { background: hsl(var(--sidebar-muted) / 0.7); color: #fff; }
.theme-toggle-icon { display: inline-flex; }

.sidebar-user { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar-user-text strong { font-size: 0.8125rem; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-text small { font-size: 0.6875rem; color: hsl(var(--sidebar-foreground) / 0.55); }
.sidebar-user .icon-btn { color: hsl(var(--sidebar-foreground) / 0.7); }
.sidebar-user .icon-btn:hover { color: #fff; background: hsl(var(--sidebar-muted)); }

.avatar {
    width: 2rem; height: 2rem; flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    background: hsl(var(--sidebar-accent));
    color: #fff; font-size: 0.8125rem; font-weight: 600;
}

.inline-form { display: inline; }

/* --- Page header --------------------------------------------------------- */
.page-header {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1rem;
    min-height: var(--header-height);
    padding: 0.875rem 1.5rem;
    background: hsl(var(--background) / 0.85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid hsl(var(--border));
}
.page-header-text { flex: 1; min-width: 0; }
.page-header-text h1 { font-size: 1.375rem; letter-spacing: -0.02em; }
.page-header-text p { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); margin-top: 0.125rem; }
.page-header-actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }
.menu-btn { display: none; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    height: 2.375rem; padding: 0 0.9375rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem; font-weight: 500;
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, box-shadow 0.15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

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

.btn-gradient { background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 50%)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-gradient:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover:not(:disabled) { background: hsl(var(--secondary) / 0.75); }

.btn-outline { border-color: hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--foreground)); }
.btn-outline:hover:not(:disabled) { background: hsl(var(--secondary)); }

.btn-ghost { color: hsl(var(--muted-foreground)); }
.btn-ghost:hover:not(:disabled) { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }

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

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.8125rem; }
.btn-lg { height: 3rem; padding: 0 1.25rem; font-size: 0.9375rem; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 2.125rem; height: 2.125rem;
    border-radius: 0.5rem;
    color: hsl(var(--muted-foreground));
    transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: hsl(var(--secondary)); color: hsl(var(--foreground)); }
.icon-btn.is-danger:hover { background: hsl(var(--destructive) / 0.12); color: hsl(var(--destructive)); }
.icon-btn.is-active { color: hsl(var(--warning)); }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-head { padding: 1.125rem 1.25rem 0.75rem; display: flex; align-items: flex-start; gap: 0.75rem; }
.card-head-text { flex: 1; min-width: 0; }
.card-title { font-size: 0.9375rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }
.card-desc { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); margin-top: 0.1875rem; }
.card-body { padding: 1.125rem 1.25rem; }
.card-head + .card-body { padding-top: 0.25rem; }
.card-foot { padding: 0.875rem 1.25rem; border-top: 1px solid hsl(var(--border)); display: flex; gap: 0.5rem; }

.card-accent-bar { height: 3px; border-radius: var(--radius) var(--radius) 0 0; }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field + .field { margin-top: 0.875rem; }

.label { font-size: 0.8125rem; font-weight: 500; color: hsl(var(--foreground)); }
.label .req { color: hsl(var(--destructive)); }

/* A label with an action opposite it — "Password ... Forgot?" */
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
.label-link { font-size: 0.75rem; color: hsl(var(--primary)); text-decoration: none; }
.label-link:hover { text-decoration: underline; }
.hint { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.hint-ok { font-size: 0.75rem; color: hsl(var(--success)); display: flex; align-items: center; gap: 0.3125rem; }
.hint-warn { font-size: 0.75rem; color: hsl(var(--warning)); display: flex; align-items: center; gap: 0.3125rem; }

.input, .textarea, .select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, .select:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
}
.input::placeholder, .textarea::placeholder { color: hsl(var(--muted-foreground) / 0.8); }
.input:disabled, .textarea:disabled, .select:disabled { background: hsl(var(--muted)); cursor: not-allowed; }

.textarea { resize: vertical; min-height: 4.5rem; line-height: 1.5; }
.input-mono { font-family: var(--font-mono); font-size: 0.8125rem; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    padding-right: 2rem;
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 2.5rem; }
.input-group-btn { position: absolute; right: 0.25rem; }
.input-icon { position: absolute; left: 0.6875rem; color: hsl(var(--muted-foreground)); pointer-events: none; }
.input-with-icon { padding-left: 2.25rem; }

.form-grid { display: grid; gap: 0.875rem; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row { display: grid; gap: 0.875rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* Checkbox and switch */
.check { display: flex; align-items: flex-start; gap: 0.625rem; cursor: pointer; }
.check input[type="checkbox"] {
    appearance: none; flex: none;
    width: 1.0625rem; height: 1.0625rem; margin-top: 0.125rem;
    border: 1px solid hsl(var(--border));
    border-radius: 0.3125rem;
    background: hsl(var(--card));
    display: grid; place-items: center;
    transition: background-color 0.15s, border-color 0.15s;
}
.check input[type="checkbox"]:checked { background: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.check input[type="checkbox"]:checked::after {
    content: ''; width: 0.5rem; height: 0.28rem;
    border-left: 2px solid #fff; border-bottom: 2px solid #fff;
    transform: rotate(-45deg) translate(1px, -1px);
}
.check-text { font-size: 0.8125rem; }
.check-text strong { display: block; font-weight: 500; }
.check-text small { color: hsl(var(--muted-foreground)); font-size: 0.75rem; }

.switch { display: flex; align-items: center; gap: 0.625rem; cursor: pointer; }
.switch input { appearance: none; width: 2.375rem; height: 1.375rem; border-radius: 999px; background: hsl(var(--muted)); position: relative; transition: background-color 0.2s; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 1rem; height: 1rem; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: var(--shadow-sm); }
.switch input:checked { background: hsl(var(--primary)); }
.switch input:checked::after { transform: translateX(1rem); }

/* Segmented control */
.segmented { display: inline-flex; padding: 0.1875rem; gap: 0.1875rem; background: hsl(var(--muted)); border-radius: calc(var(--radius) - 2px); }
.segmented button, .segmented label {
    flex: 1; padding: 0.375rem 0.75rem;
    border-radius: calc(var(--radius) - 5px);
    font-size: 0.8125rem; font-weight: 500;
    color: hsl(var(--muted-foreground));
    text-align: center; cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented .is-on, .segmented input:checked + span {
    background: hsl(var(--card)); color: hsl(var(--foreground)); box-shadow: var(--shadow-sm);
}
.segmented label span { display: block; padding: 0.375rem 0.75rem; border-radius: calc(var(--radius) - 5px); transition: background-color 0.15s, color 0.15s; }
.segmented label { padding: 0; }

/* Colour picker (custom component in the original) */
.color-picker { display: flex; align-items: center; gap: 0.5rem; }
.color-picker input[type="color"] {
    appearance: none; width: 2.25rem; height: 2.25rem; flex: none;
    border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px);
    background: none; cursor: pointer; padding: 2px;
}
.color-picker input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker input[type="color"]::-webkit-color-swatch { border: none; border-radius: calc(var(--radius) - 6px); }
.color-picker .input { font-family: var(--font-mono); text-transform: lowercase; }
.color-swatch-preview { width: 2.25rem; height: 2.25rem; flex: none; border-radius: calc(var(--radius) - 4px); border: 1px solid hsl(var(--border)); }

/* File upload dropzone */
.dropzone {
    position: relative;
    display: grid; place-items: center; gap: 0.375rem;
    min-height: 9rem; padding: 1rem;
    border: 1.5px dashed hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--muted) / 0.4);
    color: hsl(var(--muted-foreground));
    text-align: center; cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover, .dropzone.is-dragging { border-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.05); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-title { font-size: 0.8125rem; font-weight: 500; color: hsl(var(--foreground)); }
.dropzone-hint { font-size: 0.6875rem; }
.dropzone-preview { position: relative; border-radius: calc(var(--radius) - 2px); overflow: hidden; border: 1px solid hsl(var(--border)); background: hsl(var(--muted)); }
.dropzone-preview img { width: 100%; height: 9rem; object-fit: contain; background: hsl(var(--card)); }
.dropzone-remove { position: absolute; top: 0.375rem; right: 0.375rem; width: 1.625rem; height: 1.625rem; border-radius: 50%; background: hsl(var(--destructive)); color: #fff; display: grid; place-items: center; }

/* ==========================================================================
   Badges, pills, chips
   ========================================================================== */
.badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem; font-weight: 500;
    background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
    white-space: nowrap;
}
.badge-primary { background: hsl(var(--primary) / 0.12); color: hsl(var(--primary)); }
.badge-success { background: hsl(var(--success) / 0.14); color: hsl(var(--success)); }
.badge-warning { background: hsl(var(--warning) / 0.16); color: hsl(38 92% 38%); }
.badge-danger  { background: hsl(var(--destructive) / 0.12); color: hsl(var(--destructive)); }
.dark .badge-warning { color: hsl(var(--warning)); }

.pill {
    display: inline-flex; align-items: center; gap: 0.3125rem;
    padding: 0.3125rem 0.6875rem;
    border: 1px solid hsl(var(--border));
    border-radius: 999px;
    background: hsl(var(--card));
    font-size: 0.8125rem; font-weight: 500;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.pill:hover { border-color: hsl(var(--primary) / 0.5); color: hsl(var(--foreground)); }
.pill.is-on { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: #fff; }
.pill.is-on-amber { background: hsl(var(--warning) / 0.15); border-color: hsl(var(--warning)); color: hsl(38 92% 38%); }
.dark .pill.is-on-amber { color: hsl(var(--warning)); }
.pill-row { display: flex; flex-wrap: wrap; gap: 0.375rem; }

.chip {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.1875rem 0.5rem;
    border-radius: 999px;
    background: hsl(var(--secondary));
    font-size: 0.6875rem;
    color: hsl(var(--secondary-foreground));
}
.chip button { display: grid; place-items: center; opacity: 0.6; }
.chip button:hover { opacity: 1; }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: 0.1875rem; padding: 0.25rem; background: hsl(var(--muted)); border-radius: calc(var(--radius) - 2px); overflow-x: auto; }
.tab {
    flex: 1; min-width: max-content;
    padding: 0.4375rem 0.875rem;
    border-radius: calc(var(--radius) - 5px);
    font-size: 0.8125rem; font-weight: 500;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}
.tab:hover { color: hsl(var(--foreground)); }
.tab.is-active { background: hsl(var(--card)); color: hsl(var(--foreground)); box-shadow: var(--shadow-sm); }
.tab-panel { margin-top: 1.25rem; }

/* ==========================================================================
   Dialogs
   ========================================================================== */
.dialog-backdrop {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(9, 12, 20, 0.6);
    backdrop-filter: blur(2px);
    display: grid; place-items: center;
    padding: 1rem;
    overflow-y: auto;
}
.dialog {
    width: 100%; max-width: 32rem;
    background: hsl(var(--popover)); color: hsl(var(--popover-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: calc(100vh - 2rem);
    display: flex; flex-direction: column;
    margin: auto;
}
.dialog-lg { max-width: 44rem; }
.dialog-xl { max-width: 56rem; }
.dialog-head { padding: 1.125rem 1.25rem; border-bottom: 1px solid hsl(var(--border)); display: flex; align-items: center; gap: 0.75rem; }
.dialog-head h2 { font-size: 1rem; flex: 1; }
.dialog-body { padding: 1.25rem; overflow-y: auto; }
.dialog-foot { padding: 0.875rem 1.25rem; border-top: 1px solid hsl(var(--border)); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(24rem, calc(100vw - 2rem)); }
.toast {
    display: flex; align-items: flex-start; gap: 0.625rem;
    padding: 0.75rem 0.875rem;
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    box-shadow: var(--shadow-lg);
    font-size: 0.8125rem;
    animation: toast-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast span { flex: 1; }
.toast-close { display: grid; place-items: center; opacity: 0.5; margin-top: 0.125rem; }
.toast-close:hover { opacity: 1; }
.toast-success { border-left: 3px solid hsl(var(--success)); }
.toast-success > svg:first-child { color: hsl(var(--success)); }
.toast-error { border-left: 3px solid hsl(var(--destructive)); }
.toast-error > svg:first-child { color: hsl(var(--destructive)); }
.toast-info { border-left: 3px solid hsl(var(--primary)); }
.toast-info > svg:first-child { color: hsl(var(--primary)); }
.toast.is-leaving { animation: toast-out 0.18s ease-in forwards; }

@keyframes toast-in { from { opacity: 0; transform: translateX(1rem); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(1rem); } }

/* ==========================================================================
   Grids and shared blocks
   ========================================================================== */
.grid { display: grid; gap: 1rem; }
.grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.grid-thumbs { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 0.75rem; }
.grid-thumbs-sm { grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr)); gap: 0.5rem; }
.layout-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }

/* Dashboard: two balanced columns so the calendar and recent work sit side by
   side instead of the calendar owning a whole screen of vertical space. */
.dash-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.grid-recent { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }

.stat-card { display: flex; align-items: center; gap: 0.875rem; padding: 1.125rem; }
.stat-icon { width: 2.75rem; height: 2.75rem; flex: none; display: grid; place-items: center; border-radius: 0.75rem; }
.stat-icon-blue { background: hsl(220 70% 45% / 0.12); color: hsl(220 70% 45%); }
.stat-icon-green { background: hsl(152 60% 40% / 0.12); color: hsl(152 60% 40%); }
.stat-icon-amber { background: hsl(38 92% 50% / 0.14); color: hsl(38 80% 44%); }
.stat-icon-rose { background: hsl(345 80% 55% / 0.12); color: hsl(345 80% 55%); }
.stat-value { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.stat-label { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.875rem; }
.section-head h2 { font-size: 1rem; }

.thumb {
    position: relative; display: block;
    aspect-ratio: 1; overflow: hidden;
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--muted));
    border: 1px solid hsl(var(--border));
}
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.25s ease; }
.thumb:hover img { transform: scale(1.03); }
.thumb-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.75), rgba(0,0,0,0.15) 45%, transparent 70%);
    opacity: 0; transition: opacity 0.2s;
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: 0.625rem; color: #fff;
}
.thumb:hover .thumb-overlay, .thumb:focus-within .thumb-overlay { opacity: 1; }
.thumb-overlay strong { font-size: 0.75rem; font-weight: 600; }
.thumb-overlay small { font-size: 0.6875rem; opacity: 0.85; }
.thumb-badge { position: absolute; top: 0.375rem; right: 0.375rem; color: hsl(var(--warning)); filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4)); }
.thumb-status { position: absolute; top: 0.375rem; left: 0.375rem; }
.thumb-actions { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 0.375rem; opacity: 0; transition: opacity 0.2s; }
.thumb:hover .thumb-actions, .thumb:focus-within .thumb-actions { opacity: 1; }
.thumb-action { width: 2.125rem; height: 2.125rem; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,0.92); color: hsl(220 25% 15%); box-shadow: var(--shadow-md); }
.thumb-action:hover { background: #fff; }
.thumb-action.is-danger { background: hsl(var(--destructive)); color: #fff; }
.thumb-caption { padding: 0.5rem 0.125rem 0; }
.thumb-caption strong { display: block; font-size: 0.8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-caption small { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); }

.empty {
    display: grid; place-items: center; gap: 0.625rem;
    padding: 2.5rem 1.25rem;
    border: 1.5px dashed hsl(var(--border));
    border-radius: var(--radius);
    text-align: center;
    color: hsl(var(--muted-foreground));
}
.empty-icon { width: 3rem; height: 3rem; display: grid; place-items: center; border-radius: 0.875rem; background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.empty strong { font-size: 0.9375rem; color: hsl(var(--foreground)); }
.empty p { font-size: 0.8125rem; max-width: 24rem; }

.skeleton { background: hsl(var(--muted)); border-radius: calc(var(--radius) - 4px); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.spinner { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Page: brands
   ========================================================================== */
.brand-card-top { display: flex; align-items: flex-start; gap: 0.75rem; }
.brand-logo { width: 2.75rem; height: 2.75rem; flex: none; border-radius: 0.625rem; object-fit: contain; background: hsl(var(--muted)); border: 1px solid hsl(var(--border)); }
.brand-initial { width: 2.75rem; height: 2.75rem; flex: none; border-radius: 0.625rem; display: grid; place-items: center; color: #fff; font-size: 1.125rem; font-weight: 600; }
.brand-meta { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.75rem; }
.brand-meta div { display: flex; align-items: center; gap: 0.4375rem; font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.brand-meta svg { flex: none; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.swatches { display: flex; gap: 0.3125rem; margin-top: 0.75rem; }
.swatch { width: 1.125rem; height: 1.125rem; border-radius: 50%; border: 1px solid hsl(var(--border)); }

.brand-preview { border-radius: calc(var(--radius) - 2px); overflow: hidden; border: 1px solid hsl(var(--border)); }
.brand-preview-bar { padding: 0.75rem 1rem; color: #fff; font-weight: 600; }
.brand-preview-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.brand-preview-dots { display: flex; gap: 0.375rem; }
.brand-preview-dots span { width: 1.25rem; height: 1.25rem; border-radius: 50%; }
.brand-preview-cta { align-self: flex-start; padding: 0.375rem 0.875rem; border-radius: 999px; color: #fff; font-size: 0.8125rem; font-weight: 500; }

/* ==========================================================================
   Page: generate
   ========================================================================== */
.generate-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.generate-side { position: static; }

.model-list { display: grid; gap: 0.5rem; }
.model-option {
    display: flex; align-items: flex-start; gap: 0.625rem;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}
.model-option:hover { border-color: hsl(var(--primary) / 0.5); }
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-option.is-on, .model-option:has(input:checked) { border-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.05); }
.model-option-text { flex: 1; min-width: 0; }
.model-option-text strong { display: flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; font-weight: 600; }
.model-option-text small { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }
.radio-dot { width: 1rem; height: 1rem; flex: none; margin-top: 0.1875rem; border: 1.5px solid hsl(var(--border)); border-radius: 50%; display: grid; place-items: center; }
.model-option:has(input:checked) .radio-dot { border-color: hsl(var(--primary)); }
.model-option:has(input:checked) .radio-dot::after { content: ''; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: hsl(var(--primary)); }

.ratio-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.375rem; }
.ratio-btn { display: grid; place-items: center; gap: 0.25rem; padding: 0.5rem 0.25rem; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px); font-size: 0.6875rem; color: hsl(var(--muted-foreground)); transition: border-color 0.15s, color 0.15s, background-color 0.15s; }
.ratio-btn:hover { border-color: hsl(var(--primary) / 0.5); }
.ratio-btn.is-on { border-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.06); color: hsl(var(--primary)); }
.ratio-shape { border: 1.5px solid currentColor; border-radius: 2px; }

.asset-pick { position: relative; aspect-ratio: 1; border-radius: calc(var(--radius) - 4px); overflow: hidden; border: 2px solid transparent; background: hsl(var(--muted)); cursor: pointer; }
.asset-pick img { width: 100%; height: 100%; object-fit: cover; }
.asset-pick.is-on { border-color: hsl(var(--primary)); }
.asset-pick-check { position: absolute; inset: 0; display: grid; place-items: center; background: hsl(var(--primary) / 0.45); color: #fff; opacity: 0; transition: opacity 0.15s; }
.asset-pick.is-on .asset-pick-check { opacity: 1; }

.concept-card {
    display: flex; gap: 0.75rem;
    padding: 0.875rem;
    border: 1px solid hsl(var(--border));
    border-left-width: 3px;
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    text-align: left; width: 100%;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.concept-card:hover { box-shadow: var(--shadow-md); }
.concept-card.is-on { border-color: hsl(var(--primary)); border-left-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.04); }
.concept-num { width: 1.5rem; height: 1.5rem; flex: none; border-radius: 50%; display: grid; place-items: center; background: hsl(var(--muted)); font-size: 0.6875rem; font-weight: 600; }
.concept-card.is-on .concept-num { background: hsl(var(--primary)); color: #fff; }
.concept-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.375rem; }
.concept-title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.concept-title strong { font-size: 0.875rem; }
.concept-desc { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); }

/* The headline as it would be set on the image, so it can be judged as type. */
.concept-headline {
    display: block;
    padding: 0.4375rem 0.625rem;
    border-radius: calc(var(--radius) - 6px);
    background: hsl(var(--muted) / 0.7);
}
.concept-headline strong { display: block; font-size: 0.9375rem; letter-spacing: -0.01em; }
.concept-headline em { display: block; font-size: 0.75rem; font-style: normal; color: hsl(var(--muted-foreground)); margin-top: 0.125rem; }

/* The strategic connection - the reason the concept exists. */
.concept-insight {
    display: flex; align-items: flex-start; gap: 0.375rem;
    font-size: 0.75rem; line-height: 1.45;
    color: hsl(var(--primary));
}
.concept-insight svg { flex: none; margin-top: 0.1875rem; }

.preview-frame {
    display: grid; place-items: center;
    min-height: 20rem;
    border: 1.5px dashed hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--muted) / 0.35);
    padding: 1rem;
    text-align: center;
}
.preview-frame img { max-height: 60vh; width: auto; border-radius: calc(var(--radius) - 4px); box-shadow: var(--shadow-md); }
.preview-state { display: grid; place-items: center; gap: 0.625rem; color: hsl(var(--muted-foreground)); }
.preview-tile { width: 3.5rem; height: 3.5rem; display: grid; place-items: center; border-radius: 1rem; background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 50%)); color: #fff; }
.progress { width: 100%; max-width: 16rem; height: 0.375rem; border-radius: 999px; background: hsl(var(--muted)); overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, hsl(220 70% 45%), hsl(200 80% 50%)); transition: width 0.4s ease; }

.caption-box { padding: 0.75rem; border-radius: calc(var(--radius) - 4px); background: hsl(var(--muted) / 0.6); font-size: 0.8125rem; white-space: pre-wrap; line-height: 1.6; cursor: text; }

.prompt-disclosure { border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px); overflow: hidden; }
.prompt-disclosure summary { padding: 0.625rem 0.875rem; font-size: 0.8125rem; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; background: hsl(var(--muted) / 0.5); }
.prompt-disclosure summary::-webkit-details-marker { display: none; }
.prompt-text { padding: 0.875rem; font-size: 0.75rem; font-family: var(--font-mono); white-space: pre-wrap; line-height: 1.6; max-height: 22rem; overflow-y: auto; border-top: 1px solid hsl(var(--border)); }

/* ==========================================================================
   Social calendar
   ========================================================================== */
/* --- Controls ------------------------------------------------------------ */
.cal-controls {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 0.625rem 1rem;
    margin-bottom: 1rem;
}

/* Window toggle. Labels are short and nowrap on purpose - "Next 60 days (18)"
   was wrapping onto two lines inside the segmented control. */
.cal-windows { display: inline-flex; padding: 0.1875rem; gap: 0.1875rem; background: hsl(var(--muted)); border-radius: 999px; }
.cal-windows button {
    display: inline-flex; align-items: center; gap: 0.4375rem;
    padding: 0.375rem 0.875rem;
    border-radius: 999px;
    font-size: 0.8125rem; font-weight: 500;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}
.cal-windows button:hover { color: hsl(var(--foreground)); }
.cal-windows button.is-on { background: hsl(var(--card)); color: hsl(var(--foreground)); box-shadow: var(--shadow-sm); }

.cal-count {
    display: inline-grid; place-items: center;
    min-width: 1.25rem; height: 1.25rem; padding: 0 0.3125rem;
    border-radius: 999px;
    background: hsl(var(--muted-foreground) / 0.18);
    font-size: 0.6875rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cal-windows button.is-on .cal-count { background: hsl(var(--primary)); color: #fff; }

.cal-segments { display: inline-flex; flex-wrap: wrap; gap: 0.3125rem; margin-left: auto; }
.cal-segments button {
    padding: 0.3125rem 0.6875rem;
    border-radius: 999px;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--card));
    font-size: 0.75rem; font-weight: 500;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.cal-segments button:hover { border-color: hsl(var(--primary) / 0.5); color: hsl(var(--foreground)); }
.cal-segments button.is-on { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: #fff; }

/* --- List ---------------------------------------------------------------- */
/* Capped so the widget stays a panel rather than a page. */
.cal-list { display: flex; flex-direction: column; max-height: 22rem; overflow-y: auto; margin: 0 -0.25rem; padding: 0 0.25rem; }

.cal-row {
    display: flex; align-items: flex-start; gap: 0.875rem;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid hsl(var(--border));
    border-left: 2px solid transparent;
    border-radius: 0.25rem;
    transition: background-color 0.15s;
}
.cal-row:last-child { border-bottom: 0; }
.cal-row:hover { background: hsl(var(--muted) / 0.5); }
/* Within a week: the planning deadline has effectively passed. */
.cal-row.is-soon { border-left-color: hsl(var(--primary)); background: hsl(var(--primary) / 0.04); }

.cal-date {
    flex: none; width: 2.875rem; padding: 0.375rem 0;
    display: grid; place-items: center;
    border-radius: 0.625rem;
    background: hsl(var(--muted));
    line-height: 1.15;
}
.cal-date span { font-size: 0.5625rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: hsl(var(--muted-foreground)); }
.cal-date strong { font-size: 1.0625rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.cal-festival { background: hsl(var(--primary) / 0.12); }
.cal-festival strong, .cal-festival span { color: hsl(var(--primary)); }
.cal-health { background: hsl(var(--success) / 0.14); }
.cal-health strong, .cal-health span { color: hsl(var(--success)); }
.cal-national { background: hsl(var(--warning) / 0.16); }
.cal-national strong, .cal-national span { color: hsl(38 80% 34%); }
.cal-business { background: hsl(200 80% 50% / 0.14); }
.cal-business strong, .cal-business span { color: hsl(200 75% 34%); }
.cal-observance { background: hsl(var(--muted)); }

.dark .cal-national strong, .dark .cal-national span { color: hsl(var(--warning)); }
.dark .cal-business strong, .dark .cal-business span { color: hsl(200 80% 62%); }

.cal-body { flex: 1; min-width: 0; }
.cal-title { display: flex; align-items: baseline; gap: 0.4375rem; flex-wrap: wrap; }
.cal-title strong { font-size: 0.875rem; line-height: 1.35; }
.cal-meta { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); margin-top: 0.125rem; }
.cal-when { font-weight: 600; color: hsl(var(--foreground)); }
.cal-row.is-soon .cal-when { color: hsl(var(--primary)); }
.cal-angle { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.3125rem; line-height: 1.45; }
.cal-action { flex: none; align-self: center; }

/* --- "Coming up" on the Generate screen ---------------------------------- */
/* A tighter version of the dashboard calendar: the reminder belongs on the
   screen where the post is actually written. */
.upcoming-list { list-style: none; margin: 0; padding: 0; }

.upcoming-row {
    display: flex; align-items: center; gap: 0.625rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid hsl(var(--border) / 0.6);
}
.upcoming-row:last-child { border-bottom: 0; }

.upcoming-date { width: 2.5rem; padding: 0.25rem 0; border-radius: 0.5rem; }
.upcoming-date strong { font-size: 0.9375rem; }

.upcoming-text { flex: 1; min-width: 0; display: block; }
.upcoming-text strong {
    display: block; font-size: 0.8125rem; line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upcoming-text small { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); }

.upcoming-row.is-soon .upcoming-text small { color: hsl(var(--primary)); font-weight: 600; }
.upcoming-row .btn { flex: none; }

/* Concept directness. An obvious idea should read as a deliberate choice
   rather than a weak one, so "Obvious" is styled as confidently as "Lateral". */
.badge-direct   { background: hsl(var(--success) / 0.14); color: hsl(var(--success)); }
.badge-balanced { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }
.badge-lateral  { background: hsl(268 70% 55% / 0.14); color: hsl(268 60% 46%); }
.dark .badge-direct  { color: hsl(152 60% 62%); }
.dark .badge-lateral { color: hsl(268 80% 76%); }

@media (max-width: 700px) {
    .cal-segments { margin-left: 0; }
    .cal-row { flex-wrap: wrap; }
    .cal-action { width: 100%; margin-top: 0.375rem; }
}

/* --- The "one idea" card on the Generate screen --------------------------- */
.idea-card { border-color: hsl(var(--primary) / 0.4); background: linear-gradient(180deg, hsl(var(--primary) / 0.05), transparent 60%); }
.idea-headline {
    padding: 0.75rem 0.875rem;
    border-radius: calc(var(--radius) - 4px);
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
}
.idea-headline strong { display: block; font-size: 1.0625rem; letter-spacing: -0.01em; }
.idea-headline span { display: block; font-size: 0.8125rem; color: hsl(var(--muted-foreground)); margin-top: 0.1875rem; }

/* ==========================================================================
   Page: history
   ========================================================================== */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.filter-bar .input, .filter-bar .select { width: auto; min-width: 10rem; }
.filter-spacer { flex: 1; }
.result-count { font-size: 0.75rem; color: hsl(var(--muted-foreground)); }

.list-row { display: flex; align-items: center; gap: 0.875rem; padding: 0.75rem; border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px); background: hsl(var(--card)); }
.list-row + .list-row { margin-top: 0.5rem; }
.list-thumb { width: 3.5rem; height: 3.5rem; flex: none; border-radius: 0.5rem; object-fit: cover; background: hsl(var(--muted)); cursor: pointer; }
.list-body { flex: 1; min-width: 0; }
.list-title { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.list-title strong { font-size: 0.875rem; }
.list-prompt { font-size: 0.8125rem; color: hsl(var(--muted-foreground)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 0.125rem; }
.list-meta { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }
.list-actions { display: flex; align-items: center; gap: 0.125rem; flex: none; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 0.375rem; margin-top: 1.25rem; }
.pagination a, .pagination span { min-width: 2.125rem; height: 2.125rem; padding: 0 0.5rem; display: grid; place-items: center; border-radius: 0.5rem; font-size: 0.8125rem; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); }
.pagination a:hover { background: hsl(var(--secondary)); }
.pagination .is-current { background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: #fff; }
.pagination .is-disabled { opacity: 0.45; pointer-events: none; }

/* History gallery: an explicit column count rather than auto-fill, so the row
   density is predictable instead of drifting with the viewport width.
   2 on phones, 3 on tablets, 4 on desktop, 5 on wide screens. */
.grid-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.875rem; }
.grid-gallery .thumb { border-radius: calc(var(--radius) - 2px); }
.grid-gallery .thumb-caption strong { font-size: 0.8125rem; }

/* Hint that the image opens full screen. */
.thumb-zoom {
    position: absolute; inset-inline-end: 0.5rem; inset-block-end: 0.5rem;
    width: 2rem; height: 2rem; border-radius: 0.5rem;
    display: grid; place-items: center;
    background: rgba(12, 16, 24, 0.62); color: #fff;
    opacity: 0; transition: opacity 0.18s, background-color 0.15s;
    pointer-events: none;
}
.thumb:hover .thumb-zoom, .thumb:focus-within .thumb-zoom { opacity: 1; }
.thumb-clickable { cursor: zoom-in; }

/* ==========================================================================
   Lightbox
   ========================================================================== */
.lightbox {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(8, 10, 16, 0.94);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    display: flex; flex-direction: column;
}

.lightbox-bar {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #fff;
    flex: none;
}
.lightbox-title { min-width: 0; flex: 1; }
.lightbox-title strong { display: block; font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-title small { font-size: 0.75rem; color: rgba(255, 255, 255, 0.6); }

.lightbox-actions { display: flex; align-items: center; gap: 0.25rem; flex: none; }
.lightbox-btn {
    display: inline-grid; place-items: center;
    width: 2.375rem; height: 2.375rem;
    border-radius: 0.625rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.08);
    transition: background-color 0.15s, color 0.15s;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.lightbox-btn.is-active { color: hsl(var(--warning)); }

/* Flex, not grid: a grid item's max-height resolves against an auto-sized row,
   which lets a tall image render at natural size and overflow the viewport.
   In a flex column with min-height:0 the height is definite, so the image
   really is bounded. */
.lightbox-stage {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem 0.75rem;
    overflow: hidden;
}

.lightbox-stage img {
    display: block;
    max-width: 100%;
    /* Belt and braces: an explicit ceiling that does not depend on the flex
       chain resolving correctly. 100dvh accounts for mobile browser chrome. */
    max-height: calc(100vh - 8.5rem);
    max-height: calc(100dvh - 8.5rem);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
    cursor: zoom-in;
}

/* Actual-size mode: the stage scrolls instead of shrinking the image. */
.lightbox-stage.is-zoomed { overflow: auto; align-items: flex-start; }
.lightbox-stage.is-zoomed img {
    max-width: none;
    max-height: none;
    margin: auto;                 /* keeps it centred until it outgrows the stage */
    cursor: zoom-out;
    border-radius: 0;
}

.lightbox-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 3rem; height: 3rem; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, 0.1); color: #fff;
    transition: background-color 0.15s;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.22); }
.lightbox-nav[disabled] { opacity: 0.25; cursor: not-allowed; }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

.lightbox-foot {
    flex: none;
    padding: 0.5rem 1rem 0.75rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.75rem;
}
.lightbox-foot kbd {
    display: inline-block;
    padding: 0.0625rem 0.375rem;
    border-radius: 0.25rem;
    background: rgba(255, 255, 255, 0.12);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.85);
}

@media (max-width: 767px) {
    .lightbox-nav { width: 2.5rem; height: 2.5rem; }
    .lightbox-prev { left: 0.375rem; }
    .lightbox-next { right: 0.375rem; }
    .lightbox-foot { display: none; }
    /* No footer strip on small screens, so the image gets that space back. */
    .lightbox-stage img {
        max-height: calc(100vh - 5.5rem);
        max-height: calc(100dvh - 5.5rem);
    }
}

/* Row density for the History gallery.
   Breakpoints are on the VIEWPORT, but the grid sits inside the content area,
   which loses 16rem to the sidebar above 1024px - hence the thresholds below.
   The page is capped at 96rem, so 5 columns never stretch beyond ~290px. */
@media (min-width: 560px)  { .grid-gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px)  { .grid-gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1250px) { .grid-gallery { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.meta-grid dt { font-size: 0.6875rem; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.04em; }
.meta-grid dd { font-size: 0.8125rem; margin-top: 0.125rem; }

/* ==========================================================================
   Page: auth
   ========================================================================== */
.auth-body {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 1.5rem;
    background: linear-gradient(150deg, hsl(220 30% 9%), hsl(220 35% 13%) 55%, hsl(215 40% 16%));
    position: relative; overflow: hidden;
}
.auth-glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.4; pointer-events: none; }
.auth-glow-1 { width: 26rem; height: 26rem; background: hsl(220 70% 45%); top: -8rem; left: -6rem; }
.auth-glow-2 { width: 22rem; height: 22rem; background: hsl(200 80% 50%); bottom: -6rem; right: -4rem; }
.auth-glow-3 { width: 18rem; height: 18rem; background: hsl(260 70% 55%); top: 40%; left: 55%; opacity: 0.25; }
.auth-wrap { position: relative; z-index: 1; width: 100%; max-width: 25rem; }
.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-logo { width: 3.25rem; height: 3.25rem; margin: 0 auto 0.875rem; display: grid; place-items: center; border-radius: 1rem; background: linear-gradient(135deg, hsl(220 70% 45%), hsl(200 80% 50%)); color: #fff; box-shadow: 0 8px 24px -6px hsl(220 70% 45% / 0.6); }
.auth-head h1 { font-size: 1.5rem; color: #fff; letter-spacing: -0.02em; }
.auth-head p { font-size: 0.875rem; color: hsl(220 15% 65%); margin-top: 0.25rem; }
.auth-card { background: rgba(255, 255, 255, 0.06); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-lg); }
.auth-note { display: flex; align-items: center; gap: 0.5rem; padding: 0.625rem 0.75rem; border-radius: calc(var(--radius) - 4px); background: rgba(255, 255, 255, 0.05); font-size: 0.75rem; color: hsl(220 15% 70%); margin-bottom: 1.125rem; }
.auth-card .label { color: hsl(220 15% 82%); }
.auth-card .input { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.12); color: #fff; }
.auth-card .input::placeholder { color: hsl(220 12% 55%); }
.auth-card .input:focus { border-color: hsl(var(--sidebar-accent)); box-shadow: 0 0 0 3px hsl(220 70% 55% / 0.2); }
.auth-card .icon-btn { color: hsl(220 15% 65%); }
.auth-card .icon-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.auth-foot { text-align: center; font-size: 0.75rem; color: hsl(220 12% 52%); margin-top: 1.25rem; }
.auth-error { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.625rem 0.75rem; border-radius: calc(var(--radius) - 4px); background: hsl(0 70% 50% / 0.14); border: 1px solid hsl(0 70% 55% / 0.3); color: hsl(0 85% 82%); font-size: 0.8125rem; margin-bottom: 1rem; }

/* ==========================================================================
   Misc helpers
   ========================================================================== */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }
.row { display: flex; align-items: center; gap: 0.5rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: hsl(var(--muted-foreground)); }
.small { font-size: 0.8125rem; }
.xsmall { font-size: 0.75rem; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.divider { height: 1px; background: hsl(var(--border)); margin: 1rem 0; border: 0; }

kbd {
    display: inline-block;
    padding: 0.0625rem 0.3125rem;
    border: 1px solid hsl(var(--border));
    border-bottom-width: 2px;
    border-radius: 0.25rem;
    background: hsl(var(--muted));
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    line-height: 1.4;
    color: hsl(var(--foreground));
}

.alert { display: flex; align-items: flex-start; gap: 0.625rem; padding: 0.75rem 0.875rem; border-radius: calc(var(--radius) - 2px); font-size: 0.8125rem; }
.alert-warning { background: hsl(var(--warning) / 0.12); border: 1px solid hsl(var(--warning) / 0.3); color: hsl(38 80% 32%); }
.dark .alert-warning { color: hsl(38 92% 70%); }
.alert-info { background: hsl(var(--primary) / 0.08); border: 1px solid hsl(var(--primary) / 0.25); }
.alert-danger { background: hsl(var(--destructive) / 0.1); border: 1px solid hsl(var(--destructive) / 0.3); color: hsl(var(--destructive)); }

/* ==========================================================================
   Dark-mode refinements
   The token palette handles most of the app, but a few accents are stated as
   literal HSL for vibrancy and need lifting against a dark background.
   ========================================================================== */
.dark .stat-icon-blue  { background: hsl(220 70% 60% / 0.18); color: hsl(220 85% 74%); }
.dark .stat-icon-green { background: hsl(152 60% 45% / 0.18); color: hsl(152 60% 62%); }
.dark .stat-icon-amber { background: hsl(38 92% 55% / 0.18);  color: hsl(38 92% 68%); }
.dark .stat-icon-rose  { background: hsl(345 80% 60% / 0.18); color: hsl(345 85% 74%); }

.dark .badge-success { color: hsl(152 60% 62%); }
.dark .alert-danger  { color: hsl(0 85% 76%); }
.dark .hint-ok       { color: hsl(152 60% 62%); }

/* The select chevron is a data-URI, so it cannot inherit currentColor. */
.dark .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.dark .glass { background: rgba(20, 25, 40, 0.7); }
.dark .idea-card { background: linear-gradient(180deg, hsl(var(--primary) / 0.12), transparent 60%); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 640px) {
    .grid-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
    .page { padding: 1.75rem; }
    .layout-split { grid-template-columns: 2fr 1fr; }
    .dash-split { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); }
    .generate-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
    .generate-side { position: sticky; top: calc(var(--header-height) + 1rem); }
    .form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1023px) {
    .main { margin-left: 0; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: none; }
    .sidebar-backdrop { display: block; }
    .sidebar-close { display: inline-grid; }
    .menu-btn { display: inline-grid; }
}

@media (max-width: 767px) {
    .page { padding: 1rem; }
    .page-header { padding: 0.75rem 1rem; }
    .form-row, .form-grid-2 { grid-template-columns: minmax(0, 1fr); }
    .ratio-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .meta-grid { grid-template-columns: minmax(0, 1fr); }
    .toast-stack { left: 1rem; right: 1rem; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media print {
    .sidebar, .page-header-actions, .toast-stack, .filter-bar { display: none !important; }
    .main { margin-left: 0; }
}
