/* ============================================================
   HUB CEDTEC — Design System Mobile-First
   Tokens de design + utilitários customizados
   ============================================================ */

:root {
    /* Cores semânticas */
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-50: #eff6ff;
    --color-primary-100: #dbeafe;

    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;

    --color-surface: #ffffff;
    --color-surface-2: #f9fafb;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #6b7280;

    /* Tipografia mobile-first (escalável) */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);

    /* Animações */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Safe areas para iOS notch / Android nav */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Altura da bottom-nav (mobile) */
    --bottom-nav-h: 64px;
}

/* Base global */
* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
}

body {
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overscroll-behavior-y: none; /* impede pull-to-refresh fantasma no iOS */
}

/* Scrollbars sutis */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ============================================================
   PADDING SAFE-AREA — usar nas barras superior/inferior
   ============================================================ */
.safe-pt { padding-top: var(--safe-top); }
.safe-pb { padding-bottom: var(--safe-bottom); }
.safe-px { padding-left: var(--safe-left); padding-right: var(--safe-right); }

/* Conteúdo principal: empurra acima da bottom-nav no mobile */
.app-main {
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 1rem);
}
@media (min-width: 1024px) {
    .app-main { padding-bottom: 2rem; }
}

/* ============================================================
   BOTTOM NAV — App style
   ============================================================ */
.bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--color-border);
    padding-bottom: var(--safe-bottom);
}
@media (min-width: 1024px) {
    .bottom-nav { display: none; }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 4px;
    min-height: var(--bottom-nav-h);
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: color var(--transition-fast);
    -webkit-touch-callout: none;
}
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--color-primary); }
.bottom-nav-item:active { transform: scale(0.95); }

/* ============================================================
   DRAWER (slide-up no mobile, slide-in no desktop)
   ============================================================ */
.drawer-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(17, 24, 39, 0.5);
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition-base);
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer-panel {
    position: fixed; inset: auto 0 0 0;
    z-index: 51;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-lg);
    padding: 16px 16px calc(16px + var(--safe-bottom)) 16px;
    transform: translateY(100%);
    transition: transform var(--transition-base);
    max-height: 85vh;
    overflow-y: auto;
}
.drawer-panel.open { transform: translateY(0); }

/* Handle visual (ilha de arrasto iOS-style) */
.drawer-handle {
    width: 40px; height: 4px;
    background: var(--color-border);
    border-radius: 4px;
    margin: 0 auto 16px auto;
}

/* ============================================================
   CARDS — sombras + cantos arredondados modernos
   ============================================================ */
.card {
    background: var(--color-surface);
    border-radius: 16px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.card-interactive:active { transform: scale(0.98); }
.card-interactive:hover { box-shadow: var(--shadow-md); }

/* ============================================================
   FORMS — touch-friendly (mínimo 44px de altura)
   ============================================================ */
.input-modern {
    width: 100%;
    padding: 12px 14px;
    min-height: 48px;
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: 12px;
    font-size: 16px; /* impede zoom automático no iOS */
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-modern:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-100);
}
.input-modern::placeholder { color: #9ca3af; }

.btn-primary {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 12px 20px;
    background: var(--color-primary);
    color: white;
    font-weight: 700;
    font-size: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 12px -2px rgba(37, 99, 235, 0.4);
    transition: transform var(--transition-fast), background var(--transition-fast);
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 12px 20px;
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: 600;
    font-size: 15px;
    border: 1.5px solid var(--color-border);
    border-radius: 12px;
    transition: all var(--transition-fast);
}
.btn-secondary:hover { background: var(--color-surface-2); border-color: var(--color-text-muted); }

/* ============================================================
   ANIMAÇÕES UTILITÁRIAS
   ============================================================ */
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.animate-fade-in-up { animation: fade-in-up var(--transition-base) ease-out both; }

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
    border-radius: 8px;
}

/* ============================================================
   HEADER GREETING (top bar mobile)
   ============================================================ */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--color-border);
    padding-top: var(--safe-top);
}

/* ============================================================
   FOCUS RING acessível
   ============================================================ */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============================================================
   DARK MODE — ativado via classe `.dark` no <html>
   Toggle: drawer → "Tema". Preferência salva em localStorage.
   FOUC prevention: script no <head> antes do CSS.
   ============================================================ */
