/* CRM Controle Interno — Design System (fontes carregadas via header.php) */

:root {
    --crm-font: 'Inter', system-ui, -apple-system, sans-serif;
    --crm-bg: #f4f6fb;
    --crm-bg-accent: #e8eef8;
    --crm-surface: #ffffff;
    --crm-border: #e2e8f0;
    --crm-border-soft: #f1f5f9;
    --crm-text: #0f172a;
    --crm-text-muted: #64748b;
    --crm-text-soft: #94a3b8;
    --crm-primary: #0d9488;
    --crm-primary-dark: #0f766e;
    --crm-primary-light: #ccfbf1;
    --crm-sidebar: #0c1222;
    --crm-sidebar-hover: rgba(255, 255, 255, 0.06);
    --crm-sidebar-active: rgba(13, 148, 136, 0.18);
    --crm-sidebar-border: rgba(255, 255, 255, 0.08);
    --crm-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --crm-shadow: 0 4px 24px -4px rgba(15, 23, 42, 0.08);
    --crm-shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.12);
    --crm-radius: 1rem;
    --crm-radius-lg: 1.25rem;
    --crm-radius-xl: 1.5rem;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body.crm-body {
    font-family: var(--crm-font);
    color: var(--crm-text);
    background: var(--crm-bg);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

body.crm-login-body {
    font-family: var(--crm-font);
    min-height: 100vh;
    min-height: 100dvh;
    background:
        radial-gradient(ellipse 80% 60% at 20% 10%, rgba(13, 148, 136, 0.15), transparent 50%),
        radial-gradient(ellipse 60% 50% at 90% 90%, rgba(59, 130, 246, 0.1), transparent 50%),
        linear-gradient(160deg, #0c1222 0%, #1e293b 45%, #0f172a 100%);
}

/* ── Shell ── */
.crm-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.crm-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    display: flex;
    width: min(20rem, 88vw);
    max-width: 20rem;
    flex-direction: column;
    background: linear-gradient(180deg, #0f172a 0%, var(--crm-sidebar) 100%);
    color: #e2e8f0;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--crm-sidebar-border);
    box-shadow: var(--crm-shadow-lg);
}

.crm-sidebar.open { transform: translateX(0); }

@media (min-width: 1024px) {
    .crm-sidebar {
        position: static;
        width: 17rem;
        transform: none;
        box-shadow: none;
        flex-shrink: 0;
    }
}

.crm-sidebar-brand {
    padding: 1.35rem 1.25rem;
    border-bottom: 1px solid var(--crm-sidebar-border);
}

.crm-sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.crm-sidebar-logo-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    background: linear-gradient(135deg, var(--crm-primary) 0%, #0891b2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.875rem;
    color: white;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.crm-sidebar-title { font-size: 0.9375rem; font-weight: 700; line-height: 1.25; color: #fff; }
.crm-sidebar-subtitle { font-size: 0.6875rem; color: #94a3b8; margin-top: 0.125rem; letter-spacing: 0.02em; }

.crm-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.75rem;
}

.crm-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.125rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #cbd5e1;
    transition: background 0.15s, color 0.15s;
    min-height: 44px;
    touch-action: manipulation;
}

.crm-nav-link:hover { background: var(--crm-sidebar-hover); color: #f8fafc; }

.crm-nav-link.active {
    background: var(--crm-sidebar-active);
    color: #5eead4;
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--crm-primary);
}

.crm-nav-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    opacity: 0.85;
}

.crm-nav-link.active .crm-nav-icon { opacity: 1; }

.crm-sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--crm-sidebar-border);
    background: rgba(0, 0, 0, 0.15);
}

.crm-sidebar-user-name { font-size: 0.8125rem; font-weight: 600; color: #f1f5f9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-sidebar-user-role { font-size: 0.6875rem; color: #64748b; margin-top: 0.125rem; }

.crm-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
}

.crm-sidebar-backdrop.open { display: block; }

.crm-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: auto;
    background:
        radial-gradient(ellipse 100% 80% at 50% -20%, rgba(13, 148, 136, 0.06), transparent 50%),
        var(--crm-bg);
}

.crm-topbar-mobile {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--crm-border);
}

@media (min-width: 1024px) {
    .crm-topbar-mobile { display: none; }
}

.crm-topbar-desktop {
    display: none;
    padding: 1.75rem 2rem 0;
}

@media (min-width: 1024px) {
    .crm-topbar-desktop { display: block; }
}

.crm-page-title {
    font-size: 1.625rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--crm-text);
    line-height: 1.2;
}

.crm-page-subtitle {
    font-size: 0.875rem;
    color: var(--crm-text-muted);
    margin-top: 0.25rem;
}

