:root {
    --primary: #16a34a;
    --primary-hover: #15803d;
    --primary-light: #f0fdf4;
    --primary-muted: #dcfce7;
    --primary-dark: #14532d;
    --primary-ring: rgba(22, 163, 74, 0.18);
    --secondary-bg: #ecfdf5;
    --secondary-text: #4b5563;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #d97706;
    --warning-hover: #b45309;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --info-bg: #f0fdf4;
    --info-border: #bbf7d0;
    --page-bg: #f4faf6;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 4px 16px rgba(22, 163, 74, 0.12);
    --shadow-card: 0 2px 12px rgba(15, 23, 42, 0.06);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-top-h: 52px;
    --app-bottom-h: 64px;
    --app-page-max: 28rem;
    --app-shell-max: 28rem;
    --app-sidebar-w: 13.5rem;
}

*, *::before, *::after { box-sizing: border-box; }

.hidden { display: none !important; }

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

body {
    margin: 0;
    min-height: 100dvh;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    line-height: 1.45;
}

body.app-body {
    background: var(--page-bg);
    color: var(--text);
    padding: 0.5rem;
}

@media (min-width: 640px) {
    body.app-body { padding: 1rem; }
}

body.auth-body {
    background: linear-gradient(165deg, #ecfdf5 0%, #f4faf6 45%, #faf8f5 100%);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

body.has-app-shell {
    padding-top: calc(var(--app-top-h) + var(--safe-top));
    padding-bottom: calc(var(--app-bottom-h) + var(--safe-bottom) + 8px);
}

/* ——— Типографика и утилиты бренда ——— */
.text-brand { color: var(--primary) !important; }
.text-brand-dark { color: var(--primary-dark) !important; }
.bg-brand-light { background: var(--primary-light) !important; }
.border-brand { border-color: var(--info-border) !important; }
.link-brand { color: var(--primary); font-weight: 600; text-decoration: none; }
.link-brand:hover { color: var(--primary-hover); text-decoration: underline; }

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary-dark);
    margin: 0;
}

