/* ============================================================
   FarmSure Trace — Main Application CSS
   ============================================================ */

:root {
    --fs-primary: #c76b2d;
    --fs-primary-dark: #9d4d17;
    --fs-primary-light: #f2c66d;
    --fs-accent: #23463d;
    --fs-accent-soft: #6f8f49;
    --fs-bg: #f6efe3;
    --fs-surface: rgba(255, 251, 244, 0.9);
    --fs-surface-strong: #fffaf0;
    --fs-border: rgba(22, 33, 29, 0.1);
    --fs-text: #16211d;
    --fs-muted: #5f695f;
    --fs-sidebar-width: 260px;
    --fs-sidebar-collapsed: 70px;
    --fs-topbar-height: 68px;
    --fs-shadow: 0 18px 45px rgba(32, 29, 20, 0.12);
    --fs-shadow-soft: 0 8px 22px rgba(32, 29, 20, 0.08);
}

* { box-sizing: border-box; }

body.app-body {
    font-family: 'Manrope', system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(242, 198, 109, 0.28), transparent 24%),
        radial-gradient(circle at top right, rgba(111, 143, 73, 0.12), transparent 28%),
        linear-gradient(180deg, #f8f2e8 0%, #f4ebdf 48%, #f6f1e8 100%);
    margin: 0;
    color: var(--fs-text);
}

h1, h2, h3, h4, h5, h6,
.page-header h1,
.sidebar-brand,
.user-name {
    font-family: 'Space Grotesk', sans-serif;
}

a {
    color: var(--fs-primary-dark);
}

a:hover {
    color: var(--fs-primary);
}

/* ─── Sidebar ──────────────────────────────────────────── */

.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--fs-sidebar-width);
    background:
        linear-gradient(180deg, rgba(35, 70, 61, 0.98) 0%, rgba(22, 33, 29, 0.98) 100%);
    color: #f7efe3;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease;
    overflow-x: hidden;
    box-shadow: 20px 0 40px rgba(20, 24, 21, 0.12);
}

.app-sidebar.collapsed {
    width: var(--fs-sidebar-collapsed);
}

.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .nav-section-title,
.app-sidebar.collapsed .nav-link span,
.app-sidebar.collapsed .sidebar-footer span {
    display: none;
}

.app-sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0.75rem;
}

.app-sidebar.collapsed .nav-link i {
    margin-right: 0;
    font-size: 1.2rem;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: var(--fs-topbar-height);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: #fff8ef;
    font-size: 1.15rem;
    font-weight: 700;
}

.sidebar-brand i {
    width: 2.4rem;
    height: 2.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
    background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
    border-radius: 0.85rem;
    box-shadow: 0 10px 20px rgba(199, 107, 45, 0.28);
}

.sidebar-toggle,
.sidebar-close {
    background: none;
    border: none;
    color: rgba(255, 248, 239, 0.72);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
}

.sidebar-toggle:hover,
.sidebar-close:hover {
    color: #fff;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.nav-section {
    margin-bottom: 0.5rem;
}

.nav-section-title {
    display: block;
    padding: 0.5rem 1.25rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: rgba(255, 248, 239, 0.42);
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.1rem 0.75rem;
    padding: 0.7rem 0.95rem;
    color: rgba(255, 248, 239, 0.76);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.15s ease;
    border-left: 0;
    border-radius: 0.95rem;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transform: translateX(2px);
}

.sidebar-nav .nav-link.active {
    background: linear-gradient(135deg, rgba(199, 107, 45, 0.24), rgba(199, 107, 45, 0.12));
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(242, 198, 109, 0.16);
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.5rem 0;
}

.sidebar-footer .nav-link.text-danger {
    color: #f5b597 !important;
}

.sidebar-footer .nav-link.text-danger:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff1e7 !important;
}

.sidebar-footer-link {
    color: rgba(255, 248, 239, 0.88);
}

.sidebar-footer-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar-guest-note {
    margin: 0.5rem 1rem 0;
    padding: 0.9rem 1rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 248, 239, 0.82);
    font-size: 0.82rem;
    line-height: 1.55;
}

/* ─── Main Area ────────────────────────────────────────── */

