/* Heritage Confectionary — Django admin theme */

html[data-theme="light"],
:root {
    /* HC theme palette */
    --hc-bg: #F6F7F9;
    --hc-surface: #FFFFFF;
    --hc-border: #E2E8F0;
    --hc-primary: #0F172A;
    --hc-primary-2: #1E293B;
    --hc-primary-3: #334155;
    --hc-accent: #3F7F98;
    --hc-accent-dark: #0B2F4A;
    --hc-text: #0F172A;
    --hc-muted: #64748B;
    --hc-sidebar-text: #CBD5E1;
    --hc-sidebar-muted: #94A3B8;
    --hc-success: #22C55E;
    --hc-danger: #DC3545;
    --hc-warning: #E67E22;
    --hc-neutral: #6C757D;

    /* Django native CSS variables */
    --primary: #3f7f98;
    --secondary: #2a6378;
    --accent: #e8f6fb;
    --primary-fg: #fff;

    --body-fg: #0f172a;
    --body-bg: var(--hc-bg);
    --body-quiet-color: var(--hc-muted);
    --body-medium-color: var(--hc-primary-3);
    --body-loud-color: var(--hc-text);

    --header-branding-color: #ffffff;
    --header-bg: var(--hc-accent);
    --header-color: #e8f6fb;
    --header-link-color: #ffffff;

    --breadcrumbs-fg: #cbd5e1;
    --breadcrumbs-link-fg: #ffffff;
    --breadcrumbs-bg: #2a6378;

    --link-fg: #0f7895;
    --link-hover-color: #0c647d;
    --link-selected-fg: #2a6378;

    --hairline-color: var(--hc-border);
    --border-color: #dbe3ea;

    --darkened-bg: #f8fafc;
    --selected-bg: #e8f6fb;
    --selected-row: #e8f6fb;

    --button-fg: #fff;
    --button-bg: var(--hc-accent);
    --button-hover-bg: #0f7895;
    --default-button-bg: #0f7895;
    --default-button-hover-bg: #0c647d;

    --object-tools-fg: #fff;
    --object-tools-bg: var(--hc-accent);
    --object-tools-hover-bg: #0f7895;

    --font-family-primary:
        "Inter",
        system-ui,
        -apple-system,
        "Segoe UI",
        Roboto,
        "Helvetica Neue",
        Arial,
        sans-serif;
}

html[data-theme="dark"] {
    --primary: #5a9fb8;
    --secondary: #3f7f98;
    --accent: #1e3a47;
    --primary-fg: #f8fafc;

    --body-fg: #e2e8f0;
    --body-bg: #0f172a;
    --body-quiet-color: #94a3b8;
    --body-medium-color: #cbd5e1;
    --body-loud-color: #f8fafc;

    --header-bg: #1e3a47;
    --header-branding-color: #f8fafc;
    --header-link-color: #e2e8f0;

    --breadcrumbs-bg: #162029;
    --breadcrumbs-link-fg: #f8fafc;

    --link-fg: #7ec8e3;
    --link-hover-color: #a8dcef;

    --darkened-bg: #1e293b;
    --selected-bg: #334155;
    --selected-row: #1e3a47;

    --button-bg: #3f7f98;
    --button-hover-bg: #5a9fb8;
    --default-button-bg: #3f7f98;
    --default-button-hover-bg: #5a9fb8;

    --object-tools-bg: #3f7f98;
    --object-tools-hover-bg: #5a9fb8;
}

body {
    font-family: var(--font-family-primary);
}

#header {
    padding: 14px 24px;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12);
    position: sticky;
    top: 0;
    z-index: 1000;
}

#hc-branding {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#hc-branding .hc-brand-title,
#site-name a {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--header-branding-color) !important;
    text-decoration: none;
}

.hc-admin-logo {
    height: 48px;
    max-width: 260px;
    object-fit: contain;
    display: block;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.hc-brand-logo-link {
    display: inline-block;
    text-decoration: none;
    line-height: 0;
}

.hc-brand-tagline {
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.82);
    letter-spacing: 0.02em;
}

#user-tools {
    font-weight: 500;
}

#user-tools a,
#logout-form button {
    color: var(--header-link-color);
}

#logout-form button {
    background: transparent;
    border: none;
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: underline;
}

div.breadcrumbs {
    padding: 12px 24px;
    font-weight: 500;
}

#content {
    padding: 24px;
}

#content-main {
    max-width: 1400px;
}

.module,
.inline-group {
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--hairline-color);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05);
}

.module h2,
.module caption,
.inline-group h2 {
    background: var(--header-bg);
    color: var(--header-branding-color);
    font-weight: 600;
    padding: 12px 16px;
}

.dashboard #content-main .module table th {
    width: auto;
}

.dashboard .module table td a {
    font-weight: 500;
}

#changelist {
    border-radius: 14px;
    overflow: clip;
}

#changelist-form .results {
    overflow: visible !important;
}

#result_list {
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

#result_list thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    background: var(--hc-accent-dark) !important;
    color: #ffffff !important;
    font-weight: 600;
    padding: 12px 14px;
}

#result_list thead th a:link,
#result_list thead th a:visited {
    color: #ffffff;
}

#result_list thead th .text a {
    color: #ffffff;
}

#result_list thead th .sortoptions a {
    color: #9fc5d8;
}

#result_list thead th .sortoptions a:hover {
    color: #ffffff;
}

#result_list tbody tr:hover {
    background: var(--selected-row);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
    border-radius: 10px !important;
    border-color: var(--border-color) !important;
    padding: 8px 12px !important;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary) !important;
    outline: 2px solid rgba(63, 127, 152, 0.2);
}

.button:not(#changelist .actions .button),
input[type="submit"],
input[type="button"],
.submit-row input,
.object-tools a {
    border-radius: 10px !important;
    font-weight: 600 !important;
    padding: 10px 18px !important;
    transition: background 0.15s ease, transform 0.15s ease;
}

.button:not(#changelist .actions .button):hover,
input[type="submit"]:hover,
.object-tools a:hover {
    transform: translateY(-1px);
}

/* Vertically center submit-row button text */
/* Django forms.css sets height:2.1875rem + line-height:0.9375rem which with
   content-box + padding 10px leaves text off-center. Use matching height/line-height
   and zero padding so text is perfectly centered. */
.submit-row input[type="submit"],
.submit-row a.button {
    height: 40px !important;
    line-height: 40px !important;
    padding: 0 18px !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

/* Changelist bulk-action bar (Run button + action dropdown) */
#changelist .actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
}

#changelist .actions label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

#changelist .actions select {
    height: 32px;
    min-height: 32px;
    padding: 4px 8px;
    margin: 0;
    vertical-align: middle;
    line-height: 1.25;
}

#changelist .actions .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    min-height: 32px;
    margin: 0;
    padding: 0 14px !important;
    line-height: 1;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 8px !important;
    border: none;
    background: var(--button-bg);
    color: var(--button-fg);
    box-shadow: none;
    cursor: pointer;
    transform: none;
}

#changelist .actions .button:hover,
#changelist .actions .button:focus {
    background: var(--button-hover-bg);
    transform: none;
}

.object-tools {
    margin-top: 0;
}

.object-tools li a {
    border-radius: 10px;
    padding: 10px 16px;
    background: var(--object-tools-bg);
}

.object-tools li a:hover {
    background: var(--object-tools-hover-bg);
}

.messagelist li {
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 8px;
    font-weight: 500;
}

/* Login page */
body.login {
    background: linear-gradient(160deg, var(--hc-surface) 0%, var(--hc-bg) 45%, var(--hc-bg) 100%);
}

body.login #header {
    background: transparent;
    box-shadow: none;
    padding: 20px 24px 0;
}

body.login #header #branding {
    display: none;
}

body.login #container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0;
    width: auto;
    min-width: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
}

body.login #content {
    padding: 24px;
    margin: 0 auto;
    width: 100%;
    max-width: 440px;
}

.hc-login-shell {
    width: 100%;
}

