:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --card-bg-secondary: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --border-color: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --input-bg: #0f172a;
    --input-text: #ffffff;
    --dropdown-bg: #1e293b;
    --dropdown-border: #334155;
    --dropdown-hover: rgba(255, 255, 255, 0.05);
}

body.light-mode {
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --card-bg-secondary: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --border-color: #e2e8f0;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --input-bg: #ffffff;
    --input-text: #1e293b;
    --dropdown-bg: #ffffff;
    --dropdown-border: #e2e8f0;
    --dropdown-hover: #f1f5f9;
}

/* Fix input colors in light mode */
body.light-mode input,
body.light-mode select,
body.light-mode textarea {
    background-color: #f8fafc;
    color: #1e293b;
    border-color: #cbd5e1;
}

body.light-mode .btn:not(.btn-primary):not(.btn-danger):not(.btn-success):not(.btn-warning) {
    color: #1e293b !important;
}


.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    transition: width 0.3s ease;
}

/* Toggle Menu Button (Mobile) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.nav-link:hover,
.nav-link.active {
    background-color: var(--accent-color);
    color: white;
    transform: translateX(5px);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    width: 100%;
    /* Ensure content takes full width */
}

header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    /* Allow header items to wrap on small screens */
    gap: 1rem;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
}

/* Cards & Glassmorphism */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    overflow-x: auto;
    /* Allow horizontal scroll for content like tables */
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.5rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--input-text);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.875rem;
    white-space: nowrap;
    text-decoration: none;
    color: white !important;
    /* Force white text for all buttons as requested */
    gap: 8px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    filter: brightness(1.1);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background-color: var(--accent-color);
}

.btn-secondary {
    background-color: var(--border-color);
}

.btn-danger {
    background-color: var(--danger-color);
}

.btn-success {
    background-color: var(--success-color);
}

.btn-purple {
    background: rgba(168, 85, 247, 0.4);
    border: 1px solid rgba(192, 132, 252, 0.3);
}

.btn-warning {
    background-color: #f59e0b;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.tab-link {
    padding: 10px 20px;
    text-decoration: none;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-size: 0.95rem;
    font-weight: 500;
    display: inline-block;
}

.tab-link:hover {
    color: var(--text-primary);
}

.tab-link.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Status Badges */
.status-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
    display: inline-block;
}

.status-ok {
    background-color: var(--success-color);
}

.status-excesso {
    background-color: var(--accent-color);
}

.status-alerta {
    background-color: #f59e0b;
}

.status-critico {
    background-color: var(--danger-color);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    /* Ensure table doesn't squish too much */
}

/* Mantém a altura da tabela de pedidos mesmo com poucos resultados */
.pedidos-table-container {
    min-height: 600px;
}

/* Container for responsive tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

#tableContainer {
    min-height: 600px !important;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

/* Alerts */
.alert-danger {
    color: var(--danger-color);
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger-color);
    padding: 0.75rem;
    border-radius: 0.5rem;
}

.text-danger {
    color: var(--danger-color) !important;
}

/* Form Grid & Responsive Layout */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem;
        position: sticky;
        top: 0;
        z-index: 100;
        /* Make sidebar collapsible logic or simplified for mobile */
    }

    .nav-links {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 5px;
        /* Hide scrollbar for cleaner look */
        -ms-overflow-style: none;
        /* IE and Edge */
        scrollbar-width: none;
        /* Firefox */
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .link-text {
        display: none;
    }

    .nav-link {
        justify-content: center;
        padding: 0.5rem;
    }

    .nav-link svg {
        width: 24px;
        height: 24px;
    }

    .nav-link:hover,
    .nav-link.active {
        transform: none;
        /* Disable transform on mobile to prevent layout shift */
    }

    .main-content {
        padding: 1rem;
        max-width: 100vw;
        box-sizing: border-box;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

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

    .actions {
        width: 100%;
        justify-content: space-between;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    /* Make tables scrollable immediately on tablet/mobile */
    .card {
        overflow-x: auto;
        padding: 1rem;
    }

    table {
        font-size: 0.8rem;
    }

    th,
    td {
        padding: 0.75rem 0.5rem;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 0.5rem;
    }

    /* Stack buttons on very small screens */
    .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Dashboard Grid to single column */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    .nav-links {
        gap: 10px;
    }

    .nav-link {
        font-size: 0.75rem;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.05);
        /* Slight bg for visibility */
    }
}

/* Locked/Readonly Input Styling */
.locked-input {
    background-color: rgba(255, 255, 255, 0.03) !important;
    color: var(--text-secondary) !important;
    cursor: pointer;
    border-style: dashed !important;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.locked-input:hover {
    background-color: rgba(255, 255, 255, 0.07) !important;
    opacity: 1;
}

/* Slicer Filters */
.slicer-wrapper {
    position: relative;
    min-width: 140px;
}

.slicer-display {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.2s;
}

.slicer-display:hover {
    border-color: var(--accent-color);
}

.slicer-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 5px;
}

.slicer-arrow {
    font-size: 0.6rem;
    opacity: 0.6;
}

.slicer-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 250px;
    background: var(--dropdown-bg);
    border: 1px solid var(--dropdown-border);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    z-index: 2000;
    margin-top: 5px;
    padding: 10px;
}

.slicer-search-box {
    margin-bottom: 10px;
}

.slicer-search-box input {
    width: 100% !important;
    padding: 8px !important;
    background: var(--card-bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    color: var(--text-primary) !important;
    font-size: 0.85rem !important;
}

.slicer-options {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--card-bg-secondary);
}

.slicer-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.slicer-option:hover {
    background: var(--dropdown-hover);
}

.slicer-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.slicer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-slicer-apply {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 4px 15px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-slicer-cancel {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #334155;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-slicer-apply:hover {
    opacity: 0.9;
}

.btn-slicer-cancel:hover {
    background: rgba(255, 255, 255, 0.05);
}