:root {
    --sidebar-bg: #0f0f1a;
    --sidebar-hover: #1a1a2e;
    --sidebar-active: rgba(255, 123, 0, 0.15);
    --sidebar-active-border: #ff7b00;
    --sidebar-text: #7a7f93;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;
    --sidebar-collapsed: 64px;
    --accent: #ff7b00;
    --accent-hover: #e66e00;
    --accent-light: rgba(255, 123, 0, 0.08);
    --topbar-bg: #ffffff;
    --topbar-border: #e8eaed;
    --topbar-height: 60px;
    --body-bg: #f4f5f7;
    --card-bg: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #5f6368;
    --border-color: #e8eaed;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --agro-green: #1a5e2a;
    --agro-green-dark: #11431d;
    --agro-green-light: #e8f5e9;
    --agro-brown: #5d4037;
    --agro-gold: #f9a825;
}

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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: .875rem;
    color: var(--text-primary);
    background: var(--body-bg);
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.text-accent { color: var(--accent) !important; }
.bg-accent { background-color: var(--accent) !important; }

/* ========== TOPBAR ========== */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    z-index: 1030;
    display: flex;
    align-items: center;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 16px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all .2s;
}
.sidebar-toggle:hover { background: var(--accent-light); color: var(--accent); }
.device-mobile .sidebar-toggle { display: block; }
.device-tablet .sidebar-toggle { display: block; }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    text-decoration: none;
}
.topbar-brand i { color: var(--accent); font-size: 1.3rem; }
.topbar-brand:hover { color: var(--text-primary); }
.topbar-brand .brand-text small { font-weight: 400; color: var(--text-secondary); font-size: .75rem; }

/* Universe selector */
.btn-universe {
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid transparent;
    font-size: .8rem;
    padding: 4px 12px;
    border-radius: 6px;
    font-weight: 500;
}
.btn-universe:hover, .btn-universe:focus {
    background: rgba(255, 123, 0, 0.15);
    color: var(--accent-hover);
}
.universe-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

/* View switcher */
.view-switcher .btn-group { gap: 0; }
.btn-view {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    font-size: .8rem;
    border-radius: 0;
}
.btn-view:first-child { border-radius: 6px 0 0 6px; }
.btn-view:last-child { border-radius: 0 6px 6px 0; }
.btn-view.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-view:hover:not(.active) { background: var(--accent-light); color: var(--accent); }

/* Profile */
.btn-profile {
    background: transparent;
    color: var(--text-primary);
    border: none;
    padding: 4px 10px;
    font-size: .85rem;
    border-radius: 6px;
}
.btn-profile:hover, .btn-profile:focus {
    background: var(--accent-light);
    color: var(--accent);
}
.btn-profile i { font-size: 1.1rem; margin-right: 4px; }
.device-mobile .profile-name { display: none; }

/* ========== SIDEBAR ========== */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    z-index: 1020;
    display: flex;
    flex-direction: column;
    transition: width .25s ease;
    overflow: hidden;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1019;
}

.sidebar-inner {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}
.sidebar-inner::-webkit-scrollbar { width: 4px; }
.sidebar-inner::-webkit-scrollbar-track { background: transparent; }
.sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.sidebar-nav { padding: 0 8px; }

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-section-label {
    padding: 16px 16px 6px;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.25);
}

.sidebar-item { margin: 1px 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    transition: all .2s;
    white-space: nowrap;
    position: relative;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active);
    border-left: 3px solid var(--sidebar-active-border);
}
.sidebar-link.active i { color: var(--sidebar-active-border); }

.sidebar-icon {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.submenu-arrow {
    font-size: .65rem;
    transition: transform .2s;
    margin-left: auto;
}
.sidebar-item.open > .sidebar-link .submenu-arrow {
    transform: rotate(180deg);
}

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0 0 0 40px;
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
}
.sidebar-item.open .sidebar-submenu {
    max-height: 300px;
}
.sidebar-submenu li { margin: 1px 0; }
.sidebar-submenu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 6px;
    font-size: .82rem;
    transition: all .2s;
}
.sidebar-submenu a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-submenu a i { width: 16px; text-align: center; font-size: .85rem; }

.sidebar-footer {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

.sidebar-collapse-btn {
    width: 100%;
    background: none;
    border: none;
    color: var(--sidebar-text);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all .2s;
    text-align: center;
}
.sidebar-collapse-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

/* ========== SIDEBAR COLLAPSED ========== */
.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}
.sidebar-collapsed .sidebar-label,
.sidebar-collapsed .sidebar-section-label,
.sidebar-collapsed .submenu-arrow,
.sidebar-collapsed .sidebar-submenu,
.sidebar-collapsed .sidebar-footer {
    display: none;
}
.sidebar-collapsed .sidebar-link {
    padding: 12px;
    justify-content: center;
}
.sidebar-collapsed .sidebar-icon {
    margin: 0;
    font-size: 1.2rem;
}
.sidebar-collapsed .sidebar-item .sidebar-link {
    border-radius: 8px;
}
.sidebar-collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

