/* ═══════════════════════════════════════════════════
   Cattle Management System — Modern UI 2026
   Full redesign: glassmorphism, modern tables,
   pill navigation, refined typography & spacing
═══════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
    --sidebar-width:       260px;
    --topbar-height:       62px;

    /* Brand */
    --primary:             #6d28d9;
    --primary-dark:        #5b21b6;
    --primary-light:       #8b5cf6;
    --primary-soft:        rgba(109,40,217,0.12);
    --primary-glow:        rgba(109,40,217,0.28);
    --primary-border:      rgba(109,40,217,0.35);

    /* Semantic */
    --success:             #10b981;
    --success-soft:        rgba(16,185,129,0.14);
    --warning:             #f59e0b;
    --warning-soft:        rgba(245,158,11,0.14);
    --danger:              #ef4444;
    --danger-soft:         rgba(239,68,68,0.14);
    --info:                #3b82f6;
    --info-soft:           rgba(59,130,246,0.14);

    /* Surfaces — dark */
    --bg-base:             #0c0e14;
    --bg-card:             #13161f;
    --bg-card2:            #181c28;
    --bg-sidebar:          #0f1118;
    --bg-topbar:           rgba(13,15,20,0.88);
    --surface-0:           #1a1e2c;
    --surface-1:           #1f2435;
    --surface-2:           #252b3f;
    --surface-hover:       rgba(255,255,255,0.04);
    --surface-active:      rgba(109,40,217,0.14);

    /* Text */
    --text-primary:        #f0f2f8;
    --text-secondary:      #9aa3b8;
    --text-muted:          #6b7894;
    --text-placeholder:    #555f78;

    /* Borders */
    --border:              rgba(255,255,255,0.08);
    --border-strong:       rgba(255,255,255,0.14);

    /* Shadows */
    --shadow-sm:           0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.2);
    --shadow:              0 4px 16px rgba(0,0,0,0.45), 0 1px 4px rgba(0,0,0,0.2);
    --shadow-lg:           0 12px 40px rgba(0,0,0,0.55), 0 4px 12px rgba(0,0,0,0.25);
    --shadow-glow:         0 8px 32px rgba(109,40,217,0.22);
    --shadow-color:        rgba(0,0,0,0.4);

    /* Alerts */
    --alert-success-bg:    rgba(16,185,129,0.14);
    --alert-success-text:  #a7f3d0;
    --alert-danger-bg:     rgba(239,68,68,0.14);
    --alert-danger-text:   #fecaca;
    --alert-warning-bg:    rgba(245,158,11,0.14);
    --alert-warning-text:  #fde68a;

    /* Table */
    --table-head-bg:       rgba(109,40,217,0.1);
    --table-head-border:   rgba(109,40,217,0.3);
    --table-row-hover:     rgba(109,40,217,0.06);
    --table-row-border:    rgba(255,255,255,0.055);

    /* Page link */
    --page-link-bg:        rgba(255,255,255,0.04);
    --page-link-border:    rgba(255,255,255,0.08);
    --page-link-disabled:  rgba(255,255,255,0.25);

    /* Misc */
    --radius:              14px;
    --radius-sm:           9px;
    --radius-xs:           6px;
    --transition:          all 0.18s ease;
}

[data-bs-theme="light"] {
    --bg-base:             #f0f2f8;
    --bg-card:             #ffffff;
    --bg-card2:            #f7f9fd;
    --bg-sidebar:          #ffffff;
    --bg-topbar:           rgba(255,255,255,0.9);
    --surface-0:           #f0f3fb;
    --surface-1:           #eaeef8;
    --surface-2:           #e2e8f4;
    --surface-hover:       rgba(15,23,42,0.04);
    --surface-active:      rgba(109,40,217,0.08);

    --text-primary:        #111827;
    --text-secondary:      #374151;
    --text-muted:          #6b7280;
    --text-placeholder:    #9ca3af;

    --border:              rgba(15,23,42,0.1);
    --border-strong:       rgba(15,23,42,0.18);

    --shadow-sm:           0 1px 3px rgba(15,23,42,0.08);
    --shadow:              0 4px 16px rgba(15,23,42,0.1);
    --shadow-lg:           0 12px 40px rgba(15,23,42,0.14);
    --shadow-glow:         0 8px 32px rgba(109,40,217,0.14);
    --shadow-color:        rgba(15,23,42,0.12);

    --alert-success-bg:    rgba(16,185,129,0.1);
    --alert-success-text:  #065f46;
    --alert-danger-bg:     rgba(239,68,68,0.1);
    --alert-danger-text:   #991b1b;
    --alert-warning-bg:    rgba(245,158,11,0.1);
    --alert-warning-text:  #92400e;

    --table-head-bg:       rgba(109,40,217,0.07);
    --table-head-border:   rgba(109,40,217,0.2);
    --table-row-hover:     rgba(109,40,217,0.04);
    --table-row-border:    rgba(15,23,42,0.07);

    --page-link-bg:        #ffffff;
    --page-link-border:    rgba(15,23,42,0.1);
    --page-link-disabled:  rgba(15,23,42,0.3);

    --primary-glow:        rgba(109,40,217,0.18);
    --primary-soft:        rgba(109,40,217,0.08);
    --primary-border:      rgba(109,40,217,0.22);
}