.app-main {
    margin-left: var(--fs-sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

.app-main.sidebar-collapsed {
    margin-left: var(--fs-sidebar-collapsed);
}

/* ─── Top Bar ──────────────────────────────────────────── */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--fs-topbar-height);
    padding: 0 1.5rem;
    background: rgba(255, 251, 244, 0.82);
    border-bottom: 1px solid rgba(22, 33, 29, 0.08);
    box-shadow: 0 8px 24px rgba(32, 29, 20, 0.05);
    backdrop-filter: blur(16px);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-toggle {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--fs-muted);
    cursor: pointer;
    padding: 0.25rem;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-btn {
    background: rgba(35, 70, 61, 0.06);
    border: 1px solid rgba(22, 33, 29, 0.08);
    font-size: 1.25rem;
    color: var(--fs-muted);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 12px;
    transition: background 0.15s;
}

.topbar-btn:hover {
    background: rgba(199, 107, 45, 0.12);
    color: var(--fs-primary-dark);
}

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: linear-gradient(135deg, #d55433, #9e2f1b);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(35, 70, 61, 0.05);
    border: 1px solid rgba(22, 33, 29, 0.08);
    cursor: pointer;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    transition: background 0.15s;
}

.topbar-user:hover {
    background: rgba(199, 107, 45, 0.1);
}

.topbar-user::after {
    display: none; /* Hide default dropdown caret */
}

.topbar-auth-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.topbar-auth-link:hover {
    transform: translateY(-1px);
}

.topbar-auth-ghost {
    border: 1px solid rgba(22, 33, 29, 0.12);
    color: var(--fs-text);
    background: rgba(255, 255, 255, 0.52);
}

.topbar-auth-primary {
    color: #fffaf0;
    background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
    box-shadow: 0 10px 22px rgba(199, 107, 45, 0.18);
}

.user-avatar i {
    font-size: 1.75rem;
    color: var(--fs-accent);
}

.user-info {
    text-align: left;
    line-height: 1.2;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--fs-text);
}

.user-role {
    font-size: 0.75rem;
    color: var(--fs-muted);
}

.breadcrumb-item,
.breadcrumb-item a {
    color: var(--fs-muted);
    text-decoration: none;
}

.breadcrumb-item.active {
    color: var(--fs-text);
}

/* ─── Notification Dropdown ────────────────────────────── */

.notification-dropdown {
    width: 360px;
    max-height: 460px;
    overflow-y: auto;
    padding: 0;
    border: 1px solid var(--fs-border);
    border-radius: 1rem;
    background: rgba(255, 251, 244, 0.96);
    box-shadow: var(--fs-shadow);
}

.notification-dropdown .dropdown-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--fs-border);
}

.notification-list .notification-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(22, 33, 29, 0.06);
    white-space: normal;
}

.notification-item.unread {
    background: rgba(242, 198, 109, 0.14);
}

.notification-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--fs-text);
}

.notification-body {
    font-size: 0.8rem;
    color: var(--fs-muted);
    margin-top: 0.15rem;
}

.dropdown-footer {
    padding: 0.5rem;
    border-top: 1px solid var(--fs-border);
}

/* ─── Content ──────────────────────────────────────────── */

.app-content {
    padding: 1.5rem;
}

.app-content > * + * {
    margin-top: 0;
}

/* ─── Page Header ──────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--fs-accent);
    margin: 0;
}

.page-header .page-actions {
    display: flex;
    gap: 0.5rem;
}

/* ─── Cards ────────────────────────────────────────────── */

.card {
    border: 1px solid var(--fs-border);
    border-radius: 1.15rem;
    background: var(--fs-surface);
    backdrop-filter: blur(14px);
    box-shadow: var(--fs-shadow-soft);
    transition: box-shadow 0.2s, transform 0.2s;
}

.card:hover {
    box-shadow: var(--fs-shadow);
    transform: translateY(-2px);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid rgba(22, 33, 29, 0.06);
    font-weight: 600;
    padding: 1rem 1.25rem;
}

.card-footer {
    background: transparent;
    border-top: 1px solid rgba(22, 33, 29, 0.06);
}

/* ─── Stat Cards ───────────────────────────────────────── */

.stat-card {
    background: var(--fs-surface);
    border: 1px solid var(--fs-border);
    border-radius: 1.15rem;
    padding: 1.25rem;
    box-shadow: var(--fs-shadow-soft);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon.green { background: rgba(111, 143, 73, 0.16); color: var(--fs-accent-soft); }
.stat-icon.blue { background: rgba(35, 70, 61, 0.12); color: var(--fs-accent); }
.stat-icon.amber { background: rgba(242, 198, 109, 0.24); color: var(--fs-primary-dark); }
.stat-icon.red { background: rgba(213, 84, 51, 0.16); color: #a0381d; }
.stat-icon.purple { background: rgba(199, 107, 45, 0.14); color: var(--fs-primary); }
.stat-icon.teal { background: rgba(35, 70, 61, 0.1); color: var(--fs-accent); }

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--fs-text);
}

.stat-info p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--fs-muted);
}

/* ─── Status Badges ────────────────────────────────────── */

.badge-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35em 0.75em;
    border-radius: 20px;
}

.badge-active, .badge-paid, .badge-clear, .badge-completed, .badge-approved, .badge-transferred {
    background: #d1fae5;
    color: #065f46;
}

.badge-pending, .badge-pending_payment, .badge-pending_seller_confirm, .badge-draft, .badge-unknown {
    background: #fef3c7;
    color: #92400e;
}

