:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --safe-bottom: 0px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
    -webkit-user-select: none;
    user-select: none;
}

input, select, textarea { -webkit-user-select: text; user-select: text; }

.app-container {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    background: #f3f4f6;
}

/* Top bar */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: white;
    color: #1f2937;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 1px solid #e5e7eb;
}

.top-bar h1 { font-size: 16px; font-weight: 700; color: #111827; }
.top-bar .subtitle { font-size: 11px; color: #6b7280; margin-top: 1px; }
.top-bar-logo { height: 28px; }

/* Bottom nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    z-index: 50;
    padding-bottom: var(--safe-bottom);
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 4px 10px;
    text-decoration: none;
    color: #9ca3af;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav a i { font-size: 18px; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a:active { opacity: 0.7; }

/* Page content */
.page-content {
    padding: 16px 16px calc(70px + var(--safe-bottom));
}

/* Cards */
.card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.kpi-label { font-size: 11px; color: #6b7280; font-weight: 500; }
.kpi-value { font-size: 20px; font-weight: 700; color: #111827; margin-top: 4px; line-height: 1.1; }
.kpi-value.sm { font-size: 16px; }
.kpi-icon { font-size: 14px; margin-bottom: 6px; }

/* List items */
.list-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}
.list-item:last-child { border-bottom: none; }
.list-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-right: 12px;
}
.list-info { flex: 1; min-width: 0; }
.list-title { font-size: 13px; font-weight: 600; color: #1f2937; }
.list-sub { font-size: 11px; color: #9ca3af; margin-top: 1px; }
.list-right { text-align: right; flex-shrink: 0; margin-left: 8px; }
.list-amount { font-size: 14px; font-weight: 700; color: #111827; }
.list-amount.green { color: #059669; }
.list-status { font-size: 10px; margin-top: 2px; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* Filter pills */
.filter-pills {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.filter-pills::-webkit-scrollbar { display: none; }
.filter-pill {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid #e5e7eb;
    background: white;
    color: #6b7280;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s;
}
.filter-pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Section title */
.section-title {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 10px;
}

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

/* Pull to refresh indicator */
.ptr-indicator {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: #9ca3af;
    display: none;
}

/* Hamburger menu overlay */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}
.menu-overlay.open { opacity: 1; visibility: visible; }

.menu-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: white;
    z-index: 101;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}
.menu-drawer.open { transform: translateX(0); }

.menu-header {
    background: white;
    color: #1f2937;
    padding: 24px 20px 20px;
    padding-top: max(24px, calc(env(safe-area-inset-top) + 12px));
    border-bottom: 1px solid #e5e7eb;
}
.menu-header .user-name { font-size: 16px; font-weight: 700; color: #111827; }
.menu-header .user-email { font-size: 12px; color: #6b7280; margin-top: 2px; }
.menu-header .user-empresa { font-size: 11px; color: #9ca3af; margin-top: 4px; }

.menu-items { flex: 1; padding: 8px 0; overflow-y: auto; }
.menu-item {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    font-size: 14px;
    color: #374151;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.menu-item:active { background: #f9fafb; }
.menu-item i { width: 24px; margin-right: 14px; font-size: 16px; color: #6b7280; }
.menu-item.active { color: var(--primary); font-weight: 600; }
.menu-item.active i { color: var(--primary); }
.menu-divider { height: 1px; background: #f3f4f6; margin: 4px 0; }

.menu-footer {
    padding: 16px 20px;
    border-top: 1px solid #f3f4f6;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
}
.empty-state i { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* Login page */
.login-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #f3f4f6;
}
.login-card {
    background: white;
    border-radius: 20px;
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { height: 48px; }
.login-title { text-align: center; font-size: 20px; font-weight: 700; color: #111827; margin-bottom: 4px; }
.login-subtitle { text-align: center; font-size: 13px; color: #6b7280; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    color: #111827;
    background: #f9fafb;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    background: white;
}

.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.6; }

.btn-outline {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: #dc2626;
    border: 1px solid #fecaca;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.login-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 16px;
    display: none;
}

/* Profile sections */
.profile-section { margin-bottom: 8px; }
.profile-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
.profile-value { font-size: 14px; color: #1f2937; font-weight: 500; margin-top: 2px; }

/* Machine filter */
.machine-filter {
    margin-bottom: 12px;
}
.machine-filter select {
    width: 100%;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px !important;
}

/* Machine card */
.machine-status { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.machine-status.active { background: #10b981; }
.machine-status.inactive { background: #ef4444; }
