/* ============================================================
   CONTROLE DE ESTOQUE 3D - Design System Premium
   Dark Mode + Glassmorphism
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;500&display=swap');

/* --- Variáveis --- */
:root {
    --bg-base: #0a0b0f;
    --bg-surface: #12141a;
    --bg-card: #1a1d27;
    --bg-card-hover: #1e2230;
    --bg-input: #0e1018;
    --bg-sidebar: #0d0f16;

    --primary: #895af6;
    --primary-light: #9f76fb;
    --primary-glow: rgba(137, 90, 246, 0.3);

    --accent: #06b6d4;
    --accent-light: #22d3ee;
    --accent-glow: rgba(6, 182, 212, 0.25);

    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.25);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.25);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.25);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #475569;

    --border: rgba(255, 255, 255, 0.07);
    --border-focus: rgba(137, 90, 246, 0.5);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--primary-glow);

    --sidebar-width: 240px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Tema Claro --- */
[data-theme="light"] {
    --bg-base: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-input: #ffffff;
    --bg-sidebar: #ffffff;

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --border: #e2e8f0;
    --border-focus: rgba(137, 90, 246, 0.3);

    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(137, 90, 246, 0.1);

    /* Opcional: ajustar cores de contraste de botões fantasma no claro */
    --primary-glow: rgba(137, 90, 246, 0.15);
    --accent-glow: rgba(6, 182, 212, 0.15);
    --success-glow: rgba(16, 185, 129, 0.15);
    --warning-glow: rgba(245, 158, 11, 0.15);
    --danger-glow: rgba(239, 68, 68, 0.15);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

/* Utilitário global — usado pelo JavaScript para esconder elementos */
.hidden {
    display: none !important;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: var(--transition);
}

.sidebar-logo {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo .logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 0 20px var(--primary-glow);
    flex-shrink: 0;
}

.sidebar-logo h1 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.sidebar-logo span {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 16px 8px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    position: relative;
    margin-bottom: 2px;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.2), rgba(6, 182, 212, 0.05));
    color: var(--primary-light);
    border-left: 2px solid var(--primary);
}

.nav-item .nav-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 99px;
    min-width: 20px;
    text-align: center;
}

.nav-item .badge.hidden {
    display: none;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    min-width: 0;
}

.topbar {
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.topbar-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.page-content {
    padding: 32px;
    flex: 1;
    min-width: 0;
}

/* ============================================================
   SECTIONS
   ============================================================ */
.section {
    display: none;
    width: 100%;
    min-width: 0;
    max-width: 100vw;
}

.section.active {
    display: block;
}

/* ============================================================
   CARDS & KPIs
   ============================================================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
    cursor: default;
}

.kpi-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.kpi-card.alert {
    border-color: var(--danger);
    box-shadow: 0 0 20px var(--danger-glow);
}

.kpi-card.success {
    border-color: var(--success);
    box-shadow: 0 0 20px var(--success-glow);
}

.kpi-card.warning {
    border-color: var(--warning);
    box-shadow: 0 0 20px var(--warning-glow);
}

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.kpi-icon.purple {
    background: rgba(124, 58, 237, 0.2);
}

.kpi-icon.cyan {
    background: rgba(6, 182, 212, 0.2);
}

.kpi-icon.green {
    background: rgba(16, 185, 129, 0.2);
}

.kpi-icon.red {
    background: rgba(239, 68, 68, 0.2);
}

.kpi-icon.yellow {
    background: rgba(245, 158, 11, 0.2);
}

.kpi-data {
    flex: 1;
    min-width: 0;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ============================================================
   ALERTS BANNER
   ============================================================ */
.alert-banner {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.15), rgba(245, 158, 11, 0.1));
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 14px 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.alert-banner.hidden {
    display: none;
}

.alert-banner-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.alert-banner-body {
    flex: 1;
}

.alert-banner-title {
    font-weight: 700;
    color: var(--danger);
    font-size: 14px;
    margin-bottom: 6px;
}

.alert-banner-items {
    list-style: none;
}

.alert-banner-items li {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 2px 0;
}

.alert-banner-items li::before {
    content: '• ';
    color: var(--danger);
}

/* ============================================================
   TABLE
   ============================================================ */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.table-title {
    font-size: 16px;
    font-weight: 700;
}

.table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead tr {
    background: rgba(255, 255, 255, 0.03);
}

thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

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

tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

tbody td {
    padding: 14px 16px;
    color: var(--text-secondary);
    vertical-align: middle;
}

tbody td .cell-primary {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 2px;
}

tbody td .cell-sub {
    font-size: 12px;
    color: var(--text-muted);
}

/* Barra de progresso de estoque */
.stock-bar-wrap {
    min-width: 100px;
}

.stock-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}

.stock-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.stock-bar-fill.ok {
    background: linear-gradient(90deg, var(--success), var(--accent));
}

