/*
 * BagsNepal admin.
 *
 * Black on white. The storefront's warm palette belongs in the shop; this is the
 * back room — long lists, long forms, long days — and it is deliberately plain.
 * Only the label voice survives from src/app/globals.css: 11px / 800 / .12em
 * caps.
 *
 * Colour is gone except where it does safety work: red on validation errors and
 * on delete. Everything else that used to be clay, gold, olive or espresso is
 * now ink, and the greys are structure — rules, hovers, the current row — not
 * decoration.
 *
 * Loaded last (see base_site.html), so these win over base.css / dark_mode.css /
 * responsive.css without !important.
 */

@font-face {
    font-family: 'DM Serif Display';
    src: url('../fonts/dm-serif-display.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

html[data-theme="light"], :root {
    /* Black on white, and nothing else. The greys below are structural — rules,
       hovers, the stripe on the current row — not decoration; without them a form
       is one undifferentiated sheet. Red stays on errors and on delete: those are
       the two places colour is doing safety work, not styling. */
    --ink: #000000;
    --paper: #ffffff;
    --rule: #d9d9d9;
    --wash: #f4f4f4;

    --cream: var(--paper);
    --card: var(--paper);
    --espresso: var(--ink);
    --clay: var(--ink);
    --clay-dark: var(--ink);
    --line: var(--rule);
    --muted: #595959;
    --sand: var(--wash);
    --olive: var(--ink);
    --gold: var(--ink);
    --success: var(--ink);

    --bn-display: 'DM Serif Display', Georgia, serif;
    --bn-panel-radius: 10px;
    /* Was a woven stripe in four colours; now a plain rule. */
    --bn-selvedge: var(--rule);

    /* Django's variables, remapped. */
    --primary: var(--ink);
    --secondary: var(--paper);
    --accent: var(--ink);
    --primary-fg: var(--paper);

    --body-fg: var(--ink);
    --body-bg: var(--paper);
    --body-quiet-color: var(--muted);
    --body-medium-color: #333333;
    --body-loud-color: var(--ink);

    --header-color: var(--muted);
    --header-branding-color: var(--ink);
    --header-bg: var(--paper);
    --header-link-color: var(--ink);

    --breadcrumbs-fg: var(--muted);
    --breadcrumbs-link-fg: var(--ink);
    --breadcrumbs-bg: var(--paper);

    --link-fg: var(--ink);
    --link-hover-color: var(--ink);
    --link-selected-fg: var(--ink);

    --hairline-color: var(--rule);
    --border-color: #c9c9c9;

    /* The two exceptions, and only these. */
    --error-fg: #b3261e;
    --message-success-bg: var(--wash);
    --message-warning-bg: var(--wash);
    --message-error-bg: #fdecea;

    --darkened-bg: var(--wash);
    --selected-bg: var(--wash);
    --selected-row: #ededed;

    --button-fg: var(--paper);
    --button-bg: var(--ink);
    --button-hover-bg: #333333;
    --default-button-bg: var(--ink);
    --default-button-hover-bg: #333333;
    --close-button-bg: var(--muted);
    --close-button-hover-bg: var(--ink);
    --delete-button-bg: #b3261e;
    --delete-button-hover-bg: #8f1e18;

    --object-tools-bg: var(--ink);
    --object-tools-hover-bg: #333333;
}

/*
 * There is no dark admin. Not an oversight: this back room is black on white,
 * and a shop owner who has their laptop in dark mode should not get a different
 * one by accident.
 *
 * These blocks cannot simply be deleted. Django ships dark_mode.css, which
 * repaints everything under `prefers-color-scheme: dark` and on
 * html[data-theme="dark"]; with nothing here to answer it, an OS set to dark
 * would drag the admin back to #121212. So both of its hooks are answered with
 * the same white. The theme toggle is hidden further down for the same reason —
 * it would be a button that does nothing.
 */
html[data-theme="dark"],
html[data-theme="auto"] {
    color-scheme: light;
    --card: var(--paper);
    --line: var(--rule);
    --sand: var(--wash);
    --primary: var(--ink);
    --primary-fg: var(--paper);
    --body-fg: var(--ink);
    --body-bg: var(--paper);
    --body-quiet-color: var(--muted);
    --body-medium-color: #333333;
    --body-loud-color: var(--ink);
    --header-bg: var(--paper);
    --header-color: var(--muted);
    --header-branding-color: var(--ink);
    --header-link-color: var(--ink);
    --breadcrumbs-bg: var(--paper);
    --breadcrumbs-link-fg: var(--ink);
    --link-fg: var(--ink);
    --link-hover-color: var(--ink);
    --hairline-color: var(--rule);
    --border-color: #c9c9c9;
    --darkened-bg: var(--wash);
    --selected-bg: var(--wash);
    --selected-row: #ededed;
    --button-fg: var(--paper);
    --button-bg: var(--ink);
    --button-hover-bg: #333333;
    --default-button-bg: var(--ink);
    --default-button-hover-bg: #333333;
    --delete-button-bg: #b3261e;
    --delete-button-hover-bg: #8f1e18;
    --object-tools-bg: var(--ink);
    --object-tools-hover-bg: #333333;
    --message-success-bg: var(--wash);
    --message-warning-bg: var(--wash);
    --message-error-bg: #fdecea;
}

@media (prefers-color-scheme: dark) {
    html, html:not([data-theme="light"]) {
        color-scheme: light;
        --card: var(--paper);
        --line: var(--rule);
        --sand: var(--wash);
        --primary: var(--ink);
        --primary-fg: var(--paper);
        --body-fg: var(--ink);
        --body-bg: var(--paper);
        --body-quiet-color: var(--muted);
        --body-medium-color: #333333;
        --body-loud-color: var(--ink);
        --header-bg: var(--paper);
        --header-color: var(--muted);
        --header-branding-color: var(--ink);
        --header-link-color: var(--ink);
        --breadcrumbs-bg: var(--paper);
        --breadcrumbs-link-fg: var(--ink);
        --link-fg: var(--ink);
        --link-hover-color: var(--ink);
        --hairline-color: var(--rule);
        --border-color: #c9c9c9;
        --darkened-bg: var(--wash);
        --selected-bg: var(--wash);
        --selected-row: #ededed;
        --button-fg: var(--paper);
        --button-bg: var(--ink);
        --button-hover-bg: #333333;
        --default-button-bg: var(--ink);
        --default-button-hover-bg: #333333;
        --delete-button-bg: #b3261e;
        --delete-button-hover-bg: #8f1e18;
        --object-tools-bg: var(--ink);
        --object-tools-hover-bg: #333333;
        --message-success-bg: var(--wash);
        --message-warning-bg: var(--wash);
        --message-error-bg: #fdecea;
    }
}

/* A toggle between white and white is just a puzzle. */
.theme-toggle { display: none; }

/* ---- Shell ------------------------------------------------------------- */

body {
    font-size: 14px;
}

/* The storefront's label voice, lifted verbatim: 11px / 800 / .12em caps. */
.bn-stat-label,
.bn-panel h2,
#nav-sidebar .module caption .section,
.dashboard .module caption .section,
.bn-log-meta {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

#header {
    position: relative;
    align-items: center;
    padding: 14px 22px;
    line-height: 1.2;
    box-shadow: none;
}

/* The selvedge. */
#header::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: var(--bn-selvedge);
}

#site-name a {
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--clay);
    color: #fff;
    font-family: var(--bn-display);
    font-size: 13px;
    letter-spacing: 0.02em;
    flex: none;
}