.badge-for_sale, .badge-scheduled, .badge-awaiting_payment, .badge-seller_confirmed, .badge-sent {
    background: #dbeafe;
    color: #1e40af;
}

.badge-in_lab, .badge-in_transit, .badge-collected, .badge-buyer_paid, .badge-partial,
.badge-confirmed, .badge-pending_sale {
    background: #ede9fe;
    color: #5b21b6;
}

.badge-cancelled, .badge-rejected, .badge-not_clear, .badge-deceased, .badge-suspended,
.badge-deactivated, .badge-failed, .badge-disputed, .badge-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.badge-sold, .badge-seller_paid, .badge-ready_for_transfer, .badge-credited {
    background: #ccfbf1;
    color: #115e59;
}

.badge-tested, .badge-inactive, .badge-expired, .badge-overpaid, .badge-refunded, .badge-ignored {
    background: #f3f4f6;
    color: #4b5563;
}

/* ─── Tables ───────────────────────────────────────────── */

.table th {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--fs-muted);
    border-bottom-width: 1px;
}

.table td {
    vertical-align: middle;
    font-size: 0.875rem;
    color: var(--fs-text);
}

.table > :not(caption) > * > * {
    background: transparent;
    border-color: rgba(22, 33, 29, 0.08);
}

/* ─── Buttons ──────────────────────────────────────────── */

.btn-primary {
    background: linear-gradient(135deg, var(--fs-primary), var(--fs-primary-dark));
    border-color: transparent;
    box-shadow: 0 10px 20px rgba(199, 107, 45, 0.18);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--fs-primary-dark), #7f3f12);
    border-color: transparent;
}

.btn-outline-primary {
    color: var(--fs-accent);
    border-color: rgba(35, 70, 61, 0.2);
    background: rgba(255, 255, 255, 0.32);
}

.btn-outline-primary:hover {
    background: rgba(35, 70, 61, 0.08);
    border-color: rgba(35, 70, 61, 0.26);
    color: var(--fs-accent);
}

.btn,
.form-control,
.form-select,
.input-group-text,
.dropdown-menu {
    border-radius: 0.95rem;
}

.btn-secondary,
.btn-outline-secondary,
.btn-light {
    border-color: rgba(22, 33, 29, 0.1);
}

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

/* ─── Forms ────────────────────────────────────────────── */

.form-control:focus,
.form-select:focus {
    border-color: rgba(199, 107, 45, 0.6);
    box-shadow: 0 0 0 4px rgba(199, 107, 45, 0.12);
}

.form-control,
.form-select,
.input-group-text {
    border-color: rgba(22, 33, 29, 0.1);
    background: rgba(255, 255, 255, 0.72);
}

.form-label,
label {
    color: var(--fs-text);
    font-weight: 600;
}

/* ─── Animal Card ──────────────────────────────────────── */

.animal-card {
    border-radius: 1.15rem;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.animal-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.animal-card-img {
    height: 200px;
    object-fit: cover;
    background: rgba(35, 70, 61, 0.08);
}

.animal-card-body {
    padding: 1rem;
}

/* ─── Empty State ──────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--fs-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--fs-text);
}

.alert {
    border: 1px solid rgba(22, 33, 29, 0.08);
    border-radius: 1rem;
    box-shadow: var(--fs-shadow-soft);
}

.alert-success {
    background: rgba(111, 143, 73, 0.14);
    color: #23463d;
}

.alert-danger {
    background: rgba(213, 84, 51, 0.12);
    color: #8d2f1b;
}

.alert-warning {
    background: rgba(242, 198, 109, 0.2);
    color: #7a4618;
}

.alert-info {
    background: rgba(35, 70, 61, 0.1);
    color: #23463d;
}

.dropdown-menu {
    border: 1px solid var(--fs-border);
    box-shadow: var(--fs-shadow-soft);
    background: rgba(255, 251, 244, 0.96);
}

.dropdown-item {
    border-radius: 0.8rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: rgba(199, 107, 45, 0.1);
    color: var(--fs-text);
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border-radius: 0.8rem;
    border: 1px solid rgba(22, 33, 29, 0.1);
    background: rgba(255, 255, 255, 0.76);
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 400px;
    margin: 0.5rem auto;
}

/* ─── Sidebar Overlay (Mobile) ─────────────────────────── */

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1035;
}

/* ─── Responsive ───────────────────────────────────────── */

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .app-sidebar.mobile-open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0 !important;
    }

    .notification-dropdown {
        width: 300px;
    }

    .app-topbar {
        position: static;
    }
}

@media (max-width: 575.98px) {
    .app-content {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
    }

    .topbar-right {
        gap: 0.5rem;
    }

    .topbar-auth-link {
        padding: 0.5rem 0.8rem;
        font-size: 0.82rem;
    }
}
