/* ==========================================================================
   RESPONSIVE DESIGN - MOBILE FIRST
   Sistema Contábil GERIDA
   ========================================================================== */

/* ==========================================================================
   VARIÁVEIS CSS - DESIGN TOKENS
   ========================================================================== */
:root {
    /* Tipografia fluida */
    --fs-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --fs-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
    --fs-base: clamp(1rem, 0.9rem + 0.45vw, 1.125rem);
    --fs-lg: clamp(1.125rem, 1rem + 0.55vw, 1.375rem);
    --fs-xl: clamp(1.25rem, 1.1rem + 0.7vw, 1.75rem);
    --fs-2xl: clamp(1.5rem, 1.3rem + 1vw, 2.25rem);
    
    /* Espaçamento fluido */
    --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --space-md: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --space-lg: clamp(1.5rem, 1.2rem + 1.5vw, 2.5rem);
    --space-xl: clamp(2rem, 1.5rem + 2.5vw, 4rem);
    
    /* Touch targets */
    --touch-target-min: 44px;
    
    /* Safe areas (para notch de iPhones) */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ==========================================================================
   BASE - MOBILE (< 768px)
   ========================================================================== */

/* Layout principal */
body {
    font-size: var(--fs-base);
    padding-bottom: calc(70px + var(--safe-area-bottom));
}

/* Header responsivo */
.header-content {
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-md);
    padding-top: calc(var(--space-md) + var(--safe-area-top));
}

.logo {
    justify-content: center;
    text-align: center;
}

.logo-text h1 {
    font-size: var(--fs-xl);
}

.logo-text span {
    font-size: var(--fs-xs);
}

.header-actions {
    width: 100%;
    justify-content: space-between;
    gap: var(--space-sm);
}

/* Navegação por abas */
.nav-tabs {
    padding: 0 var(--space-sm);
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    gap: var(--space-xs);
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--fs-sm);
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    scroll-snap-align: start;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-tab span {
    display: none;
}

.nav-tab i {
    margin-right: 0;
    font-size: 1.25rem;
}

.nav-tab.active span {
    display: inline;
    margin-left: var(--space-xs);
}

/* Conteúdo principal */
.main-content {
    padding: var(--space-md);
    padding-left: calc(var(--space-md) + var(--safe-area-left));
    padding-right: calc(var(--space-md) + var(--safe-area-right));
}

/* Cards */
.card {
    border-radius: 12px;
    margin-bottom: var(--space-md);
}

.card-header {
    padding: var(--space-md);
    flex-direction: column;
    gap: var(--space-sm);
}

.card-header .btn {
    width: 100%;
}

.card-body {
    padding: var(--space-md);
}

.card-title {
    font-size: var(--fs-lg);
}

/* Tabelas responsivas */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(var(--space-md) * -1);
    padding: 0 var(--space-md);
}

.table {
    font-size: var(--fs-xs);
    min-width: 600px;
}

.table th,
.table td {
    padding: var(--space-sm) var(--space-xs);
    white-space: nowrap;
}

.table td:last-child {
    min-width: 100px;
}

/* Botões */
.btn {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--fs-sm);
    min-height: var(--touch-target-min);
    touch-action: manipulation;
}

.btn-icon {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
}

.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

/* Modais - Full screen em mobile */
.modal-overlay {
    padding: 0;
}

.modal-content {
    margin: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: var(--space-md);
    padding-top: calc(var(--space-md) + var(--safe-area-top));
    flex-shrink: 0;
}

.modal-body {
    padding: var(--space-md);
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: var(--space-md);
    padding-bottom: calc(var(--space-md) + var(--safe-area-bottom));
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.modal-footer .btn {
    width: 100%;
}

/* Formulários */
.form-group {
    margin-bottom: var(--space-md);
}

.form-control {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--fs-base);
    min-height: var(--touch-target-min);
}

.form-label {
    font-size: var(--fs-sm);
    margin-bottom: var(--space-xs);
}

/* Grid de estatísticas */
.stats-grid,
.grid-cols-3,
.grid-cols-4 {
    grid-template-columns: 1fr;
    gap: var(--space-md);
}

.stat-card {
    padding: var(--space-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
}

.stat-value {
    font-size: var(--fs-xl);
}

.stat-label {
    font-size: var(--fs-xs);
}

/* Calendário Mobile */
.calendar-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.calendar-grid {
    min-width: 320px;
}

.calendar-day-header {
    padding: var(--space-sm) var(--space-xs);
    font-size: var(--fs-xs);
}

.calendar-day {
    min-height: 60px;
    padding: var(--space-xs);
}

.calendar-day-number {
    font-size: var(--fs-xs);
}

.calendar-event {
    font-size: 0.625rem;
    padding: 2px 4px;
    min-height: 24px;
    display: flex;
    align-items: center;
}

/* Empty states */
.empty-state {
    padding: var(--space-xl) var(--space-md);
    text-align: center;
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: var(--space-md);
}

.empty-state h3 {
    font-size: var(--fs-lg);
}

.empty-state p {
    font-size: var(--fs-sm);
}

/* ==========================================================================
   BOTTOM NAVIGATION - MOBILE
   ========================================================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: var(--space-sm);
    padding-bottom: calc(var(--space-sm) + var(--safe-area-bottom));
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    z-index: 1000;
    border-top: 1px solid #e2e8f0;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs) var(--space-sm);
    min-width: 64px;
    min-height: var(--touch-target-min);
    color: #64748b;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item i {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.bottom-nav-item span {
    font-size: 0.625rem;
    font-weight: 500;
}

.bottom-nav-item.active {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.bottom-nav-item:active {
    transform: scale(0.95);
    background: rgba(59, 130, 246, 0.15);
}

.bottom-nav-item .badge {
    position: absolute;
    top: 0;
    right: 0;
    background: #ef4444;
    color: white;
    font-size: 0.5rem;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

/* ==========================================================================
   TABLET (768px - 1024px)
   ========================================================================== */
@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }
    
    .header-content {
        flex-direction: row;
        padding: var(--space-md) var(--space-lg);
    }
    
    .logo {
        justify-content: flex-start;
    }
    
    .header-actions {
        width: auto;
    }
    
    .nav-tab span {
        display: inline;
    }
    
    .nav-tab i {
        margin-right: var(--space-xs);
    }
    
    .card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    
    .card-header .btn {
        width: auto;
    }
    
    .stats-grid,
    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Modal tablet */
    .modal-content {
        margin: var(--space-lg) auto;
        width: 90%;
        max-width: 600px;
        height: auto;
        max-height: 90vh;
        border-radius: 16px;
    }
    
    .modal-footer {
        flex-direction: row;
        justify-content: flex-end;
    }
    
    .modal-footer .btn {
        width: auto;
    }
    
    /* Hide bottom nav on tablet/desktop */
    .bottom-nav {
        display: none;
    }
    
    .calendar-day {
        min-height: 100px;
    }
}

