/* ============================================================================
   Tema unificado com EspoCRM (tema "Espo" — claro com accent azul).
   Variaveis extraidas de: CRM-9.3.6/client/css/espo/espo.css
   ============================================================================ */

:root {
    /* Backgrounds */
    --bg: #f1f3f5;
    --surface: #ffffff;
    --surface-2: #f9f9f9;
    --surface-3: #f1f3f5;

    /* Texto */
    --text: #333333;
    --text-soft: #5c5c5c;
    --text-muted: #999999;

    /* Bordas */
    --border: #e7eaed;
    --border-input: #D1D5D6;
    --border-strong: #c2cacc;

    /* Brand / Accent (azul EspoCRM) */
    --accent: #6092d0;
    --accent-hover: #346bb0;
    --accent-active: #3a77c3;
    --accent-soft: #d6e3f3;
    --accent-bg: #ecf5fd;

    /* Estados */
    --green: #5cb85c;
    --green-bg: #dbf0de;
    --yellow: #f0ad4e;
    --yellow-bg: #fbf7e1;
    --red: #d9534f;
    --red-bg: #f2dede;

    /* Tipografia (igual CRM) */
    --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-size-base: 14px;
    --font-size-small: 12px;
    --font-size-large: 18px;
    --line-height: 1.571429;

    /* Espacamento e raios */
    --radius: 8px;
    --radius-sm: 4px;
    --shadow-modal: 0 5px 15px rgba(0,0,0,0.18);
    --shadow-soft: 0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Login ===== */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--bg);
}

.auth-card {
    width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow-soft);
}

.auth-brand {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 22px;
    display: inline-grid;
    place-items: center;
    margin-bottom: 12px;
}

.auth-logo-img {
    max-width: 180px;
    max-height: 70px;
    width: auto;
    height: auto;
    margin-bottom: 14px;
    object-fit: contain;
}

.auth-brand h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.auth-sub {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.auth-form { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }

.field span {
    font-size: var(--font-size-small);
    color: var(--text-soft);
    font-weight: 500;
}

input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="search"], select, textarea {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: var(--font-size-base);
    font-family: inherit;
    width: 100%;
    height: 36px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { height: auto; min-height: 70px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #66afe9;
    box-shadow: 0 0 0 3px rgba(102,175,233,0.25);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: var(--font-size-base);
    height: 36px;
    transition: background 0.15s, border-color 0.15s;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-primary[disabled] { opacity: 0.6; cursor: wait; }

.btn-ghost {
    background: #fcfcfc;
    color: #5c5c5c;
    border: 1px solid var(--border-strong);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    height: 36px;
    transition: background 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: #f4f4f4; border-color: #bac3c5; }

.auth-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-small);
    margin: 4px 0 0;
}

.auth-error {
    background: var(--red-bg);
    border: 1px solid #e4b9b9;
    color: #a94442;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-align: center;
    margin: 0;
}

/* ===== Layout Hibrido (sidebar em desktop, topbar em mobile) ===== */
.app-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 65px;
    flex: 0 0 auto;
}

.sidebar-logo {
    max-width: 140px;
    max-height: 36px;
    width: auto;
    height: auto;
    object-fit: contain;
}

.logo-link {
    display: inline-flex;
    cursor: pointer;
    transition: opacity 0.15s;
}
.logo-link:hover { opacity: 0.75; }

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-section {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    padding: 8px 20px 6px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--text-soft);
    padding: 9px 20px 9px 17px;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.sidebar-link:hover { background: var(--surface-2); color: var(--text); }

.sidebar-link.active {
    background: var(--accent-bg);
    color: var(--accent-hover);
    border-left-color: var(--accent);
}

.sidebar-icon {
    width: 16px;
    text-align: center;
    color: inherit;
    font-size: 13px;
}

.sidebar-link.active .sidebar-icon { color: var(--accent); }

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 0 0 auto;
}

.sidebar-footer .user-chip {
    width: 100%;
    text-align: center;
}

.sidebar-footer .btn-ghost {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.user-chip {
    background: var(--surface-3);
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-soft);
    border: 1px solid var(--border);
}

/* ===== Content ===== */
.content { padding: 20px; min-width: 0; }

.view { animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== Cards (resumo) ===== */
.cards-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--accent);
}

