/* assets/style.css — Farm Manager */

:root {
    --sidebar-w:      248px;
    --sidebar-bg:     #1c2b1c;
    --sidebar-text:   #b8cfb8;
    --sidebar-active: #4caf50;
    --topbar-h:       44px;
    --module-bar-h:   64px;
    --accent:         #4caf50;
    --accent-dark:    #388e3c;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: #f2f4f2; font-family: 'Segoe UI', sans-serif; }

/* ── Login ──────────────────────────────────────────────────────────── */
.login-bg  { background: linear-gradient(135deg, #1c2b1c 0%, #2e5c2e 100%); }
.login-card { width: 380px; border-radius: 16px; border: none; }
.farm-logo-circle {
    width: 64px; height: 64px; border-radius: 50%;
    background: #e8f5e9; display: flex; align-items: center;
    justify-content: center; font-size: 2rem;
    overflow: hidden;
}
.farm-logo-circle img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Login: uploaded logo renders at natural aspect ratio, bounded by card width. */
.farm-logo-img {
    display: flex; align-items: center; justify-content: center;
    max-width: 260px; max-height: 140px;
    margin-left: auto; margin-right: auto;
}
.farm-logo-img img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }

/* ── App shell ──────────────────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-body  { display: flex; flex: 1; min-height: 0; }

/* ── Module bar (top, full-width) ──────────────────────────────────── */
.module-bar {
    display: flex; align-items: center;
    gap: .75rem;
    height: var(--module-bar-h);
    padding: 0 1rem;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-bottom: 1px solid rgba(255,255,255,.08);
    position: sticky; top: 0; z-index: 30;
    flex-shrink: 0;
}

.module-bar-toggle {
    display: none;            /* desktop hidden; shown at <768px */
    background: none; border: none;
    color: #fff; font-size: 1.5rem;
    padding: .35rem .55rem;
    border-radius: 8px;
    cursor: pointer; line-height: 1;
    flex-shrink: 0;
}
.module-bar-toggle:hover { background: rgba(255,255,255,.1); }

.module-bar-brand {
    display: flex; align-items: center; gap: .55rem;
    padding: .25rem .35rem;
    color: #fff; text-decoration: none;
    flex-shrink: 0;
    max-width: 240px;
}
.module-bar-brand:hover { color: #fff; }
.module-bar-brand .brand-icon {
    font-size: 1.6rem;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.module-bar-brand .brand-icon img {
    max-height: 2.2rem; max-width: 5rem;
    object-fit: contain; display: block;
}
.module-bar-brand .brand-name {
    font-weight: 700; font-size: 1rem; letter-spacing: .01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.module-bar-pills {
    display: flex; align-items: stretch;
    gap: .4rem;
    flex: 1; min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.module-bar-pills::-webkit-scrollbar { height: 4px; }
.module-bar-pills::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.module-pill {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .55rem 1rem;
    border-radius: 10px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: .92rem; font-weight: 500;
    background: rgba(255,255,255,.04);
    transition: background .15s, color .15s, transform .08s;
    flex-shrink: 0;
    white-space: nowrap;
}
.module-pill:hover  { background: rgba(255,255,255,.12); color: #fff; }
.module-pill.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 2px 6px rgba(76,175,80,.35);
}
.module-pill:active { transform: translateY(1px); }
.module-pill-icon { font-size: 1.15rem; flex-shrink: 0; }
.module-pill-soon { font-size: .6rem; }

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    flex-shrink: 0;
    padding: .35rem 0 1rem;
    position: sticky;
    top: var(--module-bar-h);
    height: calc(100vh - var(--module-bar-h));
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.3);
    padding: .9rem 1rem .4rem;
}
.sidebar-module-header {
    font-size: .8rem;
    color: rgba(255,255,255,.55);
    letter-spacing: .05em;
    padding: 1rem 1rem .55rem;
}

.sidebar-divider { border-top: 1px solid rgba(255,255,255,.07); margin: .75rem .6rem; }

/* Page nav links */
.sidebar-nav { list-style: none; padding: 0 .6rem; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav li { }
.sidebar-link {
    display: flex; align-items: center; gap: .55rem;
    padding: .42rem .65rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: .85rem;
    transition: background .15s;
}
.sidebar-link i { font-size: .9rem; flex-shrink: 0; }
.sidebar-nav-emoji { font-size: .95rem; flex-shrink: 0; line-height: 1; }
.sidebar-link:hover  { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; }

/* User footer — sticky to the bottom of the scrollable sidebar so the
   Sign Out button is always visible even when the nav overflows the viewport. */
.sidebar-footer {
    margin-top: auto;
    padding: .75rem 1rem;
    border-top: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--sidebar-bg);
    z-index: 1;
}
.user-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--sidebar-active); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.user-info { min-width: 0; }
.user-name  { font-size: .82rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Main content area ──────────────────────────────────────────────── */
.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.module-topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #e8ece8;
    display: flex; align-items: center;
    padding: 0 1.5rem;
    gap: .5rem;
    position: sticky; top: var(--module-bar-h); z-index: 10;
}

/* Breadcrumb inside the topbar */
.topbar-breadcrumb {
    font-size: .85rem;
    flex-wrap: nowrap;
}
.topbar-breadcrumb .breadcrumb-item a {
    color: #666;
    text-decoration: none;
    display: flex; align-items: center; gap: .3rem;
}
.topbar-breadcrumb .breadcrumb-item a:hover { color: var(--accent); }
.topbar-breadcrumb .breadcrumb-item.active {
    font-weight: 600;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before {
    color: #bbb;
}
.topbar-module-icon { font-size: .95rem; }

.content-area { padding: 1.5rem; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card { border: none; border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,.07); }
.card-header { background: #fff; font-weight: 600; font-size: .9rem; border-radius: 12px 12px 0 0 !important; }

/* ── Stat cards ───────────────────────────────────────────────────────── */
.stat-card .card-body { padding: 1rem 1.1rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table thead th { background: #f8faf8; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: #777; }
.table td { vertical-align: middle; font-size: .88rem; }
tr.overdue  td { background: #fff5f5 !important; }
tr.due-today td { background: #fffbf0 !important; }
/* In-window: light azure tint + 4px blue left-border accent.
   The border is the colorblind-safe cue — distinguishes from tr.overdue
   even when red/green tints are ambiguous. Applied to both herd and
   tasks-module lists (tasks pages assign 'window-open' too). */
tr.window-open td { background: #e7f1ff !important; }
tr.window-open td:first-child { border-left: 4px solid #0d6efd !important; }

/* ── Page heading ────────────────────────────────────────────────────── */
.page-heading { font-size: 1.35rem; font-weight: 700; margin-bottom: 1.25rem; color: #222; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-success { background: var(--accent); border-color: var(--accent); }
.btn-success:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* ── Mobile layout ───────────────────────────────────────────────────── */

/* Backdrop for mobile sidebar drawer */
#sidebarBackdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1040;
}

@media (max-width: 767.98px) {

    /* Module bar stacks: row 1 = hamburger + compact brand icon,
       row 2 = scrolling pills. Pills get flex: 0 0 100% so they DEFINITELY
       take a full row of their own — `width: 100%` alone is overridden by
       the inherited `flex-basis: 0%` from the desktop `flex: 1` rule. */
    .module-bar {
        flex-wrap: wrap;
        height: auto;
        padding: .4rem .65rem .5rem;
        gap: .45rem;
        row-gap: .45rem;
    }
    .module-bar-toggle {
        display: inline-flex;
        align-items: center; justify-content: center;
        font-size: 1.6rem;
        padding: .25rem .45rem;
    }
    /* Mobile brand: small logo + wordmark; truncate the wordmark with
       ellipsis if a custom APP_NAME is long, so the hamburger never gets
       squeezed off-screen. */
    .module-bar-brand {
        flex: 1 1 auto;
        min-width: 0;
        padding: .15rem .25rem;
        max-width: none;
        gap: .45rem;
    }
    .module-bar-brand .brand-icon     { font-size: 1.5rem; }
    .module-bar-brand .brand-icon img { max-height: 1.9rem; max-width: 2.6rem; }
    .module-bar-brand .brand-name {
        font-size: .95rem;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .module-bar-pills {
        order: 99;
        flex: 0 0 100%;             /* forces wrap to a new row */
        width: 100%;                /* belt-and-braces */
        gap: .35rem;
        padding-bottom: 2px;        /* breathing room above the scrollbar */
    }
    .module-pill {
        flex-direction: column;
        align-items: center; justify-content: center;
        gap: .15rem;
        min-width: 74px;
        padding: .5rem .55rem;
        font-size: .72rem;
        line-height: 1.1;
        text-align: center;
    }
    .module-pill-icon { font-size: 1.45rem; }
    .module-pill-soon { display: none; }    /* save horizontal room */

    /* Sidebar slides off-screen and becomes a fixed full-height overlay.
       Override the desktop sticky positioning so the drawer covers the
       module bar too (cleaner overlay; sidebar's own header re-anchors). */
    .sidebar {
        position: fixed;
        left: 0; top: 0;
        /* Dynamic viewport height — shrinks with the mobile URL bar so the
           footer (Sign Out button) stays inside the visible area. Falls back
           to 100vh on browsers without dvh support. */
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform .24s ease;
        padding-top: .25rem;
    }
    /* Honour the iOS home-indicator safe area so the button isn't covered. */
    .sidebar-footer {
        padding-bottom: max(.75rem, env(safe-area-inset-bottom));
    }
    .sidebar.is-open    { transform: translateX(0); }
    #sidebarBackdrop.is-open { display: block; }

    /* Prevent body scroll when sidebar drawer is open */
    body.sidebar-open { overflow: hidden; }

    /* Main content takes the full viewport width */
    .main-content { width: 100%; }

    /* Breadcrumb topbar slimmer on mobile, no sticky (module bar takes the
       sticky slot — letting breadcrumb scroll away saves precious height). */
    .module-topbar {
        height: 44px;
        padding: 0 1rem;
        position: static;
        gap: .4rem;
    }
    .topbar-breadcrumb .breadcrumb-item.active { max-width: 180px; }

    /* Tighter content padding on small screens */
    .content-area  { padding: 1rem; }

    /* Page heading slightly smaller on mobile */
    .page-heading  { font-size: 1.15rem; }

    /* Full-width login card on small phones */
    .login-card    { width: calc(100vw - 2rem); max-width: 380px; }
}

@media (min-width: 768px) {
    .module-bar-toggle { display: none !important; }
    #sidebarBackdrop   { display: none !important; }
}

/* Nav pills (filter bars) — wrap cleanly on small screens */
.nav-pills { flex-wrap: wrap; }

/* Page-heading + action-button row — allow wrapping on very small screens */
.page-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1rem;
}

/* ── Sidebar nav groups (type-specific sub-navigation) ──────────────── */

.sidebar-nav-group-header {
    display: flex; align-items: center; gap: .45rem;
    padding: .65rem .65rem .2rem;
    font-size: .67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255,255,255,.38);
    user-select: none;
}
.sidebar-nav-group-header .sidebar-nav-emoji { font-size: .88rem; }
.sidebar-nav-group-header i { font-size: .78rem; }

/* Indented sub-items inside a type group */
.sidebar-subnav {
    list-style: none;
    padding: 0 .6rem 0 1.55rem;
    margin: 0 0 .15rem;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.sidebar-sublink {
    display: flex; align-items: center; gap: .5rem;
    padding: .37rem .6rem;
    border-radius: 7px;
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: .83rem;
    transition: background .15s;
}
.sidebar-sublink i { font-size: .85rem; flex-shrink: 0; }
.sidebar-sublink:hover  { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-sublink.active { background: var(--sidebar-active); color: #fff; }

/* ── Task timeline ───────────────────────────────────────────────────── */
.task-timeline-item {
    border-left: 3px solid #dee2e6;
    padding-left: 1rem; margin-left: .5rem; margin-bottom: 1rem;
    position: relative;
}
.task-timeline-item::before {
    content: ''; width: 12px; height: 12px; border-radius: 50%;
    background: #dee2e6; position: absolute; left: -7.5px; top: 4px;
}
.task-timeline-item.done    { border-color: #4caf50; }
.task-timeline-item.done::before  { background: #4caf50; }
.task-timeline-item.overdue { border-color: #dc3545; }
.task-timeline-item.overdue::before { background: #dc3545; }
.task-timeline-item.today   { border-color: #ffc107; }
.task-timeline-item.today::before { background: #ffc107; }

/* ---- Strict-day / window scheduling ---- */
.badge-strict {
    background: #6f42c1;   /* purple */
    color: #fff;
}
.badge-strict-missed {
    background: #8b1a1a;   /* dark red — distinguishes "missed strict" from regular "overdue" */
    color: #fff;
}
.task-pill.strict {
    background: #6f42c1 !important;
    color: #fff !important;
    border-color: #5936a2 !important;
}
.task-pill.strict.completed {
    background: #6f42c1 !important;
    color: #fff !important;
    opacity: .55;
    text-decoration: line-through;
}
.task-pill.strict.missed {
    background: #8b1a1a !important;
    border-color: #6b0f0f !important;
    color: #fff !important;
}

/* ── Telegram digest preview (Tasks > Settings > Integrations) ─────────────── */
.tg-preview-frame {
    background: #d6dde6;
    border-radius: 10px;
    padding: 12px;
    max-width: 480px;
}
.tg-preview-channel {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #707579;
    font-size: 13px;
    margin-bottom: 8px;
    padding: 0 4px;
}
.tg-preview-channel-meta { color: #95a3b3; }
.tg-preview-bubble {
    background: #ffffff;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: #000;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.tg-preview-bubble b { font-weight: 600; }
.tg-preview-bubble i { font-style: italic; color: #444; }
.tg-preview-meta {
    color: #95a3b3;
    font-size: 11px;
    text-align: right;
    margin-top: 4px;
}

/* ── Impersonation banner (super-admin "sign in as user" mode) ─────────────── */
.impersonation-banner {
    background: #fff3cd;
    border-bottom: 3px solid #f59f00;
    color: #533f03;
    padding: .5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: .9rem;
    flex-wrap: wrap;
}
.impersonation-banner i.bi-incognito {
    color: #856404;
    margin-right: .35rem;
    font-size: 1.05em;
}
.impersonation-banner strong { color: #4a3500; }
.impersonation-banner .badge { margin-left: .3rem; }
.impersonation-banner .btn-warning {
    background: #f59f00;
    border-color: #c57f00;
    color: #fff;
    font-weight: 500;
}
.impersonation-banner .btn-warning:hover {
    background: #c57f00;
    border-color: #a36a00;
    color: #fff;
}

/* ── Shopping List: one card per supplier (Inventory > Shopping List) ──────
   Supplier groups get a solid 5px purple (inventory module colour) left edge;
   the "No supplier" bucket is a dashed, un-accented card so it reads as
   "unsorted" by shape, not colour alone. Theme vars → dark mode for free. */
.supplier-card { border-left: 5px solid #6f42c1; overflow: hidden; }
.supplier-card .supplier-card-header { background: var(--bs-tertiary-bg); }
.supplier-card-none { border: 2px dashed var(--bs-border-color); border-left-width: 2px; }
.supplier-card-none .supplier-card-header { background: transparent; }
/* Bulk action bar stays reachable at the bottom of a long multi-supplier list. */
.shop-actions-bar { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -.25rem .75rem rgba(0,0,0,.08); }

/* ════════════════════ Dark mode ════════════════════════════════════════════
   Bootstrap 5.3 themes its OWN components from data-bs-theme="dark"; this block
   covers the app's custom light surfaces and re-points the FIXED utility classes
   the pages lean on (.bg-light / .bg-white / .text-dark / .table-light /
   .table-danger / .table-warning) — Bootstrap does not theme those automatically.
   The sidebar + module bar are already dark green and intentionally keep their
   colours. Theme is set on <html> by the inline head script (no FOUC); the
   toggle lives in the sidebar footer. Custom values use Bootstrap's theme vars
   (--bs-body-bg, --bs-secondary-bg, --bs-tertiary-bg, --bs-border-color,
   --bs-emphasis-color) so they track the active theme. */
[data-bs-theme="dark"] { color-scheme: dark; }

/* Our own body rule overrides Bootstrap's themed background — re-point it. */
[data-bs-theme="dark"] body { background: var(--bs-body-bg); }

/* Breadcrumb topbar */
[data-bs-theme="dark"] .module-topbar {
    background: var(--bs-secondary-bg);
    border-bottom-color: var(--bs-border-color);
}
[data-bs-theme="dark"] .topbar-breadcrumb .breadcrumb-item a      { color: var(--bs-secondary-color); }
[data-bs-theme="dark"] .topbar-breadcrumb .breadcrumb-item.active { color: var(--bs-emphasis-color); }
[data-bs-theme="dark"] .topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before { color: var(--bs-border-color); }

/* Cards, headers, page heading */
[data-bs-theme="dark"] .card        { box-shadow: 0 1px 6px rgba(0,0,0,.45); }
[data-bs-theme="dark"] .card-header { background: var(--bs-secondary-bg); }
[data-bs-theme="dark"] .page-heading { color: var(--bs-emphasis-color); }

/* Custom table header bg (#f8faf8) */
[data-bs-theme="dark"] .table thead th { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }

/* Fixed Bootstrap utility classes that DON'T auto-theme in 5.3 — remap to vars. */
[data-bs-theme="dark"] .bg-white { background-color: var(--bs-secondary-bg) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--bs-tertiary-bg) !important; }
[data-bs-theme="dark"] .text-dark { color: var(--bs-body-color) !important; }
[data-bs-theme="dark"] .table-light > :not(caption) > * > * {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
}

/* Colour-coded row tints — dark equivalents. The non-colour cues are preserved
   (cell icons; the blue left-border on window-open) so the scheme still works
   for colour-vision deficiency. Deep tints rather than inverted pastels. */
[data-bs-theme="dark"] tr.overdue  td    { background: #3a1f22 !important; }
[data-bs-theme="dark"] tr.due-today td    { background: #3a3520 !important; }
[data-bs-theme="dark"] tr.window-open td  { background: #163052 !important; }
[data-bs-theme="dark"] tr.window-open td:first-child { border-left-color: #4d9bff !important; }

/* Tasks-module lists use Bootstrap contextual row classes (light by default). */
[data-bs-theme="dark"] .table-danger  > td,  [data-bs-theme="dark"] .table-danger  > th { background-color: #3a1f22 !important; color: var(--bs-emphasis-color) !important; }
[data-bs-theme="dark"] .table-warning > td,  [data-bs-theme="dark"] .table-warning > th { background-color: #3a3520 !important; color: var(--bs-emphasis-color) !important; }

/* Leaflet popups/controls ship their own hardcoded-white chrome in leaflet.css,
   which data-bs-theme can't reach — repoint to theme vars so field-map popups
   (and the layer switcher) match dark mode. The tip is the little pointer
   triangle; it must share the wrapper's background to blend. */
[data-bs-theme="dark"] .leaflet-popup-content-wrapper,
[data-bs-theme="dark"] .leaflet-popup-tip {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    box-shadow: 0 3px 14px rgba(0,0,0,.5);
}
[data-bs-theme="dark"] .leaflet-popup-close-button { color: var(--bs-secondary-color) !important; }
[data-bs-theme="dark"] .leaflet-control-layers,
[data-bs-theme="dark"] .leaflet-bar a {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    border-color: var(--bs-border-color);
}

/* Telegram digest preview intentionally keeps Telegram's own light bubble look
   (it's a faithful preview of how the message renders in Telegram). */