/* ==========================================================================
   DESKTOP (> 1024px)
   ========================================================================== */
@media (min-width: 1024px) {
    .main-content {
        padding: var(--space-lg) var(--space-xl);
        max-width: 1400px;
        margin: 0 auto;
    }
    
    .stats-grid,
    .grid-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .table {
        font-size: var(--fs-sm);
    }
    
    .calendar-day {
        min-height: 120px;
    }
}

/* ==========================================================================
   SMALL MOBILE (< 480px)
   ========================================================================== */
@media (max-width: 480px) {
    .logo-text h1 {
        font-size: var(--fs-lg);
    }
    
    .nav-tab {
        padding: var(--space-xs) var(--space-sm);
    }
    
    .calendar-day {
        min-height: 50px;
    }
    
    .calendar-day-number {
        font-size: 0.625rem;
    }
    
    /* Stack action buttons vertically */
    .flex.gap-2,
    .action-buttons {
        flex-direction: column;
        gap: var(--space-xs);
    }
    
    .flex.gap-2 .btn,
    .action-buttons .btn {
        width: 100%;
    }
}

/* ==========================================================================
   TOUCH DEVICE IMPROVEMENTS
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets */
    .btn, 
    .btn-icon,
    .nav-tab,
    .bottom-nav-item {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }
    
    /* Better tap feedback */
    .btn:active,
    .card:active,
    .nav-tab:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Thicker separators for visibility */
    .table tr {
        border-bottom: 2px solid #e2e8f0;
    }
    
    /* Larger calendar events for touch */
    .calendar-event {
        min-height: 32px;
        padding: var(--space-xs) var(--space-sm);
    }
    
    /* Remove hover effects */
    .btn:hover,
    .card:hover,
    .nav-tab:hover {
        transform: none;
    }
}

/* ==========================================================================
   PULL TO REFRESH (PWA)
   ========================================================================== */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #f8fafc 0%, transparent 100%);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
}

.pull-to-refresh.visible {
    transform: translateY(0);
}

.pull-to-refresh-icon {
    width: 24px;
    height: 24px;
    border: 2px solid #3b82f6;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   SWIPE GESTURES
   ========================================================================== */
.swipeable {
    touch-action: pan-y;
}

.swipeable-card {
    transition: transform 0.3s ease;
}

.swipeable-card.swiping {
    transition: none;
}

/* ==========================================================================
   SKELETON LOADING
   ========================================================================== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-title {
    height: 1.5em;
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    left: var(--space-md);
    right: var(--space-md);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    background: #1f2937;
    color: white;
    padding: var(--space-md);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: auto;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: #10b981;
}

.toast.error {
    background: #ef4444;
}

.toast.warning {
    background: #f59e0b;
}

.toast-message {
    flex: 1;
    font-size: var(--fs-sm);
}

.toast-close {
    padding: var(--space-xs);
    cursor: pointer;
    opacity: 0.7;
}

.toast-close:hover {
    opacity: 1;
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

/* High contrast mode */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid currentColor;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    .table th,
    .table td {
        border: 1px solid currentColor;
    }
    
    .form-control {
        border: 2px solid currentColor;
    }
}

/* Reduced motion */
@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;
        background: #e0e0e0;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1f2937;
        --bg-secondary: #374151;
        --text-primary: #f9fafb;
        --text-secondary: #9ca3af;
        --border-color: #4b5563;
    }
    
    .bottom-nav {
        background: #1f2937;
        border-top-color: #374151;
    }
    
    .bottom-nav-item {
        color: #9ca3af;
    }
    
    .bottom-nav-item.active {
        color: #60a5fa;
        background: rgba(96, 165, 250, 0.15);
    }
    
    .toast {
        background: #374151;
    }
    
    .calendar-day-other {
        background: #374151;
        color: #6b7280;
    }
    
    .calendar-day-today {
        background: #1e40af;
        color: white;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */
@media print {
    .header-actions,
    .navigation,
    .nav-tabs,
    .bottom-nav,
    .btn,
    .modal-overlay,
    .toast-container {
        display: none !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #000;
        break-inside: avoid;
    }
    
    .main-content {
        padding: 0;
    }
    
    body {
        padding-bottom: 0;
    }
    
    .table {
        font-size: 10pt;
    }
}