.brand-word {
    font-family: var(--bn-display);
    font-size: 22px;
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--header-branding-color);
}

.brand-visit {
    display: inline-block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--header-color);
    text-decoration: none;
}

.brand-visit:hover { color: var(--body-loud-color); text-decoration: underline; }

#user-tools { font-size: 12px; }

.breadcrumbs {
    border-bottom: 1px solid var(--hairline-color);
    padding: 9px 22px;
    font-size: 12px;
}

#content {
    padding: 22px;
}

/* Django pins the dashboard to 600px and reserves a 300px rail; we use the
   full width and put Recent activity in the grid instead. */
.dashboard #content {
    width: auto;
}

h1, .bn-stat-value {
    font-family: var(--bn-display);
    font-weight: 400;
}

#content h1 {
    font-size: 25px;
    letter-spacing: 0.01em;
    color: var(--body-loud-color);
    margin-bottom: 16px;
}

/* ---- Workbench (app list + nav sidebar) -------------------------------- */

/* The grid goes on the container. Putting it on `> div` would make each group
   its own grid instead of laying the groups out side by side. */
.dashboard #content-main {
    float: none;
    width: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    align-items: start;
}

.dashboard .module {
    background: var(--card);
    border: 1px solid var(--hairline-color);
    border-radius: var(--bn-panel-radius);
    overflow: hidden;
}

