:root {
    --bg: #e8ecf8;
    --bg-gradient: radial-gradient(1200px circle at 18% -10%, rgba(99, 102, 241, 0.22), transparent 45%),
        radial-gradient(900px circle at 100% 0%, rgba(20, 184, 166, 0.14), transparent 40%),
        #e8ecf8;
    --card: #ffffff;
    --surface-2: rgba(255, 255, 255, 0.72);
    --text: #131722;
    --muted: #64748b;
    --border: #d5ddeb;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #14b8a6;
    --danger: #dc2626;
    --warn-bg: #fef9c3;
    --warn-border: #facc15;
    --min-bg: rgba(20, 184, 166, 0.12);
    --min-border: #14b8a6;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 10px 36px rgba(15, 23, 42, 0.1);
    --radius: 12px;
    --ease: cubic-bezier(0.33, 1, 0.68, 1);
    --focus: 0 0 0 3px rgba(99, 102, 241, 0.38);
}

.theme-dark {
    --bg: #0b1020;
    --bg-gradient: radial-gradient(900px circle at 10% 0%, rgba(129, 140, 248, 0.2), transparent 50%),
        radial-gradient(700px circle at 110% 30%, rgba(45, 212, 191, 0.08), transparent 45%),
        #0b1020;
    --card: #121a2f;
    --surface-2: rgba(18, 26, 47, 0.88);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #2a3548;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --accent: #2dd4bf;
    --danger: #fb7185;
    --warn-bg: #422006;
    --warn-border: #fbbf24;
    --min-bg: rgba(45, 212, 191, 0.12);
    --min-border: #2dd4bf;
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 22px 50px rgba(0, 0, 0, 0.45);
    --radius: 12px;
    --ease: cubic-bezier(0.33, 1, 0.68, 1);
    --focus: 0 0 0 3px rgba(129, 140, 248, 0.45);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    line-height: 1.45;
    min-height: 100vh;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.18s var(--ease), text-decoration-color 0.18s var(--ease);
}
a:hover {
    text-decoration: underline;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 230px;
    background: linear-gradient(180deg, var(--surface-2), var(--card));
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem 1rem 1.1rem;
    box-shadow: var(--shadow-md);
}

.brand {
    font-weight: 800;
    font-size: 1.08rem;
    margin-bottom: 1rem;
    letter-spacing: 0.03em;
    background: linear-gradient(120deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.nav a,
.nav-link {
    padding: 0.52rem 0.65rem;
    border-radius: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.92rem;
    transition: transform 0.16s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}
.nav a:hover,
.nav-link:hover {
    background: rgba(99, 102, 241, 0.1);
    text-decoration: none;
    transform: translateX(2px);
}

.nav-link-active {
    font-weight: 700;
    color: var(--primary) !important;
    background: linear-gradient(105deg, rgba(99, 102, 241, 0.18), rgba(20, 184, 166, 0.1)) !important;
    border: 1px solid rgba(99, 102, 241, 0.22);
}
.theme-dark .nav-link-active {
    background: linear-gradient(105deg, rgba(129, 140, 248, 0.18), rgba(45, 212, 191, 0.1)) !important;
    border-color: rgba(129, 140, 248, 0.28);
}

.sidebar-foot {
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.link-out {
    color: var(--muted);
}

.main {
    flex: 1;
    padding: 1.5rem 2rem;
    max-width: 1400px;
}

.page-head h1 {
    margin: 0 0 0.25rem;
    font-size: 1.5rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.muted {
    color: var(--muted);
    margin: 0;
}

.small {
    font-size: 0.85rem;
}

.card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem 1.35rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease), border-color 0.28s var(--ease);
}
.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.mt {
    margin-top: 1rem;
}

.mb {
    margin-bottom: 1rem;
}

.alert {
    padding: 0.7rem 0.92rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    animation: slideIn 0.4s var(--ease);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.alert-ok {
    background: #ecfdf3;
    border: 1px solid #bbf7d0;
    color: #166534;
}
.theme-dark .alert-ok {
    background: #064e3b;
    border-color: #34d399;
    color: #d1fae5;
}
.alert-err {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}
.theme-dark .alert-err {
    background: #450a0a;
    border-color: #f87171;
    color: #fee2e2;
}

.alert-warn {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    color: #854d0e;
}
.theme-dark .alert-warn {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: #fde68a;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.54rem 1.05rem;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: transform 0.14s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease),
        border-color 0.2s var(--ease);
}
.btn:active {
    transform: scale(0.98);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    box-shadow: 0 10px 24px rgba(99, 102, 241, 0.32);
    color: #fff;
}
.btn-primary:hover {
    filter: brightness(1.06);
}

.btn-secondary {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.form-stack label,
.form-grid label,
form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.88rem;
    font-weight: 600;
}

input[type="text"],
input[type="search"],
input[type="password"],
input[type="file"],
select,
textarea {
    padding: 0.54rem 0.72rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s var(--ease), box-shadow 0.22s var(--ease), transform 0.14s var(--ease);
}

input:not([type="file"]):focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus);
}

.field-hint {
    margin-top: 0.35rem;
    font-weight: 500;
}

.input-valid {
    border-color: rgba(20, 184, 166, 0.7) !important;
    box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.45);
}