body.login #content-main {
    float: none;
}

.hc-login-card {
    background: #ffffff;
    border-radius: 22px;
    border: 1px solid var(--hc-border);
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.1);

    padding: 32px 28px;
}

.hc-login-header {
    text-align: center;
    margin-bottom: 28px;
}

.hc-login-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: 16px;
    background: #e8f6fb;
    color: #0f7895;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.hc-login-header h1 {
    margin: 0 0 8px;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--hc-text);
}

.hc-login-header p {
    margin: 0;
    color: var(--hc-muted);
    font-size: 0.9rem;
}

body.login .form-row {
    margin-bottom: 16px;
    padding: 0;
}

body.login .form-row label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--hc-primary-3);
    line-height: normal;
}

body.login .form-row input {
    width: 100%;
    box-sizing: border-box;
}

body.login .submit-row {
    margin-top: 8px;
    padding: 0;
    text-align: center;
}

body.login .hc-login-submit {
    width: 100%;
    background: #0f7895;
    border: none;
    border-radius: 4px;
    padding: 12px 18px;
    font-size: 1rem;
    font-weight: normal;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

body.login .hc-login-submit:hover {
    background: #0c647d;
}

body.login .errornote {
    border-radius: 10px;
}

/* ===== Dark sidebar ===== */
#nav-sidebar {
    --hc-primary: #174A57;
    --hc-primary-2: #1E5566;
    --hc-primary-3: #256980;
    background: var(--hc-primary);
    border-right: none;
    border-top-right-radius: 14px;
    margin-top: 24px;
    padding: 8px 0;
    overflow-y: auto;
}

#nav-sidebar .module {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    padding: 0;
}

#nav-sidebar caption {
    background: transparent;
    color: var(--hc-sidebar-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
    padding: 14px 16px 4px;
    line-height: 1.4;
}

#nav-sidebar caption a {
    color: var(--hc-sidebar-muted);
    padding: 0;
    display: inline;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#nav-sidebar caption a.section {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.25;
}

#nav-sidebar caption a.section::before {
    flex-shrink: 0;
    margin-right: 0;
}

#nav-sidebar caption a:hover {
    color: var(--hc-surface);
    background: none;
}

#nav-sidebar table {
    border: none;
    background: transparent;
    width: 100%;
}

#nav-sidebar th,
#nav-sidebar td {
    padding: 0;
    vertical-align: middle;
}

#nav-sidebar th {
    font-weight: 400;
    width: auto;
    color: var(--hc-sidebar-text);
}

#nav-sidebar tr {
    border-bottom: none;
}

#nav-sidebar tr:hover {
    background: var(--hc-primary-2);
}

#nav-sidebar a {
    color: var(--hc-sidebar-text);
    padding: 8px 16px;
    display: block;
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    transition: background 0.12s ease, color 0.12s ease;
}

#nav-sidebar a:hover {
    background: var(--hc-primary-3);
    color: var(--hc-surface);
}

#nav-sidebar .current-app {
    background: transparent;
}

#nav-sidebar .current-app .section-link {
    color: var(--hc-surface);
}

#nav-sidebar .current-model {
    background: var(--hc-primary-2);
}

#nav-sidebar .current-model a {
    color: var(--hc-surface);
}

#nav-sidebar .current-model th,
#nav-sidebar .current-model td {
    background: transparent;
}

#nav-sidebar .addlink {
    font-size: 0;
    line-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0 auto;
    background: none;
    border: none;
    text-decoration: none;
}

#nav-sidebar .addlink::after {
    content: "+";
    font-size: 22px;
    font-weight: 300;
    color: #000;
    line-height: 1;
}

#nav-sidebar tr:hover .addlink::after {
    color: #000;
}

/* ===== Sidebar icons ===== */
/* Layout shared by all sidebar icons */
#nav-sidebar caption a::before,
#nav-sidebar .model-group a:not(.addlink)::before,
#nav-sidebar .model-user a:not(.addlink)::before,
#nav-sidebar .model-batch a:not(.addlink)::before,
#nav-sidebar .model-product a:not(.addlink)::before,
#nav-sidebar .model-rawmaterial a:not(.addlink)::before,
#nav-sidebar .model-rawmaterialratehistory a:not(.addlink)::before,
#nav-sidebar .model-recipecard a:not(.addlink)::before,
#nav-sidebar .model-supervisor a:not(.addlink)::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    background-size: 16px;
    background-repeat: no-repeat;
    background-position: center;
    margin-right: 8px;
    vertical-align: middle;
}

/* Section caption icons */
#nav-sidebar caption a[href*="/auth/"]::before {
    background-image: url("data:image/svg+xml,<svg 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'><rect x='3' y='11' width='18' height='11' rx='2' ry='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/></svg>");
}
#nav-sidebar caption a[href*="/production/"]::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M2 20V8l4 2 4-4 4 4 4-4 4 4v12H2z'/><path d='M6 20v-6'/><path d='M10 20v-4'/><path d='M14 20v-6'/><path d='M18 20v-4'/></svg>");
}

/* Model link icons — scoped to model classes for reliable matching */
#nav-sidebar .model-group a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 0 0-3-3.87'/><path d='M16 3.13a4 4 0 0 1 0 7.75'/></svg>");
}
#nav-sidebar .model-user a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/><circle cx='12' cy='7' r='4'/></svg>");
}
#nav-sidebar .model-batch a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/><polyline points='14 2 14 8 20 8'/><line x1='16' y1='13' x2='8' y2='13'/><line x1='16' y1='17' x2='8' y2='17'/></svg>");
}
#nav-sidebar .model-product a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z'/><polyline points='3.27 6.96 12 12.01 20.73 6.96'/><line x1='12' y1='22.08' x2='12' y2='12'/></svg>");
}
#nav-sidebar .model-rawmaterialratehistory a::before {
    background-image: url("data:image/svg+xml,<svg 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'><circle cx='12' cy='12' r='10'/><polyline points='12 6 12 12 16 14'/></svg>");
}
#nav-sidebar .model-rawmaterial a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M12 2L2 7l10 5 10-5-10-5z'/><path d='M2 17l10 5 10-5'/><path d='M2 12l10 5 10-5'/></svg>");
}
#nav-sidebar .model-supervisor a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2'/><rect x='8' y='2' width='8' height='4' rx='1' ry='1'/><path d='M9 14l2 2 4-4'/></svg>");
}
#nav-sidebar .model-recipecard a::before {
    background-image: url("data:image/svg+xml,<svg 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'><path d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2'/><rect x='9' y='3' width='6' height='4' rx='1'/><line x1='9' y1='12' x2='15' y2='12'/><line x1='9' y1='16' x2='13' y2='16'/></svg>");
}

#nav-sidebar a:hover::before {
    filter: brightness(0) invert(1);
}

/* Sidebar search filter */
#nav-filter {
    background: var(--hc-primary-2);
    border: 1px solid var(--hc-primary-3);
    border-radius: 8px;
    color: #E2E8F0;
    font-size: 0.8125rem;
    margin: 8px 12px;
    padding: 8px 12px;
    width: calc(100% - 24px);
    box-sizing: border-box;
}

#nav-filter::placeholder {
    color: var(--hc-sidebar-muted);
}

#nav-filter:focus {
    border-color: var(--hc-success);
    outline: none;
    background: var(--hc-primary-2);
}

/* Toggle button */
.toggle-nav-sidebar {
    border: none !important;
    background: var(--hc-primary) !important;
    color: var(--hc-sidebar-text) !important;
    border-radius: 0 !important;
    font-size: 16px !important;
    cursor: pointer;
}

.toggle-nav-sidebar:hover {
    color: var(--hc-surface) !important;
    background: var(--hc-primary-2) !important;
}

@media (max-width: 767px) {
    #hc-branding .hc-brand-title,
    #site-name a {
        font-size: 1rem;
    }

    .hc-brand-tagline {
        display: none;
    }

    #content {
        padding: 16px;
    }
}