.dashboard .module caption {
    padding: 12px 14px 8px;
    text-align: left;
}

.dashboard .module caption .section {
    /* --header-color, not --body-quiet-color: the caption sits on a dark bar in
       both themes, and muted brown on it fails contrast. */
    color: var(--header-color);
    background: none;
    text-decoration: none;
}

.dashboard .module table { width: 100%; }

.dashboard .module table th,
.dashboard .module table td {
    border-bottom: 1px solid var(--hairline-color);
    padding: 9px 14px;
}

.dashboard .module tr:last-child th,
.dashboard .module tr:last-child td {
    border-bottom: 0;
}

.dashboard .module table th a { font-weight: 600; }

#nav-sidebar .module caption .section {
    color: var(--body-quiet-color);
}

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

.bn-dash { margin-bottom: 26px; }

.bn-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.bn-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 15px 16px;
    border: 1px solid var(--hairline-color);
    border-radius: var(--bn-panel-radius);
    background: var(--card);
    color: var(--body-fg);
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

/* A thread of the selvedge marks the ones you can act on. */
a.bn-stat::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--border-color);
}

/* Grey = actionable, black = needs attention. The colour that used to carry
   this (clay vs gold) is gone, so weight carries it instead. */
a.bn-stat.warn::before { background: var(--body-loud-color); }
a.bn-stat:hover { border-color: var(--clay); }

.bn-stat-value {
    font-size: 27px;
    line-height: 1.05;
    color: var(--body-loud-color);
    font-variant-numeric: tabular-nums;
}

.bn-stat-label { color: var(--body-quiet-color); }

.bn-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.bn-panel {
    padding: 15px 16px;
    border: 1px solid var(--hairline-color);
    border-radius: var(--bn-panel-radius);
    background: var(--card);
}

.bn-panel h2 {
    margin: 0 0 11px;
    padding: 0;
    color: var(--body-quiet-color);
    background: none;
}

.bn-checks, .bn-log { margin: 0; padding: 0; list-style: none; }

.bn-checks li, .bn-log li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--hairline-color);
    font-size: 13px;
}

.bn-checks li:last-child, .bn-log li:last-child { border-bottom: 0; }

.bn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: none;
}

.bn-dot.ok { background: var(--success); }
.bn-dot.off { background: var(--body-quiet-color); }

.bn-check-detail, .bn-log-meta {
    margin-left: auto;
    color: var(--body-quiet-color);
    font-size: 12px;
    text-align: right;
}

.bn-log-meta { font-size: 10px; }

.bn-orders { width: 100%; border-collapse: collapse; font-size: 13px; }
/* No zebra: the panels either side of this one don't have it. */
.bn-orders tr, .bn-orders tbody tr:nth-child(odd) { background: none; }
.bn-orders td { padding: 8px 0; border-bottom: 1px solid var(--hairline-color); }
.bn-orders tr:last-child td { border-bottom: 0; }
.bn-muted { color: var(--body-quiet-color); }
.bn-right { text-align: right; font-variant-numeric: tabular-nums; }
.bn-empty { color: var(--body-quiet-color); font-size: 13px; margin: 0; }

