:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #f0f2f5;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
}

body.dark-theme {
    --bg-main: #0f172a;
    --sidebar-bg: #020617;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --card-bg: #1e293b;
    --border: #334155;
    --input-bg: #1e293b;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }
body { background: var(--bg-main); color: var(--text-main); transition: background 0.3s, color 0.3s; }

/* Utilities */
.hidden { display: none !important; }
.text-sm { font-size: 0.8rem; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }

/* Buttons */
.btn-primary { background: var(--primary); color: #fff; border: none; padding: 0.6rem 1.2rem; border-radius: 6px; font-weight: 600; cursor: pointer; transition: 0.2s; font-size: 0.9rem; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text-main); border: none; padding: 0.6rem 1.2rem; border-radius: 6px; font-weight: 500; cursor: pointer; transition: 0.2s; font-size: 0.9rem; }
.btn-secondary:hover { opacity: 0.8; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; border: none; padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 500; font-size: 0.85rem; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 6px;
    outline: none; background: var(--input-bg); color: var(--text-main); font-size: 0.9rem;
    transition: border-color 0.2s, background 0.3s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }

/* Login */
.login-body { display: flex; height: 100vh; }
.login-container { display: flex; width: 100%; }
.login-left { flex: 1; background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); color: #fff; display: flex; align-items: center; justify-content: center; padding: 3rem; }
.login-left-content { text-align: center; max-width: 420px; }
.login-left-content h1 { font-size: 2rem; margin: 1rem 0 0.5rem; }
.login-left-content p { opacity: 0.85; font-size: 1rem; }
.login-right { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg-main); }
.login-box { background: var(--card-bg); padding: 2.5rem; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); width: 100%; max-width: 400px; }
.login-box h2 { margin-bottom: 0.3rem; font-size: 1.4rem; }
.login-box p { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.85rem; }
.error-message { color: var(--danger); font-size: 0.85rem; margin-bottom: 1rem; }

/* Dashboard Layout */
.dashboard-body { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease, left 0.3s ease;
}
.sidebar.collapsed {
    width: 0;
    overflow: hidden;
}
.sidebar-header { padding: 1.2rem; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-header img { max-width: 90px; border-radius: 6px; margin-bottom: 8px; }
.sidebar-header h2 { font-size: 1rem; font-weight: 600; }
.sidebar-nav { display: flex; flex-direction: column; padding: 0.5rem 0; flex: 1; }
.sidebar-nav a { color: var(--sidebar-text); text-decoration: none; padding: 0.7rem 1.2rem; transition: 0.15s; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.sidebar-nav a:hover, .sidebar-nav a.active { background: var(--sidebar-hover); color: #fff; border-left: 3px solid var(--primary); }
.sidebar-nav .nav-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 0.5rem 1.2rem; }

.theme-toggle { background: none; border: none; color: var(--sidebar-text); cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 0.7rem 1.2rem; width: 100%; text-align: left; font-size: 0.85rem; transition: 0.2s; }
.theme-toggle:hover { background: var(--sidebar-hover); color: #fff; }

.main-content { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; transition: margin-left 0.3s ease; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }

.menu-toggle-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}
.menu-toggle-btn:hover {
    background: var(--border);
}
.topbar h1 { font-size: 1.3rem; font-weight: 700; }

/* Stats */
.dashboard-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); padding: 1.2rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); border-left: 4px solid var(--primary); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.success { border-left-color: var(--success); }
.stat-card h3 { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card p { font-size: 1.8rem; font-weight: 700; margin-top: 0.3rem; }
.stat-card .stat-sub { font-size: 1rem; font-weight: 600; margin-top: 0.5rem; }

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.toolbar .search-group { display: flex; gap: 8px; flex: 1; max-width: 500px; }
.toolbar .search-group input { flex: 1; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); color: var(--text-main); font-size: 0.9rem; }
.toolbar .search-group input:focus { border-color: var(--primary); outline: none; }

/* Product Grid - Premium Style */
.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; }
.item-card { background: var(--card-bg); border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.04); border: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column; transition: all 0.2s ease-in-out; position: relative; }
.item-card:hover { transform: translateY(-4px); box-shadow: 0 12px 25px rgba(0,0,0,0.1); }

