:root {
    /* Color Palette - Premium & Modern */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary-color: #64748b;
    --accent-color: #0ea5e9;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;

    /* Backgrounds */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.1);

    /* Text */
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #f8fafc;
    --text-sidebar: #cbd5e1;

    /* Shadows & Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 10px 10px -5px rgb(0 0 0 / 0.04);
    --radius: 0.75rem;
    --radius-sm: 0.5rem;
    --radius-lg: 1rem;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    font-size: 16px;
    overflow-x: hidden;
    /* iOS Safe Area Support */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    line-height: 1.2;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1.125rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

a:hover,
a:focus {
    color: var(--primary-hover);
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
    width: 100%;
    overflow-x: hidden;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--bg-sidebar) 0%, #0f172a 100%);
    color: var(--text-light);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 999;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-shadow: 4px 0 6px rgba(0, 0, 0, 0.1);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar-header {
    margin-bottom: 2rem;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.sidebar-header img {
    max-height: 32px;
    max-width: 32px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.sidebar-header svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    color: var(--text-sidebar);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9375rem;
    transition: var(--transition-fast);
    position: relative;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    /* Touch target size */
}

.nav-link i {
    width: 24px;
    height: 24px;
    margin-right: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.nav-link:hover {
    background-color: var(--bg-sidebar-hover);
    color: white;
    transform: translateX(4px);
}

.nav-link.active {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.2) 0%, rgba(37, 99, 235, 0.1) 100%);
    color: white;
    border-left: 3px solid var(--primary-color);
    padding-left: calc(1rem - 3px);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color);
    border-radius: 0 2px 2px 0;
}

/* Main Content - margin-left evita que o sidebar cubra o conteúdo */
.main-content {
    flex: 1;
    margin-left: 280px;
    padding: 2rem;
    max-width: calc(100% - 280px);
    /* Garante que nunca exceda o espaço disponível */
    min-width: 0;
    box-sizing: border-box;
    transition: margin-left 0.3s ease;
    position: relative;
    z-index: 1;
}

/* Suporte para elementos que estão diretamente no app-container (como o dashboard.php) */
.app-container > .stats-grid,
.app-container > h3,
.app-container > .card,
.app-container > div:not(.sidebar):not(.sidebar-overlay):not(.mobile-menu-toggle) {
    margin-left: 280px;
    max-width: calc(100% - 280px);
    padding-left: 2rem;
    padding-right: 2rem;
}

/* Ajuste específico para stats-grid */
.app-container > .stats-grid {
    padding-left: 2rem;
    padding-right: 2rem;
    box-sizing: border-box;
    width: calc(100% - 280px);
}

/* Tablet & Desktop Margin Reinforcement */
@media (min-width: 1025px) {
    .main-content {
        margin-left: 280px !important;
        max-width: calc(100% - 280px) !important;
    }
    
    .app-container > .stats-grid,
    .app-container > h3,
    .app-container > .card,
    .app-container > div:not(.sidebar):not(.sidebar-overlay):not(.mobile-menu-toggle) {
        margin-left: 280px;
        max-width: calc(100% - 280px);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 260px;
    }
    
    .main-content {
        margin-left: 260px !important;
        max-width: calc(100% - 260px) !important;
    }
    
    .app-container > .stats-grid,
    .app-container > h3,
    .app-container > .card,
    .app-container > div:not(.sidebar):not(.sidebar-overlay):not(.mobile-menu-toggle) {
        margin-left: 260px;
        max-width: calc(100% - 260px);
    }
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius-sm);
    width: 44px;
    height: 44px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-toggle:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-main);
}

/* Header Styles */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h2 {
    font-size: 1.75rem;
    margin: 0;
    flex: 1;
    min-width: 200px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    overflow: hidden;
    flex-shrink: 0;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.user-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-main);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.user-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary-color);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9375rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: var(--radius);
    font-size: 1rem;
    transition: var(--transition-fast);
    background-color: #fff;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    border: none;
    transition: var(--transition-fast);
    gap: 0.5rem;
    min-height: 44px;
    /* Touch target */
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.35);
    transform: translateY(-2px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.25);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.25);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-height: 36px;
}