/* ===== Reusable badge styles ===== */
.hc-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    color: #fff;
}
.hc-badge-red { background: var(--hc-danger); }
.hc-badge-green { background: var(--hc-success); }
.hc-badge-grey { background: var(--hc-neutral); }
.hc-badge-orange { background: var(--hc-warning); }

/* ===== Numeric column alignment ===== */
th.column-latest_rate,
td.field-latest_rate,
th.column-year_avg,
td.field-year_avg,
th.column-rate_change,
td.field-rate_change,
th.column-vs_year_avg,
td.field-vs_year_avg {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
th.column-unit,
td.field-unit {
    text-align: center;
}

/* Batch numeric columns */
th.column-quantity,
td.field-quantity,
th.column-total_rm_cost,
td.field-total_rm_cost,
th.column-unit_cost,
td.field-unit_cost {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ===== Table row refinement ===== */
#result_list tbody td {
    padding: 10px 14px;
    vertical-align: middle;
}

/* ===== BatchIngredient StackedInline card layout ===== */

/* ---- Card container ---- */
#ingredients-group {
    margin-bottom: 20px !important;
}

/* ---- Each ingredient card ---- */
#ingredients-group .inline-related {
    background: #fff !important;
    border: 1px solid var(--hc-border) !important;
    border-radius: 6px !important;
    margin-bottom: 10px !important;
    overflow: hidden !important;
}

/* ---- Card header ---- */
#ingredients-group .inline-related h3 {
    margin: 0 !important;
    padding: 8px 12px !important;
    font-size: 0.8125rem !important;
    font-weight: 600 !important;
    background: var(--darkened-bg) !important;
    border-bottom: 1px solid var(--hc-border) !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    color: var(--body-medium-color) !important;
}

#ingredients-group .inline-related h3 .inline_label {
    flex: 1 !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

/* Delete checkbox in header */
#ingredients-group .inline-related h3 span.delete {
    float: none !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    font-size: 0.75rem !important;
    color: var(--hc-danger) !important;
    margin-left: auto !important;
    flex-shrink: 0 !important;
}

#ingredients-group .inline-related h3 span.delete label {
    font-size: 0.6875rem !important;
    color: var(--hc-danger) !important;
}

#ingredients-group .inline-related h3 span.delete input {
    margin: 0 !important;
}

/* ---- Form rows (label + field) ---- */
#ingredients-group .inline-related .form-row {
    padding: 6px 12px !important;
    border-bottom: none !important;
    overflow: visible !important;
}

#ingredients-group .inline-related .form-row > div {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
}

#ingredients-group .inline-related .form-row label {
    min-width: 100px !important;
    text-align: right !important;
    font-size: 0.8125rem !important;
    font-weight: 500 !important;
    color: var(--body-medium-color) !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* The inner flex-container holding field/label */
#ingredients-group .inline-related .form-row .flex-container {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex: 1 !important;
}

/* ---- Field-specific widths ---- */

/* Raw material: wide select */
#ingredients-group .inline-related .field-raw_material select {
    min-width: 280px !important;
    width: auto !important;
}

/* Quantity: compact */
#ingredients-group .inline-related .field-quantity input {
    width: 80px !important;
}

/* Unit: compact */
#ingredients-group .inline-related .field-unit select {
    width: 100px !important;
}

/* RM Cost readonly: clearly visible, monospaced */
#ingredients-group .inline-related .field-formatted_rm_cost .readonly {
    font-size: 0.9375rem !important;
    font-weight: 600 !important;
    font-variant-numeric: tabular-nums !important;
    color: var(--hc-text) !important;
    padding: 2px 0 !important;
}

/* Remarks: compact textarea */
#ingredients-group .inline-related .field-remarks textarea {
    width: 220px !important;
    max-width: 280px !important;
    resize: vertical !important;
}

/* ---- Add more button ---- */
#ingredients-group .add-row {
    padding: 10px 12px !important;
    border: 2px dashed var(--hc-border) !important;
    border-radius: 6px !important;
    background: transparent !important;
    text-align: center !important;
}

#ingredients-group .add-row a {
    font-size: 0.8125rem !important;
    font-weight: 500 !important;
    color: var(--hc-accent) !important;
    text-decoration: none !important;
}

#ingredients-group .add-row a:hover {
    text-decoration: underline !important;
}

/* ---- Empty-form (hidden template) ---- */
#ingredients-group .empty-form {
    display: none !important;
}

/* ===== Related-object icon alignment ===== */
.related-widget-wrapper {
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    vertical-align: middle !important;
    flex-wrap: nowrap !important;
    flex-grow: 0 !important;
    margin-bottom: 0 !important;
}

.related-widget-wrapper select,
.related-widget-wrapper input[type="text"] {
    flex: 0 1 auto !important;
}

.related-widget-wrapper-link {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 22px !important;
    height: 22px !important;
    margin: 0 !important;
    padding: 0 !important;
    vertical-align: middle !important;
    border-radius: 3px !important;
    transition: background 0.15s ease !important;
    text-decoration: none !important;
}

.related-widget-wrapper-link:hover {
    background: var(--hc-border) !important;
}

.related-widget-wrapper-link img {
    display: block !important;
    width: 16px !important;
    height: 16px !important;
}

/* ===== Fix select dropdown vertical text clipping ===== */
body.model-batch.change-form select,
body.model-recipecard.change-form select,
body.model-recipedevelopmentproject.change-form select,
body.model-recipedevelopmentversion.change-form select {
    min-height: 36px !important;
    height: auto !important;
    line-height: 1.4 !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    box-sizing: border-box !important;
}

body.app-hr.change-form select {
    min-height: 36px !important;
    height: auto !important;
    line-height: 1.4 !important;
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    box-sizing: border-box !important;
}

/* ===== Remove plus icon from Batch add button ===== */
body.model-batch.change-list .object-tools a.addlink {
    background-image: none !important;
    padding-right: 12px !important;
}

/* ===== RecipeCard tabular inline: compact ===== */
body.model-recipecard.change-form #ingredients-group .tabular table {
    table-layout: auto;
}

body.model-recipecard.change-form #ingredients-group .tabular td {
    padding: 4px 6px !important;
    vertical-align: middle !important;
}

body.model-recipecard.change-form #ingredients-group .tabular th {
    padding: 6px 6px !important;
    font-size: 0.75rem;
}

/* Hide Django original object label (e.g. "Sugar – 39.8947 g") */
body.model-recipecard.change-form #ingredients-group td.original p {
    display: none !important;
}

/* Remove extra top padding Django adds for rows with original labels */
body.model-recipecard.change-form #ingredients-group tr.has_original td.original {
    padding-top: 4px !important;
    padding-bottom: 0 !important;
}

body.model-recipecard.change-form #ingredients-group .tabular select,
body.model-recipecard.change-form #ingredients-group .tabular input[type="number"] {
    min-height: 28px !important;
    padding: 1px 4px !important;
    font-size: 0.8125rem !important;
}

body.model-recipecard.change-form #ingredients-group .tabular textarea {
    min-height: 30px !important;
    max-height: 44px !important;
    width: 180px !important;
    padding: 2px 4px !important;
    font-size: 0.8125rem !important;
    resize: vertical;
    box-sizing: border-box !important;
}

body.model-recipecard.change-form #ingredients-group .field-quantity input,
body.model-recipecard.change-form #ingredients-group .field-display_order input,
body.model-recipecard.change-form #ingredients-group .field-rm_cost_display {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

body.model-recipecard.change-form #ingredients-group .delete {
    text-align: center;
    width: 30px;
}

body.model-recipecard.change-form #ingredients-group .field-raw_material {
    min-width: 160px;
}

body.model-recipecard.change-form #ingredients-group .field-unit {
    min-width: 60px;
    text-align: center;
}

/* Raw material display label + Edit button (JS toggles select) */
body.model-recipecard.change-form #ingredients-group .rc-rm-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