.batch-banner {
    background: var(--primary-muted);
    border: 1px solid var(--info-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    text-align: center;
}

.panel-finance {
    background: var(--primary-light);
    border: 1px solid var(--info-border);
    border-radius: var(--radius);
    padding: 1rem;
}

.panel-norms {
    background: var(--info-bg);
    border: 1px solid var(--info-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--primary-dark);
}

.panel-warn {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.stat-highlight {
    background: linear-gradient(135deg, #16a34a 0%, #059669 100%);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow);
}

.spinner-brand {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    border: 4px solid var(--primary-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.auth-card {
    width: 100%;
    max-width: 28rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--info-border);
    padding: 1.5rem;
}

.auth-hint {
    background: var(--primary-light);
    border: 1px solid var(--info-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    color: var(--primary-dark);
}

.auth-header { text-align: center; margin-bottom: 1.25rem; }
.auth-subtitle { font-size: 0.875rem; color: var(--text-muted); margin: 0.35rem 0 0; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }
.auth-field { display: flex; flex-direction: column; gap: 0.25rem; }
.auth-error {
    font-size: 0.875rem;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
}
.auth-error.hidden,
.auth-loading.hidden { display: none !important; }
.auth-footer { text-align: center; font-size: 0.875rem; color: var(--text-muted); margin: 1.25rem 0 0; }
.auth-hint-title { font-weight: 700; margin: 0 0 0.5rem; }
.auth-steps { margin: 0; padding-left: 1.25rem; line-height: 1.5; }
.auth-steps li + li { margin-top: 0.35rem; }
.auth-note { margin: 0.75rem 0 0; font-size: 0.7rem; opacity: 0.9; }
.auth-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Кнопки в формах — всегда зелёные (перебиваем Tailwind CDN на других страницах) */
button.btn-primary,
.btn.btn-primary {
    background: var(--primary) !important;
    color: #fff !important;
    border: none !important;
}
button.btn-primary:hover:not(:disabled),
.btn.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover) !important;
}

/* ——— Кнопки ——— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.25rem;
    min-height: 44px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease, opacity 0.15s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.5rem 0.875rem; min-height: 38px; font-size: 0.8125rem; border-radius: var(--radius-sm); }

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--secondary-text);
}
.btn-secondary:hover:not(:disabled) { background: #d1fae5; }

.btn-warning {
    background: var(--warning);
    color: #fff;
    box-shadow: 0 4px 14px rgba(217, 119, 6, 0.22);
}
.btn-warning:hover:not(:disabled) { background: var(--warning-hover); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.2);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-ghost {
    background: transparent;
    color: #9ca3af;
    padding: 0.5rem 0.75rem;
    min-height: 36px;
    font-size: 0.6875rem;
    font-weight: 500;
    box-shadow: none;
}
.btn-ghost:hover:not(:disabled) { color: var(--danger); background: transparent; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: #fef2f2;
    color: var(--danger);
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}
.btn-icon:hover { background: #fee2e2; }

.btn-accordion {
    width: 100%;
    background: #f8fafc;
    color: #374151;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    justify-content: space-between;
    box-shadow: none;
    border: 1px solid var(--border);
    white-space: normal;
    text-align: left;
}
.btn-accordion:hover { background: var(--primary-light); }

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-row .btn-grow { flex: 2; min-width: 0; }
.btn-row .btn { flex: 1; min-width: 0; }

.feed-type-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.375rem;
    margin-top: 0.375rem;
}

.feed-type-btn {
    min-height: 42px;
    padding: 0.5rem 0.35rem;
    border: 1.5px solid #d1d5db;
    border-radius: var(--radius-sm);
    background: #f9fafb;
    color: #374151;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

.feed-type-btn:hover {
    border-color: var(--primary);
    background: #ecfdf5;
}

.feed-type-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.feed-type-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #e5e7eb;
    background: #f3f4f6;
    color: #9ca3af;
    box-shadow: none;
}

/* Вкладки */
.tabs-bar {
    display: flex;
    gap: 0.25rem;
    background: #fff;
    padding: 0.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab-link {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.5rem;
    min-height: 40px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--secondary-text);
    text-decoration: none;
    text-align: center;
    transition: all 0.2s ease;
}
.tab-link.active {
    background: var(--primary);
    color: #fff;
}
.tab-link:hover:not(.active) {
    background: var(--primary-light);
    color: var(--primary);
}

/* Меню в шапке (nav.js) */
#app-top-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    padding-top: var(--safe-top);
    background: linear-gradient(to bottom, rgba(244, 250, 246, 0.97), rgba(244, 250, 246, 0.88));
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(187, 247, 208, 0.5);
}

.app-top-menu-inner {
    padding-top: 0.5rem;
    padding-bottom: 0.25rem;
}

.app-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: #fff;
    border: 1px solid var(--info-border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    min-height: 40px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-dark);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: background-color 0.2s ease;
}
.app-menu-btn:hover { background: var(--primary-light); }

.app-menu-item {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    min-height: 44px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #374151;
    font-family: inherit;
    font-weight: 500;
    transition: background-color 0.15s ease;
}
.app-menu-item:hover,
.app-menu-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

/* Нижняя навигация (телефон) / боковая (ноутбук) */
#app-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: #fff;
    border-top: 1px solid var(--info-border);
    box-shadow: 0 -4px 16px rgba(22, 101, 52, 0.06);
    padding-bottom: var(--safe-bottom);
}

.app-bottom-nav-inner {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    min-height: var(--app-bottom-h);
    width: 100%;
    max-width: var(--app-shell-max);
    margin: 0 auto;
    padding: 0 0.25rem;
}

.app-nav-item {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    min-height: var(--app-bottom-h);
    padding: 0.35rem 0.25rem;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.app-nav-item.active { color: var(--primary); }

.app-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
}

.app-nav-label {
    font-size: 0.625rem;
    font-weight: 500;
    line-height: 1.1;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-nav-item.active .app-nav-label { font-weight: 700; }

#app-top-menu.hidden { display: none !important; }

.period-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem 0.85rem;
    min-width: 110px;
    min-height: 40px;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: #fff;
    color: #6b7280;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.period-pill.active {
    border: 2px solid var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

/* Поля ввода (единый стиль) */
.input-field,
.field-input {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.625rem 0.75rem;
    min-height: 44px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm);
    background: #f9fafb;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    font-family: inherit;
    color: var(--text);
}
.input-field:focus,
.field-input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.field-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.15rem;
}

/* Карточка страницы фермера */
.app-page {
    width: 100%;
    max-width: var(--app-page-max);
    margin-left: auto;
    margin-right: auto;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(187, 247, 208, 0.45);
    overflow: hidden;
    padding: 1.25rem;
}

