:root {
    --bg:           #f5f6f8;
    --bg-card:      #ffffff;
    --bg-soft:      #f9fafb;
    --bg-soft-2:    #f3f4f6;
    --fg:           #1f2937;
    --fg-soft:      #6b7280;
    --fg-muted:     #94a3b8;
    --border:       #e5e7eb;
    --border-soft:  #f1f5f9;
    --primary:      #1e3a8a;
    --primary-hover:#1e40af;
}

[data-theme="dark"] {
    --bg:           #0b1220;
    --bg-card:      #131c2e;
    --bg-soft:      #1a2438;
    --bg-soft-2:    #243046;
    --fg:           #e5e7eb;
    --fg-soft:      #94a3b8;
    --fg-muted:     #64748b;
    --border:       #334155;
    --border-soft:  #1e293b;
    --primary:      #3b82f6;
    --primary-hover:#60a5fa;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

.card {
    background: var(--bg-card);
}
table {
    background: var(--bg-card);
    color: var(--fg);
}
th { background: var(--bg-soft-2); color: var(--fg); }
th, td { border-bottom-color: var(--border); }
tr.total-row { background: var(--bg-soft); }
.ped-detail td { background: var(--bg-soft) !important; }
input[type="text"], input[type="file"], input[type="search"],
input[type="number"], input[type="date"], select, textarea {
    background: var(--bg-card);
    color: var(--fg);
    border-color: var(--border);
}
.nav-dropdown-menu { background: var(--bg-card); color: var(--fg); }
.nav-dropdown-menu a, .nav-dropdown-menu form button { color: var(--fg); }
.nav-dropdown-menu a:hover { background: var(--bg-soft-2); }
.muted-row { color: var(--fg-soft); }
.muted { color: var(--fg-muted); }
[data-theme="dark"] .ped-row:hover { background: var(--bg-soft); }
[data-theme="dark"] .ped-row.expanded { background: #1e2b47; }

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

.topbar {
    background: #1e3a8a;
    color: #fff;
    padding: 0.75rem 0;
}
.topbar .container { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.1rem 1rem; flex: 1; margin: 0 1rem; }
.topbar nav > a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.15s;
}
.topbar nav > a:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* Dropdowns no menu */
.nav-dropdown { position: relative; padding-bottom: 6px; margin-bottom: -6px; }
.nav-dropdown-trigger {
    background: none;
    border: 0;
    color: #cbd5e1;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: background 0.15s;
}
.nav-dropdown-trigger:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    color: #1f2937;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 200px;
    padding: 0.4rem 0;
    margin-top: 0;
    z-index: 100;
    opacity: 0; visibility: hidden; pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
}
/* Bridge invisível pra mouse não perder o hover ao descer do botão pro menu */
.nav-dropdown::after {
    content: "";
    position: absolute;
    top: 100%; left: 0; right: 0;
    height: 10px;
    background: transparent;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0);
}
.nav-dropdown-menu a {
    display: block;
    padding: 0.55rem 1rem;
    color: #1f2937;
    text-decoration: none;
    font-size: 0.88rem;
}
.nav-dropdown-menu a:hover { background: #f3f4f6; }

.user-area { display: flex; align-items: center; gap: 0.5rem; color: #fff; font-size: 0.85rem; }
.user-area .user-name { font-weight: 600; }

main.container { padding-top: 1.5rem; padding-bottom: 2rem; }

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    background: #1e3a8a;
    color: #fff;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.95rem;
}
.btn:hover { background: #1e40af; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }

input[type="text"], input[type="file"], input[type="search"], select {
    padding: 0.5rem 0.65rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
}
input[type="search"] { min-width: 280px; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}
.cards-grid.two  { grid-template-columns: repeat(2, 1fr); }
.cards-grid.five { grid-template-columns: repeat(5, 1fr); }
.cards-grid.six  { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1100px) {
    .cards-grid.six { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
    .cards-grid, .cards-grid.two, .cards-grid.five, .cards-grid.six { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .cards-grid, .cards-grid.two, .cards-grid.five, .cards-grid.six { grid-template-columns: 1fr; }
}

.stat .stat-label { font-size: 0.75rem; text-transform: uppercase; color: #6b7280; letter-spacing: 0.5px; }
.stat .stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; }
.stat-ontime    .stat-value { color: #16a34a; }
.stat-vence7    .stat-value { color: #ca8a04; }
.stat-atraso15  .stat-value { color: #f97316; }
.stat-atraso30  .stat-value { color: #ef4444; }
.stat-atrasoMax .stat-value { color: #7f1d1d; }
.stat-semprazo  .stat-value { color: #64748b; }

.table-wrap {
    overflow-x: auto;
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.85rem;
}
th, td {
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
}
th { background: #f3f4f6; font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td small { color: #6b7280; }
tr.total-row { background: #f9fafb; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-entregue  { background: #ccfbf1; color: #115e59; }
.badge-cancelado { background: #e5e7eb; color: #1f2937; }
.badge-ontime    { background: #d1fae5; color: #065f46; }
.badge-vence7    { background: #fef9c3; color: #854d0e; }
.badge-atraso15  { background: #ffedd5; color: #9a3412; }
.badge-atraso30  { background: #fee2e2; color: #991b1b; }
.badge-atrasoMax { background: #fecaca; color: #7f1d1d; }
.badge-semprazo  { background: #e2e8f0; color: #334155; }
.badge-default   { background: #e5e7eb; color: #374151; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-info    { background: #dbeafe; color: #1e3a8a; }

.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.btn.disabled, .btn[aria-disabled="true"] {
    pointer-events: none;
    opacity: 0.4;
    cursor: not-allowed;
}
.pagination input[type=number] {
    padding: 0.4rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
}

.footer {
    margin-top: 2rem;
    padding: 1rem 0;
    color: #6b7280;
    text-align: center;
}

.form-row { margin-bottom: 0.75rem; }
.form-row label { display: block; font-size: 0.85rem; color: #374151; margin-bottom: 0.25rem; }
.form-row input[type=text], .form-row input[type=date], .form-row select, .form-row textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
    border-left: 3px solid #cbd5e1;
    padding: 0 0 1rem 1rem;
    margin-left: 0.5rem;
    position: relative;
}
.timeline li::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 0.5rem;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: #1e3a8a;
}
.timeline-meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.25rem; }
.timeline-body { color: #374151; font-size: 0.9rem; line-height: 1.4; }

/* === Calendário === */
.calendario { width: 100%; table-layout: fixed; border-collapse: collapse; }
.calendario th { font-size: 0.7rem; padding: 0.5rem; text-align: center; background: var(--bg-soft-2); }
.calendario td {
    border: 1px solid var(--border);
    padding: 0.4rem;
    height: 100px;
    vertical-align: top;
    background: var(--bg-card);
}
.calendario td.fora-mes { background: var(--bg-soft); color: var(--fg-muted); }
.calendario td.fora-mes .dia-num { color: var(--fg-muted); }
.calendario td.hoje { box-shadow: inset 0 0 0 2px var(--primary); }
.dia-num { font-size: 0.75rem; font-weight: 600; color: var(--fg-soft); margin-bottom: 0.25rem; }
.dia-pedidos { display: flex; flex-direction: column; gap: 2px; }
.cal-badge {
    display: block;
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 3px;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #e5e7eb;
    color: #1f2937;
}
.cal-badge:hover { background: #d1d5db; }
.cal-more {
    background: none;
    border: 0;
    color: var(--primary);
    font-size: 0.65rem;
    cursor: pointer;
    padding: 1px 4px;
    text-align: left;
    font-family: inherit;
    text-decoration: underline;
}
.cal-more:hover { color: var(--primary-hover); }

/* Modal do calendário */
.cal-modal[hidden] { display: none !important; }
.cal-modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.cal-modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
}
.cal-modal-content {
    position: relative;
    background: var(--bg-card);
    color: var(--fg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 720px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.cal-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.cal-modal-close {
    background: none; border: 0;
    font-size: 1.5rem; line-height: 1;
    cursor: pointer; color: var(--fg-soft);
    padding: 0 0.5rem;
}
.cal-modal-close:hover { color: var(--fg); }
.cal-modal-body { padding: 1rem 1.5rem; overflow-y: auto; }
.cal-modal-body table { width: 100%; font-size: 0.85rem; }
.cal-modal-body table th { background: var(--bg-soft-2); padding: 0.5rem; }
.cal-modal-body table td { padding: 0.5rem; border-bottom: 1px solid var(--border-soft); }
.cal-modal-body table .cal-badge { display: inline-block; font-size: 0.7rem; }

.cal-no-prazo { background:#d1fae5; color:#065f46; }
.cal-vence-em-ate-7-dias { background:#fef9c3; color:#854d0e; }
.cal-atraso-ate-15-dias { background:#ffedd5; color:#9a3412; }
.cal-atraso-entre-15-e-30-dias { background:#fee2e2; color:#991b1b; }
.cal-atraso-maior-que-30-dias { background:#fecaca; color:#7f1d1d; }
.cal-entregue { background:#ccfbf1; color:#115e59; }
.cal-cancelado { background:#e5e7eb; color:#374151; }

.btn-mini {
    background: #d1fae5;
    color: #065f46;
    border: 0;
    border-radius: 4px;
    padding: 0 0.35rem;
    font-size: 0.7rem;
    cursor: pointer;
    line-height: 1.2;
}
.btn-mini:hover { background: #a7f3d0; }
.btn-link {
    background: none;
    border: 0;
    color: #b91c1c;
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: underline;
    padding: 0;
}

/* === Tabela compacta com linhas expansíveis (Relatório) === */
.table-compact {
    font-size: 0.68rem;
    table-layout: fixed !important;
    width: 100%;
    word-break: keep-all;
}
/* Linhas de DADOS — uma linha só com ellipsis */
.table-compact > thead > tr > th,
.table-compact > tbody > tr.ped-row > td {
    padding: 0.2rem 0.35rem !important;
    white-space: nowrap !important;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 0;
}

/* Linha de DETALHE expandida — layout livre */
.table-compact > tbody > tr.ped-detail > td {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    max-width: none !important;
    padding: 0.85rem 1.25rem !important;
}
/* (legacy: regra removida) */
/* Larguras fixas das colunas (15 colunas) */
.table-compact col.c-toggle  { width: 22px; }
.table-compact col.c-pedido  { width: 70px; }
.table-compact col.c-status  { width: 95px; }
.table-compact col.c-erp     { width: 78px; }
.table-compact col.c-fu      { width: 110px; }
.table-compact col.c-stint   { width: 90px; }
.table-compact col.c-compr   { width: 70px; }
.table-compact col.c-comprsel{ width: 100px; }
.table-compact td.cell-comprsel { padding: 2px 4px; }
.table-compact td.cell-comprsel select {
    width: 100%; box-sizing: border-box; font-size: 0.72rem;
    padding: 2px 4px; border: 1px solid #d1d5db; border-radius: 4px;
    background: #fff;
}
.table-compact col.c-site    { width: 75px; }
.table-compact col.c-forn    { width: 18%;  }
.table-compact col.c-item    { width: 22%;  }
.table-compact col.c-qtd     { width: 50px; }
.table-compact col.c-valor   { width: 95px; }
.table-compact col.c-aprov   { width: 65px; }
.table-compact col.c-lim     { width: 65px; }
.table-compact col.c-dias    { width: 50px; }

.table-compact th {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #475569;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}
.table-compact .badge { font-size: 0.65rem; padding: 0.1rem 0.35rem; }
.table-compact tfoot .tot-row td {
    background: var(--bg-soft-2);
    border-top: 2px solid var(--border);
    padding: 0.5rem 0.4rem !important;
    font-size: 0.8rem;
}

.ped-row { cursor: pointer; transition: background 0.12s; }
.ped-row:hover { background: #f8fafc; }
.ped-row.expanded { background: #eef2ff; }
.ped-row.expanded .caret { transform: rotate(90deg); }

.cell-toggle { color: #94a3b8; font-size: 0.7rem; padding: 0 !important; text-align: center; }

/* utilitários de células de tabela */
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Botão hamburger — default oculto no desktop; media query abaixo ativa no mobile */
.nav-mobile-toggle { display: none; }

/* ========== RESPONSIVO MOBILE ========== */
@media (max-width: 768px) {
    .container { padding: 0 0.6rem; }
    .topbar .container { flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem 0.6rem; }
    .brand { font-size: 1rem; }

    /* Menu colapsa: dropdowns viram links empilhados em accordion natural */
    .topbar nav { order: 3; width: 100%; display: none; flex-direction: column; gap: 0.25rem; margin-top: 0.5rem; }
    .topbar nav.mobile-open { display: flex; }
    .nav-dropdown { width: 100%; padding-bottom: 0; margin-bottom: 0; }
    .nav-dropdown-trigger { width: 100%; text-align: left; padding: 0.55rem 0.75rem; }
    .nav-dropdown-menu {
        position: static; opacity: 1; visibility: visible; pointer-events: auto; transform: none;
        display: none; box-shadow: none; margin-left: 0.6rem; min-width: 0;
        background: rgba(255,255,255,0.05); border-radius: 4px;
    }
    .nav-dropdown-menu a { color: #cbd5e1; padding: 0.4rem 0.75rem; }
    .nav-dropdown-menu a:hover { background: rgba(255,255,255,0.08); color: #fff; }
    .nav-dropdown:hover .nav-dropdown-menu,
    .nav-dropdown:focus-within .nav-dropdown-menu,
    .nav-dropdown.expanded .nav-dropdown-menu { display: block; }
    .nav-dropdown::after { display: none; }

    /* Botão hamburger */
    .nav-mobile-toggle {
        display: block; background: none; border: 1px solid #475569; color: #cbd5e1;
        padding: 0.35rem 0.6rem; border-radius: 4px; cursor: pointer; font-size: 1rem;
    }

    /* Grids viram 1 coluna */
    .cards-grid, .cards-grid.two, .cards-grid.five, .cards-grid.six { grid-template-columns: 1fr !important; }

    /* Formulários de filtro empilham */
    .filters { flex-direction: column; align-items: stretch; }
    .filters > * { width: 100%; }

    /* Tabelas com scroll horizontal isolado */
    .table-wrap { overflow-x: auto; }
    .table-compact { min-width: 900px; }  /* mantém legibilidade — usuário rola horizontal */

    /* User area menor */
    .user-area { order: 2; margin-left: auto; font-size: 0.75rem; gap: 0.3rem; }
    .user-area .user-name { display: none; }
}

/* ---- Multi-combo (dropdown com checkboxes) ---- */
.multi-combo { position: relative; display: inline-block; vertical-align: middle; }
.multi-combo-trigger {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 200px;
    justify-content: space-between;
    font-family: inherit;
    color: inherit;
}
.multi-combo-trigger:hover { background: #f9fafb; }
.multi-combo-count { color: #64748b; font-size: 0.8rem; }
.multi-combo-caret { color: #94a3b8; font-size: 0.75rem; }
.multi-combo-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 50;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
    max-height: 320px;
    overflow-y: auto;
    padding: 0.4rem;
    min-width: 240px;
}
.multi-combo-panel label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.88rem;
    white-space: nowrap;
}
.multi-combo-panel label:hover { background: #f3f4f6; }
.multi-combo-panel input[type="checkbox"] { margin: 0; cursor: pointer; }
.multi-combo-actions {
    border-bottom: 1px solid #e5e7eb;
    padding: 0 0.5rem 0.4rem;
    margin-bottom: 0.25rem;
    font-size: 0.78rem;
    color: #64748b;
}
.multi-combo-actions a { color: #2563eb; text-decoration: none; }
.multi-combo-actions a:hover { text-decoration: underline; }
[data-theme="dark"] .multi-combo-trigger,
[data-theme="dark"] .multi-combo-panel { background: var(--bg); border-color: var(--bg-soft); color: var(--fg); }
[data-theme="dark"] .multi-combo-panel label:hover { background: var(--bg-soft); }

/* Tabela compacta para a lista de itens do pedido (em /followup) */
.ped-item-row > td { padding: 0.35rem 0.5rem; vertical-align: middle; font-size: 0.85rem; }
.caret { display: inline-block; transition: transform 0.18s; }

.ped-detail td { background: #f8fafc; padding: 0.85rem 1.25rem !important; border-bottom: 2px solid #e2e8f0; }
.ped-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem 1.25rem;
}
.ped-detail-grid > div { font-size: 0.85rem; line-height: 1.35; }
.ped-detail-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.4px; color: #64748b; margin-bottom: 0.15rem; }
.ped-detail-actions { margin-top: 0.85rem; padding-top: 0.6rem; border-top: 1px solid #e2e8f0; }

.muted { color: #94a3b8; }
.muted-row { color: #6b7280; font-size: 0.85rem; margin-top: 0; }