body.model-recipecard.change-form #ingredients-group .rc-rm-display {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--body-fg, #0f172a);
    white-space: nowrap;
}

body.model-recipecard.change-form #ingredients-group .rc-unit-display {
    font-size: 0.875rem;
    color: var(--body-fg, #0f172a);
    white-space: nowrap;
}

body.model-recipecard.change-form #ingredients-group .rc-rm-edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--body-quiet-color, #64748b);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

body.model-recipecard.change-form #ingredients-group .rc-rm-edit-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    color: #0f172a;
}

body.model-recipecard.change-form #ingredients-group .rc-rm-edit-btn:focus-visible {
    outline: 2px solid rgba(63, 127, 152, 0.35);
    outline-offset: 2px;
}

/* ===== Target Recipe table ===== */
.rc-target-table-wrap {
    margin: 8px 0;
}

.rc-target-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.rc-target-table thead th {
    background: var(--darkened-bg, #f6f7f9);
    border-bottom: 2px solid var(--hairline-color, #e2e8f0);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 700;
    padding: 8px 10px;
    text-align: left;
}

.rc-target-table thead th.num,
.rc-target-table tbody td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.rc-target-table tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--hairline-color, #e2e8f0);
}

.rc-target-table tbody tr:nth-child(even) {
    background: var(--darkened-bg, #f6f7f9);
}

.rc-target-table tbody tr:hover {
    background: var(--selected-row, #e8f6fb);
}

.rc-empty {
    color: var(--body-quiet-color, #64748b);
    font-style: italic;
    padding: 8px 0;
}

/* ===== View/Edit Unit Recipe toggle button ===== */
.rc-toggle-unit-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.4;
    border: 1px solid var(--primary, #3f7f98);
    background: transparent;
    color: var(--primary, #3f7f98);
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.rc-toggle-unit-btn:hover {
    background: var(--primary, #3f7f98);
    color: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.rc-toggle-unit-btn:focus-visible {
    outline: 2px solid rgba(63, 127, 152, 0.35);
    outline-offset: 2px;
}

/* Hide Unit Recipe inline initially (toggled by JS) */
body.model-recipecard.change-form #ingredients-group {
    display: none;
}

body.model-recipecard.change-form #ingredients-group.rc-visible {
    display: block;
}

/* ===== Target Recipe Calculator ===== */
.rc-calculator {
    margin: 8px 0;
}

.rc-calc-label {
    display: block;
    font-weight: 600;
    font-size: 0.8125rem;
    margin-bottom: 6px;
    color: var(--body-fg, #0f172a);
}

.rc-calc-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

#rc-target-qty {
    width: 120px !important;
    min-height: 36px !important;
    padding: 4px 8px !important;
    font-size: 0.875rem !important;
    border: 1px solid var(--hairline-color, #e2e8f0) !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
}

.rc-calc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.4;
    border: 1px solid var(--primary, #3f7f98);
    background: var(--primary, #3f7f98);
    color: #fff;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.rc-calc-btn:hover {
    background: var(--secondary, #2a6378);
    border-color: var(--secondary, #2a6378);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.rc-calc-btn:focus-visible {
    outline: 2px solid rgba(63, 127, 152, 0.35);
    outline-offset: 2px;
}

.rc-calc-summary {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--darkened-bg, #f6f7f9);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--body-fg, #0f172a);
}

.rc-calc-summary strong {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rc-calc-error {
    margin-bottom: 8px;
    padding: 4px 8px;
    font-size: 0.8125rem;
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 4px;
    display: none;
}

.rc-calc-error:not(:empty) {
    display: block;
}

.rc-calc-btn-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.rc-supervisor-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 16px;
    font-size: 0.8125rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.4;
    border: 1px solid #15803d;
    background: #15803d;
    color: #fff;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.rc-supervisor-btn:hover {
    background: #166534;
    border-color: #166534;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.rc-supervisor-btn:focus-visible {
    outline: 2px solid rgba(21, 128, 61, 0.35);
    outline-offset: 2px;
}

/* ---- Batch Analyser ---- */

.ba-page {
    max-width: none;
}

.ba-header {
    margin-bottom: 24px;
}
.ba-title {
    margin: 0 0 2px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
}
.ba-subtitle {
    margin: 0 0 2px;
    font-size: 0.9375rem;
    color: var(--body-quiet-color, #64748b);
}
.ba-helper {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--body-quiet-color, #94a3b8);
}

/* ── KPI Cards ── */

.ba-cards {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.ba-card {
    flex: 1 1 180px;
    min-width: 160px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.ba-card-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ba-card-icon--blue {
    background: #e0f2fe;
    color: #0369a1;
}
.ba-card-icon--teal {
    background: #ccfbf1;
    color: #0f766e;
}
.ba-card-icon--amber {
    background: #fef3c7;
    color: #b45309;
}
.ba-card-icon--red {
    background: #fee2e2;
    color: #b91c1c;
}
.ba-card-body {
    min-width: 0;
}
.ba-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--body-fg, #0f172a);
}
.ba-card-label {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #64748b);
    white-space: nowrap;
}

/* ── Table ── */

.ba-table-wrap {
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.ba-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.ba-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}
.ba-table thead th {
    background: var(--primary, #1a4b5e);
    color: #fff;
    padding: 12px 14px;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    text-align: left;
    border-bottom: none;
}
.ba-table thead th.num {
    text-align: right;
}
.ba-table thead th:first-child {
    border-top-left-radius: 0;
}
.ba-table thead th:last-child {
    border-top-right-radius: 0;
}
.ba-table tbody tr {
    border-bottom: 1px solid var(--hairline-color, #e2e8f0);
    transition: background 0.12s;
}
.ba-table tbody tr:last-child {
    border-bottom: none;
}
.ba-table tbody tr:nth-child(even) {
    background: var(--darkened-bg, #f8fafc);
}
.ba-table tbody tr:hover {
    background: var(--selected-bg, #e2e8f0);
}
.ba-table tbody td {
    padding: 12px 14px;
    vertical-align: middle;
    color: var(--body-fg, #0f172a);
}
.ba-table tbody td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.ba-cell-product {
    font-weight: 600;
    white-space: normal;
    max-width: 220px;
    overflow-wrap: break-word;
}

/* ── Difference cell ── */

.ba-diff-cell {
    font-variant-numeric: tabular-nums;
}
.ba-diff-cell.watch {
    color: #b45309;
    background: #fffbeb;
}
.ba-diff-cell.alert {
    color: #b91c1c;
    background: #fef2f2;
}

/* ── Status Badges ── */

.ba-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1.5;
}
.ba-badge-baseline {
    background: #dbeafe;
    color: #1e40af;
}
.ba-badge-ok {
    background: #dcfce7;
    color: #166534;
}
.ba-badge-watch {
    background: #fef9c3;
    color: #854d0e;
}
.ba-badge-alert {
    background: #fee2e2;
    color: #991b1b;
}

/* ── Footer ── */

.ba-footer {
    margin-top: 14px;
    font-size: 0.8rem;
    color: var(--body-quiet-color, #94a3b8);
}

/* ── Empty State ── */

.ba-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    background: var(--body-bg, #fff);
    border: 1px dashed var(--hairline-color, #cbd5e1);
    border-radius: 12px;
    text-align: center;
}

/* ── Product History Modal ── */

.ba-cell-link {
    cursor: pointer;
    transition: color 0.12s;
}
.ba-cell-link:hover {
    color: var(--link-fg, #0369a1);
    text-decoration: underline;
}

.ba-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}
.ba-modal {
    background: var(--body-bg, #fff);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 820px;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: baModalIn 0.18s ease-out;
}
@keyframes baModalIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ba-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid var(--hairline-color, #e2e8f0);
    flex-shrink: 0;
}
.ba-modal-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
}
.ba-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--body-quiet-color, #94a3b8);
    cursor: pointer;
    padding: 0 2px;
    transition: color 0.12s;
}
.ba-modal-close:hover {
    color: var(--body-fg, #0f172a);
}
.ba-modal-body {
    padding: 18px 22px 22px;
    overflow-y: auto;
    flex: 1;
}
.ba-modal-loading,
.ba-modal-empty,
.ba-modal-error {
    padding: 40px 0;
    text-align: center;
    color: var(--body-quiet-color, #64748b);
    font-size: 0.9rem;
}
.ba-modal-error {
    color: #b91c1c;
}

/* ── Factory Diagnosis ── */

.ba-diag {
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 14px;
    background: var(--body-bg, #fff);
}
.ba-diag--warn {
    border-left: 4px solid #b45309;
    background: #fffbeb;
}
.ba-diag--critical {
    border-left: 4px solid #b91c1c;
    background: #fef2f2;
}
.ba-diag--normal {
    border-left: 4px solid #166534;
    background: #f0fdf4;
}
.ba-diag--success {
    border-left: 4px solid #16a34a;
    background: #ecfdf5;
}
.ba-diag--success .ba-diag-header {
    color: #16a34a;
}
.ba-diag--success .ba-diag-cause {
    color: #166534;
}
.ba-diag--success .ba-diag-evidence li {
    color: #14532d;
}
.ba-diag-header {
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--body-quiet-color, #64748b);
    margin-bottom: 6px;
}
.ba-diag-cause {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
    margin-bottom: 6px;
}
.ba-diag-evidence {
    margin: 0 0 6px;
    padding: 0 0 0 18px;
    font-size: 0.8rem;
    color: var(--body-fg, #0f172a);
    line-height: 1.6;
}
.ba-diag-evidence li {
    margin-bottom: 1px;
}
.ba-diag-recs {
    font-size: 0.8rem;
    color: var(--body-fg, #0f172a);
    padding-top: 6px;
    border-top: 1px solid var(--hairline-color, #e2e8f0);
}
.ba-diag-recs-label {
    font-weight: 700;
    color: var(--body-quiet-color, #475569);
}
.ba-ph-intro {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #94a3b8);
    margin-bottom: 12px;
}

/* ── Per-batch card ── */

.ba-ph-card {
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 10px;
    margin-bottom: 14px;
    overflow: hidden;
}
.ba-ph-card:last-child {
    margin-bottom: 0;
}
.ba-ph-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 20px;
    padding: 12px 16px;
    background: #396276;
    color: #ffffff;
    border-bottom: 1px solid #2d4e5e;
}
.ba-ph-summary .ba-ph-date,
.ba-ph-summary .ba-ph-qty {
    color: #ffffff;
}
.ba-ph-summary .ba-ph-time,
.ba-ph-summary .ba-ph-batch-no {
    color: #d1dce3;
}
.ba-ph-summary .ba-ph-cost {
    color: #d1dce3;
}
.ba-ph-summary .ba-ph-cost-total {
    color: #ffffff;
}
.ba-ph-summary .ba-ph-diff-val {
    color: #ffffff;
}
.ba-ph-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.ba-ph-date {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--body-fg, #0f172a);
}
.ba-ph-time {
    font-size: 0.8rem;
    color: var(--body-quiet-color, #64748b);
}
.ba-ph-batch-no {
    font-size: 0.8rem;
    color: var(--body-quiet-color, #64748b);
    font-family: monospace;
}
.ba-ph-numbers {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ba-ph-qty {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--body-fg, #0f172a);
    white-space: nowrap;
}
.ba-ph-costs {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.ba-ph-cost {
    font-size: 0.8rem;
    color: var(--body-quiet-color, #475569);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.ba-ph-cost-total {
    font-weight: 600;
    color: var(--body-fg, #0f172a);
}
.ba-ph-diff {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.ba-ph-diff-val {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ── Detail sections ── */

.ba-ph-section {
    padding: 10px 16px 12px;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
}
.ba-ph-section:last-child {
    border-bottom: none;
}
.ba-ph-section-title {
    margin: 0 0 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--body-quiet-color, #64748b);
}
.ba-ph-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.ba-ph-detail-table thead th {
    padding: 2px 0 4px;
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--body-quiet-color, #94a3b8);
    border-bottom: 1px solid var(--hairline-color, #e2e8f0);
    text-align: left;
}
.ba-ph-detail-table thead th.ph-num {
    text-align: right;
}
.ba-ph-detail-table td {
    padding: 3px 0;
}
.ba-ph-name {
    font-weight: 500;
    color: var(--body-fg, #0f172a);
}
.ph-num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ── Yield / Cooking Loss ── */

.ba-ph-yield-section {
    background: var(--darkened-bg, #f8fafc);
}
.ba-ph-yield-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    padding: 4px 0 2px;
}
.ba-ph-yield-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.ba-ph-yield-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--body-quiet-color, #64748b);
    white-space: nowrap;
}
.ba-ph-yield-val {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
    font-variant-numeric: tabular-nums;
}
.ba-ph-yield-pct {
    color: #166534;
}
.ba-ph-loss-pct {
    color: #b91c1c;
}
.ba-ph-gain-pct {
    color: #0369a1;
}
.ba-ph-yield-conv {
    width: 100%;
}
.ba-ph-yield-conv-note {
    font-size: 0.725rem;
    color: var(--body-quiet-color, #64748b);
    font-style: italic;
}

/* ── Yield Intelligence ── */

.ba-yi {
    border-top: 1px solid var(--hairline-color, #e2e8f0);
    padding: 10px 16px 12px;
    font-size: 0.8rem;
}
.ba-yi-status {
    font-weight: 700;
    font-size: 0.8125rem;
    margin-bottom: 4px;
}
.ba-yi-ok {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    border-left: 4px solid #22c55e;
    border-radius: 8px;
    padding: 12px 16px;
}
.ba-yi-ok .ba-yi-status {
    color: #166534;
}
.ba-yi-warn {
    background: #fffbeb;
    border-left: 3px solid #b45309;
    padding-left: 13px;
}
.ba-yi-warn .ba-yi-status {
    color: #b45309;
}
.ba-yi-norm-box {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 12px;
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #166534;
    background: #bbf7d0;
    border-radius: 4px;
}
.ba-yi-recs,
.ba-yi-reason {
    margin: 0 0 6px;
    color: var(--body-fg, #0f172a);
    line-height: 1.5;
}
.ba-yi-btn {
    display: inline-block;
    padding: 6px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: var(--primary, #1a4b5e);
    color: #fff;
    cursor: pointer;
    transition: background 0.12s;
}
.ba-yi-btn:hover {
    background: var(--secondary, #0f3448);
}
.ba-yi-btn:disabled {
    opacity: 0.6;
    cursor: default;
}
.ba-yi-btn-saved {
    background: transparent;
    color: #166534;
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0;
}

/* ── Core Formula ── */

.ba-ph-core-section {
    background: #ecfdf5;
}
.ba-ph-core-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    padding: 4px 0 2px;
}
.ba-ph-core-note {
    font-size: 0.7rem;
    font-style: italic;
    color: var(--body-quiet-color, #64748b);
    margin-top: 6px;
}

/* ── Train This Product ── */

.ba-ph-train-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
}
.ba-train-btn {
    display: inline-block;
    padding: 7px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid #c4b5fd;
    border-radius: 8px;
    background: var(--body-bg, #fff);
    color: #7c3aed;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.ba-train-btn:hover {
    background: #f5f3ff;
    border-color: #7c3aed;
}
.ba-train-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: #166534;
    background: #bbf7d0;
    padding: 3px 9px;
    border-radius: 5px;
    white-space: nowrap;
}

/* ── Training tags / badges ── */

.ba-tag-badge {
    display: inline-block;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1.4;
}
.ba-tag-role {
    color: #6b21a8;
    background: #f3e8ff;
    border: 1px solid #d8b4fe;
}
.ba-tag-noncore {
    color: #b45309;
    background: #fffbeb;
    border: 1px solid #fde68a;
}

/* ── AI Actions ── */

.ba-ai-section {
    margin-bottom: 14px;
}
.ba-ai-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* ── Product Training List ── */

.pt-page { padding: 20px 0; }
.pt-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.pt-header h1 { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--body-fg, #0f172a); }
.pt-actions { display: flex; align-items: center; gap: 8px; }
.pt-add-btn, .pt-back-btn {
    display: inline-flex; align-items: center; box-sizing: border-box;
    padding: 7px 16px; font-size: 0.8rem; font-weight: 600; line-height: 1.4;
    border-radius: 8px; text-decoration: none; cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
.pt-add-btn {
    background: #3f7f98; color: #fff !important; border: 1px solid #3f7f98;
}
.pt-add-btn:hover {
    background: #4e95b0; border-color: #4e95b0;
}
.pt-back-btn {
    background: var(--body-bg, #fff); color: var(--body-fg, #0f172a);
    border: 1px solid var(--hairline-color, #cbd5e1);
}
.pt-back-btn:hover { background: #f1f5f9; }
.pt-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.pt-table thead th {
    padding: 8px 10px; font-size: 0.675rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--body-quiet-color, #94a3b8);
    border-bottom: 2px solid var(--hairline-color, #e2e8f0); text-align: left;
}
.pt-table tbody td { padding: 8px 10px; border-bottom: 1px solid var(--hairline-color, #f1f5f9); vertical-align: middle; }
.pt-table tbody tr:hover { background: var(--darkened-bg, #f8fafc); }
.pt-item-name { font-weight: 600; color: var(--body-fg, #0f172a); }
.pt-type-badge {
    display: inline-block; font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
    padding: 1px 6px; border-radius: 3px; margin-left: 5px; vertical-align: middle; line-height: 1.5;
}
.pt-type-rm { color: #1e40af; background: #dbeafe; border: 1px solid #bfdbfe; }
.pt-type-ih { color: #6b21a8; background: #f3e8ff; border: 1px solid #e9d5ff; }
.pt-role { color: var(--body-quiet-color, #64748b); }
.pt-edit-link { color: var(--primary, #3f7f98); text-decoration: none; font-weight: 600; }
.pt-edit-link:hover { text-decoration: underline; }
.pt-empty { text-align: center; padding: 40px 20px; color: var(--body-quiet-color, #94a3b8); font-size: 0.875rem; }
.pt-source { font-size: 0.725rem; color: var(--body-quiet-color, #94a3b8); }
.pt-toggle { font-size: 0.7rem; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.pt-toggle-on { color: #166534; background: #bbf7d0; }
.pt-toggle-off { color: #991b1b; background: #fecaca; }

/* ── Product Training Form ── */

.ptf-page { max-width: 850px; padding: 20px 0; }
.ptf-header-card {
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 20px;
}
.ptf-header-top {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
}
.ptf-title { margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--body-fg, #0f172a); }
.ptf-product-badge {
    display: inline-block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.03em; padding: 3px 10px; border-radius: 20px;
    color: #1e40af; background: #dbeafe; border: 1px solid #bfdbfe; white-space: nowrap;
}
.ptf-subtitle {
    margin: 8px 0 0; font-size: 0.8rem; color: var(--body-quiet-color, #64748b);
    line-height: 1.5;
}
.ptf-form-card {
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 12px;
    padding: 8px 24px 24px;
}
.ptf-section {
    padding: 18px 0;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
}
.ptf-section-last { border-bottom: none; }
.ptf-section-item {
    background: #f0f9ff;
    margin: 0 -24px;
    padding: 18px 24px;
    border-bottom: 1px solid #bae6fd;
    border-radius: 12px 12px 0 0;
}
.ptf-section-header { margin-bottom: 14px; }
.ptf-section-title {
    margin: 0 0 2px; font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--body-quiet-color, #64748b);
}
.ptf-section-desc {
    margin: 0; font-size: 0.75rem; color: var(--body-quiet-color, #94a3b8);
}
.ptf-field {
    margin-bottom: 14px;
}
.ptf-field:last-child { margin-bottom: 0; }
.ptf-field-row {
    display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 14px;
}
.ptf-field-half {
    flex: 1 1 180px; margin-bottom: 0;
}
.ptf-label {
    display: block; font-size: 0.8rem; font-weight: 600;
    color: var(--body-fg, #0f172a); margin-bottom: 4px;
}
.ptf-label-inline {
    display: inline-flex; align-items: center; gap: 6px;
    cursor: pointer; margin-bottom: 0;
}
.ptf-label-inline input[type="checkbox"] { margin: 0; }
.ptf-control { }
.ptf-help {
    font-size: 0.7rem; color: var(--body-quiet-color, #94a3b8);
    margin-top: 3px; line-height: 1.4;
}
.ptf-input, .ptf-item-select {
    width: 100%; box-sizing: border-box;
    font-size: 0.8rem; min-height: 42px; line-height: normal;
    padding: 9px 12px;
    border: 1px solid var(--hairline-color, #d1d5db);
    border-radius: 6px; background: var(--body-bg, #fff);
    color: var(--body-fg, #0f172a);
    transition: border-color 0.12s;
}
.ptf-input:focus, .ptf-item-select:focus {
    border-color: #3f7f98; outline: none; box-shadow: 0 0 0 2px rgba(63, 127, 152, 0.15);
}
.ptf-textarea { resize: vertical; min-height: 80px; padding-top: 10px; padding-bottom: 10px; }
.ptf-checkbox {
    width: auto; margin: 0 4px 0 0; vertical-align: middle;
}
select.ptf-input, select.ptf-item-select {
    min-width: 200px;
}
.ptf-field .errorlist {
    color: #dc2626; font-size: 0.75rem; list-style: none; margin: 3px 0 0; padding: 0;
}
.ptf-field-item .ptf-item-select {
    border-color: #93c5fd;
    border-width: 2px;
    font-weight: 600;
}
.ptf-actions {
    display: flex; gap: 10px; align-items: center;
    padding-top: 20px; flex-wrap: wrap;
}
.ptf-btn-save {
    display: inline-flex; align-items: center;
    padding: 8px 20px; font-size: 0.8rem; font-weight: 600; line-height: 1.4;
    border: 1px solid #3f7f98; border-radius: 8px;
    background: #3f7f98; color: #fff; cursor: pointer;
    transition: background 0.12s;
}
.ptf-btn-save:hover { background: #4e95b0; }
.ptf-btn-back {
    display: inline-flex; align-items: center;
    padding: 8px 20px; font-size: 0.8rem; font-weight: 600; line-height: 1.4;
    border: 1px solid var(--hairline-color, #cbd5e1); border-radius: 8px;
    background: var(--body-bg, #fff); color: var(--body-fg, #0f172a);
    text-decoration: none; cursor: pointer; transition: background 0.12s;
}
.ptf-btn-back:hover { background: #f1f5f9; }

/* ── Product Training: 2-col layout ── */

.ptf-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
    gap: 24px;
    align-items: start;
    width: 100%;
    max-width: 1400px;
    padding: 20px 0;
}
.ptf-col-form {
    min-width: 0;
}
.ptf-col-guide {
    min-width: 0;
}

@media (max-width: 1000px) {
    .ptf-layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ── Product Training Guide ── */

.ptf-guide-card {
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 12px;
    padding: 20px;
}
.ptf-guide-title {
    margin: 0 0 4px; font-size: 0.95rem; font-weight: 700;
    color: var(--body-fg, #0f172a);
}
.ptf-guide-product {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 16px; padding-bottom: 12px;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
}
.ptf-guide-product-label {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--body-quiet-color, #94a3b8);
}
.ptf-guide-product-name {
    font-size: 0.8rem; font-weight: 600; color: #1e40af;
}
.ptf-guide-block {
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
}
.ptf-guide-block-last { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.ptf-guide-heading {
    margin: 0 0 6px; font-size: 0.725rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--body-quiet-color, #64748b);
}
.ptf-guide-text {
    margin: 0 0 8px; font-size: 0.75rem; color: var(--body-fg, #0f172a); line-height: 1.5;
}
.ptf-guide-text-muted {
    margin: 0; font-size: 0.725rem; color: var(--body-quiet-color, #94a3b8);
    line-height: 1.5;
}
.ptf-guide-sub { margin-bottom: 8px; }
.ptf-guide-sub:last-child { margin-bottom: 0; }
.ptf-guide-sub-label {
    display: block; font-size: 0.675rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--body-quiet-color, #94a3b8); margin-bottom: 3px;
}
.ptf-guide-list {
    margin: 0; padding: 0; list-style: none;
}
.ptf-guide-list li {
    font-size: 0.75rem; color: var(--body-fg, #0f172a);
    padding: 2px 0 2px 12px; position: relative; line-height: 1.5;
}
.ptf-guide-list li::before {
    content: ""; position: absolute; left: 0; top: 9px;
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--primary, #3f7f98);
}
.ptf-guide-dl { margin: 0; }
.ptf-guide-dl dt {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--primary, #3f7f98); margin-top: 8px;
}
.ptf-guide-dl dt:first-child { margin-top: 0; }
.ptf-guide-dl dd {
    margin: 1px 0 0; font-size: 0.725rem; color: var(--body-fg, #0f172a);
    line-height: 1.5;
}
.ptf-guide-examples { display: flex; flex-direction: column; gap: 6px; }
.ptf-guide-example {
    padding: 8px 10px; border-radius: 6px;
    background: #f0f9ff; border: 1px solid #bae6fd;
}
.ptf-guide-example-item {
    display: block; font-size: 0.75rem; font-weight: 700;
    color: #1e40af; margin-bottom: 2px;
}
.ptf-guide-example-detail {
    display: block; font-size: 0.675rem; color: #3b82f6; line-height: 1.4;
}

/* ── AI Buttons ── */

.ba-ai-btn {
    display: inline-block;
    padding: 7px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 8px;
    background: var(--body-bg, #fff);
    color: var(--body-fg, #0f172a);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.ba-ai-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}
.ba-ai-btn:disabled {
    opacity: 0.6;
    cursor: default;
}
.ba-ai-loading {
    font-size: 0.8rem;
    color: var(--body-quiet-color, #64748b);
    padding: 10px 0;
}
.ba-ai-body {
    font-size: 0.8rem;
    color: var(--body-fg, #0f172a);
    line-height: 1.65;
    padding: 12px 16px;
    background: var(--darkened-bg, #f8fafc);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 8px;
    margin-top: 8px;
}
.ba-ai-error {
    font-size: 0.8rem;
    color: #b91c1c;
    padding: 10px 0;
}
.ba-ref-analysis-btn {
    background: #1e40af !important;
    color: #fff !important;
    border-color: #1e40af !important;
}
.ba-ref-analysis-btn:hover {
    background: #1e3a8a !important;
    border-color: #1e3a8a !important;
}
.ba-ref-analysis-output {
    font-size: 0.8rem;
    color: var(--body-fg, #0f172a);
    padding: 10px 14px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    margin-top: 8px;
}
.ba-ref-analysis-output.ba-ref-none {
    background: #fefce8;
    border-color: #fde68a;
}
.ba-ph-qty {
    text-align: center;
    padding: 0 12px;
    color: var(--body-quiet-color, #475569);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.ba-ph-cost {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

/* ── Recipe difference ── */

.ba-ph-diff-section {
    background: var(--message-warning-bg, #fffbeb);
}
.ba-ph-diff-note {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--body-quiet-color, #94a3b8);
}
.ba-ph-diff-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 0.8rem;
    padding: 2px 0;
}
.ba-ph-diff-label {
    font-weight: 600;
    white-space: nowrap;
    min-width: 82px;
}
.ba-ph-add-label {
    color: #166534;
}
.ba-ph-miss-label {
    color: #b91c1c;
}

/* ── Reference Recipe Comparison ── */

.ba-ph-ref-section {
    border-top: 1px solid var(--hairline-color, #e2e8f0);
}
.ba-ph-ref-note {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #64748b);
    font-style: italic;
    margin-bottom: 8px;
    line-height: 1.5;
}
.ba-ph-ref-needs-review {
    font-size: 0.8rem;
    color: #b45309;
    font-weight: 600;
    padding: 4px 0;
}
.ba-ph-ref-non-norm {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #64748b);
    margin: 8px 0 4px;
    padding: 6px 10px;
    background: #fefce8;
    border-left: 3px solid #eab308;
    line-height: 1.5;
}
.ba-ph-ref-non-norm p {
    margin: 0 0 2px;
    font-weight: 500;
}
.ba-ph-ref-non-norm ul {
    margin: 0;
    padding-left: 1.25rem;
}
.ba-ph-ref-non-norm li {
    margin: 0;
    list-style: disc;
}
.ba-ph-ref-excluded {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #64748b);
    margin: 8px 0 4px;
    padding: 6px 10px;
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    line-height: 1.5;
}
.ba-ph-ref-excluded p {
    margin: 0 0 2px;
    font-weight: 500;
}
.ba-ph-ref-excluded ul {
    margin: 0;
    padding-left: 1.25rem;
}
.ba-ph-ref-excluded li {
    margin: 0;
    list-style: disc;
}
.ba-ph-ref-source {
    font-size: 0.7rem;
    color: var(--body-quiet-color, #94a3b8);
    margin-top: 6px;
}
.ba-ph-ref-extra {
    font-size: 0.7rem;
    color: var(--body-quiet-color, #64748b);
    font-style: italic;
}
.ba-ph-ref-diff-med {
    color: #b45309;
}
.ba-ph-ref-diff-high {
    color: #b91c1c;
    font-weight: 700;
}

/* ── Reference candidate (fuzzy match) ── */
.ba-ref-candidate {
    margin: 10px 0;
    padding: 14px 16px;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 6px;
}
.ba-ref-candidate-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #0369a1;
    margin-bottom: 6px;
}
.ba-ref-candidate-body {
    font-size: 0.78rem;
    color: #1e293b;
    line-height: 1.6;
}
.ba-ref-candidate-body p {
    margin: 0 0 2px;
}
.ba-ref-candidate-btn {
    margin-top: 8px;
    font-size: 0.75rem !important;
    padding: 5px 14px !important;
    background: #0369a1 !important;
    color: #fff !important;
    border: 1px solid #0369a1 !important;
    border-radius: 4px;
    cursor: pointer;
}
.ba-ref-candidate-btn:hover {
    background: #075985 !important;
}
.ba-ref-candidate-btn:disabled {
    opacity: 0.6;
    cursor: default;
}
.ba-ref-candidate-saved {
    font-size: 0.78rem;
    color: #15803d;
    font-weight: 600;
    margin-top: 6px;
    padding: 6px 10px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 4px;
}

/* ── Reference clarification ── */
.ba-ref-clarify {
    margin: 12px 0 4px;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}
.ba-ref-clarify-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 2px;
}
.ba-ref-clarify-text {
    font-size: 0.75rem;
    color: #475569;
    margin: 0 0 8px;
}
.ba-ref-clarify-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
    border-top: 1px solid #f1f5f9;
}
.ba-ref-clarify-item:first-child {
    border-top: none;
}
.ba-ref-clarify-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #334155;
    min-width: 160px;
}
.ba-ref-clarify-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.ba-clarify-btn {
    font-size: 0.7rem !important;
    padding: 2px 8px !important;
    line-height: 1.6 !important;
}
.ba-clarify-btn-saved {
    font-size: 0.7rem;
    color: #15803d;
    background: none;
    border: none;
    font-style: italic;
    cursor: default;
}

/* ─── Gateway (admin home) ─── */

body.hc-gateway {
    overflow-x: hidden;
}

/* Hide sidebar + toggle on home page */
body.hc-gateway #nav-sidebar,
body.hc-gateway .toggle-nav-sidebar {
    display: none !important;
}

/* Force every wrapper to full width — overriding Django's .dashboard #content { width:600px }
   DOM chain: .main > main.content > #content.colM > #content-main > .hc-gateway > .hc-gate-body */

/* Override nav_sidebar.css: .main > #nav-sidebar + .content { max-width: calc(100% - 23px) } */
body.hc-gateway .main > #nav-sidebar + .content {
    max-width: none !important;
}

body.hc-gateway #content {
    width: 100% !important;
    max-width: none !important;
    padding: 20px 24px 20px 40px;
    box-sizing: border-box;
}
body.hc-gateway #content-main {
    width: 100% !important;
    max-width: none !important;
    float: none;
}
body.hc-gateway .hc-gateway {
    width: 100% !important;
    max-width: none !important;
    padding: 0 0 40px;
}

/* ─── Full-width form pages (HR) ─── */

/* Hide sidebar + toggle on HR add/change forms for clean data entry */
body.app-hr.change-form #nav-sidebar,
body.app-hr.change-form .toggle-nav-sidebar,
body.app-hr.model-employeeonboardingrequest #nav-sidebar,
body.app-hr.model-employeeonboardingrequest .toggle-nav-sidebar,
body.app-hr.model-employeeadvancerequest #nav-sidebar,
body.app-hr.model-employeeadvancerequest .toggle-nav-sidebar {
    display: none !important;
}

/* Override nav_sidebar.css max-width constraint when sibling hidden */
body.app-hr.change-form .main > #nav-sidebar + .content,
body.app-hr.model-employeeonboardingrequest .main > #nav-sidebar + .content,
body.app-hr.model-employeeadvancerequest .main > #nav-sidebar + .content {
    max-width: none !important;
}

body.app-hr.change-form #content,
body.app-hr.model-employeeonboardingrequest #content,
body.app-hr.model-employeeadvancerequest #content {
    max-width: none !important;
}

body.app-hr.change-form #content-main,
body.app-hr.model-employeeonboardingrequest #content-main,
body.app-hr.model-employeeadvancerequest #content-main {
    max-width: none !important;
    float: none;
}

.hc-gate-hero {
    margin-bottom: 36px;
}
.hc-gate-hero-title {
    margin: 0 0 4px;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
    letter-spacing: -0.02em;
}
.hc-gate-hero-sub {
    margin: 0;
    font-size: 1rem;
    color: var(--body-quiet-color, #64748b);
}

/* ── Body: workspaces + recent ── */

.hc-gate-body {
    display: block;
    position: relative;
    width: 100% !important;
    max-width: none !important;
}
.hc-gate-workspaces {
    width: 620px;
    max-width: 620px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Workspace cards ── */

.hc-gate-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    border-radius: 14px;
    text-decoration: none;
    transition: box-shadow 0.2s, transform 0.15s;
    border: 1px solid var(--hairline-color, #e2e8f0);
    background: var(--body-bg, #fff);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.hc-gate-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}
.hc-gate-card-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.hc-gate-card-auth .hc-gate-card-icon {
    background: #e0e7ff;
    color: #4338ca;
}
.hc-gate-card-prod .hc-gate-card-icon {
    background: #ccfbf1;
    color: #0f766e;
}
.hc-gate-card-hr .hc-gate-card-icon {
    background: #f3e8ff;
    color: #7c3aed;
}
.hc-gate-card-label {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: var(--body-fg, #0f172a);
}
.hc-gate-card-arrow {
    flex-shrink: 0;
    color: var(--body-quiet-color, #94a3b8);
    transition: transform 0.2s;
}
.hc-gate-card:hover .hc-gate-card-arrow {
    transform: translateX(4px);
}

/* ── Recent Actions ── */

.hc-gate-recent {
    position: absolute;
    top: 0;
    right: 0;
    width: 210px;
    max-width: 210px;
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.hc-gate-recent-title {
    background: #396276;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: -20px -20px 14px;
    padding: 12px 20px;
    border-radius: 14px 14px 0 0;
}
.hc-gate-actionlist {
    list-style: none;
    margin: 0;
    padding: 0;
}
.hc-gate-action-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--hairline-color, #f1f5f9);
    align-items: flex-start;
}
.hc-gate-action-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}
.hc-gate-action-badge {
    flex-shrink: 0;
    display: inline-block;
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-top: 2px;
    line-height: 1.5;
}
.hc-gate-action-badge-add {
    background: #dcfce7;
    color: #166534;
}
.hc-gate-action-badge-change {
    background: #dbeafe;
    color: #1e40af;
}
.hc-gate-action-badge-delete {
    background: #fee2e2;
    color: #991b1b;
}
.hc-gate-action-body {
    min-width: 0;
    flex: 1;
}
.hc-gate-action-repr {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--body-fg, #0f172a);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
a.hc-gate-action-repr:hover {
    color: var(--link-fg, #1a4b5e);
    text-decoration: underline;
}
.hc-gate-action-type {
    display: block;
    font-size: 0.6875rem;
    color: var(--body-quiet-color, #94a3b8);
    margin-top: 1px;
}
.hc-gate-empty {
    font-size: 0.8125rem;
    color: var(--body-quiet-color, #94a3b8);
    margin: 0;
}

/* ── Dashboard landing pages (production, auth) ─── */

body.hc-dash {
    overflow-x: hidden;
}
.hc-dash-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 0 32px;
}
.hc-dash-header {
    margin-bottom: 28px;
}
.hc-dash-title {
    margin: 0 0 4px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--body-fg, #0f172a);
}
.hc-dash-sub {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--body-quiet-color, #64748b);
}
.hc-dash-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.hc-dash-card {
    background: var(--body-bg, #fff);
    border: 1px solid var(--hairline-color, #e2e8f0);
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s, border-color 0.2s;
}
.hc-dash-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}
.hc-dash-card-body {
    flex: 1;
    padding: 18px 18px 8px;
    min-width: 0;
}
.hc-dash-card-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--body-fg, #0f172a);
    margin-bottom: 2px;
}
.hc-dash-card-desc {
    font-size: 0.75rem;
    color: var(--body-quiet-color, #64748b);
    line-height: 1.4;
}
.hc-dash-card-actions {
    display: flex;
    gap: 8px;
    padding: 8px 18px 16px;
    align-items: center;
}
.hc-dash-btn {
    display: inline-flex;
    align-items: center;
    text-decoration: none !important;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 8px;
    transition: background 0.15s;
}
.hc-dash-btn:link,
.hc-dash-btn:visited {
    text-decoration: none !important;
}
.hc-dash-btn:hover,
.hc-dash-btn:focus,
.hc-dash-btn:active {
    text-decoration: none !important;
}
.hc-dash-btn-primary {
    background: var(--primary, #1a4b5e);
    color: #fff !important;
}
.hc-dash-btn-primary:link,
.hc-dash-btn-primary:visited {
    color: #fff !important;
}
.hc-dash-btn-primary:hover {
    background: var(--secondary, #0f3448);
    color: #fff !important;
}
.hc-dash-btn-primary:focus {
    color: #fff !important;
}
.hc-dash-btn-ghost {
    background: var(--darkened-bg, #f1f5f9);
    color: var(--body-fg, #0f172a);
}
.hc-dash-btn-ghost:hover {
    background: var(--hairline-color, #e2e8f0);
    color: var(--body-fg, #0f172a);
}

/* ── Responsive ── */

@media (max-width: 1000px) {
    body.hc-gateway .hc-gate-recent {
        position: static;
        width: 100%;
        max-width: none;
        margin-top: 24px;
    }
    body.hc-gateway .hc-gate-workspaces {
        width: 100%;
        max-width: none;
    }
    .hc-dash-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }
    #changelist table,
    .module table {
        overflow-x: auto;
        display: block;
    }
    .aligned .form-row {
        display: flex;
        flex-direction: column;
    }
    .aligned .form-row > div {
        width: 100% !important;
        margin-left: 0 !important;
    }
    .aligned .form-row label {
        float: none !important;
        width: auto !important;
    }
    .vLargeTextField,
    .vTextField {
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box;
    }
}