/* Общая обёртка шапки/контента (телефон → планшет → ПК) */
.app-shell-inner {
    width: 100%;
    max-width: var(--app-shell-max);
    margin-left: auto;
    margin-right: auto;
}

/* Сетки внутри карточек — без зависимости от Tailwind CDN */
.app-page .grid {
    display: grid;
    gap: 1rem;
}
.app-page .grid-cols-2 {
    grid-template-columns: 1fr;
}
.app-page .grid-cols-3 {
    grid-template-columns: 1fr;
}

.app-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.app-table-wrap table {
    width: 100%;
    min-width: 280px;
    border-collapse: collapse;
}

/* Sticky под шапкой */
.app-sticky-under-menu {
    top: calc(var(--app-top-h) + var(--safe-top));
}

/* Setup: вакцины на узких экранах */
@media (max-width: 420px) {
    .row-vaccine .flex.items-center.justify-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
    }
    .row-vaccine .vac-cost {
        width: 100% !important;
    }
    .period-pill { min-width: 96px; padding-left: 0.6rem; padding-right: 0.6rem; }
    .app-page { padding: 1rem; border-radius: 0.75rem; }
}

@media (max-width: 360px) {
    .app-nav-label { font-size: 0.55rem; }
    h1, .page-title { font-size: 1.125rem !important; }
}

/* ——— Планшет (640px+) ——— */
@media (min-width: 640px) {
    :root {
        --app-page-max: 42rem;
        --app-shell-max: 42rem;
        --app-top-h: 56px;
        --app-bottom-h: 68px;
    }

    body.app-body { padding: 1.25rem 1.5rem; }
    body.auth-body { padding: 2rem; }

    .app-page { padding: 1.5rem 1.75rem; }
    .page-title { font-size: 1.5rem; }
    .auth-card { max-width: 32rem; padding: 2rem; }

    .app-page .grid-cols-2 { grid-template-columns: 1fr 1fr; }
    .app-page .grid-cols-3 { grid-template-columns: repeat(3, 1fr); }

    .panel-finance .grid-cols-2 {
        grid-template-columns: 1fr 1fr;
    }

    #app-bottom-nav .app-bottom-nav-inner,
    #app-top-menu .app-top-menu-inner {
        max-width: var(--app-shell-max);
    }

    .app-nav-label { font-size: 0.6875rem; }
    .app-nav-icon { font-size: 1.35rem; }
}

/* ——— Планшет альбом / маленький ноутбук (768px+) ——— */
@media (min-width: 768px) {
    :root {
        --app-page-max: 48rem;
        --app-shell-max: 48rem;
    }

    .batch-banner { padding: 1rem 1.25rem; }
    .panel-finance,
    .panel-warn,
    .panel-norms { padding: 1.25rem; }

    /* Финансы: две колонки на широком экране */
    .finance-layout-split {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        align-items: start;
    }
}