.stock-bar-fill.baixo {
    background: linear-gradient(90deg, var(--warning), #fb923c);
}

.stock-bar-fill.critico {
    background: linear-gradient(90deg, var(--danger), var(--warning));
}

.stock-bar-fill.esgotado {
    background: var(--text-muted);
}

.stock-pct {
    font-size: 12px;
    font-weight: 700;
}

.stock-pct.ok {
    color: var(--success);
}

.stock-pct.baixo {
    color: var(--warning);
}

.stock-pct.critico {
    color: var(--danger);
}

.stock-pct.esgotado {
    color: var(--text-muted);
}

/* Status badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.status-badge.baixo {
    background: var(--warning-glow);
    color: var(--warning);
}

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

.status-badge.esgotado {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 0 20px var(--primary-glow);
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 0 30px var(--primary-glow);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: white;
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-accent:hover {
    opacity: 0.9;
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #34d399);
    color: white;
    box-shadow: 0 0 20px var(--success-glow);
}

.btn-success:hover {
    opacity: 0.9;
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

.btn-icon {
    padding: 8px;
}

/* ============================================================
   FORMS & INPUTS
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full {
    grid-column: 1 / -1;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-label span {
    color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-select option {
    background: var(--bg-card);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Input com unidade */
.input-group {
    position: relative;
    display: flex;
}

.input-group .form-input {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.input-addon {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-left: none;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    display: flex;
    align-items: center;
}

/* Barra de filtro */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-bar .form-input {
    max-width: 280px;
}

.filter-bar .form-select {
    max-width: 180px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modal-in 0.2s ease;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 24px 28px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

.modal-body {
    padding: 24px 28px;
}

.modal-footer {
    padding: 16px 28px 24px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ============================================================
   CALCULADORA CARD
   ============================================================ */
.calc-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 32px;
    max-width: 600px;
}

.calc-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 4px;
}

.calc-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.calc-result {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.3);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 20px;
    display: none;
}

.calc-result.show {
    display: block;
}

.calc-result-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 12px;
}

.calc-result-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.calc-result-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--primary-light);
}

.calc-result-value.danger {
    color: var(--danger);
}

/* ============================================================
   SECTION HEADERS
   ============================================================ */
.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
}

.section-sub {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state .empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state .empty-sub {
    font-size: 13px;
}

/* ============================================================
   LOADING
   ============================================================ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 420px;
    box-shadow: var(--shadow);
    animation: toast-in 0.3s ease;
    font-size: 14px;
    font-weight: 500;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.warning {
    border-left: 3px solid var(--warning);
}

.toast.info {
    border-left: 3px solid var(--accent);
}

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast-msg {
    flex: 1;
    color: var(--text-primary);
}

.toast-close {
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
}

.toast-close:hover {
    color: var(--text-primary);
}

/* ============================================================
   CONFIG SCREEN
   ============================================================ */
.config-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px;
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.config-icon {
    font-size: 52px;
    margin-bottom: 20px;
}

.config-title {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 8px;
}

.config-sub {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.config-steps {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    text-align: left;
    margin-bottom: 28px;
}

.config-steps ol {
    padding-left: 20px;
}

.config-steps li {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0;
    line-height: 1.6;
}

.config-steps li strong {
    color: var(--primary-light);
}

.config-steps li a {
    color: var(--accent);
}

.config-form {
    text-align: left;
}

/* ============================================================
   HISTORICO
   ============================================================ */
.hist-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hist-type-badge.consumo {
    background: rgba(124, 58, 237, 0.2);
    color: var(--primary-light);
}

.hist-type-badge.reposicao {
    background: var(--success-glow);
    color: var(--success);
}

.hist-type-badge.perda {
    background: var(--danger-glow);
    color: var(--danger);
}

.hist-type-badge.ajuste {
    background: var(--warning-glow);
    color: var(--warning);
}

/* ============================================================
   COLOR DOT
   ============================================================ */
.color-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    vertical-align: middle;
    margin-right: 6px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main {
        margin-left: 0;
    }

    .page-content {
        padding: 20px 16px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .mobile-menu-btn {
        display: flex !important;
    }

    .topbar {
        padding: 10px 12px;
        height: auto;
        min-height: 64px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .topbar-title {
        font-size: 16px;
    }

    .topbar>div:first-child {
        min-width: 100px;
        align-items: center;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
}

/* Overlay mobile */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
}

.sidebar-overlay.open {
    display: block;
}

/* ============================================================
   TAGS DE TEMPERATURA
   ============================================================ */
.temp-tag {
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    background: rgba(6, 182, 212, 0.1);
    color: var(--accent);
    padding: 2px 7px;
    border-radius: 4px;
    display: inline-block;
}

/* ============================================================
   PROGRESSÃO DO DASHBOARD
   ============================================================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.dash-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
}

.dash-widget-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Linha de item nos widgets */
.widget-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.widget-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.widget-row-icon {
    font-size: 18px;
    width: 30px;
    text-align: center;
    flex-shrink: 0;
}

.widget-row-body {
    flex: 1;
    min-width: 0;
}

.widget-row-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-row-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.widget-row-right {
    text-align: right;
    flex-shrink: 0;
}

/* Segurança */
input[type=number]::-webkit-inner-spin-button {
    opacity: 0.5;
}

/* PWA Install Banner */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================================
   BOTTOM NAVIGATION BAR (MOBILE ONLY)
   ============================================================ */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    background: rgba(18, 20, 26, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
    padding: 12px 8px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
}

.bottom-nav-item.active {
    color: var(--primary);
    font-weight: 700;
}

.bottom-nav-item .bottom-nav-icon {
    font-size: 20px;
}

.bottom-nav-item.active .bottom-nav-icon {
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
    }

    body {
        padding-bottom: 90px !important;
    }

    .main-content {
        padding-bottom: 30px !important;
    }
}

/* ============================================================
   RELATÓRIOS - STITCH UI COMPONENTS
   ============================================================ */
.relatórios-pills-container {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
    width: 100%;
    max-width: 100%;
    /* Firefox */
}

.relatórios-pills-container::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.rel-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    height: 36px;
    border-radius: 99px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: var(--transition);
}

.rel-pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.rel-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.rel-kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.02);
    min-width: 0;
    word-wrap: break-word;
}