html.dark {
    --color-surface:    #0f172a;  /* slate-900 */
    --color-surface-2:  #1e293b;  /* slate-800 */
    --color-border:     #334155;  /* slate-700 */
    --color-text:       #f1f5f9;  /* slate-100 */
    --color-text-muted: #94a3b8;  /* slate-400 */

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45), 0 2px 4px -2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}
html.dark body { background: #020617; color: var(--color-text); }

/* Topbar/bottom-nav/drawer ficam translúcidos no dark */
html.dark .app-topbar,
html.dark .bottom-nav { background: rgba(15, 23, 42, 0.85); }

/* Toast */
html.dark .toast { background: var(--color-surface); color: var(--color-text); }
html.dark .toast-close { color: var(--color-text-muted); }

/* Sheet */
html.dark .sheet-content { background: var(--color-surface); }
html.dark .sheet-header { background: var(--color-surface); }

/* Inputs */
html.dark .input-modern {
    background: var(--color-surface-2);
    color: var(--color-text);
    border-color: var(--color-border);
}
html.dark .input-modern::placeholder { color: var(--color-text-muted); opacity: 0.7; }
html.dark .input-modern:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25); }

/* Skeleton */
html.dark .skeleton,
html.dark .img-skel {
    background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #1e293b 100%);
    background-size: 200% 100%;
}

/* ============================================================
   UTILS
   ============================================================ */
.line-clamp-2 { display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden; }
.line-clamp-3 { display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden; }
.line-clamp-4 { display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden; }

.no-tap-highlight { -webkit-tap-highlight-color: transparent; }

/* ============================================================
   TOAST SYSTEM — notificações deslizantes
   ============================================================ */
.toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: calc(100% - 24px);
    max-width: 420px;
}
@media (min-width: 1024px) {
    .toast-container {
        top: 16px;
        left: auto;
        right: 16px;
        transform: none;
    }
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
    transform: translateY(-12px);
    opacity: 0;
    transition: transform var(--transition-base), opacity var(--transition-base);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.hide { transform: translateY(-12px); opacity: 0; }

.toast-icon {
    flex-shrink: 0;
    width: 20px; height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.toast-success { border-left: 4px solid var(--color-success); }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error   { border-left: 4px solid var(--color-danger); }
.toast-error .toast-icon { color: var(--color-danger); }
.toast-info    { border-left: 4px solid var(--color-primary); }
.toast-info .toast-icon { color: var(--color-primary); }
.toast-warn    { border-left: 4px solid var(--color-warning); }
.toast-warn .toast-icon { color: var(--color-warning); }

.toast-close {
    margin-left: auto;
    color: var(--color-text-muted);
    background: transparent;
    border: 0;
    padding: 0 2px;
    cursor: pointer;
    line-height: 1;
    font-size: 18px;
}
.toast-close:hover { color: var(--color-text); }

/* ============================================================
   SHEET / MODAL GENÉRICO — bottom-sheet mobile, centered modal desktop
   Uso: <div class="sheet" id="meu-sheet">...</div>
        openSheet('meu-sheet') / closeSheet('meu-sheet')
   ============================================================ */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
}
@media (min-width: 640px) {
    .sheet { align-items: center; }
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.sheet-content {
    position: relative;
    z-index: 1;
    background: white;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform var(--transition-base);
    padding-bottom: var(--safe-bottom);
}
@media (min-width: 640px) {
    .sheet-content {
        max-width: 480px;
        margin: 16px;
        border-radius: 20px;
        transform: translateY(20px) scale(0.96);
        opacity: 0;
        transition: transform var(--transition-base), opacity var(--transition-base);
    }
}

.sheet.open { pointer-events: auto; }
.sheet.open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet.open .sheet-content { transform: translateY(0); }
@media (min-width: 640px) {
    .sheet.open .sheet-content { transform: translateY(0) scale(1); opacity: 1; }
}

/* Header padrão de sheet */
.sheet-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 2;
}
.sheet-title { font-weight: 700; font-size: 16px; color: var(--color-text); margin: 0; }
.sheet-handle {
    width: 40px; height: 4px;
    background: var(--color-border);
    border-radius: 4px;
    margin: 8px auto 4px;
}
@media (min-width: 640px) { .sheet-handle { display: none; } }

.sheet-close {
    flex-shrink: 0;
    width: 32px; height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: transparent;
    border: 0;
    color: var(--color-text-muted);
    cursor: pointer;
}
.sheet-close:hover { background: var(--color-surface-2); color: var(--color-text); }

.sheet-body { padding: 16px 20px 24px; }

/* ============================================================
   SKELETON LOADING — placeholder shimmer durante carregamento
   ============================================================ */
.skel-line { height: 12px; border-radius: 6px; margin: 6px 0; }
.skel-line-sm { height: 10px; }
.skel-line-lg { height: 16px; }
.skel-block { border-radius: 12px; }
.skel-circle { border-radius: 9999px; }
.skel-w-full { width: 100%; }
.skel-w-3-4  { width: 75%; }
.skel-w-1-2  { width: 50%; }
.skel-w-1-3  { width: 33%; }

/* Imagens com fundo skeleton até carregarem.
   Use no container: <div class="img-skel aspect-[16/9]">
   Na imagem: <img class="img-fade" onload="this.classList.add('loaded')"> */
.img-skel {
    background: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
    overflow: hidden;
    position: relative;
}
.img-fade {
    opacity: 0;
    transition: opacity 300ms ease-out;
}
.img-fade.loaded { opacity: 1; }
/* Quando a imagem carrega, desliga shimmer (sem JS extra) */
.img-skel:has(.img-fade.loaded) {
    background: transparent;
    animation: none;
}

/* ============================================================
   ADMIN TABS — navegação horizontal scrollável (mobile-first)
   ============================================================ */
.admin-tabs {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.15) transparent;
    scroll-snap-type: x proximity;
}
.admin-tabs::-webkit-scrollbar { height: 4px; }
.admin-tabs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }
html.dark .admin-tabs { scrollbar-color: rgba(255,255,255,0.15) transparent; }
html.dark .admin-tabs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }
.admin-tabs > a {
    flex-shrink: 0;
    scroll-snap-align: start;
    white-space: nowrap;
}