/* ——— Компьютер (1024px+) ——— */
@media (min-width: 1024px) {
    :root {
        --app-page-max: 72rem;
        --app-shell-max: 72rem;
        --app-top-h: 0px;
        --app-bottom-h: 0px;
        --app-sidebar-w: 15.5rem;
    }

    body.app-body {
        padding: 1.25rem 1.75rem 1.5rem calc(var(--app-sidebar-w) + 1.25rem);
        background: linear-gradient(180deg, #ecfdf5 0%, var(--page-bg) 160px);
    }

    body.has-app-shell,
    body.desktop-sidebar.has-app-shell {
        padding-top: 1.25rem;
        padding-bottom: 1.5rem;
    }

    .app-page {
        padding: 1.5rem 2rem;
        border-radius: calc(var(--radius) + 2px);
        max-width: none;
        width: 100%;
    }

    .page-title { font-size: 1.625rem; text-align: left; }

    #app-top-menu { display: none !important; }

    #app-bottom-nav {
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: var(--app-sidebar-w);
        height: 100dvh;
        transform: none;
        border-top: none;
        border-right: 1px solid #bbf7d0;
        border-radius: 0;
        box-shadow: 4px 0 28px rgba(22, 101, 52, 0.08);
        padding-bottom: 0;
        padding-top: 0;
        background: linear-gradient(180deg, #ffffff 0%, #f7fdf9 55%, #f0fdf4 100%);
    }

    .app-bottom-nav-inner {
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        min-height: auto;
        height: 100%;
        max-width: none;
        padding: 0;
        gap: 0;
        overflow-y: auto;
    }

    .app-sidebar-brand {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1.35rem 1rem 1.1rem;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid #dcfce7;
        background: linear-gradient(135deg, rgba(22, 163, 74, 0.06) 0%, transparent 100%);
    }

    .app-sidebar-logo-wrap {
        width: 2.75rem;
        height: 2.75rem;
        border-radius: 0.85rem;
        background: linear-gradient(145deg, #22c55e 0%, #16a34a 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.35rem;
        box-shadow: 0 6px 16px rgba(22, 163, 74, 0.28);
        flex-shrink: 0;
    }

    .app-sidebar-title {
        display: block;
        font-weight: 800;
        font-size: 1.125rem;
        color: #14532d;
        line-height: 1.15;
        letter-spacing: -0.02em;
    }

    .app-sidebar-sub {
        display: block;
        font-size: 0.6875rem;
        color: #6b7280;
        margin-top: 0.1rem;
    }

    .app-sidebar-section {
        padding: 0.65rem 0.75rem 0.35rem;
    }

    .app-sidebar-section + .app-sidebar-section {
        padding-top: 0.35rem;
        margin-top: 0.15rem;
        border-top: 1px solid #ecfdf5;
    }

    .app-sidebar-section-title {
        margin: 0 0 0.4rem;
        padding: 0 0.5rem;
        font-size: 0.625rem;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #9ca3af;
    }

    .app-nav-item {
        flex: 0 0 auto;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        gap: 0.7rem;
        min-height: 44px;
        padding: 0.5rem 0.65rem;
        margin-bottom: 0.2rem;
        border-radius: 0.65rem;
        width: 100%;
        color: #4b5563;
        border: 1px solid transparent;
    }

    .app-nav-item .app-nav-icon {
        width: 2rem;
        height: 2rem;
        border-radius: 0.5rem;
        background: #f3f4f6;
        font-size: 1rem;
        flex-shrink: 0;
        transition: background-color 0.15s ease;
    }

    .app-nav-item:hover {
        background: #f0fdf4;
        color: #14532d;
        border-color: #dcfce7;
    }

    .app-nav-item:hover .app-nav-icon {
        background: #dcfce7;
    }

    .app-nav-item.active {
        background: #fff;
        color: #14532d;
        font-weight: 600;
        border-color: #bbf7d0;
        box-shadow: 0 2px 8px rgba(22, 163, 74, 0.1);
    }

    .app-nav-item.active::before {
        content: "";
        position: absolute;
        left: -0.75rem;
        top: 50%;
        transform: translateY(-50%);
        width: 3px;
        height: 1.5rem;
        background: #16a34a;
        border-radius: 0 3px 3px 0;
    }

    .app-nav-item.active .app-nav-icon {
        background: #dcfce7;
    }

    .app-nav-label {
        font-size: 0.875rem;
        font-weight: 500;
        white-space: nowrap;
        text-align: left;
    }

    .app-nav-item.active .app-nav-label { font-weight: 700; }

    .app-sidebar-section-extra {
        margin-top: auto;
        padding-bottom: 1rem;
        border-top: 1px dashed #d1fae5 !important;
    }

    .btn:hover:not(:disabled) { transform: translateY(-1px); }

    .stat-highlight { padding: 1rem 1.25rem; }

    .page-home-grid {
        grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
        gap: 2rem;
    }
}

/* ——— Большой монитор (1280px+) ——— */
@media (min-width: 1280px) {
    :root {
        --app-page-max: 80rem;
        --app-shell-max: 80rem;
        --app-sidebar-w: 15.5rem;
    }

    body.app-body {
        padding-left: calc(var(--app-sidebar-w) + 1.5rem);
        padding-right: 2rem;
    }

    .app-page { padding: 1.75rem 2.25rem; }

    .page-home-grid {
        grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
    }
}

/* Переопределение Tailwind max-w-md внутри приложения */
body.app-body .max-w-md,
body.has-app-shell .max-w-md {
    max-width: var(--app-shell-max) !important;
    width: 100%;
}

/* График — адаптивная высота */
#weightChart {
    max-width: 100%;
    height: auto !important;
}

.chart-panel {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

/* Главная: две колонки на ноутбуке */
.page-home-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.page-home-main,
.page-home-side {
    min-width: 0;
}

.page-home-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

    .page-home-side .panel-finance {
        flex: 1;
    }

/* Setup: форма не растягивается на весь экран */
.page-setup-inner {
    max-width: 36rem;
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .page-setup-inner {
        max-width: 42rem;
        margin: 0;
    }
}

/* Аптечка: карточки в сетке на компьютере */
.page-medication .med-page-toolbar {
    max-width: 100%;
}

.med-category-block {
    margin-bottom: 0.25rem;
}

.med-category-title {
    margin: 0 0 0.65rem;
    padding: 0 0.15rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9ca3af;
}

.med-category-grid {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.med-card {
    display: block;
    width: 100%;
    text-align: left;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-card);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.med-card--has-desc {
    border-left: 3px solid #22c55e;
}

.med-card--no-desc {
    border-left: 3px solid #e5e7eb;
}

.med-card:hover {
    border-color: #bbf7d0;
    box-shadow: 0 4px 14px rgba(22, 163, 74, 0.1);
}

.med-card:active {
    transform: scale(0.995);
}

.med-card-body {
    min-width: 0;
}

.med-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.45rem;
}

.med-name {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}

.med-card-preview {
    margin: 0 0 0.5rem;
    font-size: 0.8125rem;
    color: #4b5563;
    line-height: 1.45;
}

.med-card-no-desc {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    color: #9ca3af;
    font-style: italic;
    line-height: 1.4;
}

.med-card-action {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #16a34a;
}

.med-card-action--muted {
    color: #6b7280;
    font-weight: 500;
}

.med-card-price {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: #047857;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
    white-space: nowrap;
}

.med-page-hint strong {
    color: #14532d;
}

/* Модальное окно препарата */
.med-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.45);
}