.crm-content {
    flex: 1;
    padding: 1rem;
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 640px) {
    .crm-content { padding: 1.5rem; }
}

@media (min-width: 1024px) {
    .crm-content {
        padding: 1.5rem 2rem 2rem;
        padding-bottom: 2rem;
    }
}

/* ── Bottom nav ── */
.crm-bottomnav {
    position: fixed;
    inset: auto 0.75rem calc(0.5rem + env(safe-area-inset-bottom, 0px)) 0.75rem;
    z-index: 30;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    border: 1px solid var(--crm-border);
    border-radius: 1.25rem;
    box-shadow: var(--crm-shadow-lg);
    padding: 0.375rem;
}

@media (min-width: 1024px) {
    .crm-bottomnav { display: none; }
}

.crm-bottomnav-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
}

.crm-bottomnav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.5rem 0.25rem;
    border-radius: 0.875rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--crm-text-soft);
    transition: background 0.15s, color 0.15s;
    min-height: 52px;
    touch-action: manipulation;
}

.crm-bottomnav-link:hover { color: var(--crm-text-muted); }

.crm-bottomnav-link.active {
    background: var(--crm-primary-light);
    color: var(--crm-primary-dark);
}

.crm-bottomnav-link .crm-nav-icon { width: 1.375rem; height: 1.375rem; }

.crm-bottomnav-icon { font-size: 1.25rem; line-height: 1; }

/* ── Cards ── */
.crm-card {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-lg);
    box-shadow: var(--crm-shadow-sm);
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.2s;
}

.crm-card:hover { box-shadow: var(--crm-shadow); }

.crm-card-interactive:hover {
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.crm-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--crm-border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.crm-card-body { padding: 1.25rem; }

.crm-card-footer {
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--crm-border-soft);
    background: #fafbfc;
    border-radius: 0 0 var(--crm-radius-lg) var(--crm-radius-lg);
}

/* ── Stats ── */
.crm-stat {
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-lg);
    padding: 1.25rem;
    box-shadow: var(--crm-shadow-sm);
    position: relative;
    overflow: hidden;
}

.crm-stat::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--crm-stat-accent, var(--crm-primary));
    border-radius: var(--crm-radius-lg) var(--crm-radius-lg) 0 0;
}

