:root {
    --theme-bg: #f3f6f5;
    --theme-surface: #ffffff;
    --theme-surface-soft: #f7f9f8;
    --theme-ink: #17212b;
    --theme-muted: #687480;
    --theme-line: #e3e8e6;
    --theme-control: #ffffff;
}

.app-theme-toggle {
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid #cbd6d3;
    border-radius: 8px;
    background: #fff;
    color: #31544a;
    font: 700 .76rem/1 "Segoe UI", system-ui, sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: background .18s, border-color .18s, color .18s;
}

.app-theme-toggle--floating {
    position: fixed;
    z-index: 10000;
    right: 16px;
    bottom: 16px;
    box-shadow: 0 5px 18px rgba(13, 35, 29, .16);
}

.app-theme-toggle--menu {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 40px;
    padding: 10px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #3f4b55;
    font-size: .86rem;
    font-weight: 400;
    line-height: 1.2;
    text-align: left;
    box-shadow: none;
}

.app-theme-toggle--menu:hover { background:#f3f6f5; color:var(--ink); }

body:has(.app-theme-toggle--inline) > .app-theme-toggle--floating { display: none; }
html.app-embedded .app-theme-toggle { display: none !important; }

html[data-app-theme="dark"] {
    color-scheme: dark;
    --theme-bg: #0e1614;
    --theme-surface: #17211e;
    --theme-surface-soft: #13201c;
    --theme-ink: #e6efeb;
    --theme-muted: #9caea7;
    --theme-line: #31423d;
    --theme-control: #0f1916;
    --ink: var(--theme-ink);
    --muted: var(--theme-muted);
    --line: var(--theme-line);
    --surface: var(--theme-surface);
    --bg: var(--theme-bg);
    --background: var(--theme-bg);
    --brand: #43aa8f;
    --brand-dark: #2d806b;
    --brand-soft: #183a32;
    --rnc: #43aa8f;
    --rnc-dark: #256d5b;
    --rnc-soft: #183a32;
    --scrap: #4fa9ad;
    --scrap-dark: #70c0c4;
    --scrap-soft: #173538;
}

html[data-app-theme="dark"] body {
    background-color: var(--theme-bg) !important;
    color: var(--theme-ink);
}

html[data-app-theme="dark"] .navbar,
html[data-app-theme="dark"] footer,
html[data-app-theme="dark"] .topbar,
html[data-app-theme="dark"] .drawer,
html[data-app-theme="dark"] .card,
html[data-app-theme="dark"] .panel,
html[data-app-theme="dark"] .upload,
html[data-app-theme="dark"] .empty,
html[data-app-theme="dark"] .login-box,
html[data-app-theme="dark"] .senha-container,
html[data-app-theme="dark"] .summary-card:not(.main),
html[data-app-theme="dark"] .kpi:not(.main),
html[data-app-theme="dark"] .decision-item,
html[data-app-theme="dark"] .tax-item,
html[data-app-theme="dark"] .operation-card,
html[data-app-theme="dark"] .metric-card,
html[data-app-theme="dark"] .lane,
html[data-app-theme="dark"] .filter-card,
html[data-app-theme="dark"] .chart-card,
html[data-app-theme="dark"] .table-card {
    background-color: var(--theme-surface) !important;
    border-color: var(--theme-line) !important;
    color: var(--theme-ink);
    box-shadow: none;
}

html[data-app-theme="dark"] .filters,
html[data-app-theme="dark"] .analysis-filters,
html[data-app-theme="dark"] .source,
html[data-app-theme="dark"] .tools,
html[data-app-theme="dark"] .panel-head,
html[data-app-theme="dark"] .toolbar,
html[data-app-theme="dark"] .report-toolbar,
html[data-app-theme="dark"] .detail-toolbar,
html[data-app-theme="dark"] .drawer-footer,
html[data-app-theme="dark"] .volume-item {
    background-color: var(--theme-surface-soft) !important;
    border-color: var(--theme-line) !important;
    color: var(--theme-ink);
}

html[data-app-theme="dark"] input,
html[data-app-theme="dark"] select,
html[data-app-theme="dark"] textarea,
html[data-app-theme="dark"] .form-control,
html[data-app-theme="dark"] .form-select {
    background-color: var(--theme-control) !important;
    border-color: #40534d !important;
    color: var(--theme-ink) !important;
}

html[data-app-theme="dark"] input::placeholder,
html[data-app-theme="dark"] textarea::placeholder { color: #81928c !important; }

html[data-app-theme="dark"] .app-theme-toggle,
html[data-app-theme="dark"] .theme-toggle,
html[data-app-theme="dark"] .link-button,
html[data-app-theme="dark"] .back,
html[data-app-theme="dark"] .btn-voltar,
html[data-app-theme="dark"] .panel-trigger {
    background: #1b2925 !important;
    border-color: #40534d !important;
    color: #d9e7e2 !important;
}

html[data-app-theme="dark"] a:not(.button):not(.btn):not(.logout) { color: #72c9b1; }
html[data-app-theme="dark"] .navbar-brand,
html[data-app-theme="dark"] .nav-link,
html[data-app-theme="dark"] h1,
html[data-app-theme="dark"] h2,
html[data-app-theme="dark"] h3,
html[data-app-theme="dark"] strong { color: inherit; }
html[data-app-theme="dark"] .text-muted,
html[data-app-theme="dark"] .muted,
html[data-app-theme="dark"] .subtitle { color: var(--theme-muted) !important; }
html[data-app-theme="dark"] .border,
html[data-app-theme="dark"] .border-top,
html[data-app-theme="dark"] .border-bottom { border-color: var(--theme-line) !important; }

html[data-app-theme="dark"] th {
    background-color: #1d2a26 !important;
    border-color: var(--theme-line) !important;
    color: #aebdb7 !important;
}
html[data-app-theme="dark"] td { border-color: #2b3a36 !important; }
html[data-app-theme="dark"] tbody tr:hover > td { background-color: #1b2a26; }
html[data-app-theme="dark"] .bar-track,
html[data-app-theme="dark"] .track,
html[data-app-theme="dark"] .month-column { background-color: #293632 !important; }

html[data-app-theme="dark"] .notice,
html[data-app-theme="dark"] .status-alert,
html[data-app-theme="dark"] .filter-empty { background:#332b18 !important; border-color:#6b582b !important; color:#f1d18a !important; }
html[data-app-theme="dark"] .error,
html[data-app-theme="dark"] .alert-error,
html[data-app-theme="dark"] .validation-summary-errors { background:#351d20 !important; border-color:#6d353a !important; color:#f0a1a7 !important; }
html[data-app-theme="dark"] .success,
html[data-app-theme="dark"] .alert-success { background:#193e33 !important; border-color:#286b58 !important; color:#8de0c2 !important; }

/* Portal navigation: preserve hierarchy and readable interaction states. */
html[data-app-theme="dark"] .drawer-backdrop.open { background:rgba(2,9,7,.66); }
html[data-app-theme="dark"] .drawer { box-shadow:18px 0 50px rgba(0,0,0,.42); }
html[data-app-theme="dark"] .drawer-header { border-color:var(--theme-line); }
html[data-app-theme="dark"] .drawer-title span,
html[data-app-theme="dark"] .section-label { color:#91a69e; }
html[data-app-theme="dark"] .drawer-content::-webkit-scrollbar-thumb { background:#40534d; }
html[data-app-theme="dark"] .search-box {
    background:#0f1916;
    border-color:#40534d;
    color:#91a69e;
}
html[data-app-theme="dark"] .search-box:focus-within {
    background:#13221e;
    border-color:#43aa8f;
    box-shadow:0 0 0 3px rgba(67,170,143,.16);
}
html[data-app-theme="dark"] .icon-button,
html[data-app-theme="dark"] .user-trigger { color:#aebdb7; }
html[data-app-theme="dark"] .icon-button:hover,
html[data-app-theme="dark"] .icon-button:focus-visible,
html[data-app-theme="dark"] .user-trigger:hover,
html[data-app-theme="dark"] .user-trigger:focus-visible { background:#20302b; color:#eef7f3; }
html[data-app-theme="dark"] .category[open] {
    background:#13201c;
    border-color:#31423d;
}
html[data-app-theme="dark"] .category summary:hover,
html[data-app-theme="dark"] .menu-item:hover,
html[data-app-theme="dark"] .quick-item:hover { background:#20302b; }
html[data-app-theme="dark"] .category .icon { background:#183a32; color:#63c4a9; }
html[data-app-theme="dark"] .category-count,
html[data-app-theme="dark"] .chevron { color:#91a69e; }
html[data-app-theme="dark"] .menu-item,
html[data-app-theme="dark"] .quick-item { color:#dfeae6; }
html[data-app-theme="dark"] .menu-item.active {
    background:#1b3b32;
    border-left-color:#58bea2;
    color:#f1faf7;
}
html[data-app-theme="dark"] .menu-description,
html[data-app-theme="dark"] .quick-copy small { color:#9caea7; }
html[data-app-theme="dark"] .star-button { color:#74877f; }
html[data-app-theme="dark"] .star-button:hover { background:#273832; color:#e0ad48; }
html[data-app-theme="dark"] .star-button.favorite { color:#e0ad48; }
html[data-app-theme="dark"] .drawer-footer a { color:#b8c9c2; }
html[data-app-theme="dark"] .drawer-footer a:hover { background:#20302b; color:#73cdb4; }
html[data-app-theme="dark"] .user-dropdown {
    background:#17211e;
    border-color:#40534d;
    box-shadow:0 16px 42px rgba(0,0,0,.38);
}
html[data-app-theme="dark"] .user-dropdown a:not(.logout) { color:#d5e2dd; }
html[data-app-theme="dark"] .user-dropdown a:hover { background:#20302b; color:#eef7f3; }
html[data-app-theme="dark"] .user-dropdown .logout { color:#f08c93; }
html[data-app-theme="dark"] .app-theme-toggle--menu { background:transparent !important; border:0 !important; color:#d5e2dd !important; }
html[data-app-theme="dark"] .app-theme-toggle--menu:hover { background:#20302b !important; color:#eef7f3 !important; }

/* Scrap explorer uses a dense, page-specific visual language. */
html[data-app-theme="dark"] .scrap-dashboard {
    color:#e7f0ed;
    --success:#55c590;
    --danger:#ef7972;
}
html[data-app-theme="dark"] .scrap-dashboard .title-block h1 { color:#f0f7f4; }
html[data-app-theme="dark"] .scrap-dashboard .title-block p,
html[data-app-theme="dark"] .scrap-dashboard .filter-field label,
html[data-app-theme="dark"] .scrap-dashboard .kpi-label,
html[data-app-theme="dark"] .scrap-dashboard .kpi-note,
html[data-app-theme="dark"] .scrap-dashboard .panel-head span,
html[data-app-theme="dark"] .scrap-dashboard .day-label,
html[data-app-theme="dark"] .scrap-dashboard .center-note,
html[data-app-theme="dark"] .scrap-dashboard .empty,
html[data-app-theme="dark"] .scrap-dashboard .donut-hole span { color:#94aaa2; }
html[data-app-theme="dark"] .scrap-dashboard .kpi-value { color:#f1f8f5; }
html[data-app-theme="dark"] .scrap-dashboard .kpi-value.good { color:#55c590; }
html[data-app-theme="dark"] .scrap-dashboard .kpi-value.bad { color:#ef7972; }
html[data-app-theme="dark"] .scrap-dashboard .kpi-value.neutral { color:#b4c5bf; }
html[data-app-theme="dark"] .scrap-dashboard .insight {
    background:#14383a;
    border-color:#438387;
    color:#bfe1df;
}
html[data-app-theme="dark"] .scrap-dashboard .insight strong { color:#effaf8; }
html[data-app-theme="dark"] .scrap-dashboard .insight-mark { background:#39a8ae; color:#071716; }
html[data-app-theme="dark"] .scrap-dashboard .filter-actions a {
    background:#21302c;
    border:1px solid #40534d;
    color:#c9d8d3;
}
html[data-app-theme="dark"] .scrap-dashboard .filter-actions a:hover { background:#293b35; color:#eff8f5; }
html[data-app-theme="dark"] .scrap-dashboard .day-value { color:#c4d4cf; }
html[data-app-theme="dark"] .scrap-dashboard .center-name { color:#dce9e5; }
html[data-app-theme="dark"] .scrap-dashboard .center-value { color:#f2f8f6; }
html[data-app-theme="dark"] .scrap-dashboard .center-share { color:#a9c3bb; }
html[data-app-theme="dark"] .scrap-dashboard .center-row:hover,
html[data-app-theme="dark"] .scrap-dashboard .center-row:focus {
    background:#1c332d;
    border-color:#3f7569;
}
html[data-app-theme="dark"] .scrap-dashboard .center-row:hover .center-name,
html[data-app-theme="dark"] .scrap-dashboard .center-row:focus .center-name { color:#70d0b6; }
html[data-app-theme="dark"] .scrap-dashboard .donut-area { border-color:#31423d; }
html[data-app-theme="dark"] .scrap-dashboard .pie-slice { stroke:#17211e; }
html[data-app-theme="dark"] .scrap-dashboard .donut-hole {
    background:#17211e;
    box-shadow:0 0 0 1px #40534d;
    color:#edf6f3;
}
html[data-app-theme="dark"] .scrap-dashboard tr.reason-excluded { background:#111b18; opacity:.68; }
html[data-app-theme="dark"] .scrap-dashboard tr.reason-excluded:hover { background:#1b2925; opacity:.9; }
html[data-app-theme="dark"] .scrap-dashboard .reason-selector-box {
    background:#0f1916;
    border-color:#637a72;
}
html[data-app-theme="dark"] .scrap-dashboard .reason-selector-input:checked + .reason-selector-box {
    background:#43aa8f;
    border-color:#43aa8f;
}
html[data-app-theme="dark"] .scrap-dashboard .detail-link,
html[data-app-theme="dark"] .scrap-dashboard .order-link { color:#70d0b6; text-decoration-color:#3f7569; }
html[data-app-theme="dark"] .scrap-dashboard .order-link:hover,
html[data-app-theme="dark"] .scrap-dashboard .order-link:focus { color:#f09a79; text-decoration-color:#f09a79; }
html[data-app-theme="dark"] .scrap-dashboard .share { color:#a8bbb5; }

/* Scrap order drill-through report. */
html[data-app-theme="dark"] .order-report { color:#dce8e4; }
html[data-app-theme="dark"] .order-report .heading h1,
html[data-app-theme="dark"] .order-report .total strong { color:#f1f8f5; }
html[data-app-theme="dark"] .order-report .heading span,
html[data-app-theme="dark"] .order-report .total span,
html[data-app-theme="dark"] .order-report .metric span,
html[data-app-theme="dark"] .order-report .empty { color:#98aca5; }
html[data-app-theme="dark"] .order-report .back {
    background:#172722;
    border-color:#577068;
    color:#d5e4df;
}
html[data-app-theme="dark"] .order-report .back:hover { background:#21352e; border-color:#70b9a5; color:#fff; }
html[data-app-theme="dark"] .order-report .tab {
    background:#18241f;
    border-color:#40534d;
    color:#c8d7d2;
}
html[data-app-theme="dark"] .order-report .tab:hover { background:#21332d; border-color:#577068; }
html[data-app-theme="dark"] .order-report .tab.active {
    background:#43aa8f;
    border-color:#43aa8f;
    color:#071713;
}
html[data-app-theme="dark"] .order-report .operation {
    background:#17211e;
    border-color:#40534d;
    box-shadow:0 2px 10px rgba(0,0,0,.18);
}
html[data-app-theme="dark"] .order-report .operation-head { background:#192622; border-color:#31423d; }
html[data-app-theme="dark"] .order-report .operation-title h2 { color:#edf6f3; }
html[data-app-theme="dark"] .order-report .operation-center {
    background:#173b33;
    border-color:#356f61;
    color:#8bdec6;
}
html[data-app-theme="dark"] .order-report .metric { border-color:#40534d; }
html[data-app-theme="dark"] .order-report .metric strong { color:#edf6f3; }
html[data-app-theme="dark"] .order-report .metric-scrap strong,
html[data-app-theme="dark"] .order-report .scrap-value { color:#ff9278; }
html[data-app-theme="dark"] .order-report td { color:#c8d7d2; background:#17211e; }
html[data-app-theme="dark"] .order-report tbody tr:hover > td { background:#20332d; color:#eef7f4; }

/* Purchases and consumption product matrix. */
html[data-app-theme="dark"] .report-page .context span {
    background:#193a32;
    border:1px solid #35695c;
    color:#9addca;
}
html[data-app-theme="dark"] .report-page .badge-muted {
    background:#273832;
    color:#c7d7d1;
}
html[data-app-theme="dark"] .report-page .products-table tbody tr:hover > td {
    background:#20302b;
    color:#eff7f4;
}
html[data-app-theme="dark"] .report-page .matrix-table tfoot td {
    background:#20342d;
    border-top:2px solid #5d8075 !important;
    color:#f1f8f5;
}
html[data-app-theme="dark"] .report-page .stock-warning {
    background:#332b18;
    border-color:#80672d;
    color:#f2d58e;
}

/* The login artwork is intentionally atmospheric in both modes. */
html[data-app-theme="light"] .login-page .login-box { color:#f7fbff; }
html[data-app-theme="dark"] .login-page::after { background:rgba(1,8,18,.7); }

@media print {
    .app-theme-toggle { display:none !important; }
}

@media (max-width: 600px) {
    .app-theme-toggle--floating { right:10px; bottom:10px; }
}
