/* ============================================================
   DoIFarms Enterprise - Application Stylesheet
   Light/Dark theme via CSS variables, Bootstrap 5 based.
   ============================================================ */

:root {
    --brand: #8b4513;
    --brand-dark: #6b3410;
    --brand-light: #f3e4d5;
    --brand-600: #8b4513;
    --sidebar-bg: #3e2210;
    --sidebar-bg-2: #2a1509;
    --sidebar-text: #e3cdbb;
    --sidebar-active: #d2691e;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --bg: #faf6f1;
    --surface: #ffffff;
    --surface-2: #f7f0e9;
    --border: #eadfd3;
    --text: #2e1a0e;
    --text-muted: #8a6e58;
    --topbar-h: 64px;
    --sidebar-w: 268px;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(62, 34, 16, 0.06), 0 4px 16px rgba(62, 34, 16, 0.05);
    --shadow-lg: 0 8px 30px rgba(62, 34, 16, 0.12);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
    --bg: #1a0f07;
    --surface: #261509;
    --surface-2: #2f1b0e;
    --border: #472a18;
    --text: #f6ebe0;
    --text-muted: #b79a82;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
    --sidebar-bg: #170c05;
    --sidebar-bg-2: #120802;
    --sidebar-text: #c4a58c;
    --sidebar-hover: rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

/* ---------- Bootstrap overrides ---------- */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
    --bs-btn-disabled-bg: var(--brand);
    --bs-btn-disabled-border-color: var(--brand);
    font-weight: 600;
}

.form-control, .form-select {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--text);
    padding: 0.55rem 0.85rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(139, 69, 19, 0.15);
    background-color: var(--surface);
    color: var(--text);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-hover-bg: var(--surface-2);
    margin-bottom: 0;
}
.table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td { vertical-align: middle; font-size: 0.875rem; }

.dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.dropdown-item { color: var(--text); font-size: 0.875rem; }
.dropdown-item:hover { background: var(--surface-2); color: var(--brand); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
}
.alert { border-radius: 12px; border: 0; }
.alert-success { background: var(--brand-light); color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #e0f2fe; color: #075985; }

/* ---------- Badges ---------- */
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-danger  { background: #fee2e2; color: #991b1b; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-info    { background: #e0f2fe; color: #075985; }
.badge-soft-secondary { background: #e5e7eb; color: #374151; }
.badge-soft-primary { background: #dbeafe; color: #1d4ed8; }
.badge {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.4em 0.7em;
    border-radius: 20px;
}
[data-theme="dark"] .badge-soft-success { background: rgba(22,163,74,.18); color: #86efac; }
[data-theme="dark"] .badge-soft-danger  { background: rgba(239,68,68,.18); color: #fca5a5; }
[data-theme="dark"] .badge-soft-warning { background: rgba(245,158,11,.18); color: #fcd34d; }
[data-theme="dark"] .badge-soft-info    { background: rgba(14,165,233,.18); color: #7dd3fc; }
[data-theme="dark"] .badge-soft-secondary { background: rgba(107,114,128,.2); color: #d1d5db; }
[data-theme="dark"] .badge-soft-primary { background: rgba(59,130,246,.18); color: #93c5fd; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.25s ease;
    scrollbar-width: thin;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-logo {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #d2691e, #6b3410);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.35);
    flex-shrink: 0;
}
.sidebar-brand .brand-img {
    width: 42px; height: 42px; border-radius: 12px;
    object-fit: contain; background: #fff; padding: 4px;
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.35);
    flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: 0.98rem; font-weight: 700; }
.brand-text span { font-size: 0.72rem; color: var(--sidebar-text); letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar-collapse { display: none; }

.sidebar-search {
    margin: 14px 14px 6px;
    position: relative;
}
.sidebar-search i {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--sidebar-text); font-size: 0.8rem;
}
.sidebar-search input {
    width: 100%;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.08);
    color: #fff;
    border-radius: 10px;
    padding: 9px 12px 9px 34px;
    font-size: 0.82rem;
}
.sidebar-search input::placeholder { color: var(--sidebar-text); }
.sidebar-search input:focus { outline: none; border-color: var(--brand); }

.sidebar-nav { padding: 8px 12px 20px; flex: 1; }
.nav-section {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--sidebar-text);
    opacity: 0.65;
    padding: 16px 10px 6px;
    font-weight: 700;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--sidebar-text);
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.865rem;
    font-weight: 500;
    transition: all 0.15s ease;
}
.nav-link i { width: 20px; text-align: center; font-size: 0.95rem; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active {
    background: linear-gradient(90deg, rgba(139,69,19,0.22), rgba(139,69,19,0.08));
    color: #fff;
    border-left: 3px solid var(--brand);
}
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 12px;
}
.logout-btn { color: #fca5a5 !important; }
.logout-btn:hover { background: rgba(239,68,68,0.12) !important; }

.sidebar-backdrop { display: none; }

/* ---------- Main area ---------- */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.breadcrumbs { font-size: 0.82rem; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--brand); }
.breadcrumbs i { font-size: 0.6rem; opacity: 0.6; }
.breadcrumbs span.active { color: var(--text); font-weight: 600; }

.btn-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.btn-icon:hover { border-color: var(--brand); color: var(--brand); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.notif-badge {
    position: absolute; top: 2px; right: 2px;
    background: #ef4444; color: #fff;
    font-size: 0.62rem; font-weight: 700;
    border-radius: 20px;
    padding: 2px 6px;
    min-width: 18px;
}
.notif-menu { width: 360px; max-width: 92vw; padding: 0; }
.notif-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item {
    display: flex; gap: 12px; padding: 12px 16px;
    color: var(--text); border-bottom: 1px solid var(--border);
}
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: rgba(139,69,19,0.06); }
.notif-icon {
    width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-2); color: var(--brand);
}
.notif-item strong { font-size: 0.83rem; display: block; }
.notif-item p { margin: 2px 0; font-size: 0.78rem; color: var(--text-muted); }
.notif-item small { font-size: 0.7rem; color: var(--text-muted); }
.notif-empty { text-align: center; padding: 32px; color: var(--text-muted); }
.notif-empty i { font-size: 2rem; opacity: 0.5; }
.notif-footer {
    display: block; text-align: center; padding: 10px;
    font-size: 0.8rem; color: var(--brand); font-weight: 600;
    border-top: 1px solid var(--border);
}

.user-chip {
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 12px;
    background: var(--surface);
    color: var(--text);
}
.user-chip:hover { border-color: var(--brand); }
.user-avatar {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, #d2691e, #6b3410);
    color: #fff; font-weight: 700; font-size: 0.85rem;
    display: flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-meta strong { font-size: 0.82rem; }
.user-meta small { font-size: 0.7rem; color: var(--text-muted); }

.page-content { padding: 24px; flex: 1; }
.app-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.78rem;
    display: flex; justify-content: space-between;
}

/* ---------- Page header ---------- */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.4rem; font-weight: 800; margin: 0; }
.page-header .subtitle { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Stat cards ---------- */
.stat-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 18px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
    width: 46px; height: 46px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem; margin-bottom: 12px;
}
.stat-card .stat-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; margin-top: 2px; }
.stat-card .stat-trend { font-size: 0.75rem; margin-top: 6px; }
.trend-up { color: #8b4513; }
.trend-down { color: #ef4444; }
.stat-soft-green { background: var(--brand-light); color: var(--brand-dark); }
.stat-soft-blue { background: #dbeafe; color: #1d4ed8; }
.stat-soft-amber { background: #fef3c7; color: #92400e; }
.stat-soft-rose { background: #fee2e2; color: #991b1b; }
.stat-soft-violet { background: #ede9fe; color: #6d28d9; }
.stat-soft-cyan { background: #cffafe; color: #0e7490; }
[data-theme="dark"] .stat-soft-green { background: rgba(139,69,19,.15); }
[data-theme="dark"] .stat-soft-blue { background: rgba(59,130,246,.15); }
[data-theme="dark"] .stat-soft-amber { background: rgba(245,158,11,.15); }
[data-theme="dark"] .stat-soft-rose { background: rgba(239,68,68,.15); }
[data-theme="dark"] .stat-soft-violet { background: rgba(139,92,246,.15); }
[data-theme="dark"] .stat-soft-cyan { background: rgba(6,182,212,.15); }

/* ---------- Charts ---------- */
.chart-card { padding: 18px; }
.chart-card .card-title { font-size: 0.95rem; font-weight: 700; }
.chart-box { position: relative; height: 300px; }
.chart-box-sm { position: relative; height: 240px; }

/* ---------- Filter bar ---------- */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* ---------- Tables card ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-card .table-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; }
.table-card .table-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.table-card .table-wrap { overflow-x: auto; }
.table-card .card-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 14px 20px; }

.actions-dropdown .btn { padding: 4px 10px; font-size: 0.8rem; }
.avatar-sm {
    width: 36px; height: 36px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.78rem; color: #fff;
}

/* ---------- Forms ---------- */
.form-card { max-width: 860px; }
.form-section-title {
    font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.07em; color: var(--brand); margin: 8px 0 14px;
    display: flex; align-items: center; gap: 8px;
}
.form-section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.input-group-text { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); }

/* ---------- Detail view ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.detail-item { padding: 12px 14px; background: var(--surface-2); border-radius: 10px; }
.detail-item .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.detail-item .value { font-weight: 600; font-size: 0.92rem; margin-top: 3px; }

/* ---------- Login ---------- */
.auth-body {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 20% 10%, #3e2210 0%, transparent 55%),
                radial-gradient(1000px 500px at 90% 90%, #6b3410 0%, transparent 50%),
                #2a1509;
    padding: 24px;
}
.auth-wrapper { width: 100%; max-width: 430px; }
.auth-panel {
    background: var(--surface);
    border-radius: 20px;
    padding: 36px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.08);
}
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .brand-logo {
    margin: 0 auto 14px;
    width: 58px;
    height: 58px;
    font-size: 1.6rem;
    border-radius: 16px;
    background: linear-gradient(135deg, #d2691e, #6b3410);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.35);
    flex-shrink: 0;
}
.auth-brand .auth-logo {
    width: 72px; height: 72px; object-fit: contain;
    border-radius: 16px; background: #fff; padding: 6px;
    margin: 0 auto 14px; display: block;
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.35);
}
.auth-brand .brand-title { font-size: 1.35rem; font-weight: 800; color: var(--text); margin: 0; }
.auth-brand .brand-subtitle { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0 0; }
.auth-form .btn-primary { height: 48px; font-size: 0.95rem; }
.auth-form .toggle-password { cursor: pointer; border: 0; padding: 8px 12px; }
.auth-form .toggle-password:hover { background-color: rgba(139, 69, 19, 0.1) !important; }
.auth-footer { text-align: center; font-size: 0.75rem; margin-top: 22px; margin-bottom: 0; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state i { font-size: 3rem; opacity: 0.35; display: block; margin-bottom: 12px; }
.empty-state h4 { color: var(--text); font-weight: 700; }
.empty-state p { font-size: 0.85rem; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120, 140, 130, 0.35); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 140, 130, 0.55); }

/* ---------- Pagination ---------- */
.pagination .page-link {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
    font-size: 0.8rem;
}
.pagination .page-item.active .page-link { background: var(--brand); border-color: var(--brand); }
.pagination .page-item.disabled .page-link { color: var(--text-muted); }

/* ---------- Nav tabs ---------- */
.nav-tabs { border-bottom: 1px solid var(--border); }
.nav-tabs .nav-link { color: var(--text-muted); border: 0; font-weight: 600; font-size: 0.85rem; padding: 10px 16px; }
.nav-tabs .nav-link.active { color: var(--brand); background: transparent; border-bottom: 2px solid var(--brand); }

/* ---------- Toast ---------- */
.toast-item {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 12px 16px;
    min-width: 280px;
    margin-bottom: 10px;
    animation: slideIn 0.3s ease;
    font-size: 0.85rem;
}
.toast-item.success { border-left-color: #16a34a; }
.toast-item.error { border-left-color: #ef4444; }
.toast-item.warning { border-left-color: #f59e0b; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------- Login rate / misc ---------- */
.metric-spark { display: flex; gap: 18px; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.4); }
    .sidebar-collapse { display: inline-flex; }
    .main-area { margin-left: 0; }
    .sidebar-backdrop.show {
        display: block;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1035;
    }
    .page-content { padding: 16px; }
}

@media (max-width: 575.98px) {
    .topbar { padding: 0 14px; }
    .stat-card .stat-value { font-size: 1.25rem; }
    .user-meta { display: none; }
}