/* ── Backward-compatible aliases (blade templates still reference old names) ── */
:root {
    --border-color:      var(--border);
    --bg-dark:           var(--bg-base);
    --surface-elevated:  var(--surface-0);
    --surface-input:     var(--surface-1);
    --surface-overlay:   var(--bg-card);
    --surface-soft:      var(--surface-hover);
    --surface-strong:    rgba(255,255,255,0.1);
    --nav-progress-height: 2px;
}
[data-bs-theme="light"] {
    --surface-strong: rgba(15,23,42,0.1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', 'Noto Sans Khmer', system-ui, -apple-system, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    font-size: 0.9rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
html[data-bs-theme="dark"], html[data-bs-theme="dark"] body { color-scheme: dark; }
html[data-bs-theme="light"], html[data-bs-theme="light"] body { color-scheme: light; }
body.font-khmer { font-family: 'Noto Sans Khmer', 'Inter', sans-serif; }

.text-muted, .text-body-secondary { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-dark, .text-body { color: var(--text-primary) !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }


/* ═══════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width 0.22s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(20px);
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-badge { display: none; }
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
    margin-inline: 6px;
}
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 8px; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px 16px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    flex-shrink: 0;
}
.brand-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
}
.brand-icon img {
    width: 26px;
    height: 26px;
    display: block;
    object-fit: contain;
}
.brand-name {
    display: block;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.4px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.brand-sub {
    display: block;
    font-size: 0.67rem;
    color: var(--text-muted);
    margin-top: 1px;
    letter-spacing: 0.2px;
}

.sidebar-nav {
    padding: 10px 8px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.nav-section-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 10px 12px 4px;
    opacity: 0.7;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 500;
    margin-bottom: 1px;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    position: relative;
}
.nav-item i {
    font-size: 1rem;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    transition: color 0.15s ease;
}
.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.nav-item:hover i { color: var(--primary-light); }
.nav-item.active {
    background: linear-gradient(135deg, rgba(109,40,217,0.22), rgba(109,40,217,0.1));
    color: var(--text-primary);
    font-weight: 600;
}
.nav-item.active i { color: var(--primary-light); }
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--primary-light);
    border-radius: 0 3px 3px 0;
}
.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    border-radius: 99px;
    padding: 1px 7px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.5;
}


/* ═══════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════ */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-topbar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    z-index: 999;
    transition: left 0.22s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed ~ .main-wrapper .topbar { left: 68px; }

.sidebar-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: var(--radius-xs);
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.05rem;
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.topbar-breadcrumb {
    flex: 1;
    color: var(--text-muted);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.topbar-breadcrumb i { color: var(--primary-light); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.user-menu-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 5px;
    transition: var(--transition);
    line-height: 1;
}
.user-menu-btn:hover {
    background: var(--surface-active);
    border-color: var(--primary-border);
    color: var(--text-primary);
}
.user-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: white;
    flex-shrink: 0;
    letter-spacing: 0;
}
.user-name { font-size: 0.84rem; font-weight: 500; }

/* topbar dropdown trigger buttons */
.topbar-actions .btn-outline-secondary {
    border-color: var(--border);
    color: var(--text-secondary);
    background: transparent;
    border-radius: var(--radius-xs);
    padding: 5px 12px;
    font-size: 0.83rem;
    height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.topbar-actions .btn-outline-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}


/* ═══════════════════════════════════════════
   MAIN WRAPPER
═══════════════════════════════════════════ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.22s cubic-bezier(.4,0,.2,1);
}
.main-wrapper.expanded { margin-left: 68px; }
.page-content { padding: 26px 28px; }


/* ═══════════════════════════════════════════
   PAGE HEADER
═══════════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 26px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.6px;
    color: var(--text-primary);
    line-height: 1.15;
}
.page-title i { color: var(--primary-light); }
.page-subtitle {
    color: var(--text-muted);
    font-size: 0.84rem;
    margin-top: 3px;
}


/* ═══════════════════════════════════════════
   CARDS
═══════════════════════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    background: var(--surface-0);
    border-bottom: 1px solid var(--border);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.card-body {
    background: var(--bg-card);
    padding: 20px;
}
.card-footer {
    background: var(--surface-0);
    border-top: 1px solid var(--border);
    padding: 12px 20px;
}
.card-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text-primary);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title i { color: var(--primary-light); font-size: 1rem; }
.card > .table-responsive { margin: 0; }


/* ═══════════════════════════════════════════
   STAT CARDS
═══════════════════════════════════════════ */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    border-left: 3px solid var(--accent, var(--primary));
}
.stat-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(var(--accent-r,109), var(--accent-g,40), var(--accent-b,217), 0.05) 0%, transparent 55%);
    pointer-events: none;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow), 0 0 0 1px var(--border-strong);
}
.stat-icon {
    width: 50px; height: 50px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.stat-card > div:last-child { min-width: 0; flex: 1 1 auto; }
.stat-value {
    font-size: 1.85rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
}
.stat-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 3px;
}
.stat-change {
    font-size: 0.75rem;
    margin-top: 4px;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 4px;
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    .stat-card { padding: 16px; gap: 12px; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.15rem; }
    .stat-value { font-size: clamp(1.25rem, 1.1rem + 0.65vw, 1.6rem); }
}


/* ═══════════════════════════════════════════
   TABLES — Modern Redesign
═══════════════════════════════════════════ */
.table {
    color: var(--text-primary);
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 0;
    width: 100%;
}

/* Header */
.table thead th {
    background: var(--table-head-bg);
    border-bottom: 1.5px solid var(--table-head-border);
    border-top: none;
    border-right: none;
    border-left: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 13px 18px;
    white-space: nowrap;
    vertical-align: middle;
}
.table thead th:first-child { padding-left: 20px; }
.table thead th:last-child  { padding-right: 20px; }

/* Body cells */
.table tbody td {
    border: none;
    border-bottom: 1px solid var(--table-row-border);
    padding: 13px 18px;
    vertical-align: middle;
    font-size: 0.87rem;
    color: var(--text-primary);
    transition: background 0.12s ease;
}
.table tbody td:first-child { padding-left: 20px; }
.table tbody td:last-child  { padding-right: 20px; }
.table tbody tr:last-child td { border-bottom: none; }

/* Row hover */
.table tbody tr {
    transition: background 0.12s ease;
}
.table tbody tr:hover td {
    background: var(--table-row-hover);
}

