/* === TryCotacao Design System === */
/* Font: Plus Jakarta Sans | Colors: Navy #0F172A + Blue CTA #0369A1 */

:root {
    --primary: #0F172A;
    --secondary: #334155;
    --accent: #0369A1;
    --accent-hover: #075985;
    --success: #16A34A;
    --warning: #F59E0B;
    --danger: #DC2626;
    --info: #0EA5E9;
    --bg: #F8FAFC;
    --bg-card: #FFFFFF;
    --text: #020617;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --sidebar-width: 250px;
    --topbar-height: 56px;
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

/* === Layout === */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
}

.layout-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.top-bar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 12px;
}

.top-bar-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
    display: none;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.user-name { color: var(--secondary); font-weight: 500; font-size: 13px; }

.btn-logout {
    color: var(--danger);
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
}

/* Hamburger toggle (hidden on desktop) */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-left: -8px;
}

.menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
    transition: transform 200ms, opacity 200ms;
}

/* Overlay (hidden on desktop) */
.sidebar-overlay {
    display: none;
}

.page-content {
    padding: 24px;
    flex: 1;
    min-width: 0; /* prevent grid overflow */
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand {
    font-size: 20px;
    font-weight: 700;
    color: white;
    margin: 0;
}

.sidebar-nav {
    padding: 12px 0;
}

.nav-section {
    padding: 16px 20px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.4);
}

.nav-item {
    display: block;
    padding: 8px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 200ms, color 200ms;
    cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: rgba(255,255,255,0.12); color: white; }

/* === Page Header === */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h2 { font-size: 22px; font-weight: 700; }

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
}

.card h4 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* === KPI Grid === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    border-left: 4px solid var(--accent);
}

.kpi-card.kpi-warning { border-left-color: var(--warning); }
.kpi-card.kpi-success { border-left-color: var(--success); }
.kpi-card.kpi-info { border-left-color: var(--info); }

.kpi-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.kpi-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

/* === Tables === */
.table-simple {
    width: 100%;
    border-collapse: collapse;
}