.crm-stat-label { font-size: 0.75rem; font-weight: 600; color: var(--crm-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.crm-stat-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; margin-top: 0.375rem; line-height: 1; }

.crm-stat--danger { --crm-stat-accent: #ef4444; background: linear-gradient(180deg, #fff 0%, #fef2f2 100%); }
.crm-stat--warning { --crm-stat-accent: #f59e0b; background: linear-gradient(180deg, #fff 0%, #fffbeb 100%); }
.crm-stat--success { --crm-stat-accent: #10b981; background: linear-gradient(180deg, #fff 0%, #ecfdf5 100%); }
.crm-stat--info { --crm-stat-accent: #6366f1; background: linear-gradient(180deg, #fff 0%, #eef2ff 100%); }

/* ── Buttons ── */
.crm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 44px;
    padding: 0.625rem 1.125rem;
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
    touch-action: manipulation;
    text-decoration: none;
    white-space: nowrap;
}

.crm-btn:active { transform: scale(0.98); }

.crm-btn-primary {
    background: linear-gradient(135deg, var(--crm-primary) 0%, #0891b2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.3);
}

.crm-btn-primary:hover {
    background: linear-gradient(135deg, var(--crm-primary-dark) 0%, #0e7490 100%);
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.crm-btn-secondary {
    background: var(--crm-surface);
    color: var(--crm-text);
    border: 1px solid var(--crm-border);
}

.crm-btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }

.crm-btn-ghost {
    background: transparent;
    color: var(--crm-text-muted);
}

.crm-btn-ghost:hover { background: #f1f5f9; color: var(--crm-text); }

.crm-btn-teal { background: transparent; color: var(--crm-primary-dark); }
.crm-btn-teal:hover { background: var(--crm-primary-light); }

.crm-btn-danger { background: transparent; color: #dc2626; }
.crm-btn-danger:hover { background: #fef2f2; }

.crm-btn-sm { min-height: 36px; padding: 0.375rem 0.875rem; font-size: 0.75rem; border-radius: 0.625rem; }

/* ── Forms ── */
.crm-content input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="hidden"]),
.crm-content select,
.crm-content textarea,
.crm-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--crm-border);
    border-radius: 0.625rem;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--crm-text);
    background: var(--crm-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.crm-content input:focus,
.crm-content select:focus,
.crm-content textarea:focus,
.crm-input:focus {
    outline: none;
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

@media (max-width: 1023px) {
    .crm-content input,
    .crm-content select,
    .crm-content textarea { font-size: 16px !important; }
}

.crm-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.375rem;
}

/* ── Badges ── */
.crm-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* ── Flash ── */
.crm-flash {
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--crm-radius);
    font-size: 0.8125rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.crm-flash--success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.crm-flash--error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* ── Section headers ── */
.crm-section {
    margin-bottom: 2.5rem;
}

.crm-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.crm-section-title {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--crm-text);
}

.crm-section-desc {
    font-size: 0.8125rem;
    color: var(--crm-text-muted);
    margin-top: 0.25rem;
    max-width: 36rem;
}

.crm-section-count {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 700;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* ── Questionnaire cards (dashboard) ── */
.crm-qcard {
    display: block;
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-xl);
    overflow: hidden;
    box-shadow: var(--crm-shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
}

.crm-qcard:hover {
    transform: translateY(-3px);
    box-shadow: var(--crm-shadow-lg);
}

.crm-qcard-accent {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--crm-border-soft);
}

.crm-qcard-body { padding: 1.25rem 1.5rem 1.5rem; }

.crm-qcard-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: white;
}

/* ── Visit cards ── */
.crm-visit-card {
    display: flex;
    flex-direction: column;
    background: var(--crm-surface);
    border-radius: var(--crm-radius-lg);
    border: 1px solid var(--crm-border);
    padding: 1.25rem;
    box-shadow: var(--crm-shadow-sm);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.crm-visit-card--draft {
    border-color: #fcd34d;
    background: linear-gradient(180deg, #fff 0%, #fffbeb 100%);
}

.crm-visit-card:hover { box-shadow: var(--crm-shadow); }

.crm-progress {
    height: 6px;
    border-radius: 9999px;
    background: #e2e8f0;
    overflow: hidden;
}

.crm-progress-bar {
    height: 100%;
    border-radius: 9999px;
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    transition: width 0.3s ease;
}

.crm-progress-bar--success {
    background: linear-gradient(90deg, var(--crm-primary), #0891b2);
}

/* ── Empty state ── */
.crm-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--crm-text-muted);
    font-size: 0.875rem;
}

.crm-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

/* ── List rows ── */
.crm-list-row {
    display: block;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--crm-border-soft);
    transition: background 0.12s;
    text-decoration: none;
    color: inherit;
}

.crm-list-row:last-child { border-bottom: none; }
.crm-list-row:hover { background: #f8fafc; }

/* ── Login ── */
.crm-login-wrap {
    width: 100%;
    max-width: 28rem;
    margin: 0 auto;
    padding: 1.5rem;
}

.crm-login-card {
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--crm-radius-xl);
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
}

.crm-login-logo {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 1rem;
    background: linear-gradient(135deg, var(--crm-primary), #0891b2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-weight: 800;
    font-size: 1.125rem;
    color: white;
    box-shadow: 0 8px 20px rgba(13, 148, 136, 0.4);
}

/* ── Questionnaire form ── */
.choice-sim:has(input:checked) {
    border-color: #10b981 !important;
    background: #ecfdf5 !important;
    color: #047857 !important;
    font-weight: 600;
}

.choice-nao:has(input:checked) {
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
    color: #b91c1c !important;
    font-weight: 600;
}

.choice-sim, .choice-nao { transition: background 0.15s, border-color 0.15s; }

.touch-target { min-height: 44px; min-width: 44px; touch-action: manipulation; }

/* ── Icon button ── */
.crm-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.625rem;
    border: none;
    background: transparent;
    color: var(--crm-text-muted);
    cursor: pointer;
    transition: background 0.15s;
}

.crm-icon-btn:hover { background: #f1f5f9; color: var(--crm-text); }

/* ── Legacy pages (Tailwind classes) ── */
.crm-content .bg-white.rounded-xl,
.crm-content .bg-white.rounded-2xl {
    border-radius: var(--crm-radius-lg) !important;
    border-color: var(--crm-border) !important;
    box-shadow: var(--crm-shadow-sm);
}

.crm-content .shadow-sm { box-shadow: var(--crm-shadow-sm) !important; }

.crm-content a.text-primary-600,
.crm-content a.text-teal-600,
.crm-content a.text-teal-700 { color: var(--crm-primary-dark) !important; font-weight: 600; }

#crm-draft-indicator {
    background: rgba(15, 23, 42, 0.88) !important;
    border-radius: 9999px !important;
    font-size: 0.625rem !important;
    letter-spacing: 0.02em;
}

.crm-draft-banner {
    border-radius: var(--crm-radius) !important;
}

@media (prefers-reduced-motion: reduce) {
    .crm-sidebar, .crm-qcard, .crm-btn, .crm-visit-card { transition: none; }
}