/*
 * One pill, every status. These used to be green / amber / red so a list of
 * orders could be read at a glance; the word now does that work alone, which is
 * the honest cost of dropping colour. The s-* classes stay in the template and
 * in the markup — they cost nothing and are where colour would go back.
 */
.bn-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    white-space: nowrap;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--body-loud-color);
}

/* ---- Lists and forms --------------------------------------------------- */

.module {
    border-radius: var(--bn-panel-radius);
}

#changelist .results {
    border-radius: var(--bn-panel-radius);
    overflow-x: auto;
}

#changelist table thead th {
    background: var(--darkened-bg);
    border-bottom: 1px solid var(--border-color);
}

#changelist table tbody td, #changelist table tbody th {
    border-bottom: 1px solid var(--hairline-color);
}

.object-tools a {
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.06em;
}

.button, input[type=submit], input[type=button], .submit-row input, a.button {
    border-radius: 7px;
    font-weight: 600;
}

fieldset.module { border: 1px solid var(--hairline-color); background: var(--card); }
.submit-row { border-radius: var(--bn-panel-radius); background: var(--darkened-bg); }

/* Focus you can actually see, on every theme. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, .button:focus-visible {
    outline: 2px solid var(--clay);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- Responsive -------------------------------------------------------- */
/* Django's own breakpoints are 1024 / 767 / 480; matching them keeps our rules
   and its rules switching at the same widths instead of fighting midway. */

@media (max-width: 1024px) {
    #header { padding: 12px 16px; }
    #content { padding: 16px; }
    .dashboard #content { width: auto; }
}

@media (max-width: 767px) {
    /* Django already stacks the header into a column here. Forcing it back to a
       row puts the brand and the whole user-tools strip on one line, which
       overflows the viewport — so only the spacing is touched. */
    #header { padding: 11px 14px; }

    .brand-word { font-size: 19px; }
    .brand-mark { width: 27px; height: 27px; }

    #content { padding: 14px; }

    .bn-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .bn-stat { padding: 13px 13px 13px 16px; }
    .bn-stat-value { font-size: 23px; }

    .bn-cols, .dashboard #content-main { grid-template-columns: 1fr; }

    /* Thumb-sized targets on the lists you tap most. */
    .bn-checks li, .bn-log li, .bn-orders td { padding-top: 11px; padding-bottom: 11px; }
    .dashboard .module table th a { display: block; padding: 3px 0; }

    /* Long values stop shoving the row off-screen. */
    .bn-check-detail { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    #content h1 { font-size: 21px; }
}

@media (max-width: 480px) {
    .bn-stats { grid-template-columns: repeat(2, 1fr); }
    .bn-stat-value { font-size: 21px; }
    .brand-visit { display: none; }
    .bn-check-detail { display: none; }
    .bn-orders td:nth-child(2) { display: none; }
}

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


/* ---- Icons -------------------------------------------------------------- */

/*
 * Django ships its icons as coloured SVG files — a green plus, a red cross, a
 * blue eye — referenced as background or <img> sources. There is no variable to
 * repoint, so grayscale() is what is left; it keeps them legible rather than
 * hiding them.
 *
 * The :link selector is not decoration: base.css greys *disabled* related-object
 * links with grayscale(100%) and un-greys the live ones with
 * `.related-widget-wrapper-link:link { filter: grayscale(0%) }`. That is two
 * classes worth of specificity, so a bare class here loses and the icons stay
 * green.
 */
img[src*="/admin/img/"],
/* These are <a>s with the icon as a CSS background, not <img>s — the attribute
   selector above cannot see them. */
.addlink, .changelink, .deletelink, .viewlink,
.related-widget-wrapper-link:link,
.selector-chooseall, .selector-clearall,
.selector-add, .selector-remove,
.datetimeshortcuts a,
.object-tools a::before {
    filter: grayscale(1);
}
