/**
 * Mobile Optimizations - Complete Responsive Design
 * Adicionar DEPOIS de dashboard.css
 */

/* ============================================
   RECENT FATURAS (Dashboard)
   ============================================ */

.recent-faturas-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.recent-fatura-item {
    padding: 12px;
    background: #f8f9fa;
    border-left: 3px solid #3498db;
    border-radius: 6px;
    transition: all 0.2s;
}

.recent-fatura-item:hover {
    background: #e9ecef;
    transform: translateX(3px);
}

.recent-fatura-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.fatura-categoria {
    font-weight: 600;
    color: var(--text-color, #2c3e50);
    font-size: 0.95rem;
}

.fatura-valor {
    font-size: 1.1rem;
    font-weight: 700;
    color: #3498db;
}

.recent-fatura-details {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.85rem;
    color: #718096;
    margin-bottom: 6px;
}

.fatura-data {
    font-weight: 500;
}

.fatura-desc {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fatura-tags-small {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tag-small {
    display: inline-block;
    padding: 2px 8px;
    background: #e3f2fd;
    color: #1976d2;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

@media (max-width: 768px) {
    .recent-fatura-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .recent-fatura-details {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .fatura-desc {
        white-space: normal;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        display: -webkit-box;
    }
}

/* ============================================
   LOGO & BRANDING
   ============================================ */

.sidebar-logo {
    max-width: 180px;
    width: 100%;
    height: auto;
    object-fit: contain;
}

.sidebar-header {
    padding: 15px !important;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 1024px) {
    .sidebar-logo {
        max-width: 140px;
    }

    .sidebar-header {
        min-height: 55px;
        padding: 12px !important;
    }
}

/* Logo no Auth (Login/Register) */
.auth-header .logo img {
    max-width: 280px !important;
    width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .auth-header .logo img {
        max-width: 220px !important;
    }
}

@media (max-width: 480px) {
    .auth-header .logo img {
        max-width: 180px !important;
    }
}

/* ============================================
   MOBILE FIRST - BASE OVERRIDES
   ============================================ */

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    z-index: 98;
    padding: 0 15px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

@media (max-width: 1024px) {
    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-top: 60px !important;
        padding-top: 20px;
    }
}

.mobile-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-header-menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    transition: background 0.2s;
}

.mobile-header-menu-btn:active {
    background: rgba(255,255,255,0.1);
}

.mobile-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-header-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    background: white;
    padding: 4px;
}

.mobile-header-title > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mobile-header-title h1 {
    font-size: 1.1rem !important;
    margin: 0;
    font-weight: 700;
}

.mobile-header-title .obra-name {
    font-size: 0.75rem;
    opacity: 0.9;
    font-weight: 400;
}

.mobile-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-header-obra-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.mobile-header-obra-btn:active {
    background: rgba(255,255,255,0.3);
}

/* Sidebar Mobile Toggle */
@media (max-width: 1024px) {
    body {
        overflow-x: hidden;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        top: 60px; /* Below mobile header */
        height: calc(100vh - 60px);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Overlay when sidebar is open */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 97;
        animation: fadeIn 0.3s;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Hide original topbar on mobile */
    .topbar {
        display: none;
    }

    /* Mobile Menu Button (fallback) */
    .mobile-menu-toggle {
        display: none !important; /* Using header button instead */
    }
}

/* ============================================
   TABLET (768px - 1024px)
   ============================================ */

@media (max-width: 1024px) and (min-width: 769px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .faturas-grid {
        grid-template-columns: 1fr;
    }
}

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

@media (max-width: 768px) {
    /* Typography */
    h1, .page-title {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    /* Topbar */
    .topbar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch !important;
        padding: 15px !important;
    }

    .topbar-left {
        width: 100%;
    }

    .topbar-right {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }

    .obra-selector {
        width: 100%;
    }

    .obra-selector select {
        width: 100%;
        font-size: 0.95rem;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .stat-card {
        padding: 16px !important;
    }

    .stat-value {
        font-size: 1.75rem !important;
    }

    .stat-label {
        font-size: 0.85rem !important;
    }

    /* Section Headers */
    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }

    .section-header h2 {
        font-size: 1.25rem !important;
    }

    .section-header button,
    .section-header .btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* Charts */
    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    .chart-card {
        padding: 16px !important;
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    .form-control {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px;
    }

    input[type="date"],
    input[type="number"],
    input[type="text"],
    input[type="email"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Modals */
    .modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 10px !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-header h2 {
        font-size: 1.25rem !important;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 16px;
        flex-direction: column;
        gap: 10px;
    }

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

    /* Tables */
    .faturas-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .faturas-table table {
        min-width: 600px;
    }

    .faturas-table th,
    .faturas-table td {
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    /* Fatura Cards (Better for mobile than tables) */
    .fatura-item {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 15px;
        background: white;
        border-radius: 8px;
        border: 1px solid var(--border-color);
        margin-bottom: 12px;
    }

    .fatura-item-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
    }

    .fatura-item-title {
        font-weight: 600;
        color: var(--text-color);
        font-size: 1rem;
    }

    .fatura-item-valor {
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--primary-color);
    }

    .fatura-item-details {
        display: flex;
        flex-direction: column;
        gap: 6px;
        font-size: 0.85rem;
        color: var(--text-light);
    }

    .fatura-item-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
    }

    .fatura-item-actions button {
        flex: 1;
        padding: 8px;
        font-size: 0.85rem;
    }

    /* Buttons */
    .btn,
    button {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    .btn-icon {
        padding: 10px;
    }

    /* Filters */
    .filters {
        flex-direction: column !important;
        gap: 10px;
    }

    .filters > * {
        width: 100% !important;
    }

    .search-box {
        width: 100% !important;
    }

    .search-box input {
        width: 100%;
    }

    /* Tags */
    .tag {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    /* Profile */
    .profile-grid {
        grid-template-columns: 1fr !important;
    }

    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .avatar {
        width: 80px !important;
        height: 80px !important;
        font-size: 2rem !important;
    }

    /* Obras Grid */
    .obras-grid {
        grid-template-columns: 1fr !important;
    }

    .obra-card {
        padding: 16px;
    }

    /* Lista de Compras */
    .compra-item {
        padding: 16px;
    }

    .compra-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }

    .compra-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .compra-badges {
        width: 100%;
        flex-wrap: wrap;
    }

    /* Upload Zone */
    .upload-zone {
        padding: 1.5rem 1rem;
    }

    .upload-zone i {
        font-size: 2rem !important;
    }

    .upload-zone p {
        font-size: 0.9rem;
    }

    /* OCR Status */
    #ocr-status,
    #file-preview {
        font-size: 0.85rem;
    }

    /* Sidebar Footer */
    .sidebar-footer {
        padding: 15px;
    }

    .user-info h4 {
        font-size: 0.9rem;
    }

    .user-info p {
        font-size: 0.75rem;
    }
}

/* ============================================
   SMALL MOBILE (< 480px)
   ============================================ */

@media (max-width: 480px) {
    .stat-card {
        padding: 12px !important;
    }

    .stat-value {
        font-size: 1.5rem !important;
    }

    .chart-card {
        padding: 12px !important;
    }

    h1, .page-title {
        font-size: 1.25rem !important;
    }

    .topbar {
        padding: 12px !important;
    }

    .section-header h2 {
        font-size: 1.1rem !important;
    }

    .modal-content {
        margin: 5px !important;
        width: calc(100vw - 10px) !important;
    }

    .fatura-item {
        padding: 12px;
    }

    .fatura-item-valor {
        font-size: 1.1rem;
    }

    .compra-item {
        padding: 12px;
    }
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */

/* Larger touch targets */
@media (max-width: 768px) {
    button,
    .btn,
    a.nav-item {
        min-height: 44px; /* iOS recommended minimum */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-item {
        padding: 15px 20px;
    }

    /* Better tap highlight */
    button,
    a,
    .clickable {
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    }

    /* Remove hover effects on touch devices */
    .nav-item:hover {
        background: transparent;
    }

    .nav-item:active {
        background: var(--bg-light);
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 85vh;
    }

    .sidebar {
        overflow-y: auto;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ============================================
   SAFE AREAS (iPhone Notch, etc)
   ============================================ */

@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar-footer {
        padding-bottom: calc(15px + env(safe-area-inset-bottom));
    }

    .mobile-menu-toggle {
        bottom: calc(20px + env(safe-area-inset-bottom));
        right: calc(20px + env(safe-area-inset-right));
    }

    .main-content {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Hide on mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Responsive Text */
.text-responsive {
    font-size: clamp(0.875rem, 2vw, 1rem);
}

/* Prevent text zoom on iOS */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Smooth scrolling */
@media (max-width: 768px) {
    html {
        scroll-behavior: smooth;
    }

    * {
        -webkit-overflow-scrolling: touch;
    }
}