/* Wrapper de tabela com scroll horizontal limpo */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: inherit;
}
.table-scroll table { min-width: 100%; }

/* Hide scrollbar utility (visual mais limpo em alguns lugares) */
.scrollbar-hide { scrollbar-width: none; }
.scrollbar-hide::-webkit-scrollbar { display: none; }

/* ============================================================
   ADMIN SHELL — overrides em massa para dark mode
   Aplica em qualquer partial admin SEM precisar editar cada um.
   Especificidade alta o suficiente para sobrepor Tailwind utility classes.
   ============================================================ */
html.dark .admin-shell .bg-white       { background-color: #1e293b !important; }
html.dark .admin-shell .bg-gray-50     { background-color: #0f172a !important; }
html.dark .admin-shell .bg-gray-100    { background-color: #334155 !important; }
html.dark .admin-shell .bg-yellow-50   { background-color: rgba(234, 179, 8, 0.08) !important; }
html.dark .admin-shell .bg-green-50    { background-color: rgba(34, 197, 94, 0.10) !important; }
html.dark .admin-shell .bg-red-50      { background-color: rgba(239, 68, 68, 0.10) !important; }
html.dark .admin-shell .bg-blue-50     { background-color: rgba(59, 130, 246, 0.12) !important; }
html.dark .admin-shell .bg-indigo-50   { background-color: rgba(99, 102, 241, 0.12) !important; }
html.dark .admin-shell .bg-purple-50   { background-color: rgba(168, 85, 247, 0.12) !important; }
html.dark .admin-shell .bg-orange-50   { background-color: rgba(249, 115, 22, 0.12) !important; }
html.dark .admin-shell .bg-emerald-50  { background-color: rgba(16, 185, 129, 0.12) !important; }

html.dark .admin-shell .text-gray-900  { color: #f1f5f9 !important; }
html.dark .admin-shell .text-gray-800  { color: #e2e8f0 !important; }
html.dark .admin-shell .text-gray-700  { color: #cbd5e1 !important; }
html.dark .admin-shell .text-gray-600  { color: #94a3b8 !important; }
html.dark .admin-shell .text-gray-500  { color: #94a3b8 !important; }
html.dark .admin-shell .text-gray-400  { color: #64748b !important; }
html.dark .admin-shell .text-gray-300  { color: #475569 !important; }

html.dark .admin-shell .border-gray-100 { border-color: #1e293b !important; }
html.dark .admin-shell .border-gray-200 { border-color: #334155 !important; }
html.dark .admin-shell .border-gray-300 { border-color: #475569 !important; }
html.dark .admin-shell .divide-gray-100 > :not([hidden]) ~ :not([hidden]) { border-color: #1e293b !important; }
html.dark .admin-shell .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: #334155 !important; }

/* Hover states ajustados */
html.dark .admin-shell .hover\:bg-gray-50:hover  { background-color: #0f172a !important; }
html.dark .admin-shell .hover\:bg-gray-100:hover { background-color: #334155 !important; }

/* Inputs e selects no admin */
html.dark .admin-shell input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
html.dark .admin-shell select,
html.dark .admin-shell textarea {
    background-color: #0f172a !important;
    color: #f1f5f9 !important;
    border-color: #334155 !important;
}
html.dark .admin-shell input::placeholder,
html.dark .admin-shell textarea::placeholder { color: #64748b !important; }

/* prefers-reduced-motion — desliga animações para utilizadores sensíveis */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .skeleton { animation: none !important; background: #e5e7eb !important; }
}