.med-modal.hidden {
    display: none !important;
}

.med-modal-panel {
    width: 100%;
    max-width: 32rem;
    max-height: min(88vh, 640px);
    overflow-y: auto;
    background: #fff;
    border-radius: 1rem 1rem 0.75rem 0.75rem;
    padding: 1.25rem 1.25rem 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

@media (min-width: 640px) {
    .med-modal {
        align-items: center;
    }
    .med-modal-panel {
        border-radius: 1rem;
    }
}

.med-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.med-modal-label {
    margin: 0 0 0.15rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #9ca3af;
}

.med-modal-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 800;
    color: #111827;
    line-height: 1.25;
}

.med-modal-close {
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.med-modal-price-box {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 0.75rem;
}

.med-modal-price-label {
    font-size: 0.8125rem;
    color: #166534;
    font-weight: 500;
}

.med-modal-price-value {
    font-size: 1.125rem;
    font-weight: 800;
    color: #14532d;
}

.med-modal-section {
    margin-bottom: 1.25rem;
}

.med-modal-section-title {
    margin: 0 0 0.65rem;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #374151;
}

.med-modal-desc {
    font-size: 0.875rem;
    color: #1f2937;
    line-height: 1.55;
    white-space: pre-wrap;
    padding: 0.85rem 1rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
}

.med-modal-empty {
    padding: 0.85rem 1rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    color: #92400e;
    line-height: 1.5;
}

.med-modal-empty p {
    margin: 0 0 0.5rem;
}

.med-modal-empty-note {
    margin: 0 !important;
    font-size: 0.75rem;
    color: #b45309;
}

@media (min-width: 768px) {
    .med-category-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }
}

@media (min-width: 1280px) {
    .med-category-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Склад корма на странице заявки */
.feed-stock-panel {
    padding: 1rem 1.1rem;
    background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.feed-stock-title {
    margin: 0 0 0.75rem;
    font-size: 0.9375rem;
    font-weight: 700;
    color: #14532d;
}

.feed-stock-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    .feed-stock-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.feed-stock-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border-radius: 0.65rem;
    background: #fff;
    border: 1px solid #e5e7eb;
}

.feed-stock-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #374151;
}

.feed-stock-value {
    font-size: 0.875rem;
    font-weight: 800;
    color: #14532d;
    white-space: nowrap;
}

.feed-stock-note {
    margin: 0.75rem 0 0;
    font-size: 0.6875rem;
    color: #6b7280;
    line-height: 1.4;
}

@media (min-width: 900px) {
    .page-home-grid {
        display: grid;
        grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
        gap: 1.5rem;
        align-items: start;
    }

    .page-home-side {
        position: sticky;
        top: calc(var(--app-top-h) + var(--safe-top) + 0.75rem);
    }

    .chart-panel canvas {
        min-height: 260px;
    }

    .finance-costs { font-size: 0.8125rem !important; }
}