/* ========== MAIN CONTENT ========== */
.main-content {
    margin-top: var(--topbar-height);
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left .25s ease;
    display: flex;
    flex-direction: column;
    padding-bottom: 50px;
}
.main-content-full {
    margin-left: 0;
}

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

/* ========== FOOTER ========== */
.footer {
    position: fixed;
    bottom: 0;
    right: 0;
    left: var(--sidebar-width);
    background: var(--topbar-bg);
    border-top: 1px solid var(--topbar-border);
    z-index: 100;
    transition: left .25s ease;
    font-size: .78rem;
    padding: 10px 0;
}
.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
}
.footer-left, .footer-right { color: var(--text-secondary); }
.footer a { color: var(--text-secondary); }
.footer a:hover { color: var(--accent); }

.sidebar-collapsed .footer {
    left: var(--sidebar-collapsed);
}

/* ========== RESPONSIVE: MOBILE / TABLET ========== */
@media (max-width: 991.98px) {
    .sidebar {
        left: calc(-1 * var(--sidebar-width));
        width: var(--sidebar-width) !important;
    }
    .sidebar-open .sidebar { left: 0; }
    .sidebar-open .sidebar-overlay { display: block; }
    .main-content { margin-left: 0 !important; }
    .footer { left: 0 !important; }
    .sidebar-collapse-btn { display: none; }

    .device-mobile .topbar-brand .brand-text small { display: none; }
    .device-mobile .view-switcher { display: none; }
    .device-tablet .view-switcher { display: inline-flex; }
}

@media (min-width: 992px) {
    .sidebar-overlay { display: none !important; }
}

/* ========== COMMON COMPONENTS ========== */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    transition: box-shadow .2s;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .85rem;
}
.card-body { padding: 1rem; }
.card-footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
}

.btn-agro {
    color: #fff;
    background-color: var(--accent);
    border-color: var(--accent);
    border-radius: 8px;
    font-weight: 500;
    font-size: .85rem;
    padding: .45rem 1rem;
    transition: all .2s;
}
.btn-agro:hover, .btn-agro:focus {
    color: #fff;
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-outline-agro {
    color: var(--accent);
    border-color: var(--accent);
    border-radius: 8px;
    font-weight: 500;
    font-size: .85rem;
}
.btn-outline-agro:hover {
    color: #fff;
    background-color: var(--accent);
    border-color: var(--accent);
}

.btn-outline-secondary { border-radius: 8px; font-size: .85rem; }

.bg-agro { background-color: var(--agro-green) !important; }
.bg-agro-light { background-color: var(--agro-green-light) !important; }
.text-agro { color: var(--agro-green) !important; }

.table {
    font-size: .85rem;
    margin-bottom: 0;
}
.table th {
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}
.table td { vertical-align: middle; }

.badge { font-weight: 500; font-size: .75rem; padding: .3em .65em; border-radius: 6px; }

.form-label { font-weight: 500; font-size: .82rem; color: var(--text-primary); }
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: .85rem;
    padding: .45rem .75rem;
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 123, 0, .12);
}
.device-mobile .form-control,
.device-mobile .form-select { font-size: 16px; }

h4 { font-size: 1.2rem; font-weight: 700; margin-bottom: .75rem; }
h5 { font-size: 1rem; font-weight: 600; }
h6 { font-size: .9rem; font-weight: 600; }

/* Loading */
.loading { opacity: .6; pointer-events: none; }

/* Cookie banner */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background: var(--card-bg);
    border-top: 2px solid var(--accent);
    padding: 1rem;
    z-index: 9999;
    box-shadow: 0 -2px 10px rgba(0,0,0,.1);
    transition: left .25s ease;
}
.sidebar-collapsed .cookie-banner { left: var(--sidebar-collapsed); }

/* Print */
@media print {
    .sidebar, .topbar, .footer, .btn { display: none !important; }
    .main-content { margin: 0 !important; }
}

/* Accessibility */
a:focus, button:focus, .form-control:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Device-specific */
.device-mobile body { padding-bottom: 0; }
.device-mobile .table { font-size: .8rem; }
.device-mobile .card-body { padding: .75rem; }
.device-mobile h4 { font-size: 1rem; }
.device-mobile .footer { font-size: .7rem; }
.device-mobile .dropdown-menu { border-radius: 0; border: none; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.device-mobile .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
.device-tablet .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