.theme-dark .input-valid {
    border-color: rgba(45, 212, 191, 0.65) !important;
}

.input-invalid {
    border-color: rgba(239, 68, 68, 0.9) !important;
    animation: shake 0.35s ease;
}

@keyframes shake {
    25% {
        transform: translateX(-3px);
    }
    50% {
        transform: translateX(3px);
    }
    75% {
        transform: translateX(-2px);
    }
}

.form-grid {
    display: grid;
    gap: 1rem;
}
.form-grid.cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.form-grid.cols-3 {
    grid-template-columns: 2fr 2fr 1fr;
    align-items: end;
}
.form-grid .full {
    grid-column: 1 / -1;
}

.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.form-inline.wrap {
    align-items: flex-end;
}

.align-end {
    display: flex;
    align-items: flex-end;
}

.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.table th,
.table td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.table th {
    font-weight: 600;
    background: rgba(99, 102, 241, 0.06);
}

.theme-dark .table th {
    background: rgba(129, 140, 248, 0.1);
}

.table tbody tr {
    transition: background 0.18s var(--ease);
}

.table tbody tr:hover td {
    background: rgba(99, 102, 241, 0.055);
}

.theme-dark .table tbody tr:hover td {
    background: rgba(129, 140, 248, 0.08);
}
.col-actions {
    white-space: nowrap;
    width: 90px;
}

.col-thumb {
    width: 52px;
}
.thumb {
    display: block;
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem;
}
.btn-icon.danger {
    color: var(--danger);
}

