/* ============================================================
   AGRISEED ERP - Professional Master Design System
   Premium Enterprise UI Kit
============================================================ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 68px;
    --bg-main: #f0f4f8;
    --bg-card: #ffffff;
    --bg-sidebar: #0f1629;
    --bg-sidebar-hover: rgba(16,185,129,0.12);
    --bg-sidebar-active: rgba(16,185,129,0.2);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --primary: #10b981;
    --primary-hover: #059669;
    --secondary: #3b82f6;
    --accent: #6366f1;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-color: #e2e8f0;
    --card-shadow: 0 1px 8px rgba(0,0,0,0.08), 0 4px 24px rgba(0,0,0,0.04);
    --sidebar-transition: all 0.28s cubic-bezier(0.4,0,0.2,1);
    --nav-item-height: 44px;
}

[data-theme="dark"] {
    --bg-main: #0b0f19;
    --bg-card: #1a2235;
    --bg-sidebar: #060c19;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #1e2d45;
    --card-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    font-size: 0.9rem;
}

/* ── Layout ── */
#wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
}

/* ── Sidebar ── */
#sidebar-wrapper {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #cbd5e1;
    transition: var(--sidebar-transition);
    flex-shrink: 0;
    z-index: 1050;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}

/* Collapsed state */
#wrapper.sidebar-collapsed #sidebar-wrapper {
    width: var(--sidebar-collapsed-width);
}

/* ── Sidebar Header / Brand ── */
.sidebar-heading {
    padding: 1.1rem 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    min-height: 64px;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
}

.sidebar-brand-text {
    opacity: 1;
    transition: var(--sidebar-transition);
    overflow: hidden;
}

#wrapper.sidebar-collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.sidebar-brand-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #10b981;
    line-height: 1.2;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.sidebar-brand-sub {
    font-size: 0.65rem;
    color: #64748b;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ── Sidebar Nav ── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Section headers */
.sidebar-section-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #475569;
    padding: 1rem 1.1rem 0.35rem;
    white-space: nowrap;
    overflow: hidden;
    transition: var(--sidebar-transition);
    user-select: none;
}

#wrapper.sidebar-collapsed .sidebar-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
    pointer-events: none;
}

/* Nav items */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 0.6rem;
    margin: 1px 0;
    text-decoration: none;
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 8px;
    min-height: var(--nav-item-height);
    transition: color 0.2s ease, background 0.2s ease;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.sidebar-item:hover {
    background: var(--bg-sidebar-hover);
    color: #10b981;
    text-decoration: none;
}

.sidebar-item.active {
    background: var(--bg-sidebar-active);
    color: #10b981;
    font-weight: 600;
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: #10b981;
    border-radius: 0 3px 3px 0;
}

.sidebar-item-icon {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
    transition: var(--sidebar-transition);
}

.sidebar-item-label {
    opacity: 1;
    transition: var(--sidebar-transition);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

#wrapper.sidebar-collapsed .sidebar-item {
    justify-content: center;
    padding: 0;
    width: 44px;
    margin-left: 12px;
    border-radius: 10px;
}

#wrapper.sidebar-collapsed .sidebar-item-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Tooltip on collapse */
#wrapper.sidebar-collapsed .sidebar-item {
    position: relative;
}

#wrapper.sidebar-collapsed .sidebar-item::after {
    content: attr(title);
    position: absolute;
    left: 56px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #e2e8f0;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: opacity 0.15s ease;
}

#wrapper.sidebar-collapsed .sidebar-item:hover::after {
    opacity: 1;
}

/* ── Sidebar Collapse Toggle ── */
.sidebar-toggle-btn {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #64748b;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.sidebar-toggle-btn:hover {
    background: rgba(16,185,129,0.15);
    color: #10b981;
    border-color: #10b981;
}

/* ── Page Content ── */
#page-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: var(--sidebar-transition);
}

/* ── Top Navbar ── */
.top-navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* ── Cards ── */
.card-custom {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-custom:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 28px rgba(0,0,0,0.1);
}

/* ── KPI Cards ── */
.kpi-card {
    padding: 1.25rem 1.5rem;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.bg-emerald-subtle { background: rgba(16,185,129,0.12); color: #10b981; }
.bg-blue-subtle { background: rgba(59,130,246,0.12); color: #3b82f6; }
.bg-amber-subtle { background: rgba(245,158,11,0.12); color: #f59e0b; }
.bg-rose-subtle { background: rgba(239,68,68,0.12); color: #ef4444; }
.text-emerald { color: #10b981; }
.text-amber { color: #f59e0b; }

/* ── Tables ── */
.table-custom {
    color: var(--text-main);
    vertical-align: middle;
}

.table-custom thead th {
    background: rgba(0,0,0,0.025);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.table-custom tbody tr {
    transition: background 0.15s ease;
}

.table-custom tbody tr:hover {
    background: rgba(16,185,129,0.04);
}

/* ── Buttons ── */
.btn { border-radius: 8px; font-weight: 500; }
.btn-sm { border-radius: 6px; }

/* ── Mobile Overlay ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
    backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
    #sidebar-wrapper {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100vh;
    }
    #wrapper.sidebar-open #sidebar-wrapper {
        left: 0;
    }
    #wrapper.sidebar-open .sidebar-overlay {
        display: block;
    }
    #wrapper.sidebar-collapsed #sidebar-wrapper {
        width: var(--sidebar-width);
    }
    .sidebar-toggle-btn { display: none; }
}

/* ── Print ── */
@media print {
    #sidebar-wrapper, .top-navbar, .btn-print-hide,
    .dataTables_filter, .dataTables_paginate, .sidebar-overlay {
        display: none !important;
    }
    #page-content-wrapper { margin: 0 !important; }
    body { background: #fff !important; color: #000 !important; }
    .card-custom { border: none !important; box-shadow: none !important; }
}
