/*
 * FrouBooks admin additions on top of django-unfold.
 *
 * Unfold ships precompiled Tailwind; its utility classes only exist if Unfold itself
 * uses them. Anything custom lives here as small, named components (fb-*) built on
 * Unfold's color tokens (--color-base-*, --color-primary-*), so light and dark mode
 * and the palette in settings.UNFOLD["COLORS"] apply automatically.
 */

:root {
    --fb-radius: var(--border-radius, 6px);
    --fb-surface: #fff;
    --fb-border: var(--color-base-200);
    --fb-border-strong: var(--color-base-300);
    --fb-text: var(--color-base-900);
    --fb-text-muted: var(--color-base-500);
    --fb-hover: var(--color-base-50);
    --fb-thumb-bg: var(--color-base-100);
    --fb-warn: oklch(55% 0.13 60);
    --fb-warn-bg: oklch(97% 0.03 80);
    --fb-warn-border: oklch(88% 0.07 75);
}

.dark {
    --fb-surface: var(--color-base-900);
    --fb-border: var(--color-base-800);
    --fb-border-strong: var(--color-base-700);
    --fb-text: var(--color-base-100);
    --fb-text-muted: var(--color-base-400);
    --fb-hover: oklch(100% 0 0 / 0.03);
    --fb-thumb-bg: var(--color-base-800);
    --fb-warn: oklch(80% 0.12 75);
    --fb-warn-bg: oklch(80% 0.12 75 / 0.08);
    --fb-warn-border: oklch(80% 0.12 75 / 0.25);
}

/* Numbers line up in tables and stats. */
#result_list td,
.fb-stat__value,
.fb-table__num,
.fb-kv dd {
    font-variant-numeric: tabular-nums;
}

/* --- Thumbnails ------------------------------------------------------------------ */

.fb-thumb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    overflow: hidden;
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    background: var(--fb-thumb-bg);
    vertical-align: middle;
}

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

.fb-thumb--sm { width: 40px; height: 40px; }
.fb-thumb--md { width: 96px; height: 96px; }
.fb-thumb--lg { width: 240px; height: 240px; }
.fb-thumb--xl { width: 320px; height: 320px; }
.fb-thumb--lg img,
.fb-thumb--xl img { object-fit: contain; }

.fb-thumb--empty { color: var(--color-base-400); }
.fb-thumb--empty .material-symbols-outlined { font-size: 18px; }
.fb-thumb--md.fb-thumb--empty .material-symbols-outlined { font-size: 28px; }
.fb-thumb--lg.fb-thumb--empty .material-symbols-outlined,
.fb-thumb--xl.fb-thumb--empty .material-symbols-outlined { font-size: 40px; }

.fb-thumb-link {
    position: relative;
    display: inline-block;
    border-radius: var(--fb-radius);
}

.fb-thumb-link:hover .fb-thumb { border-color: var(--fb-border-strong); }
.fb-thumb-link:focus-visible { outline: 2px solid var(--color-primary-600); outline-offset: 2px; }

.fb-primary-badge {
    position: absolute;
    left: 4px;
    bottom: 4px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--color-primary-700);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 16px;
}

/* --- List cells ------------------------------------------------------------------- */

.fb-cell-title {
    display: block;
    color: var(--fb-text);
    font-weight: 500;
}

.fb-cell-sub {
    display: block;
    color: var(--fb-text-muted);
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.fb-muted { color: var(--fb-text-muted); }

.fb-chip {
    display: inline-block;
    margin: 1px 4px 1px 0;
    padding: 0 6px;
    border: 1px solid var(--fb-border);
    border-radius: 4px;
    color: var(--fb-text-muted);
    font-size: 11px;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
}

/* --- Dashboard -------------------------------------------------------------------- */

.fb-dash {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.fb-dash__head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.fb-dash__title {
    color: var(--fb-text);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.fb-dash__lead { margin-top: 2px; color: var(--fb-text-muted); }

.fb-section-label {
    margin-bottom: 10px;
    color: var(--fb-text-muted);
    font-size: 12px;
    font-weight: 500;
}

.fb-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.fb-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    background: var(--fb-surface);
    transition: border-color 120ms ease;
}

.fb-stat:hover { border-color: var(--fb-border-strong); }
.fb-stat:focus-visible { outline: 2px solid var(--color-primary-600); outline-offset: 2px; }

.fb-stat__label { color: var(--fb-text-muted); font-size: 13px; }

.fb-stat__value {
    color: var(--fb-text);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.fb-stat__note { color: var(--fb-text-muted); font-size: 12px; }

.fb-stat--warn {
    border-color: var(--fb-warn-border);
    background: var(--fb-warn-bg);
}

.fb-stat--warn .fb-stat__value { color: var(--fb-warn); }
.fb-stat--warn:hover { border-color: var(--fb-warn); }

.fb-dash__grid {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 16px;
    align-items: start;
}

.fb-dash__side { display: flex; flex-direction: column; gap: 16px; }

.fb-panel {
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    background: var(--fb-surface);
    overflow: hidden;
}

.fb-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--fb-border);
}

.fb-panel__title { color: var(--fb-text); font-size: 14px; font-weight: 600; }

.fb-link { color: var(--color-primary-700); font-size: 13px; font-weight: 500; }
.fb-link:hover { text-decoration: underline; text-underline-offset: 2px; }
.dark .fb-link { color: var(--color-primary-400); }
.fb-link--quiet,
.dark .fb-link--quiet { color: inherit; font-weight: 400; }

.fb-list > li + li { border-top: 1px solid var(--fb-border); }

.fb-list__row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
}