.btn-icon {
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.875rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-primary {
    background: var(--primary-light);
    color: var(--primary-color);
}

.badge-warning {
    background: #fef3c7;
    color: #d97706;
}

.badge-success {
    background: #d1fae5;
    color: #059669;
}

.badge-danger {
    background: #fee2e2;
    color: #dc2626;
}

.badge-info {
    background: #dbeafe;
    color: var(--primary-color);
}

/* Tables */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: var(--bg-card);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

thead {
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    color: var(--text-main);
}

tbody tr {
    transition: var(--transition-fast);
}

tbody tr:hover {
    background: #f8fafc;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    animation: pulse 20s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h2 {
    color: var(--text-main);
    font-size: 1.875rem;
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

/* Document Mapper Styles */
.mapper-container {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    height: calc(100vh - 140px);
}

.pdf-section {
    flex: 1;
    background: #e2e8f0;
    border-radius: var(--radius-lg);
    overflow: auto;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1.5rem;
    border: 1px solid #cbd5e1;
    -webkit-overflow-scrolling: touch;
}

.pdf-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    background: white;
    max-width: 100%;
}

.pdf-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.sidebar-tools {
    width: 350px;
    flex-shrink: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: var(--shadow-md);
    height: 100%;
    min-height: 0;
    /* Required for flex child to allow overflow */
    overflow: visible;
    /* Campos devem ser sempre visíveis */
}

.tool-section h4 {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #e2e8f0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.field-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
    min-height: 380px;
    /* Espaço mínimo para exibir vários campos sem scroll inicial */
    min-width: 0;
    overflow-y: auto;
    /* Scroll quando necessário - todos os campos permanecem acessíveis */
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.5rem;
}

.field-list::-webkit-scrollbar {
    width: 6px;
}

.field-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.field-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Garantia: todos os campos do mapeamento DEVEM ser exibidos - nunca ocultar */
.field-item-enhanced {
    flex-shrink: 0;
    /* Impede que campos sejam comprimidos ou cortados */
    display: flex !important;
    /* Bloqueia tentativa de ocultar via display:none */
    visibility: visible !important;
    /* Bloqueia tentativa de ocultar via visibility */
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    padding: 0.875rem;
    border-radius: var(--radius);
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.9375rem;
    transition: var(--transition-fast);
}

.field-item-enhanced .field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.field-item-enhanced .field-name {
    font-weight: 600;
    color: var(--text-main);
}

.field-item-enhanced .field-status {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
}

.field-item-enhanced .field-status.status-empty {
    background: #fef3c7;
    color: #92400e;
}

.field-item-enhanced .field-status.status-mapped {
    background: #d1fae5;
    color: #065f46;
}

.field-item-enhanced .field-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.field-item-enhanced .mapped-coords {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mapper-fields-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Container controla; .field-list faz scroll */
}

.field-item {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9375rem;
    transition: var(--transition-fast);
}

.field-item.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.delete-btn {
    color: var(--danger-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    background: #fee2e2;
}

/* Selection Layer */
.selection-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: crosshair;
    touch-action: none;
}

.selection-box {
    position: absolute;
    border: 2px solid var(--primary-color);
    background-color: rgba(37, 99, 235, 0.15);
    z-index: 20;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 4px;
}

.selection-box:hover,
.selection-box.selected {
    background-color: rgba(37, 99, 235, 0.3);
    border-color: var(--primary-hover);
    z-index: 30;
}

.selection-label {
    position: absolute;
    top: -28px;
    left: -2px;
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px 4px 0 0;
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.p-1 {
    padding: 0.5rem;
}

.p-2 {
    padding: 1rem;
}

.p-3 {
    padding: 1.5rem;
}

/* Responsive Design */
/* Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 260px;
    }

    .main-content {
        margin-left: 260px;
        padding: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }

    .mapper-container {
        flex-direction: column;
    }

    /* Garantia: sidebar de campos SEM altura máxima restritiva - todos os campos visíveis com scroll */
    .sidebar-tools {
        max-height: none;
        min-height: 400px;
        height: auto;
    }
}

/* Mobile & Small Tablets */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 4.5rem;
        max-width: 100%;
        /* Space for mobile menu button */
    }

    /* Elementos do dashboard também devem ter margem zero no mobile */
    .app-container > .stats-grid,
    .app-container > h3,
    .app-container > .card,
    .app-container > div:not(.sidebar):not(.sidebar-overlay):not(.mobile-menu-toggle) {
        margin-left: 0;
        max-width: 100%;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .app-container > .stats-grid {
        width: 100%;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header h2 {
        font-size: 1.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .user-info {
        flex: 1;
        min-width: 0;
    }

    .user-details {
        min-width: 0;
        overflow: hidden;
    }

    .user-name,
    .user-role,
    .user-date {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .card {
        padding: 1.25rem;
        border-radius: var(--radius);
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .table-container {
        border-radius: var(--radius);
    }

    table {
        font-size: 0.875rem;
    }

    th,
    td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8125rem;
    }

    /* Stack table on mobile */
    .table-responsive {
        display: block;
    }

    .table-responsive thead {
        display: none;
    }

    .table-responsive tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e2e8f0;
        border-radius: var(--radius);
        padding: 1rem;
        background: var(--bg-card);
    }

    .table-responsive tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f1f5f9;
        text-align: right;
    }

    .table-responsive tbody td:last-child {
        border-bottom: none;
    }

    .table-responsive tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-main);
        text-align: left;
        margin-right: 1rem;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .btn-sm {
        width: auto;
    }

    .login-card {
        padding: 2rem 1.5rem;
    }

    .login-header h2 {
        font-size: 1.5rem;
    }

    .mapper-container {
        height: auto;
        min-height: 400px;
    }

    .pdf-section {
        padding: 1rem;
        min-height: 300px;
    }

    /* Garantia: todos os campos sempre visíveis em mobile - scroll vertical quando necessário */
    .sidebar-tools {
        max-height: none;
        min-height: 350px;
        height: auto;
    }

    .field-list {
        max-height: 65vh;
        /* Permite scroll para acessar TODOS os 8+ campos - nenhum fica oculto */
    }

    .form-group {
        margin-bottom: 1.25rem;
    }

    input,
    select,
    textarea {
        padding: 0.75rem;
        font-size: 16px;
        /* Prevents zoom on iOS */
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
        padding-top: 4rem;
    }

    .page-header h2 {
        font-size: 1.25rem;
    }

    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .login-card {
        padding: 1.5rem 1.25rem;
    }

    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    .nav-link {
        padding: 0.75rem;
        font-size: 0.875rem;
    }

    .sidebar {
        width: 100%;
        max-width: 320px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .main-content {
        padding-top: 3.5rem;
    }

    .sidebar {
        width: 240px;
    }
}

/* Print Styles */
@media print {

    .sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #e2e8f0;
        page-break-inside: avoid;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles for Keyboard Navigation */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --bg-card: #ffffff;
        --text-main: #000000;
        --border-color: #000000;
    }

    .card {
        border: 2px solid var(--text-main);
    }
}

/* PWA & Mobile Specific Enhancements */
@media (max-width: 768px) {

    /* Improve touch targets */
    input,
    select,
    button,
    .nav-link {
        min-height: 48px;
    }

    /* Better spacing for PWA fixed elements */
    .main-content {
        padding-bottom: 80px;
        /* Space for potential bottom navs or OS bars */
    }

    /* Fix weird iOS inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"] {
        -webkit-appearance: none;
        appearance: none;
        border-radius: var(--radius);
    }
}

/* iOS PWA Install Prompt */
.ios-prompt {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    padding: 1.5rem;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    border-top: 1px solid #e2e8f0;
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    text-align: center;
    animation: slideUp 0.3s ease-out;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

.ios-prompt.active {
    display: flex;
}

.ios-prompt h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    color: var(--text-main);
}

.ios-prompt p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.ios-prompt .instructions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--primary-color);
}

.ios-prompt-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* Android Install Button */
.android-install-btn {
    display: none;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-right: 1rem;
}