.table-simple th {
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.table-simple td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.table-simple tbody tr:hover { background: #F1F5F9; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-rascunho, .badge-aberta { background: #E2E8F0; color: #475569; }
.badge-pendente, .badge-enviada { background: #FEF3C7; color: #92400E; }
.badge-aprovada, .badge-respondido, .badge-emanalise { background: #DCFCE7; color: #166534; }
.badge-rejeitada, .badge-cancelada { background: #FEE2E2; color: #991B1B; }
.badge-convertida, .badge-fechada, .badge-pedidogerado { background: #DBEAFE; color: #1E40AF; }
.badge-vencedor { background: #16A34A; color: white; }
.badge-baixa { background: #E2E8F0; color: #475569; }
.badge-normal { background: #DBEAFE; color: #1E40AF; }
.badge-alta { background: #FEF3C7; color: #92400E; }
.badge-critica { background: #FEE2E2; color: #991B1B; }

/* === Buttons === */
.btn, a.btn, a.btn:hover, a.btn:visited, a.btn:active {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 200ms;
    text-decoration: none !important;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803D; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #B91C1C; }
.btn-secondary { background: #E2E8F0; color: var(--secondary); }
.btn-lg { padding: 12px 32px; font-size: 15px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-group a { text-decoration: none !important; }

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    padding: 4px 8px;
}

.btn-link:hover { text-decoration: underline; }

/* === Forms === */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: var(--font);
    font-size: 14px;
    transition: border-color 200ms;
    min-height: 42px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Form page container: limit width for readability */
.page-content > .card,
.page-content > .card:first-child {
    max-width: 900px;
}

/* Full-width override for grids/tables/maps that need it */
.card.card-full, .card:has(.table-simple), .card:has(.dxbl-grid),
.card:has(.mapa-table), .card.mapa-desktop {
    max-width: 100%;
}

.form-card { max-width: 560px; }

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}

.form-check input[type="checkbox"] { width: auto; }

.form-card { max-width: 500px; }

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-danger { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-info { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

/* === Supplier Layout (public portal) === */
.supplier-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.supplier-header {
    background: var(--primary);
    color: white;
    padding: 16px 24px;
    text-align: center;
}

.supplier-header h3 { margin: 0; font-weight: 700; }

.supplier-content {
    flex: 1;
    max-width: 700px;
    margin: 0 auto;
    padding: 24px 16px;
    width: 100%;
    box-sizing: border-box;
}

.supplier-footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

/* === Supplier Form === */
.cotacao-info {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.cotacao-info h3 { font-weight: 700; margin-bottom: 8px; }
.prazo { color: var(--danger); font-size: 13px; margin-top: 8px; }

.produto-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.produto-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.produto-header h4 { font-size: 15px; font-weight: 600; margin: 0; }
.produto-qtd { font-weight: 600; color: var(--accent); white-space: nowrap; }
.preco-ref { font-size: 12px; color: var(--text-muted); }
.obs-comprador { font-size: 12px; color: var(--secondary); font-style: italic; }

.impostos-detail { margin: 8px 0; }
.impostos-detail summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    padding: 4px 0;
}

.dados-gerais {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
}

.dados-gerais h4 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }

.submit-area {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 16px;
    text-align: center;
    border-top: 1px solid var(--border);
    z-index: 10;
}

.submit-area .btn { min-width: 200px; }

.supplier-success, .supplier-error {
    text-align: center;
    padding: 48px 24px;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.supplier-success h3 { color: var(--success); }
.supplier-error h3 { color: var(--danger); }

/* === Login === */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70vh;
}

/* Sticky bottom actions (desktop: normal, mobile: fixed) */
.sticky-bottom-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h3 { font-weight: 700; margin-bottom: 4px; }
.login-card > p { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 12px; }

/* === Aprovacao === */
.aprovacao-card .card-body { padding-top: 0; }

/* === Mobile Card Views (hidden on desktop, shown on mobile) === */
.mobile-cards { display: none; }
.desktop-view { display: block; }

.mobile-card-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color 150ms;
}

.mobile-card-item.mc-selected {
    border-color: var(--accent);
    background: #F0F7FF;
}

.mobile-card-item .mc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.mobile-card-item .mc-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--primary);
}

.mobile-card-item .mc-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.mobile-card-item .mc-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 2px 0;
}

.mobile-card-item .mc-row .mc-label { color: var(--text-muted); }
.mobile-card-item .mc-row .mc-value { font-weight: 600; }

.mobile-card-item .mc-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.mobile-card-item .mc-actions .btn {
    flex: 1;
    text-align: center;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}

/* === Mapa Mobile (accordion por produto) === */
.mapa-mobile { display: none; }

.mapa-mobile-produto {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.mapa-mobile-produto summary {
    padding: 12px 14px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
}

.mapa-mobile-produto summary::-webkit-details-marker { display: none; }

.mapa-mobile-produto summary::after {
    content: "▸";
    transition: transform 200ms;
    font-size: 12px;
}

.mapa-mobile-produto[open] summary::after {
    transform: rotate(90deg);
}

.mapa-mobile-forn {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}

.mapa-mobile-forn .mf-nome {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.mapa-mobile-forn .mf-preco {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.mapa-mobile-forn .mf-preco.menor { color: var(--success); }

.mapa-mobile-forn .mf-total {
    font-size: 11px;
    color: var(--text-muted);
}

.mapa-mobile-forn .mf-qtd-input {
    margin-top: 6px;
}

.mapa-mobile-forn .mf-qtd-input input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: var(--font);
}

.mapa-mobile-forn .mf-qtd-input label {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 2px;
}

/* === Responsive: Mobile (<= 768px) === */
@media (max-width: 768px) {
    /* Global mobile touch optimization */
    * { touch-action: manipulation; }

    /* Prevent DevExpress components from overflowing */
    .dxbl-combobox, .dxbl-spin-edit, .dxbl-date-edit, .dxbl-text-box, .dxbl-memo {
        max-width: 100% !important;
    }

    /* Page content overflow protection */
    .page-content { overflow-x: hidden; }
    .card { overflow: hidden; }

    /* Sidebar: off-canvas drawer */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 250ms ease;
        z-index: 200;
    }

    .menu-open .sidebar { transform: translateX(0); }

    .menu-open .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 150;
    }

    .layout-content { margin-left: 0; }

    .menu-toggle { display: flex; }
    .top-bar-title { display: block; }
    .top-bar { padding: 0 12px; }
    .user-name { display: none; }

    .page-content { padding: 16px 12px; }

    /* Page header */
    .page-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    .page-header h2 { font-size: 18px; }

    /* KPIs: 2 columns */
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .kpi-value { font-size: 20px; }
    .kpi-label { font-size: 11px; }
    .kpi-card { padding: 12px; }

    /* Forms */
    .form-row { grid-template-columns: 1fr; }

    /* Buttons: stack full width, min touch target */
    .btn { min-height: 44px; font-size: 14px; display: flex; align-items: center; justify-content: center; }
    .btn-group { flex-direction: column; width: 100%; }
    .btn-group .btn { width: 100%; }

    /* Cards */
    .card { padding: 14px; margin-bottom: 10px; }
    .card h4 { font-size: 14px; }

    /* Show mobile views, hide desktop */
    .mobile-cards { display: block; }
    .desktop-view { display: none; }
    .mapa-mobile { display: block; }
    .mapa-desktop { display: none; }

    /* DevExpress Grid on mobile: still scroll but smaller */
    .dxbl-grid { overflow-x: auto !important; font-size: 12px; }

    /* Login */
    .login-card { margin: 12px; padding: 24px 16px; }

    /* Templates */
    .templates-grid { grid-template-columns: 1fr; }
    .form-card { max-width: 100%; }

    /* Approval: side-by-side buttons */
    .aprovacao-card .btn-group { flex-direction: row; }
    .aprovacao-card .btn-group .btn { flex: 1; min-height: 44px; }
    .aprovacao-card .table-simple { font-size: 12px; white-space: normal; }

    /* Inputs: larger touch targets */
    .form-group input, .form-group select, .form-group textarea {
        min-height: 44px;
        font-size: 16px; /* prevents iOS zoom */
    }

    /* Sticky bottom actions on mobile */
    .sticky-bottom-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        padding: 12px;
        z-index: 50;
        flex-direction: column;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    }

    .sticky-bottom-actions .btn {
        width: 100%;
    }

    /* Add padding at bottom of page to prevent content being hidden behind sticky buttons */
    .page-content:has(.sticky-bottom-actions) {
        padding-bottom: 140px;
    }

    /* Supplier portal */
    .supplier-content { padding: 16px 12px; }
    .produto-card { padding: 12px; }
    .dados-gerais { padding: 14px; }
    .submit-area .btn { width: 100%; }
}

/* === Small mobile (<= 480px) === */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .top-bar-title { font-size: 14px; }
    .page-header h2 { font-size: 16px; }
}

/* === Mapa de Cotacao === */
.mapa-table th.fornecedor-col {
    text-align: center;
    min-width: 160px;
    vertical-align: top;
}

.mapa-table th.fornecedor-col div { font-weight: 600; margin-bottom: 4px; }
.mapa-table th.nao-respondido, .mapa-table td.nao-respondido { opacity: 0.5; }

.preco-cell {
    text-align: center;
    vertical-align: top;
    padding: 8px !important;
}

.preco-valor { font-size: 15px; font-weight: 700; color: var(--primary); }
.preco-total { font-size: 11px; color: var(--text-muted); }

.preco-cell.menor-preco {
    background: #F0FDF4;
}

.preco-cell.menor-preco .preco-valor { color: var(--success); }

.preco-cell.vencedor {
    background: #DCFCE7;
    border: 2px solid var(--success);
}

.preco-cell .indisponivel {
    color: var(--danger);
    font-weight: 600;
    font-size: 12px;
}

.total-row td { font-size: 15px; border-top: 2px solid var(--border); }

.mapa-table small { font-size: 11px; color: var(--text-muted); }

.qtd-pedido-input {
    margin-top: 6px;
    display: flex;
    justify-content: center;
}

.qtd-pedido-input input {
    width: 80px;
    padding: 3px 6px;
    font-size: 12px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font);
}

.qtd-pedido-input input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 2px rgba(3, 105, 161, 0.15);
}

.qtd-alocada {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--success);
}

.text-center { text-align: center; }

.qtd-ok { background: #F0FDF4; }
.qtd-parcial { background: #FEF3C7; }

/* === Comentarios === */
.comentarios-section h4 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }

.comentarios-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.comentario-item {
    padding: 8px 12px;
    border-left: 3px solid var(--accent);
    margin-bottom: 8px;
    background: var(--bg);
    border-radius: 0 6px 6px 0;
}

.comentario-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 4px;
}

.comentario-texto { font-size: 13px; line-height: 1.5; }

.comentario-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: var(--font);
    font-size: 13px;
    resize: vertical;
}

.comentario-form textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(3, 105, 161, 0.1);
}

/* === Templates Grid === */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.template-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

/* === Upload === */
.text-danger { color: var(--danger); }

/* === Blazor error UI === */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* === Focus visible === */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* === Reduced motion === */
@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; }
}