.fb-list__row:hover { background: var(--fb-hover); }
.fb-list__main { min-width: 0; flex: 1; }
.fb-list__main .fb-cell-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fb-list__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--fb-text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.fb-table { width: 100%; }
.fb-table td { padding: 8px 16px; border-top: 1px solid var(--fb-border); }
.fb-table tr:first-child td { border-top: 0; }
.fb-table__code { width: 1%; color: var(--fb-text-muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: nowrap; }
.fb-table__num { width: 1%; color: var(--fb-text); font-weight: 500; text-align: right; }

.fb-kv__row {
    display: flex;
    justify-content: space-between;
    padding: 8px 16px;
    border-top: 1px solid var(--fb-border);
}

.fb-kv__row:first-child { border-top: 0; }
.fb-kv dd { color: var(--fb-text); font-weight: 500; }

.fb-empty { padding: 20px 16px; color: var(--fb-text-muted); }

.fb-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px 0 10px;
    border-radius: var(--fb-radius);
    background: var(--color-primary-600);
    color: #fff;
    font-weight: 500;
    white-space: nowrap;
}

.fb-button:hover { background: var(--color-primary-700); }
.fb-button .material-symbols-outlined { font-size: 18px; }

@media (max-width: 1024px) {
    .fb-dash__grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
    .fb-stats { grid-template-columns: minmax(0, 1fr); }
    .fb-dash__head { align-items: flex-start; flex-direction: column; }
    .fb-thumb--lg, .fb-thumb--xl { width: 100%; max-width: 320px; height: auto; aspect-ratio: 1; }
}

/* --- Confirmation page for per-item actions ---------------------------------------- */

.fb-confirm { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.fb-confirm__item { display: flex; align-items: center; gap: 16px; padding: 16px; }
.fb-confirm__text { color: var(--fb-text); line-height: 1.6; }
.fb-confirm__actions { display: flex; gap: 8px; }

.fb-button { border: 0; cursor: pointer; padding: 0 14px; }
.fb-button--quiet {
    border: 1px solid var(--fb-border);
    background: var(--fb-surface);
    color: var(--fb-text);
}
.fb-button--quiet:hover { background: var(--fb-hover); }

/* --- Layout: use the full width next to the sidebar --------------------------------- */
/*
 * Unfold centers every page in Tailwind's `container` (max 1536px), leaving a wide gap
 * on big screens. Its `list_fullwidth` option only covers change lists, and the submit
 * row and toolbar always use `container`, so lift the cap everywhere instead. Form
 * inputs keep Unfold's own max width (max-w-2xl), left-aligned next to their labels.
 */
body .container {
    max-width: none;
}

/* Breadcrumb in the header: keep "Items" etc. whole and let only the last part (the
 * object's name) shorten, so the toolbar never squeezes it down to "C… › I…". */
#header-inner h1 > a {
    flex: none;
}

#header-inner h1 > span.truncate:last-child {
    min-width: 6rem;
}

@media (max-width: 1535px) {
    /* The app name ("Catalog") is the least useful part; drop it when space is short. */
    #header-inner h1 > a:first-child,
    #header-inner h1 > a:first-child + .material-symbols-outlined {
        display: none;
    }
}

/* Toolbar dropdowns (Clone, Publish): size to the longest label instead of 13rem. */
nav.w-52.end-0.top-10 {
    width: max-content;
    min-width: 13rem;
}

nav.w-52.end-0.top-10 a,
nav.w-52.end-0.top-10 a * {
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
}