.item-card .card-img { width: 100%; height: 180px; background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; border-bottom: 1px solid var(--border); }
.item-card .card-img img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease; }
.item-card:hover .card-img img { transform: scale(1.05); }
.item-card .card-img .no-img { color: #cbd5e1; font-size: 3.5rem; }

.item-info { padding: 1.2rem; flex: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 1rem; }
.item-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.2rem; line-height: 1.3; color: var(--text-main); }
.item-model { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.5rem; }

.item-details { font-size: 0.75rem; color: var(--text-muted); margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.item-details div { background: var(--bg-main); padding: 5px 8px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.item-footer { display: flex; justify-content: space-between; align-items: center; padding-top: 1rem; border-top: 1px solid var(--border); }

.badge-estoque { position: absolute; top: 12px; right: 12px; padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; color: #fff; z-index: 2; box-shadow: 0 2px 5px rgba(0,0,0,0.15); }
.badge-estoque.ok { background: var(--success); }
.badge-estoque.falta { background: var(--danger); }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 1000; }
.modal.active { display: flex; }
.modal-content { background: var(--card-bg); width: 100%; max-width: 560px; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { padding: 1.2rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header h2 { font-size: 1.1rem; }
.close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.8rem; margin-top: 1.2rem; }

/* AI Box */
.ai-box { background: var(--input-bg); border: 2px dashed var(--primary); padding: 1rem; border-radius: 8px; margin-bottom: 1.2rem; text-align: center; position: relative; }
.ai-box .paste-area { min-height: 60px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px; }
.ai-box .paste-area img { max-height: 80px; border-radius: 4px; }

/* Config Card */
.config-card { background: var(--card-bg); padding: 2rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); max-width: 600px; }
.config-card h3 { margin-bottom: 0.5rem; }

/* Admin Lock */
.admin-lock { display: flex; align-items: center; gap: 8px; padding: 0.7rem 1.2rem; color: var(--sidebar-text); cursor: pointer; font-size: 0.9rem; background: none; border: none; width: 100%; text-align: left; transition: 0.15s; }
.admin-lock:hover { background: var(--sidebar-hover); color: #fff; }
.admin-active { color: var(--success) !important; }

/* Responsive */
@media (max-width: 768px) {
    .login-container { flex-direction: column; }
    .login-left { display: none; }
    .sidebar {
        position: fixed;
        top: 0;
        left: -250px;
        bottom: 0;
        width: 250px;
        z-index: 1001;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    }
    .sidebar.active {
        left: 0;
    }
    .main-content {
        padding: 1rem;
        margin-left: 0;
        width: 100%;
    }
    .mobile-menu-toggle {
        display: block !important;
    }
    /* Overlay when sidebar is open on mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
    }
    .sidebar-overlay.active {
        display: block;
    }
    .items-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .search-group { max-width: 100%; }
    
    .dashboard-charts-grid, .config-grid, .user-dashboard-grid { grid-template-columns: 1fr; }
    
    /* Table Responsive Cards */
    .estoque-table thead { display: none; }
    .estoque-table, .estoque-table tbody, .estoque-table tr, .estoque-table td { display: block; width: 100%; box-sizing: border-box; }
    .estoque-table tr { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 1rem; padding: 0.8rem; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
    .estoque-table td { text-align: right !important; padding: 0.5rem 0.2rem; border-bottom: 1px dashed var(--border); position: relative; padding-left: 45%; min-height: 2rem; display: flex; align-items: center; justify-content: flex-end; }
    .estoque-table td:last-child { border-bottom: none; }
    .estoque-table td::before { content: attr(data-label); position: absolute; left: 10px; width: 40%; text-align: left; font-weight: 600; color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .estoque-table td.no-print { padding-left: 10px; justify-content: center; text-align: center !important; }
    .estoque-table td.no-print::before { display: none; }
}

/* Responsive Grid Classes */
.dashboard-charts-grid { display: grid; grid-template-columns: 1fr 1fr; }
.form-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.user-dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }

@media (max-width: 576px) {
    .form-row-grid { grid-template-columns: 1fr; }
}

/* Draggable Columns styling */
th[draggable="true"] {
    cursor: grab;
    user-select: none;
}
th[draggable="true"]:active {
    cursor: grabbing;
}
th.drag-over {
    border-left: 3px dashed var(--primary) !important;
    background: rgba(37, 99, 235, 0.15) !important;
}