.inline-form {
    display: inline;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.52rem 0.92rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s var(--ease), box-shadow 0.25s var(--ease);
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: var(--focus);
}
.search-bar input {
    flex: 1;
    border: none;
    background: transparent;
}
.search-ico {
    opacity: 0.6;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.82rem;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.stat-num {
    font-size: 1.75rem;
    font-weight: 700;
}
.stat-label {
    color: var(--muted);
    font-size: 0.88rem;
}

.tree-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    overflow: hidden;
}
.tree-parent {
    padding: 0.6rem 0.85rem;
    background: var(--bg);
}
.tree-children {
    margin: 0;
    padding: 0.35rem 0.85rem 0.65rem 1.5rem;
    list-style: disc;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    width: 100%;
    max-width: 412px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.25rem;
    box-shadow: var(--shadow-md);
    animation: fadeUp 0.55s var(--ease);
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
.login-card h1 {
    margin-top: 0;
    font-size: 1.35rem;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.hidden {
    display: none;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
}
.modal-box {
    position: relative;
    background: var(--surface-2);
    border-radius: 16px;
    padding: 1.35rem 1.65rem;
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    z-index: 51;
    animation: modalIn 0.32s var(--ease);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
.modal-wide {
    max-width: 720px;
}
.modal-x {
    position: absolute;
    top: 0.5rem;
    right: 0.65rem;
    border: none;
    background: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    border-radius: 8px;
    transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.modal-x:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.prices-block {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.prices-title {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.prices-title .ico {
    color: var(--primary);
    font-weight: 700;
}

.supplier-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.supplier-row {
    display: grid;
    grid-template-columns: 1fr minmax(120px, 140px) 1fr;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.9rem;
}
.sup-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.money-in {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
}
.money-in input {
    width: 100%;
    max-width: 110px;
}
.sale-hint {
    font-size: 0.82rem;
    color: var(--muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.table-scroll {
    overflow-x: auto;
}
.table-compact th,
.table-compact td {
    font-size: 0.82rem;
}
.th-sup {
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.subhead th {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--muted);
}
.subhead .tiny {
    font-size: 0.7rem;
}
.price-stack {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.tiny {
    font-size: 0.75rem;
}
.cell-min {
    background: var(--min-bg);
    outline: 1px solid var(--min-border);
}

.report-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.report-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .nav {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .supplier-row {
        grid-template-columns: 1fr;
    }
}

/* — Painel premium / busca / glass UI — */
.role-pill {
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.28rem 0.52rem;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.32);
    margin-bottom: 0.55rem;
    display: inline-block;
}
.top-toolbar.glass-bar {
    position: sticky;
    top: 0;
    z-index: 40;
}
.glass-bar {
    backdrop-filter: blur(12px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.62rem 0.92rem;
    margin-bottom: 1.35rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.global-search-form {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 1;
    min-width: 210px;
}
.global-search-form input[type='search'] {
    flex: 1;
    min-width: 160px;
    border-radius: 12px !important;
}
.btn-sm {
    padding: 0.32rem 0.72rem !important;
    font-size: 0.82rem !important;
}
.search-suggest-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    z-index: 50;
    max-height: 240px;
    overflow-y: auto;
}
.theme-dark .search-suggest-panel {
    background: var(--surface-2);
}
.search-suggest-item {
    width: 100%;
    padding: 0.45rem 0.72rem;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text);
}
.search-suggest-item:hover {
    background: rgba(99, 102, 241, 0.09);
}
.gqs-ico {
    opacity: 0.55;
}
.grid-2-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}
.premium-hero {
    backdrop-filter: blur(14px);
    background: var(--surface-2);
    border-radius: 16px;
    padding: 1.4rem 1.6rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.hero-lead {
    margin: 0.45rem 0 0;
    font-size: 1.06rem;
    color: var(--muted);
}
.kbd-hint {
    margin-top: 1rem;
    display: inline-block;
    font-size: 0.82rem;
}
.kbd-hint kbd {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.12rem 0.35rem;
}
.layout-dashboard {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.35rem;
    align-items: start;
}
.chart-canvas-wrap {
    position: relative;
    height: 280px;
    margin-top: 0.85rem;
}
.elevation-lg {
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
}
.elevation-md {
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}
.rank-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.rank-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.tag {
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.78rem;
}
.tag-ok {
    background: rgba(34, 197, 94, 0.15);
    color: #166534;
}
.tag-down {
    background: rgba(16, 185, 129, 0.2);
    color: #065f46;
}
.tag-up {
    background: rgba(248, 113, 113, 0.18);
    color: #991b1b;
}
.tag-warn {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
}
.stale-mini-list {
    max-height: 320px;
    overflow-y: auto;
}
.stale-line {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
}
.stale-line .grow {
    flex: 1;
}
.mb0 {
    margin-bottom: 0;
}
.small-indent {
    margin: 0.15rem 0 0.5rem;
}
@media (max-width: 980px) {
    .layout-dashboard {
        grid-template-columns: 1fr;
    }
}