.rel-kpi-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.rel-kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.rel-kpi-trend {
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.rel-kpi-trend.up {
    color: var(--success);
}

.rel-kpi-trend.down {
    color: var(--danger);
}

.rel-kpi-trend.neutral {
    color: var(--text-muted);
}

.rel-section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    padding: 0 4px;
}

.rel-card-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}

/* ============================================================
   AJUSTES (CONFIGURAÇÕES) MOBILE
   ============================================================ */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
    text-decoration: none;
}

.settings-item:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.settings-item-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings-item-icon {
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.settings-item-title {
    font-weight: 600;
    font-size: 15px;
}

.settings-item-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.settings-item-right {
    color: var(--text-muted);
}

.rel-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.rel-list-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.rel-list-item:first-child {
    padding-top: 0;
}

.rel-progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    margin-top: 8px;
    overflow: hidden;
}

.rel-progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 1s ease-in-out;
}

.rel-cat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================================
   MATERIAIS CARD GRID
   ============================================================ */
.materiais-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding-bottom: 24px;
}

.materiais-card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, .06);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.materiais-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.materiais-card-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
    line-height: 1.3;
}

.materiais-card-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.materiais-card-badge {
    position: absolute;
    top: 16px;
    right: 16px;
}

.materiais-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    background: rgba(0, 0, 0, 0.15);
    padding: 12px;
    border-radius: 10px;
    margin-top: auto;
}

.materiais-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.materiais-card-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.materiais-card-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.materiais-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.rel-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

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

.rel-kpi-body {
    flex: 1;
    min-width: 0;
}

.rel-kpi-value {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rel-kpi-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.rel-kpi-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 30% 40%, rgba(124, 58, 237, .18) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 60%, rgba(6, 182, 212, .12) 0%, transparent 60%),
        var(--bg-base);
    backdrop-filter: blur(2px);
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid rgba(124, 58, 237, .3);
    border-radius: 20px;
    padding: 40px 36px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .04);
    animation: loginFadeIn .35s ease;
}

@keyframes loginFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}

.login-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .08), transparent);
    margin-bottom: 28px;
}

.login-error {
    background: rgba(239, 68, 68, .12);
    border: 1px solid rgba(239, 68, 68, .35);
    border-radius: var(--radius);
    color: #fca5a5;
    font-size: 13px;
    padding: 10px 14px;
    margin-bottom: 16px;
    line-height: 1.4;
}

/* =========================================
   # HISTÓRICO (FEED / EXTRATO)
   ========================================= */
.historico-feed {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.historico-item {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s ease;
}

.historico-item:last-child {
    border-bottom: none;
}

.historico-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.historico-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}

.historico-icon.consumo {
    border: 1px solid rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

.historico-icon.perda {
    border: 1px solid rgba(255, 71, 87, 0.2);
    color: #ff4757;
}

.historico-icon.reposicao {
    border: 1px solid rgba(46, 213, 115, 0.2);
    color: #2ed573;
}

.historico-icon.ajuste {
    border: 1px solid rgba(255, 165, 2, 0.2);
    color: #ffa502;
}

.historico-content {
    flex: 1;
    min-width: 0;
}

.historico-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.historico-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.historico-meta {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-light);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.historico-obs {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.historico-value-group {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.historico-value {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.historico-value.positivo {
    color: #2ed573;
}

.historico-value.negativo {
    color: #ff6b6b;
}

.historico-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}