.card-sem-prog::before { background: #adb5bd; }
.card-programadas::before { background: #1976d2; }
.card-agendadas::before { background: var(--green); }
.card-pendentes::before { background: var(--yellow); }
.card-vencidas::before { background: var(--red); }

.card-label {
    font-size: var(--font-size-small);
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
}

/* ===== Painels ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-wide { grid-column: 1 / -1; }
.panel-alert { border-color: #e4b9b9; }

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    background: var(--surface);
}

.panel-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.panel-badge {
    background: var(--surface-3);
    color: var(--text-soft);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    border: 1px solid var(--border);
}

.badge-red {
    background: var(--red-bg);
    color: #a94442;
    border-color: #e4b9b9;
}

/* ===== Listas ===== */
.lista {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 380px;
    overflow-y: auto;
}

.lista li {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    transition: background 0.1s;
}

.lista li:last-child { border-bottom: none; }
.lista li:hover { background: var(--surface-2); }

.lista-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lista-titulo { font-size: 13px; font-weight: 600; color: var(--text); }
.lista-sub { font-size: 12px; color: var(--text-muted); }

.lista-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.countdown {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
    background: var(--green-bg);
    color: #3c763d;
}

.countdown.warning { background: var(--yellow-bg); color: #8a6d3b; }
.countdown.danger { background: var(--red-bg); color: #a94442; }

.lista-acoes { display: flex; gap: 6px; }

.btn-mini {
    background: #fcfcfc;
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.btn-mini:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-hover); }

.lista-vazia {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Tabela ===== */
.tabela { width: 100%; border-collapse: collapse; background: var(--surface); }
.tabela th, .tabela td {
    text-align: left;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.tabela thead th {
    background: var(--surface-3);
    color: var(--text-soft);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tabela tbody tr:hover { background: var(--surface-2); }

.search-input { width: 260px; }

.panel-header-veiculos { gap: 10px; flex-wrap: wrap; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
.panel-actions .btn-primary { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }

.td-acoes { white-space: nowrap; }
.td-acoes .btn-mini + .btn-mini { margin-left: 4px; }

.badge-status {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-ativo {
    background: var(--green-bg);
    color: #2d6a30;
    border: 1px solid #c9e8cd;
}

.badge-programado {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
}

.badge-sem-prog {
    background: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.badge-agendado {
    background: var(--accent-bg);
    color: var(--accent-hover);
    border: 1px solid var(--accent-soft);
}

.badge-pendente {
    background: var(--yellow-bg);
    color: #8a6d3b;
    border: 1px solid #f5ebb4;
}

.badge-atrasado {
    background: var(--red-bg);
    color: #a94442;
    border: 1px solid #e4b9b9;
}

.badge-inativo {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.badge-ausente {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.badge-vendido {
    background: #e9ecef;
    color: #6c757d;
    border: 1px solid #ced4da;
}

.td-num { text-align: right; font-variant-numeric: tabular-nums; }

.row-status-vendido td { color: var(--text-muted); }
.row-status-vendido td strong { color: var(--text-muted); }
.row-status-inativo { background: rgba(255, 193, 7, 0.04); }
.row-status-ausente { background: rgba(255, 193, 7, 0.04); }
.row-status-atrasado { background: rgba(217, 83, 79, 0.04); }
.row-status-pendente { background: rgba(240, 173, 78, 0.04); }
.row-status-sem_programacao td { color: var(--text-muted); }

.prox-agendada { font-weight: 600; color: var(--accent-hover); }
.prox-programada { color: var(--text-soft); }
.prox-programada small { color: var(--text-muted); font-size: 11px; }

.btn-primary-mini {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent) !important;
}
.btn-primary-mini:hover {
    background: var(--accent-hover) !important;
    border-color: var(--accent-hover) !important;
    color: white !important;
}

.btn-danger-mini {
    color: var(--red) !important;
    border-color: #e4b9b9 !important;
}
.btn-danger-mini:hover {
    background: var(--red-bg) !important;
    border-color: var(--red) !important;
    color: #a94442 !important;
}

.modal-hint {
    margin: 0 0 4px;
    font-size: 13px;
    color: var(--text-soft);
    background: var(--surface-2);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.fa-spin { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(219, 219, 219, 0.5);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    z-index: 100;
    padding: 20px;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-modal);
}

.modal-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-3);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-soft);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 16px; display: grid; gap: 12px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-3);
    border-radius: 0 0 var(--radius) var(--radius);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-modal);
    z-index: 200;
    font-size: 13px;
    color: var(--text);
    animation: slideIn 0.2s ease-out;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); color: #a94442; }

@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Calendar overrides ===== */
#calendar { background: var(--surface); padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.fc { color: var(--text); font-family: var(--font); }
.fc-theme-standard td, .fc-theme-standard th, .fc-theme-standard .fc-scrollgrid { border-color: var(--border); }
.fc-col-header-cell { background: var(--surface-3); }
.fc-button-primary {
    background: #fcfcfc !important;
    border-color: var(--border-strong) !important;
    color: var(--text-soft) !important;
    font-weight: 500 !important;
    box-shadow: none !important;
}
.fc-button-primary:hover { background: #f4f4f4 !important; border-color: #bac3c5 !important; }
.fc-button-active, .fc-button-primary:not(:disabled).fc-button-active {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: white !important;
}
.fc-day-today { background: var(--accent-bg) !important; }
.fc-event { background: var(--accent) !important; border-color: var(--accent) !important; cursor: pointer; }
.fc-event:hover { background: var(--accent-hover) !important; }
.fc-list-event-dot { border-color: var(--accent) !important; }
.fc-list-event:hover td { background: var(--accent-bg) !important; }
.fc-list-day-cushion { background: var(--surface-3) !important; }

/* Sistema focado em desktop — sem media queries.
   Largura minima recomendada: 1024px. */
