/* ============================================
   CRM eMerchan - Estilos
   ============================================ */

:root {
    --em-green: #4CAF50;
    --em-green-dark: #388E3C;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #888;
    --border: #e0e0e0;
    --bg-light: #f8f9fa;
    --bg-card: #fff;
    --bg-body: #f0f2f5;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    background: var(--bg-body);
    font-size: 14px;
    line-height: 1.6;
}

/* ========== LOGIN ========== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1c1b1e 0%, #2d2d30 100%);
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
}

.login-card img { height: 56px; margin-bottom: 24px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; color: var(--text-primary); }
.login-card p { font-size: 13px; color: var(--text-muted); margin-bottom: 32px; }

.login-card .field {
    text-align: left;
    margin-bottom: 16px;
}
.login-card .field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.login-card .field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
}
.login-card .field input:focus {
    outline: none;
    border-color: var(--em-green);
    box-shadow: 0 0 0 3px rgba(76,175,80,0.1);
}

.login-card .btn-login {
    width: 100%;
    padding: 12px;
    background: var(--em-green);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.login-card .btn-login:hover { background: var(--em-green-dark); }

.login-card .error-msg {
    color: #e53935;
    font-size: 13px;
    margin-top: 12px;
    display: none;
}

/* ========== DASHBOARD ========== */
.crm-header {
    background: #1c1b1e;
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.crm-header img { height: 32px; border-radius: 50%; }
.crm-header h1 { font-size: 16px; font-weight: 600; }
.crm-header .spacer { flex: 1; }
.crm-header .user-info { font-size: 13px; color: #aaa; }
.crm-header button {
    background: transparent;
    border: 1px solid #555;
    color: #ccc;
    padding: 6px 16px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.crm-header button:hover { border-color: #888; color: #fff; }
.crm-header .menu-toggle {
    background: #2a2b31;
    border-color: #5c6374;
    color: #f1f4f8;
    font-weight: 600;
}

.crm-side-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.crm-side-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.crm-side-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: min(320px, 90vw);
    height: 100vh;
    background: #121318;
    color: #fff;
    z-index: 200;
    border-right: 1px solid #2f3440;
    box-shadow: 8px 0 26px rgba(0, 0, 0, 0.35);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
}
.crm-side-menu.open {
    transform: translateX(0);
}
.crm-side-header {
    padding: 16px;
    border-bottom: 1px solid #2f3440;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.crm-side-close {
    background: transparent;
    border: 1px solid #4d5568;
    color: #d6dce7;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
}
.crm-side-actions {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.crm-side-actions a,
.crm-side-actions button {
    width: 100%;
    text-align: left;
    text-decoration: none;
    background: #1b1f2a;
    border: 1px solid #343b4b;
    color: #dfe5f0;
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.crm-side-actions a:hover,
.crm-side-actions button:hover {
    border-color: #5e677d;
    background: #232938;
}
.crm-side-actions a.menu-active {
    border-color: #00b94a;
    background: #1f3a2a;
    color: #d9ffe8;
}

.crm-content {
    max-width: none;
    margin: 24px auto;
    padding: 0 24px;
}

.crm-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.stat-card .number {
    font-size: 28px;
    font-weight: 700;
    color: var(--em-green-dark);
}
.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.crm-section {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}
.crm-section > table,
.crm-section > .table-wrap {
    overflow-x: auto;
}
.crm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.crm-section-header h2 { font-size: 16px; font-weight: 600; }

.btn-new {
    background: var(--em-green);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-new:hover { background: var(--em-green-dark); }

.crm-table {
    width: 100%;
    border-collapse: collapse;
}
.crm-table th {
    background: var(--bg-light);
    padding: 10px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.crm-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.crm-table tr:hover { background: var(--bg-light); }
.crm-table .empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.badge.rascunho { background: #fff3cd; color: #856404; }
.badge.enviado { background: #cce5ff; color: #004085; }
.badge.assinado { background: #d4edda; color: #155724; }

.crm-table .actions {
    display: flex;
    gap: 8px;
}
.crm-table .actions a, .crm-table .actions button {
    font-size: 12px;
    color: var(--em-green-dark);
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    padding: 2px 6px;
    border-radius: 4px;
}
.crm-table .actions a:hover, .crm-table .actions button:hover {
    background: var(--bg-light);
}
.crm-table .actions .delete { color: #e53935; }

/* ========== TOOLBAR (Proposta/Contrato) ========== */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #1c1b1e;
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.toolbar button {
    background: var(--em-green);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
}
.toolbar button:hover { opacity: 0.9; }
.toolbar button.secondary {
    background: transparent;
    border: 1px solid #555;
    color: #ccc;
}
.toolbar .spacer { flex: 1; }
.toolbar span { font-size: 13px; color: #aaa; }
.toolbar a {
    color: #ccc;
    text-decoration: none;
    font-size: 13px;
    padding: 8px 16px;
    border: 1px solid #555;
    border-radius: 6px;
}
.toolbar a:hover { border-color: #888; color: #fff; }

/* ========== DOCUMENTO (Proposta/Contrato) ========== */
.documento {
    max-width: none;
    margin: 80px auto 40px;
    padding: 0 24px;
}

.documento-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 24px;
    border-bottom: 3px solid var(--em-green);
    margin-bottom: 32px;
}
.documento-header img { height: 50px; }
.documento-header .info-right {
    text-align: right;
    font-size: 10px;
    color: var(--text-muted);
}

.documento h1 {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    color: var(--em-green-dark);
}
.documento h2 {
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 32px;
    color: var(--text-secondary);
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--em-green-dark);
    margin: 32px 0 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--em-green);
    display: inline-block;
}

.field-group { margin-bottom: 20px; }
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 12px;
}
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.field-row.four { grid-template-columns: 1fr 1fr 1fr 1fr; }
.field-row.full { grid-template-columns: 1fr; }

.field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.field input, .field textarea, .field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-light);
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none;
    border-color: var(--em-green);
    background: #fff;
}
.field textarea { resize: vertical; min-height: 60px; }

/* Tabela de valores */
.tabela-valores {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}
.tabela-valores th {
    background: var(--em-green-dark);
    color: #fff;
    padding: 8px 10px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
}
.tabela-valores td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
}
.tabela-valores tr:nth-child(even) { background: var(--bg-light); }
.tabela-valores input {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 11px;
    width: 100%;
    padding: 2px 0;
}
.tabela-valores input:focus {
    outline: none;
    border-bottom: 1px solid var(--em-green);
}
.tabela-valores .valor {
    font-weight: 700;
    color: var(--em-green-dark);
    text-align: right;
    white-space: nowrap;
}

/* Resumo financeiro */
.resumo-financeiro {
    background: var(--bg-light);
    border: 2px solid var(--em-green);
    border-radius: 8px;
    padding: 20px;
    margin: 24px 0;
}
.resumo-linha {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
}
.resumo-linha.total {
    border-top: 2px solid var(--em-green);
    margin-top: 8px;
    padding-top: 12px;
    font-weight: 700;
    font-size: 16px;
    color: var(--em-green-dark);
}

/* Features list */
.features-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 24px;
    margin: 12px 0 24px;
}
.features-list .item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    padding: 4px 0;
}
.features-list .check { color: var(--em-green); font-weight: 700; }

/* Condições / Texto legal */
.texto-legal {
    font-size: 11px;
    line-height: 1.8;
    color: var(--text-primary);
    text-align: justify;
}
.texto-legal p { margin-bottom: 12px; }
.texto-legal .clausula-titulo {
    font-size: 12px;
    font-weight: 700;
    color: var(--em-green-dark);
    margin: 24px 0 8px;
}
.texto-legal .sub-item { margin-left: 24px; margin-bottom: 8px; }
.texto-legal .sub-sub-item { margin-left: 48px; margin-bottom: 6px; }

/* Assinaturas */
.assinaturas {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 48px;
    margin-top: 48px;
    padding-top: 24px;
}
.assinatura-box { text-align: center; }
.assinatura-box .linha {
    border-top: 1px solid var(--text-primary);
    margin-bottom: 6px;
    margin-top: 60px;
}
.assinatura-box .nome { font-weight: 600; font-size: 11px; }
.assinatura-box .cargo { font-size: 10px; color: var(--text-muted); }

/* Rodapé doc */
.documento-footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
}

/* Evitar corte de conteúdo nas quebras de página (PDF e print) */
.texto-legal p,
.texto-legal p,
.texto-legal .clausula-titulo,
.texto-legal .sub-item,
.texto-legal .sub-sub-item {
    break-inside: avoid;
    page-break-inside: avoid;
}
.clausula-titulo {
    break-after: avoid;
    page-break-after: avoid;
}
.assinaturas {
    break-inside: avoid;
    page-break-inside: avoid;
}
.tabela-valores tr {
    break-inside: avoid;
    page-break-inside: avoid;
}
.section-title {
    break-after: avoid;
    page-break-after: avoid;
}
.resumo-financeiro {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Print styles */
@media print {
    .toolbar { display: none !important; }
    .crm-header { display: none !important; }
    .documento { max-width: 800px; margin: 0 auto; padding: 20px; }
    .field input, .field textarea, .field select {
        border: none;
        background: transparent;
        padding: 4px 0;
    }
    .tabela-valores input { border: none; }
    body { font-size: 12px; background: #fff; }
    @page { margin: 15mm 20mm; }
}

/* ========== MODAIS ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}
.modal-card {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalIn 0.2s ease;
}
.modal-card.modal-lg { max-width: 700px; }
@keyframes modalIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}
.modal-body .field { margin-bottom: 16px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
.modal-footer button {
    padding: 8px 24px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--em-green);
    color: #fff;
}
.modal-footer button:hover { background: var(--em-green-dark); }
.modal-footer button.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.modal-footer button.secondary:hover { background: var(--bg-light); }
.modal-msg {
    font-size: 13px;
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    display: none;
}
.modal-msg.error {
    display: block;
    background: #fce4ec;
    color: #c62828;
    border: 1px solid #ef9a9a;
}
.modal-msg.success {
    display: block;
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.tenant-access-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tenant-access-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--bg-light);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.tenant-access-item input[type="checkbox"] {
    margin: 0;
}

.seller-board {
    padding: 18px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 14px;
    background:
        radial-gradient(1200px 220px at top left, rgba(76,175,80,.08), transparent 60%),
        linear-gradient(180deg, #ffffff, #fafcfb);
}
.seller-empty {
    padding: 26px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    text-align: center;
    color: var(--text-muted);
    background: #fff;
}
.seller-card {
    border: 1px solid #d8e6dd;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(16, 50, 22, 0.08);
    padding: 14px;
}
.seller-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.seller-name {
    font-size: 18px;
    font-weight: 700;
    color: #183325;
}
.seller-kpi {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
}
.seller-kpi strong {
    color: #0c8f3e;
    font-size: 20px;
}
.seller-kpi span {
    font-size: 11px;
    color: #5f7466;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.seller-progress {
    height: 8px;
    border-radius: 999px;
    background: #edf4ef;
    overflow: hidden;
    margin-bottom: 12px;
}
.seller-progress span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #12a84b, #8adf5e);
}
.seller-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.seller-col h4 {
    font-size: 12px;
    color: #385247;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.seller-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.chip {
    font-size: 11px;
    border: 1px solid #d6ddd8;
    color: #4f6055;
    border-radius: 999px;
    padding: 4px 8px;
    background: #f8faf9;
}
.chip-info {
    border-color: #b7d8ff;
    color: #0b4f8e;
    background: #eaf4ff;
}
.chip-warn {
    border-color: #f2d28f;
    color: #8e5b00;
    background: #fff6e4;
}
.chip-ok {
    border-color: #98d9aa;
    color: #0c7132;
    background: #e8f8ee;
}

/* Modal aditivos - checkbox list */
.modal-aditivos-list {
    margin: 16px 0 8px;
}
.modal-aditivos-list label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-light);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 8px;
    transition: border-color 0.15s, background 0.15s;
}
.modal-aditivos-list label:hover {
    border-color: var(--em-green);
    background: #f0f9f1;
}
.modal-aditivos-list input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--em-green);
    cursor: pointer;
    flex-shrink: 0;
}
.modal-aditivos-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Fix date picker on dark toolbar (Chrome) */
.toolbar input[type="date"] {
    color-scheme: dark;
    position: relative;
}
.toolbar input[type="date"]::-webkit-calendar-picker-indicator {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .crm-stats { grid-template-columns: repeat(2, 1fr); }
    .field-row, .field-row.three, .field-row.four { grid-template-columns: 1fr; }
    .assinaturas { grid-template-columns: 1fr; gap: 24px; }
    .features-list { grid-template-columns: 1fr; }
    .crm-header {
        padding: 12px;
        gap: 10px;
    }
    .crm-header h1 {
        font-size: 15px;
    }
    .crm-header .user-info {
        font-size: 12px;
    }
    .seller-columns {
        grid-template-columns: 1fr;
    }
}