/* Wrapper */
.table-responsive {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Strip bottom border from last row inside card */
.card > .table-responsive > .table > tbody > tr:last-child > td,
.card > .table > tbody > tr:last-child > td {
    border-bottom: none;
}


/* ═══════════════════════════════════════════
   BADGES
═══════════════════════════════════════════ */
.badge {
    font-size: 0.71rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 99px;
    border: 1px solid transparent;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge.bg-primary,  .badge.text-bg-primary  { background: rgba(109,40,217,0.18) !important; border-color: rgba(139,92,246,0.3); color: #c4b5fd !important; }
.badge.bg-secondary,.badge.text-bg-secondary{ background: rgba(100,116,139,0.18) !important; border-color: rgba(148,163,184,0.28); color: #cbd5e1 !important; }
.badge.bg-success,  .badge.text-bg-success,
.badge.bg-theme-success                     { background: rgba(16,185,129,0.18) !important; border-color: rgba(16,185,129,0.3); color: #6ee7b7 !important; }
.badge.bg-danger,   .badge.text-bg-danger   { background: rgba(239,68,68,0.18) !important;  border-color: rgba(239,68,68,0.3); color: #fca5a5 !important; }
.badge.bg-warning,  .badge.text-bg-warning  { background: rgba(245,158,11,0.18) !important; border-color: rgba(245,158,11,0.3); color: #fcd34d !important; }
.badge.bg-info,     .badge.text-bg-info     { background: rgba(59,130,246,0.18) !important; border-color: rgba(59,130,246,0.3); color: #93c5fd !important; }
.badge.bg-light,    .badge.text-bg-light    { background: rgba(248,250,252,0.9) !important; border-color: rgba(203,213,225,0.5); color: #0f172a !important; }
.badge.bg-dark,     .badge.text-bg-dark     { background: rgba(15,23,42,0.85) !important;  border-color: rgba(51,65,85,0.5); color: #f8fafc !important; }

/* Light mode badge overrides */
[data-bs-theme="light"] .badge.bg-primary,
[data-bs-theme="light"] .badge.text-bg-primary  { background: rgba(109,40,217,0.1) !important; border-color: rgba(109,40,217,0.2); color: #6d28d9 !important; }
[data-bs-theme="light"] .badge.bg-success,
[data-bs-theme="light"] .badge.text-bg-success,
[data-bs-theme="light"] .badge.bg-theme-success  { background: rgba(16,185,129,0.1) !important; border-color: rgba(16,185,129,0.2); color: #065f46 !important; }
[data-bs-theme="light"] .badge.bg-danger,
[data-bs-theme="light"] .badge.text-bg-danger   { background: rgba(239,68,68,0.1) !important;  border-color: rgba(239,68,68,0.2); color: #991b1b !important; }
[data-bs-theme="light"] .badge.bg-warning,
[data-bs-theme="light"] .badge.text-bg-warning  { background: rgba(245,158,11,0.1) !important; border-color: rgba(245,158,11,0.2); color: #92400e !important; }
[data-bs-theme="light"] .badge.bg-info,
[data-bs-theme="light"] .badge.text-bg-info     { background: rgba(59,130,246,0.1) !important; border-color: rgba(59,130,246,0.2); color: #1d4ed8 !important; }
[data-bs-theme="light"] .badge.bg-secondary,
[data-bs-theme="light"] .badge.text-bg-secondary{ background: rgba(71,85,105,0.1) !important;  border-color: rgba(71,85,105,0.18); color: #334155 !important; }

.badge.bg-primary-subtle,
.badge.bg-secondary-subtle,
.badge.bg-secondary-emphasis,
.badge.text-primary-emphasis,
.badge.text-secondary-emphasis { /* handled above */ }

/* Audit event badges */
.audit-event-badge {
    min-width: 76px;
    justify-content: center;
    padding: 4px 10px;
}
.audit-event-created { background: rgba(16,185,129,0.16); border-color: rgba(16,185,129,0.28); color: #6ee7b7; }
.audit-event-deleted { background: rgba(239,68,68,0.16); border-color: rgba(239,68,68,0.28); color: #fca5a5; }
.audit-event-login   { background: rgba(59,130,246,0.18); border-color: rgba(59,130,246,0.3);  color: #93c5fd; }
.audit-event-logout  { background: rgba(100,116,139,0.18); border-color: rgba(148,163,184,0.28); color: #cbd5e1; }
.audit-event-updated { background: rgba(14,165,233,0.18); border-color: rgba(14,165,233,0.3);  color: #7dd3fc; }
.audit-event-neutral { background: rgba(168,85,247,0.18); border-color: rgba(168,85,247,0.3);  color: #d8b4fe; }

[data-bs-theme="light"] .audit-event-created { background: rgba(16,185,129,0.1);  border-color: rgba(16,185,129,0.18); color: #065f46; }
[data-bs-theme="light"] .audit-event-deleted { background: rgba(239,68,68,0.1);   border-color: rgba(239,68,68,0.18);  color: #991b1b; }
[data-bs-theme="light"] .audit-event-login   { background: rgba(37,99,235,0.1);   border-color: rgba(37,99,235,0.18);  color: #1d4ed8; }
[data-bs-theme="light"] .audit-event-logout  { background: rgba(71,85,105,0.1);   border-color: rgba(71,85,105,0.18);  color: #334155; }
[data-bs-theme="light"] .audit-event-updated { background: rgba(2,132,199,0.1);   border-color: rgba(2,132,199,0.18);  color: #0369a1; }
[data-bs-theme="light"] .audit-event-neutral { background: rgba(147,51,234,0.1);  border-color: rgba(147,51,234,0.18); color: #7e22ce; }


/* ═══════════════════════════════════════════
   FORMS
═══════════════════════════════════════════ */
.form-control, .form-select {
    background: var(--surface-1);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    min-height: 40px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    padding: 8px 13px;
}
.form-control:hover, .form-select:hover {
    border-color: var(--border-strong);
}
.form-control:focus, .form-select:focus {
    background: var(--surface-1);
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    outline: none;
}
.form-control:disabled, .form-control[readonly], .form-select:disabled {
    background: var(--surface-0);
    color: var(--text-muted);
    opacity: 1;
    cursor: not-allowed;
}
[data-bs-theme="dark"] .form-select, [data-bs-theme="dark"] select { color-scheme: dark; }
[data-bs-theme="light"] .form-select, [data-bs-theme="light"] select { color-scheme: light; }
.form-select option, .form-select optgroup { background: var(--bg-card); color: var(--text-primary); }
[data-bs-theme="dark"] .form-select option,
[data-bs-theme="dark"] .form-select optgroup { color-scheme: dark; background: #13161f; color: #f0f2f8; }
[data-bs-theme="light"] .form-select option,
[data-bs-theme="light"] .form-select optgroup { color-scheme: light; background: #ffffff; color: #111827; }

.input-group-text {
    background: var(--surface-0);
    border-color: var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    min-height: 40px;
}
.form-control::placeholder { color: var(--text-placeholder); opacity: 1; }
.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}
.form-text { font-size: 0.78rem; color: var(--text-muted); }

.form-check-input {
    background-color: var(--surface-1);
    border-color: var(--border-strong);
    width: 16px;
    height: 16px;
    cursor: pointer;
}
.form-check-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

.permission-checklist {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px 14px;
    background: var(--surface-1);
}
.permission-checklist-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    color: var(--text-primary);
    font-size: 0.84rem;
    line-height: 1.35;
}
.permission-checklist-item .form-check-input { margin-top: 0.15rem; flex-shrink: 0; }
.permission-checklist-item span { word-break: break-word; }

[data-bs-theme="light"] .form-control,
[data-bs-theme="light"] .form-select {
    background: #ffffff;
    border-color: rgba(15,23,42,0.14);
}
[data-bs-theme="light"] .input-group-text { background: var(--surface-1); border-color: rgba(15,23,42,0.14); }


/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    letter-spacing: 0.01em;
    line-height: 1;
    padding: 8px 16px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border: none;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(109,40,217,0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(109,40,217,0.4);
    color: #ffffff;
    background: linear-gradient(135deg, #9b69fb, #7c3aed);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface-1);
    border: 1px solid var(--border);
    color: var(--text-primary);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-primary); }

/* .btn-warning is repurposed as "edit/blue" in this app */
.btn-warning {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: none;
    color: #eff6ff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}
.btn-warning:hover, .btn-warning:focus, .btn-warning:active {
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(37,99,235,0.35);
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
}
[data-bs-theme="light"] .btn-warning { color: #ffffff; }

.btn-danger {
    background: linear-gradient(135deg, #f87171, #ef4444);
    border: none;
    color: #fff;
    box-shadow: 0 2px 8px rgba(239,68,68,0.25);
}
.btn-danger:hover {
    color: #fff;
    box-shadow: 0 4px 14px rgba(239,68,68,0.35);
    background: linear-gradient(135deg, #fca5a5, #f87171);
}

.btn-success {
    background: linear-gradient(135deg, #34d399, #10b981);
    border: none;
    color: #fff;
}
.btn-success:hover { color: #fff; background: linear-gradient(135deg, #6ee7b7, #34d399); }

/* Outline variants */
.btn-outline-primary {
    background: transparent;
    border: 1px solid rgba(139,92,246,0.35);
    color: #a78bfa;
}
.btn-outline-primary:hover { background: rgba(109,40,217,0.14); border-color: var(--primary); color: #c4b5fd; box-shadow: 0 2px 8px rgba(109,40,217,0.15); }
[data-bs-theme="light"] .btn-outline-primary { background: rgba(109,40,217,0.04); border-color: rgba(109,40,217,0.22); color: #6d28d9; }
[data-bs-theme="light"] .btn-outline-primary:hover { background: rgba(109,40,217,0.1); border-color: rgba(109,40,217,0.3); color: #5b21b6; }

.btn-outline-info {
    background: transparent;
    border: 1px solid rgba(59,130,246,0.35);
    color: #93c5fd;
}
.btn-outline-info:hover { background: rgba(59,130,246,0.14); border-color: rgba(59,130,246,0.55); color: #bfdbfe; }
[data-bs-theme="light"] .btn-outline-info { background: rgba(59,130,246,0.04); border-color: rgba(59,130,246,0.22); color: #1d4ed8; }
[data-bs-theme="light"] .btn-outline-info:hover { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.3); color: #1e40af; }

.btn-outline-warning {
    background: transparent;
    border: 1px solid rgba(59,130,246,0.4);
    color: #93c5fd;
}
.btn-outline-warning:hover { background: rgba(59,130,246,0.14); border-color: rgba(59,130,246,0.55); color: #bfdbfe; }
[data-bs-theme="light"] .btn-outline-warning { background: rgba(37,99,235,0.04); border-color: rgba(37,99,235,0.22); color: #1d4ed8; }
[data-bs-theme="light"] .btn-outline-warning:hover { background: rgba(37,99,235,0.1); border-color: rgba(37,99,235,0.3); color: #1e40af; }

.btn-outline-danger {
    background: transparent;
    border: 1px solid rgba(239,68,68,0.35);
    color: #fca5a5;
}
.btn-outline-danger:hover { background: rgba(239,68,68,0.14); border-color: rgba(239,68,68,0.55); color: #fecaca; }
[data-bs-theme="light"] .btn-outline-danger { background: rgba(239,68,68,0.04); border-color: rgba(239,68,68,0.22); color: #dc2626; }
[data-bs-theme="light"] .btn-outline-danger:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: #b91c1c; }

.btn-outline-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-outline-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--text-primary); }

/* Size adjustments */
.btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-xs);
    min-height: 34px;
}
/* Inline filter button — exact height match with form-select-sm */
.filter-btn-inline {
    height: 34px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
    white-space: nowrap;
}
.btn-sm.btn-outline-primary,
.btn-sm.btn-outline-info,
.btn-sm.btn-outline-warning,
.btn-sm.btn-outline-danger { min-width: 2.1rem; }

/* Table action button group */
.table td.text-center .btn.btn-sm,
.table td.text-center a.btn.btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}
.table td.text-center .btn.btn-sm + .btn.btn-sm,
.table td.text-center a.btn.btn-sm + .btn.btn-sm { margin-left: 4px; }
.record-action-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}

.btn-close { filter: none; }
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(180%); }


/* ═══════════════════════════════════════════
   DROPDOWN MENUS
═══════════════════════════════════════════ */
.dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    padding: 4px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    min-width: 160px;
}
.dropdown-item {
    color: var(--text-primary);
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    padding: 7px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.12s ease, color 0.12s ease;
}
.dropdown-item i { width: 16px; text-align: center; color: var(--text-muted); flex-shrink: 0; }
.dropdown-item:hover, .dropdown-item:focus, .dropdown-item.active, .dropdown-item:active {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.dropdown-item:hover i, .dropdown-item:focus i { color: var(--primary-light); }
.dropdown-divider { border-color: var(--border); margin: 4px; }
.dropdown-header { color: var(--text-muted); font-size: 0.75rem; padding: 6px 12px 4px; }


/* ═══════════════════════════════════════════
   NOTIFICATION DROPDOWN
═══════════════════════════════════════════ */
.notification-dropdown {
    width: min(340px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    max-height: 480px;
    overflow-y: auto;
}
.notification-item.unread { background: rgba(109,40,217,0.06); }
[data-bs-theme="light"] .notification-item.unread { background: rgba(109,40,217,0.07); }


/* ═══════════════════════════════════════════
   ALERTS / FLASH
═══════════════════════════════════════════ */
.alert {
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.87rem;
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert i { flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--alert-success-bg); color: var(--alert-success-text); border-color: rgba(16,185,129,0.25); }
.alert-danger   { background: var(--alert-danger-bg);  color: var(--alert-danger-text);  border-color: rgba(239,68,68,0.25); }
.alert-warning  { background: var(--alert-warning-bg); color: var(--alert-warning-text); border-color: rgba(245,158,11,0.25); }

.flash-stack {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    width: min(420px, calc(100vw - 32px));
    display: grid;
    gap: 8px;
    pointer-events: none;
}
.alert-flash {
    position: relative;
    margin: 0;
    width: 100%;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: slideDown 0.25s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* ═══════════════════════════════════════════
   FILTER BAR
═══════════════════════════════════════════ */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
}
.filter-bar form { align-items: center !important; }
.filter-bar .col-auto .btn,
.filter-bar .col-auto a.btn {
    height: 40px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
    white-space: nowrap;
}


/* ═══════════════════════════════════════════
   PAGINATION
═══════════════════════════════════════════ */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0;
    margin: 0;
    list-style: none;
}
.page-link {
    min-width: 38px;
    height: 38px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--page-link-bg);
    border: 1px solid var(--page-link-border);
    color: var(--text-secondary);
    border-radius: 99px !important;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s ease;
}
.page-link:hover {
    transform: translateY(-1px);
    background: rgba(109,40,217,0.14);
    color: var(--text-primary);
    border-color: rgba(109,40,217,0.4);
}
.page-item.active .page-link {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border-color: var(--primary);
    color: white;
    box-shadow: 0 4px 14px rgba(109,40,217,0.3);
    transform: translateY(-1px);
}
.page-item.disabled .page-link {
    background: transparent;
    color: var(--page-link-disabled);
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
}
.cattle-pagination-wrap .page-link { min-width: 34px; height: 34px; padding: 0 10px; font-size: 0.78rem; }


/* ═══════════════════════════════════════════
   AUTH PAGES
═══════════════════════════════════════════ */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 65% 35%, rgba(109,40,217,0.15) 0%, transparent 60%),
                radial-gradient(ellipse at 20% 80%, rgba(59,130,246,0.08) 0%, transparent 50%),
                var(--bg-base);
    padding: 24px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 44px 38px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 30px; }
.auth-logo .brand-icon { display: inline-flex; width: 64px; height: 64px; border-radius: 16px; }
.auth-logo .brand-icon img { width: 42px; height: 42px; }
.auth-logo .brand-name { font-size: 1.5rem; font-weight: 800; background: linear-gradient(135deg, var(--primary-light), var(--primary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.auth-logo .brand-sub { color: var(--text-muted); font-size: 0.84rem; }
[data-bs-theme="light"] .brand-icon { background: rgba(109,40,217,0.1); border-color: rgba(109,40,217,0.2); }


/* ═══════════════════════════════════════════
   MODALS & OFFCANVAS
═══════════════════════════════════════════ */
.modal-content, .offcanvas, .list-group-item, .popover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border);
}
.modal-header, .modal-footer, .offcanvas-header, .offcanvas-footer,
.list-group-item + .list-group-item { border-color: var(--border); }
.offcanvas-backdrop.show, .modal-backdrop.show { opacity: 0.55; }

.modal-content {
    border: 1px solid var(--border-strong);
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius);
}
.modal-header { padding: 18px 22px; background: var(--surface-0); }
.modal-body   { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; background: var(--surface-0); }
.modal-title  { font-weight: 700; font-size: 1rem; color: var(--text-primary); }


/* ═══════════════════════════════════════════
   EDITOR COMPONENTS (slide panels, forms)
═══════════════════════════════════════════ */
.editor-shell { max-width: 1100px; margin-inline: auto; }

.editor-card {
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}
.editor-card .card-body { padding: 22px; }

.editor-form { display: flex; flex-direction: column; gap: 16px; }

.editor-section {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-0);
}
.editor-section-heading { margin-bottom: 14px; }
.editor-section-title { margin: 0; font-size: 0.9rem; font-weight: 700; color: var(--text-primary); }
.editor-section-subtitle { margin: 2px 0 0; font-size: 0.77rem; color: var(--text-muted); }
.editor-section .form-label { margin-bottom: 6px; }

.editor-actions {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    padding-top: 4px;
}

/* Editor modal */
.editor-modal .modal-dialog { max-width: min(720px, 94vw); }
.editor-modal .modal-body { padding: 18px 22px; }
.editor-modal .modal-footer.editor-actions { padding: 14px 22px; }

/* Slide panel */
.editor-slide-panel { --bs-modal-width: min(560px, 94vw); }
.editor-slide-panel .modal-dialog {
    margin: 0 0 0 auto;
    width: min(560px, 94vw);
    max-width: min(560px, 94vw);
    min-height: 100%;
    height: 100%;
}
.editor-slide-panel .modal-content,
.editor-slide-panel form.modal-content {
    min-height: 100%;
    height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}
.editor-slide-panel .modal-header { align-items: flex-start; }
.editor-slide-panel .modal-body {
    flex: 1 1 auto;
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.editor-slide-panel .modal-body > * {
    margin-bottom: 0 !important;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-0);
}
.editor-slide-panel .modal-body > .row { --bs-gutter-y: 14px; }
.editor-slide-panel .modal-footer { margin-top: auto; }

/* Modals: primary action first */
.modal:not(#globalDeleteConfirmModal) .modal-footer { justify-content: flex-start; }
.modal:not(#globalDeleteConfirmModal) .modal-footer > button[type="submit"] { order: 1; }
.modal:not(#globalDeleteConfirmModal) .modal-footer > [data-bs-dismiss="modal"] { order: 2; }
.offcanvas-form-actions > button[type="submit"] { order: 1; }
.offcanvas-form-actions > [data-bs-dismiss] { order: 2; }

/* Sale edit panel */
.sale-edit-panel { --bs-offcanvas-width: min(560px, 94vw); }
.sale-edit-panel .offcanvas-header { align-items: flex-start; }
.sale-edit-panel .offcanvas-body { padding-top: 14px; }
.sale-edit-panel .sale-edit-form { gap: 0; }
.sale-edit-panel .sale-edit-section {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-0);
}
.sale-edit-panel .sale-edit-section-heading { margin-bottom: 12px; }
.sale-edit-panel .sale-edit-section-title { margin: 0; font-size: 0.9rem; font-weight: 700; color: var(--text-primary); }
.sale-edit-panel .sale-edit-section .form-label { margin-bottom: 6px; }
.sale-edit-panel .offcanvas-form-actions { display: flex; justify-content: flex-start; gap: 8px; background: transparent; }

/* Expense-style form */
.expense-style-form .form-control,
.expense-style-form .form-select,
.expense-style-form textarea { background: transparent !important; }
.expense-style-form .form-control:focus,
.expense-style-form .form-select:focus,
.expense-style-form textarea:focus { background: transparent !important; }
.expense-style-form .editor-section,
.expense-style-form .card,
.expense-style-form .modal-body > .mb-3,
.expense-style-form .modal-body > .row,
.expense-style-form .modal-body > .form-check,
.expense-style-form .offcanvas-body > .mb-3,
.expense-style-form .offcanvas-body > .row,
.expense-style-form .offcanvas-body > .form-check {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm);
    padding: 14px;
    background: transparent !important;
    box-shadow: none !important;
    margin-bottom: 14px;
}
.expense-style-form .card-body { background: transparent !important; box-shadow: none !important; padding: 0 !important; }
.expense-style-form .editor-section-heading { display: none; }
.expense-style-form .modal-body > .mb-3:last-child,
.expense-style-form .modal-body > .row:last-child,
.expense-style-form .offcanvas-body > .mb-3:last-child,
.expense-style-form .offcanvas-body > .row:last-child,
.expense-style-form .editor-section:last-child,
.expense-style-form .card:last-child { margin-bottom: 0; }


/* ═══════════════════════════════════════════
   CATTLE DETAIL TABS
═══════════════════════════════════════════ */
.cattle-detail-tab-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    /* No overflow:hidden — it clips the margin-bottom:-1px tab connection */
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
}

/* Header strip — rounded top corners manually since overflow:hidden is removed */
.cattle-detail-tab-card > .card-header {
    padding: 0;
    background: var(--surface-0);
    border-bottom: 1px solid var(--border);
    border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}

/* Tab list */
.cattle-detail-tabs {
    gap: 0;
    padding: 10px 12px 0;
    flex-wrap: wrap;
    background: transparent;
    margin-bottom: 0;
    border-bottom: none;
}
.cattle-detail-tabs .nav-item,
.cattle-detail-tabs .nav-item:hover {
    background: transparent !important;
    padding: 0;
    margin-bottom: 0;
    border-radius: 0;
    color: inherit;
    gap: 0;
}

/* Individual tab links */
.cattle-detail-tabs .nav-link {
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-xs) var(--radius-xs) 0 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 9px 15px 10px;
    margin-bottom: -1px;        /* overlap the header border-bottom → zero gap */
    white-space: nowrap;
    transition: color 0.15s ease;
}
/* No hover effect at all */
.cattle-detail-tabs .nav-link:hover,
.nav-tabs.cattle-detail-tabs .nav-link:hover {
    background: transparent !important;
    border-color: transparent;
    color: var(--text-secondary);
}

/* Active tab: bg = card body color, bottom border erased → truly attached */
.cattle-detail-tabs .nav-link.active {
    color: var(--primary-light);
    font-weight: 700;
    background: var(--bg-card);
    border-color: var(--border) var(--border) var(--bg-card);
}
/* Protect active tab connection when hovered */
.cattle-detail-tabs .nav-link.active:hover,
.nav-tabs.cattle-detail-tabs .nav-link.active:hover {
    background: var(--bg-card) !important;
    border-color: var(--border) var(--border) var(--bg-card) !important;
    color: var(--primary-light);
}
[data-bs-theme="light"] .cattle-detail-tabs .nav-link.active {
    color: var(--primary);
    background: #ffffff;
    border-color: var(--border) var(--border) #ffffff;
}
[data-bs-theme="light"] .cattle-detail-tabs .nav-link.active:hover,
[data-bs-theme="light"] .nav-tabs.cattle-detail-tabs .nav-link.active:hover {
    background: #ffffff !important;
    border-color: var(--border) var(--border) #ffffff !important;
    color: var(--primary);
}

/* Content area */
.cattle-detail-tab-card > .tab-content { border-top: none; }
.cattle-detail-tab-card .tab-pane { min-height: 240px; }
.cattle-detail-tab-card .card-body { padding: 20px 22px; }
.cattle-detail-tab-card .border-bottom { border-color: var(--border) !important; }

/* Record items inside tabs */
.cattle-tab-record {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}
.cattle-tab-record:last-child { border-bottom: none; padding-bottom: 0; }
.cattle-tab-record-icon {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--surface-1);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 0.88rem;
    color: var(--text-secondary);
}
.cattle-tab-record-body { flex: 1; min-width: 0; }
.cattle-tab-record-date {
    font-size: 0.73rem;
    color: var(--text-muted);
    margin-bottom: 2px;
    display: block;
}
.cattle-tab-record-title {
    font-size: 0.87rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.35;
}
.cattle-tab-record-sub {
    font-size: 0.77rem;
    color: var(--text-secondary);
    margin-top: 3px;
}
.cattle-tab-record-amount {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--success);
    flex-shrink: 0;
    align-self: center;
}

/* Section heading within a tab */
.cattle-tab-section {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
}
.cattle-tab-section:first-child { margin-top: 0; }

/* Empty state */
.cattle-tab-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    color: var(--text-muted);
    gap: 8px;
    text-align: center;
}
.cattle-tab-empty i { font-size: 2rem; opacity: 0.35; }
.cattle-tab-empty p { margin: 0; font-size: 0.84rem; }

@media (max-width: 767.98px) {
    .cattle-detail-tabs { padding: 8px 8px 0; }
    .cattle-detail-tabs .nav-link { padding: 8px 10px 9px; font-size: 0.78rem; }
    .cattle-detail-tab-card .card-body { padding: 14px 16px; }
}


/* ═══════════════════════════════════════════
   HEALTH RECORD SPECIFICS
═══════════════════════════════════════════ */
.health-record-row { cursor: pointer; }
.health-record-row:focus-visible { outline: 2px solid var(--primary-light); outline-offset: -2px; }
.health-detail-item { display: flex; flex-direction: column; gap: 4px; }
.health-detail-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.health-detail-value { color: var(--text-primary); line-height: 1.5; overflow-wrap: anywhere; }


/* ═══════════════════════════════════════════
   AUDIT LOG
═══════════════════════════════════════════ */
.audit-log-page .page-header { align-items: flex-end; }
.audit-log-toolbar {
    padding: 14px 18px;
    background: var(--surface-0);
    border-bottom: 1px solid var(--border);
}
.audit-log-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.audit-log-filters .form-control,
.audit-log-filters .form-select { min-height: 42px; }
.audit-log-filter-search { flex: 1 1 180px; min-width: 160px; }
.audit-log-filter-select { flex: 0 0 auto; min-width: 150px; }
.audit-log-filter-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.audit-log-filter-actions .btn {
    height: 42px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
    padding-inline: 16px;
    white-space: nowrap;
}
[data-bs-theme="light"] .audit-log-toolbar { background: var(--surface-1); }


/* ═══════════════════════════════════════════
   SALE TREND FILTER
═══════════════════════════════════════════ */
.sale-trend-filter-form {
    width: 100%;
    align-items: center !important;   /* override Bootstrap align-items-end/stretch */
}
.sale-trend-filter-field { min-width: 110px; }
.sale-trend-filter-actions { display: flex; align-items: center; gap: 6px; }
.sale-trend-filter-actions .btn {
    white-space: nowrap;
    height: 34px;                     /* exact match with form-select-sm */
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-top: 0;
    padding-bottom: 0;
}
@media (min-width: 576px) {
    .sale-trend-filter-form { width: auto; }
}
@media (max-width: 575.98px) {
    /* Keep sale-trend filter in one row on small screens */
    .sale-trend-filter-form { flex-direction: row !important; flex-wrap: nowrap; align-items: center !important; }
    .sale-trend-filter-field { min-width: 0; flex: 1 1 70px; }
    .sale-trend-filter-actions { width: auto; flex-direction: row; }
    .sale-trend-filter-actions .btn { width: auto; height: 34px; padding-inline: 9px; font-size: 0.78rem; }
    /* Hide button icons to save space — text alone is enough */
    .sale-trend-filter-actions .btn i { display: none; }
}


/* ═══════════════════════════════════════════
   NAV PROGRESS BAR
═══════════════════════════════════════════ */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 2px;
    background: linear-gradient(90deg, var(--primary-light), var(--primary));
    transform: scaleX(0);
    transform-origin: left center;
    opacity: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
    z-index: 3000;
    pointer-events: none;
}


/* ═══════════════════════════════════════════
   SIDEBAR OVERLAY (mobile)
═══════════════════════════════════════════ */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}
.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
body.sidebar-mobile-open { overflow: hidden; }


/* ═══════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION
═══════════════════════════════════════════ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 998;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    align-items: stretch;
    justify-content: space-around;
}
.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    padding: 6px 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item i {
    font-size: 1.2rem;
    transition: transform 0.15s ease, color 0.15s ease;
}
.mobile-nav-item:hover,
.mobile-nav-item:active { color: var(--primary-light); }
.mobile-nav-item:active i { transform: scale(0.9); }
.mobile-nav-item.active {
    color: var(--primary-light);
}
.mobile-nav-item.active i {
    filter: drop-shadow(0 0 6px rgba(139,92,246,0.5));
}
[data-bs-theme="light"] .mobile-nav-item.active { color: var(--primary); }


/* ═══════════════════════════════════════════
   RESPONSIVE — Tablet (768px – 1199px)
═══════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .page-content { padding: 20px 22px; }
    .page-title { font-size: 1.4rem; }
    .card-body { padding: 16px; }
}

/* Sidebar starts icon-only on tablets when not expanded by user */
@media (min-width: 768px) and (max-width: 991.98px) {
    body:not(.sidebar-expanded) .sidebar { width: 68px; }
    body:not(.sidebar-expanded) .sidebar .brand-text,
    body:not(.sidebar-expanded) .sidebar .nav-item span,
    body:not(.sidebar-expanded) .sidebar .nav-section-label,
    body:not(.sidebar-expanded) .sidebar .nav-badge { display: none; }
    body:not(.sidebar-expanded) .sidebar .nav-item { justify-content: center; padding: 10px 0; margin-inline: 6px; }
    body:not(.sidebar-expanded) .sidebar .sidebar-brand { justify-content: center; padding: 16px 8px; }
    body:not(.sidebar-expanded) .main-wrapper { margin-left: 68px; }
    body:not(.sidebar-expanded) .topbar { left: 68px; }
    /* When user expands it */
    body.sidebar-expanded .main-wrapper { margin-left: var(--sidebar-width); }
    body.sidebar-expanded .topbar { left: var(--sidebar-width); }
}


/* ═══════════════════════════════════════════
   RESPONSIVE — Mobile (< 768px)
═══════════════════════════════════════════ */
@media (max-width: 767.98px) {
    /* ── Sidebar: fully off-canvas, slides over everything ── */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.26s cubic-bezier(.4,0,.2,1);
        width: min(var(--sidebar-width), 85vw);
        z-index: 1050;   /* above topbar (999) and overlay (1040) */
    }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }

    /* Undo any collapsed-state overrides on mobile — sidebar always shows full menu when open */
    .sidebar.collapsed { width: min(var(--sidebar-width), 85vw); }
    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .nav-item span,
    .sidebar.collapsed .nav-section-label,
    .sidebar.collapsed .nav-badge { display: revert; }
    .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 9px 12px; margin-inline: 0; }
    .sidebar.collapsed .sidebar-brand { justify-content: flex-start; padding: 18px 16px 16px; }

    /* ── Overlay: sits between topbar and sidebar ── */
    .sidebar-overlay { z-index: 1040; }

    /* ── Main wrapper: no left margin, keep top margin for fixed topbar ── */
    .main-wrapper {
        margin-left: 0 !important;
        /* margin-top kept as var(--topbar-height) — topbar remains position:fixed */
    }

    /* ── Topbar: keep fixed, just span full width ── */
    .topbar {
        left: 0 !important;
        padding: 0 14px;
        gap: 6px;
    }
    .topbar-breadcrumb { display: none; }
    .topbar-actions {
        margin-left: auto;
        gap: 4px;
        flex-shrink: 0;
    }
    .topbar-actions .dropdown-menu {
        position: fixed !important;
        inset: auto 12px auto 12px !important;
        transform: none !important;
        width: calc(100vw - 24px) !important;
        max-width: none !important;
    }
    .notification-dropdown { width: calc(100vw - 24px); max-width: calc(100vw - 24px); }
    .topbar-actions .btn-outline-secondary { padding: 5px 9px; }
    .topbar-actions .dropdown-toggle::after { display: none; }

    /* Page content: padding + bottom nav spacing */
    .page-content {
        padding: 14px 14px 80px;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 16px;
    }
    .page-title { font-size: 1.25rem; }
    .page-header > a.btn,
    .page-header > button.btn,
    .page-header > div > a.btn,
    .page-header > div > button.btn { align-self: flex-start; }

    /* Cards: tighter */
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }
    .card-footer { padding: 10px 14px; }

    /* Stat cards: 2-col */
    .stat-card { padding: 14px; gap: 10px; }
    .stat-icon { width: 40px; height: 40px; font-size: 1rem; }
    .stat-value { font-size: 1.5rem; }

    /* Auth */
    .auth-card { padding: 28px 18px; }

    /* Alerts */
    .flash-stack {
        top: calc(var(--topbar-height) + 8px);
        left: 12px; right: 12px;
        width: auto;
        transform: none;
    }

    /* Editor components */
    .editor-card .card-body { padding: 14px; }
    .editor-section { padding: 12px; }

    /* Audit log */
    .audit-log-page .page-header { align-items: stretch; }
    .audit-log-filter-search { flex: 1 1 100%; }
    .audit-log-filter-select { min-width: 130px; }
    .audit-log-filter-actions { width: 100%; }
    .audit-log-filter-actions .btn { flex: 1 1 0; }
    .audit-log-toolbar { padding-inline: 12px; }

    /* Show mobile bottom nav */
    .mobile-bottom-nav { display: flex; }

    /* Table: smaller cell padding on mobile */
    .table thead th { padding: 10px 12px; font-size: 0.65rem; }
    .table tbody td { padding: 10px 12px; font-size: 0.84rem; }
    .table thead th:first-child, .table tbody td:first-child { padding-left: 14px; }
    .table thead th:last-child,  .table tbody td:last-child  { padding-right: 14px; }
}


/* ═══════════════════════════════════════════
   RESPONSIVE — Small mobile (< 576px)
═══════════════════════════════════════════ */
@media (max-width: 575.98px) {
    :root { --sidebar-width: 280px; }

    .topbar-actions .btn-outline-secondary,
    .topbar-actions .user-menu-btn { padding-inline: 7px; }
    .notification-dropdown { max-height: min(65vh, 400px); }

    /* Full-width slide panels */
    .editor-slide-panel .modal-dialog { width: 100vw; max-width: 100vw; }
    .sale-edit-panel { --bs-offcanvas-width: 100vw; }
    .sale-edit-panel .sale-edit-section { padding: 12px; }

    /* Stat cards: stack to single column on very small */
    .row.g-3 > [class*="col-md-3"],
    .row.g-3 > [class*="col-md-4"] { flex: 0 0 100%; max-width: 100%; }

    /* Page content */
    .page-content { padding: 12px 12px 80px; }

    /* Bottom nav safe area */
    .mobile-bottom-nav { height: calc(60px + env(safe-area-inset-bottom, 0px)); }
}

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


/* ═══════════════════════════════════════════
   MOBILE CARD TABLE
   Tables convert to stacked key-value cards
   on screens narrower than 768 px.
   Add class="mob-card-table" to the .card
   wrapping .table-responsive.
═══════════════════════════════════════════ */
@media (max-width: 767.98px) {
    /* No horizontal scroll */
    .mob-card-table .table-responsive { overflow-x: hidden; }
    .mob-card-table .table { min-width: 0; }

    /* Hide column headers */
    .mob-card-table .table thead { display: none; }

    /* Each non-empty row becomes a card */
    .mob-card-table .table tbody tr:not(:has(td[colspan])) {
        display: block;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin-bottom: 10px;
        background: var(--bg-card);
        overflow: hidden;
    }
    .mob-card-table .table tbody tr:not(:has(td[colspan])):hover td {
        background: transparent;
    }

    /* Each data cell becomes a labelled row */
    .mob-card-table .table tbody td:not([colspan]) {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        padding: 9px 14px !important;
        border-bottom: 1px solid var(--table-row-border) !important;
        border-left: none;
        border-right: none;
        font-size: 0.855rem;
        white-space: normal !important;
        min-height: 0;
    }
    .mob-card-table .table tbody td:not([colspan]):last-child {
        border-bottom: none !important;
    }

    /* Label injected via JS: ::before shows attr(data-label) */
    .mob-card-table .table tbody td:not([colspan])::before {
        content: attr(data-label);
        font-size: 0.67rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--text-muted);
        flex-shrink: 0;
        min-width: 82px;
        max-width: 82px;
        padding-top: 3px;
        line-height: 1.4;
    }

    /* Actions cell (JS sets data-label=""): hide label, right-align */
    .mob-card-table .table tbody td[data-label=""] {
        justify-content: flex-end;
        border-top: 2px solid var(--border);
    }
    .mob-card-table .table tbody td[data-label=""]::before { display: none; }

    /* Filter bar: give submit button group full width */
    .filter-bar .col-auto { flex: 1 1 100%; }

    /* Page header button group: left-align buttons on mobile */
    .page-header .d-flex.gap-2.flex-wrap { justify-content: flex-start; }
}

/* ═══════════════════════════════════════════
   UTILITY EXTRAS
═══════════════════════════════════════════ */
.fw-semibold { font-weight: 600 !important; }

/* Subtle "glass" card variant */
.card-glass {
    background: color-mix(in srgb, var(--bg-card) 85%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; display: block; color: var(--primary-light); opacity: 0.5; }
.empty-state p { font-size: 0.88rem; margin: 0; }

/* Divider with label */
.divider-label {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.divider-label::before, .divider-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}


/* ═══════════════════════════════════════════
   NAV TABS (settings page etc.)
═══════════════════════════════════════════ */
.nav-tabs {
    border-bottom: 1px solid var(--border);
    gap: 2px;
    flex-wrap: wrap;
    margin-bottom: 0;
}
.nav-tabs .nav-link {
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-xs) var(--radius-xs) 0 0;
    color: var(--text-muted);
    font-size: 0.84rem;
    font-weight: 600;
    padding: 9px 18px;
    transition: color 0.15s ease, background 0.15s ease;
    background: transparent;
}
.nav-tabs .nav-link:hover {
    color: var(--text-primary);
    background: transparent;
    border-color: transparent;
}
.nav-tabs .nav-link.active {
    color: var(--primary-light);
    background: var(--bg-card);
    border-color: var(--border) var(--border) var(--bg-card);
    font-weight: 700;
}
[data-bs-theme="light"] .nav-tabs .nav-link.active {
    color: var(--primary);
    background: #ffffff;
    border-color: var(--border) var(--border) #ffffff;
}
.tab-content > .tab-pane { padding: 20px 0; }
.card-header-none { border-top-left-radius: 0 !important; }

/* ═══════════════════════════════════════════
   INVENTORY — fix take() crash hint (safe iteration)
   No CSS change needed, handled in blade.
═══════════════════════════════════════════ */

/* ═══════════════════════════════════════════
   MISC POLISH
═══════════════════════════════════════════ */
/* Make offcanvas/modal use new border variable */
.offcanvas { border-color: var(--border) !important; }

/* Spinner */
.spinner-border { color: var(--primary-light); }

/* Code tags in tables */
td code, th code {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.8em;
    color: var(--primary-light);
}
[data-bs-theme="light"] td code, [data-bs-theme="light"] th code { color: var(--primary); }

/* Better dl rows */
dl.row dt { color: var(--text-muted); font-size: 0.82rem; font-weight: 600; }
dl.row dd { color: var(--text-primary); font-size: 0.87rem; }

/* Inline form compact */
.form-select-sm, .form-control-sm { min-height: 34px !important; font-size: 0.82rem; }

/* ── Custom Select Enhancement ── */
.cselect-wrap {
    position: relative;
}

.cselect-trigger {
    width: 100%;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    text-align: left;
    user-select: none;
    background-image: none !important;
}

.cselect-trigger:disabled {
    pointer-events: none;
    opacity: 0.65;
}

.cselect-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cselect-arrow {
    flex-shrink: 0;
    margin-left: 0.5rem;
    opacity: 0.55;
    transition: transform 0.15s ease;
    line-height: 1;
}

.cselect-trigger[aria-expanded="true"] .cselect-arrow {
    transform: rotate(180deg);
}

.cselect-dropdown {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 0;
    right: 0;
    z-index: 1085;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-elevated);
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.cselect-options {
    max-height: 240px;
    overflow-y: auto;
    padding: 0.35rem;
}

.cselect-option {
    display: block;
    width: 100%;
    border: 0;
    border-radius: calc(var(--radius-sm) - 2px);
    background: transparent;
    color: inherit;
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.9375rem;
    cursor: pointer;
}

.cselect-option:hover,
.cselect-option:focus {
    background: rgba(148, 163, 184, 0.16);
    outline: none;
}

.cselect-option[data-selected="true"] {
    background: var(--primary-soft, rgba(109,40,217,0.12));
    color: var(--primary, #6d28d9);
    font-weight: 500;
}

.cselect-wrap:has(select.is-invalid) .cselect-trigger {
    border-color: var(--danger, #ef4444);
}
