/* =================================================================
 * Sistema de Orçamentos - Paleta inspirada em idplus.com.br
 * Azul institucional + laranja como acento
 * ================================================================= */

:root {
    /* Paleta inspirada no site IDPlus */
    --azul-escuro: #0c2340;
    --azul-medio: #163a6b;
    --azul-claro: #1e3a8a;
    --azul-light: #3b82f6;
    --laranja: #f59e0b;
    --laranja-dark: #d97706;
    --verde: #10b981;
    --vermelho: #ef4444;

    /* Neutros */
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #94a3b8;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
    --shadow: 0 4px 12px rgba(12,35,64,.08);
    --shadow-lg: 0 12px 32px rgba(12,35,64,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

h1, h2, h3, h4 { color: var(--text); font-weight: 700; }
a { color: var(--azul-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =================================================================
 * LAYOUT PRINCIPAL com sidebar
 * ================================================================= */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
    background: linear-gradient(180deg, var(--azul-escuro) 0%, #081929 100%);
    color: #e2e8f0;
    padding: 22px 14px 18px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 18px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    margin-bottom: 16px;
}
.brand-logo {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, var(--laranja), var(--laranja-dark));
    border-radius: 9px;
    display: grid; place-items: center;
    color: white; font-weight: 800; font-size: 15px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.brand-logo-img {
    width: 42px; height: 42px;
    border-radius: 9px;
    object-fit: contain;
    background: white;
    padding: 2px;
    flex-shrink: 0;
}
.brand-text strong { color: white; font-size: 15px; display: block; line-height: 1.2; }
.brand-text span { color: #94a3b8; font-size: 11px; }

.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    color: #cbd5e1;
    border-radius: 7px;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: white; }
.sidebar nav a.active {
    background: rgba(245,158,11,.18);
    color: white;
    border-left: 3px solid var(--laranja);
    padding-left: 9px;
}
.sidebar nav a .ico { font-size: 17px; opacity: .9; }

.sidebar-section {
    font-size: 10px; text-transform: uppercase;
    color: #64748b; letter-spacing: 0.06em;
    padding: 14px 12px 6px;
    font-weight: 700;
}

.user-card {
    margin-top: auto;
    padding: 12px;
    background: rgba(255,255,255,.04);
    border-radius: 9px;
    display: flex; align-items: center; gap: 10px;
}
.user-avatar {
    width: 36px; height: 36px;
    background: var(--laranja);
    border-radius: 50%;
    color: white; font-weight: 700;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info strong { color: white; font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.perfil-badge {
    display: inline-block; padding: 1px 7px;
    font-size: 10px; border-radius: 4px;
    text-transform: uppercase; font-weight: 700;
    margin-top: 2px;
}
.perfil-admin { background: #f59e0b; color: #78350f; }
.perfil-comercial { background: #3b82f6; color: white; }
.perfil-cliente { background: #10b981; color: white; }
.logout-btn {
    color: #94a3b8; font-size: 18px;
    padding: 4px 8px; border-radius: 5px;
    text-decoration: none;
}
.logout-btn:hover { background: rgba(255,255,255,.08); color: white; }

/* Conteúdo */
.content { background: var(--bg); }
.topbar {
    background: white; padding: 18px 28px;
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 22px; color: var(--azul-escuro); }
.topbar .subtitulo { font-size: 13px; color: var(--text-2); margin-top: 3px; }
.page-body { padding: 24px 28px; }

/* =================================================================
 * COMPONENTES
 * ================================================================= */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
}
.card h2 {
    font-size: 16px;
    color: var(--azul-escuro);
    margin-bottom: 14px;
    display: flex; justify-content: space-between;
    align-items: center; flex-wrap: wrap; gap: 8px;
}
.card-actions { display: flex; gap: 6px; }

.card-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 900px) { .card-grid-2 { grid-template-columns: 1fr; } }

/* Botões */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border: none; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: all 0.15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--azul-escuro); color: white; }
.btn-primary:hover { background: var(--azul-medio); color: white; }
.btn-laranja { background: var(--laranja); color: white; }
.btn-laranja:hover { background: var(--laranja-dark); color: white; }
.btn-outline { background: white; color: var(--text-2); border: 1px solid var(--border-strong); }
.btn-outline:hover { background: var(--surface-2); color: var(--azul-escuro); }
.btn-success { background: var(--verde); color: white; }
.btn-success:hover { background: #059669; color: white; }
.btn-danger { background: var(--vermelho); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }

/* Forms */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text); text-transform: uppercase; letter-spacing: 0.04em; }
.form-row input, .form-row select, .form-row textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.15s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none;
    border-color: var(--azul-light);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-row textarea { resize: vertical; min-height: 80px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; } }

/* Filtros */
.filtros {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 18px;
    align-items: end;
}
.filtros label { display: block; font-size: 11px; font-weight: 700; margin-bottom: 4px; color: var(--text-2); text-transform: uppercase; }
.filtros input, .filtros select { width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 5px; font-size: 13px; font-family: inherit; }
.filtros .actions { display: flex; gap: 6px; align-items: end; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
table th {
    text-align: left;
    background: var(--surface-2);
    padding: 11px 12px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-2);
    font-weight: 700;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
}
table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table tr:hover td { background: var(--surface-2); }
table .num { text-align: right; font-variant-numeric: tabular-nums; }
table .center { text-align: center; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-rascunho { background: #e2e8f0; color: #475569; }
.badge-enviado { background: #dbeafe; color: #1e40af; }
.badge-aprovado { background: #d1fae5; color: #065f46; }
.badge-reprovado { background: #fee2e2; color: #991b1b; }
.badge-cancelado { background: #f1f5f9; color: #64748b; }
.badge-em_projeto { background: #fef3c7; color: #92400e; }
.badge-concluido { background: #d1fae5; color: #065f46; }
.badge-pendente { background: #fef3c7; color: #78350f; }
.badge-em_andamento { background: #dbeafe; color: #1e3a8a; }
.badge-concluida { background: #d1fae5; color: #065f46; }
.badge-bloqueada { background: #fee2e2; color: #991b1b; }
.badge-sim { background: #d1fae5; color: #065f46; }
.badge-nao { background: #fee2e2; color: #991b1b; }
.badge-pausado { background: #f1f5f9; color: #475569; }

/* KPIs */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi {
    background: var(--surface);
    padding: 18px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left: 4px solid var(--azul-escuro);
    box-shadow: var(--shadow-sm);
}
.kpi-laranja { border-left-color: var(--laranja); }
.kpi-verde { border-left-color: var(--verde); }
.kpi-vermelho { border-left-color: var(--vermelho); }
.kpi-azul { border-left-color: var(--azul-light); }
.kpi-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; font-weight: 700; letter-spacing: 0.05em; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--azul-escuro); margin-top: 6px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Mensagens */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-info { background: #eff6ff; border-left: 4px solid var(--azul-light); color: #1e40af; }
.alert-success { background: #d1fae5; border-left: 4px solid var(--verde); color: #065f46; }
.alert-warning { background: #fef3c7; border-left: 4px solid var(--laranja); color: #78350f; }
.alert-danger { background: #fee2e2; border-left: 4px solid var(--vermelho); color: #991b1b; }

/* Login */
.login-page {
    background: linear-gradient(135deg, var(--azul-escuro) 0%, #081929 100%);
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 20px;
}
.login-card {
    background: white;
    padding: 38px 36px;
    border-radius: 14px;
    width: 100%; max-width: 380px;
    box-shadow: 0 25px 50px rgba(0,0,0,.3);
}
.login-card .brand { border-bottom: none; padding: 0 0 22px 0; justify-content: center; }
.login-card h2 { font-size: 18px; text-align: center; color: var(--azul-escuro); margin-bottom: 4px; }
.login-card .login-sub { text-align: center; font-size: 13px; color: var(--text-2); margin-bottom: 26px; }
.login-btn { width: 100%; padding: 12px; background: var(--azul-escuro); color: white; border: none; border-radius: 7px; font-size: 14px; font-weight: 700; cursor: pointer; margin-top: 8px; }
.login-btn:hover { background: var(--azul-medio); }

/* Timeline de projeto */
.timeline {
    position: relative;
    padding: 10px 0;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 22px; top: 0; bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding: 0 0 18px 56px;
}
.timeline-dot {
    position: absolute;
    left: 14px; top: 4px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--border-strong);
    z-index: 1;
}
.timeline-item.done .timeline-dot { background: var(--verde); border-color: var(--verde); }
.timeline-item.active .timeline-dot { background: var(--laranja); border-color: var(--laranja); box-shadow: 0 0 0 6px rgba(245,158,11,.18); }
.timeline-item.pending .timeline-dot { background: white; border-color: var(--border-strong); }

.timeline-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 14px 16px;
}
.timeline-card.active { border-color: var(--laranja); }
.timeline-card.done { background: #f0fdf4; border-color: #6ee7b7; }
.timeline-titulo { font-weight: 700; color: var(--azul-escuro); font-size: 14px; }
.timeline-meta { font-size: 11px; color: var(--text-2); margin-top: 3px; }
.timeline-prog { margin-top: 8px; }
.timeline-prog-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.timeline-prog-fill { height: 100%; background: linear-gradient(90deg, var(--azul-light), var(--laranja)); border-radius: 3px; transition: width 0.3s; }

/* Misc */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-2 { margin-top: 10px; }
.mb-2 { margin-bottom: 10px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.wrap-cnpj { font-family: monospace; font-size: 11px; color: var(--text-2); }

/* Editor de orçamento */
.orcamento-categoria {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.orcamento-categoria-head {
    background: var(--azul-escuro);
    color: white;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.orcamento-categoria-head input {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,.2);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 700;
}
.orcamento-categoria table { width: 100%; }
.orcamento-categoria th { background: var(--surface-2); padding: 8px; font-size: 10px; }
.orcamento-categoria td { padding: 6px 8px; border-bottom: 1px solid #f1f5f9; }
.orcamento-categoria td input { width: 100%; border: 1px solid transparent; padding: 5px 7px; font-size: 12px; border-radius: 4px; }
.orcamento-categoria td input:focus { border-color: var(--azul-light); background: white; }
.orcamento-categoria td input.num { text-align: right; font-variant-numeric: tabular-nums; }

.cc-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    margin-right: 3px;
}
.cc-ac { background: #dbeafe; color: #1e40af; }
.cc-av { background: #fce7f3; color: #9d174d; }
.cc-gr { background: #d1fae5; color: #065f46; }

.toast {
    position: fixed;
    top: 20px; right: 20px;
    background: var(--verde);
    color: white;
    padding: 12px 18px;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-12px);
    transition: all 0.3s;
    z-index: 9999;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--vermelho); }

/* =================================================================
 * RESPONSIVO
 * Breakpoints: 1024px (tablet) e 768px (mobile)
 * ================================================================= */

/* Botão hambúrguer - escondido no desktop */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    background: var(--azul-escuro);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    font-size: 22px;
    cursor: pointer;
    box-shadow: var(--shadow);
    align-items: center;
    justify-content: center;
}

/* Overlay escuro quando menu mobile abre */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 150;
}
.sidebar-overlay.active { display: block; }

/* Tablet (até 1024px) - sidebar mais estreita */
@media (max-width: 1024px) {
    .layout { grid-template-columns: 200px 1fr; }
    .sidebar { padding: 18px 10px 14px; }
    .sidebar nav a { font-size: 13px; padding: 9px 10px; }
    .topbar, .page-body { padding-left: 18px; padding-right: 18px; }
    .card-grid-2 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* Mobile (até 768px) - sidebar vira drawer com hambúrguer */
@media (max-width: 768px) {
    .layout {
        grid-template-columns: 1fr;
    }

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

    /* Sidebar vira drawer lateral */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 180;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding: 22px 14px 18px;
        overflow-y: auto;
        flex-direction: column;
    }
    .sidebar.active { transform: translateX(0); }

    .sidebar nav { flex-direction: column; }
    .sidebar nav a {
        padding: 10px 12px;
        font-size: 14px;
        white-space: normal;
    }

    .content { width: 100%; }

    /* Topbar com espaço para o botão hambúrguer */
    .topbar {
        padding: 16px 18px 14px 68px;
    }
    .topbar h1 { font-size: 18px; }
    .topbar .subtitulo { font-size: 12px; }

    .page-body { padding: 16px; }

    /* Cards mais compactos */
    .card { padding: 14px; margin-bottom: 12px; }
    .card h2 { font-size: 15px; }

    /* KPIs em 2 colunas no mobile, depois 1 */
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi { padding: 12px; }
    .kpi-value { font-size: 22px; }
    .kpi-label { font-size: 10px; }

    /* Formulários em coluna única */
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; gap: 10px; }
    .filtros { grid-template-columns: 1fr; gap: 8px; padding: 12px; }

    /* Tabelas: scroll horizontal sem quebrar layout */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    table { min-width: 600px; font-size: 12px; }
    table th, table td { padding: 8px 10px; }

    /* Editor de orçamento: tabelas com scroll */
    .editor-cat-tabela {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .editor-cat-tabela table { min-width: 720px; }

    /* Botões maiores para toque */
    .btn { padding: 10px 16px; min-height: 40px; }
    .btn-sm { padding: 7px 12px; min-height: 32px; }
    .btn-lg { padding: 14px 22px; font-size: 15px; }

    /* Inputs maiores para toque */
    input[type="text"], input[type="email"], input[type="number"],
    input[type="password"], input[type="date"], select, textarea {
        font-size: 16px; /* evita zoom no iOS */
        padding: 10px 12px;
        min-height: 42px;
    }

    /* Hero do projeto e orçamento */
    .hero-orcamento, .hero-projeto {
        padding: 18px;
        grid-template-columns: 1fr !important;
        text-align: center;
    }
    .hero-orcamento h2, .hero-projeto h2 { font-size: 18px; }
    .progresso-circulo { margin: 0 auto; }

    /* Botões de aprovar/reprovar em coluna no mobile */
    .acao-cliente .botoes {
        flex-direction: column;
        gap: 10px;
    }
    .acao-cliente .botoes .btn { width: 100%; justify-content: center; }

    /* Timeline mais compacta */
    .timeline { padding-left: 18px; }

    /* Card user na sidebar */
    .user-card { padding: 8px; }

    /* Resumo financeiro - itens em coluna no mobile */
    .resumo-financeiro {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px;
    }
    .resumo-financeiro .resumo-item div:last-child {
        font-size: 18px !important;
    }
    .resumo-financeiro .resumo-item.destaque div:last-child {
        font-size: 22px !important;
    }

    /* Modal ocupa quase toda tela no mobile */
    .modal { padding: 16px; min-width: auto; width: calc(100vw - 32px); }

    /* Esconder colunas menos importantes em tabelas de listagem no mobile */
    .hide-mobile { display: none !important; }
}

/* Mobile pequeno (até 480px) - ainda mais compacto */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .topbar h1 { font-size: 16px; }
    .topbar { padding-left: 60px; }
    table { font-size: 11px; }
}

/* =================================================================
 * AJUSTES MOBILE ADICIONAIS - garante responsividade em qualquer página
 * ================================================================= */
@media (max-width: 768px) {
    /* Hero do orçamento e projeto - empilha tudo */
    .orc-header,
    .proj-header,
    .proj-hero {
        grid-template-columns: 1fr !important;
        padding: 18px !important;
        text-align: center;
    }
    .orc-header h2,
    .proj-hero h2,
    .proj-header h2 { font-size: 18px !important; }
    .orc-header .status-big { text-align: center !important; }

    .proj-hero-info,
    .proj-header-info { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }

    /* Totais finais do orçamento */
    .totais-final .grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .totais-final .grid .v { font-size: 18px !important; }
    .totais-final .grid .v.destaque { font-size: 22px !important; }

    /* Forçar tabelas a terem scroll horizontal */
    .table-wrap,
    .card .table-wrap { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
    table { min-width: 100%; }

    /* Cards com gradiente do hero respeitam padding */
    .card { padding: 14px !important; }

    /* Sidebar section header fica melhor no mobile drawer */
    .sidebar-section { padding: 14px 12px 6px !important; }

    /* Inputs de cor (paletas pré-definidas) menores no mobile */
    .paleta-btn { min-width: 110px !important; font-size: 11px !important; }

    /* Filtros de listagem em coluna */
    .filtros > div { width: 100%; }
}

@media (max-width: 480px) {
    .proj-hero-info,
    .proj-header-info,
    .totais-final .grid { grid-template-columns: 1fr !important; }
}
