/* ============================================
   PRESUYA — Estilos mobile-first
   Paleta: Naranja #F5A623 · Negro #1A1A1A
============================================ */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
    --primary: #F5A623;
    --primary-dark: #D88F15;
    --primary-light: #FEF3DF;
    --primary-glow: rgba(245,166,35,0.18);
    --black: #1A1A1A;
    --gray-900: #2C2C2C;
    --gray-700: #4A4A4A;
    --gray-500: #8A8A8A;
    --gray-400: #B0B0B0;
    --gray-300: #D1D1D1;
    --gray-200: #E8E8E8;
    --gray-100: #F5F5F5;
    --gray-50:  #FAFAFA;
    --whatsapp: #25D366;
    --whatsapp-dark: #1EBE5B;
    --success: #2ECC71;
    --danger: #E74C3C;
    --warning: #F39C12;
    --info: #3498DB;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --header-h: 56px;
    --bottom-nav-h: 64px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.45;
    font-size: 15px;
    min-height: 100vh;
    overscroll-behavior-y: contain;
}

/* ============================================
   LAYOUT GLOBAL
============================================ */
.app {
    min-height: 100vh;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--black);
    color: white;
    height: var(--header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
}
.app-header h1 {
    font-size: 17px;
    font-weight: 600;
}
.app-header .brand-mini {
    display: flex;
    align-items: center;
    gap: 10px;
}
.app-header .brand-mini .logo-dot {
    width: 28px; height: 28px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--black);
    font-weight: 800;
    font-size: 14px;
}
.app-header .icon-btn {
    background: transparent;
    border: none;
    color: white;
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
}
.app-header .icon-btn:hover { background: rgba(255,255,255,0.1); }

.page {
    padding: 16px;
    max-width: 720px;
    margin: 0 auto;
}

/* ============================================
   AUTH (login/signup)
============================================ */
.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: linear-gradient(180deg, var(--primary-light) 0%, white 100%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: white;
    border-radius: var(--radius);
    padding: 28px 24px;
    box-shadow: var(--shadow-lg);
}
.auth-brand {
    text-align: center;
    margin-bottom: 24px;
}
.auth-brand .big-logo {
    width: 64px; height: 64px;
    background: var(--primary);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--black);
    font-size: 30px;
    font-weight: 800;
    margin-bottom: 10px;
}
.auth-brand h1 {
    font-size: 26px;
    color: var(--black);
    font-weight: 800;
    letter-spacing: -0.5px;
}
.auth-brand .tagline {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}
.auth-tabs {
    display: flex;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}
.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.auth-tab.active {
    background: white;
    color: var(--black);
    box-shadow: var(--shadow-sm);
}

.auth-foot {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--gray-200);
    font-size: 13px;
    color: var(--gray-500);
    line-height: 1.55;
    text-align: center;
}
.auth-foot strong { color: var(--gray-700); }
.auth-foot a {
    color: var(--whatsapp);
    font-weight: 700;
    text-decoration: none;
}
.auth-foot a:hover { text-decoration: underline; }

/* ============================================
   FORMS
============================================ */
.field {
    margin-bottom: 14px;
}
.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    color: var(--gray-900);
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.field textarea { resize: vertical; min-height: 70px; }

.field .hint {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
}

.field-row {
    display: flex;
    gap: 10px;
}
.field-row > .field { flex: 1; }

/* ============================================
   BUTTONS
============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.05s, background 0.15s;
    min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--black); }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: white;
    color: var(--gray-900);
    border: 1px solid var(--gray-300);
}
.btn-secondary:hover { background: var(--gray-50); }

.btn-ghost {
    background: transparent;
    color: var(--gray-700);
}
.btn-ghost:hover { background: var(--gray-100); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }

.btn-whatsapp { background: var(--whatsapp); color: white; }
.btn-whatsapp:hover { background: var(--whatsapp-dark); }

.btn-block { width: 100%; }

.btn-link {
    background: transparent;
    border: none;
    color: var(--primary-dark);
    text-decoration: underline;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
}

/* ============================================
   CARDS
============================================ */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
}
.card h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--black);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   DASHBOARD — listado de presupuestos
============================================ */
.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.toolbar .search-box {
    flex: 1;
    min-width: 180px;
    position: relative;
}
.toolbar .search-box input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: white;
}
.toolbar .search-box::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    opacity: 0.5;
}

.filter-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-bottom: 12px;
    scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 100px;
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: inherit;
}
.chip.active {
    background: var(--black);
    color: white;
    border-color: var(--black);
}

.budget-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.budget-card {
    background: white;
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    border-left: 4px solid var(--gray-300);
    transition: transform 0.05s, box-shadow 0.15s;
}
.budget-card:active { transform: scale(0.98); }
.budget-card.estado-borrador   { border-left-color: var(--gray-400); }
.budget-card.estado-enviado    { border-left-color: var(--info); }
.budget-card.estado-aprobado   { border-left-color: var(--success); }
.budget-card.estado-rechazado  { border-left-color: var(--danger); }
.budget-card.estado-vencido    { border-left-color: var(--gray-500); opacity: 0.75; }

.budget-card .row1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.budget-card .numero {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 600;
    letter-spacing: 0.5px;
}
.budget-card .cliente {
    font-size: 16px;
    font-weight: 600;
    color: var(--black);
}
.budget-card .row2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.budget-card .monto {
    font-size: 17px;
    font-weight: 700;
    color: var(--primary-dark);
}
.budget-card .fecha {
    font-size: 12px;
    color: var(--gray-500);
}

.estado-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.estado-badge.borrador  { background: var(--gray-200); color: var(--gray-700); }
.estado-badge.enviado   { background: #D6EAF8; color: #1F618D; }
.estado-badge.aprobado  { background: #D5F5E3; color: #1E8449; }
.estado-badge.rechazado { background: #FADBD8; color: #B03A2E; }
.estado-badge.vencido   { background: var(--gray-200); color: var(--gray-500); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}
.empty-state .icon { font-size: 48px; margin-bottom: 10px; opacity: 0.4; }
.empty-state h3 { font-size: 17px; color: var(--gray-700); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* ============================================
   FAB (Floating Action Button)
============================================ */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--black);
    border: none;
    box-shadow: var(--shadow-lg);
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}
.fab:active { transform: scale(0.92); }

/* ============================================
   BOTTOM NAV
============================================ */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: white;
    border-top: 1px solid var(--gray-200);
    display: flex;
    z-index: 18;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--gray-500);
    font-size: 11px;
    font-weight: 500;
    gap: 2px;
    transition: color 0.15s;
}
.bottom-nav a.active { color: var(--primary-dark); }
.bottom-nav a .nav-icon { font-size: 22px; }

/* ============================================
   EDITOR de presupuesto
============================================ */
.editor-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.editor-head .numero-label {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 600;
}
.editor-head .numero-value {
    font-size: 18px;
    color: var(--black);
    font-weight: 700;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}
.items-empty {
    text-align: center;
    color: var(--gray-500);
    padding: 22px 14px;
    font-size: 13px;
    background: var(--gray-50);
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-sm);
    margin: 0 0 4px;
}

.item-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 14px 14px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.item-index {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.item-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 5px;
}
.item-field { display: flex; flex-direction: column; }
.item-desc-input {
    width: 100%;
    min-height: 52px;
    max-height: 320px;
    padding: 11px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 15px;
    line-height: 1.45;
    background: white;
    font-family: inherit;
    color: var(--black);
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
    overflow-y: auto;
}
.item-desc-input::placeholder {
    color: var(--gray-400, #bbb);
    font-size: 14px;
}
.item-desc-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.item-nums-grid {
    display: grid;
    grid-template-columns: 90px 1fr 1fr;
    gap: 10px;
    align-items: end;
}
.item-num-cell { display: flex; flex-direction: column; }
.item-num-cell input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: white;
    text-align: right;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
}
.item-num-cell input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.item-subtotal-value {
    padding: 11px 12px;
    font-size: 15px;
    font-weight: 700;
    color: var(--black);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}
.item-remove {
    background: transparent;
    border: none;
    color: var(--gray-500);
    width: 32px; height: 32px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}
.item-remove:hover { background: #ffebeb; color: var(--danger); }

@media (max-width: 460px) {
    .item-nums-grid {
        grid-template-columns: 1fr 1fr;
    }
    .item-subtotal-cell {
        grid-column: 1 / -1;
    }
}

.total-box {
    background: var(--primary);
    color: var(--black);
    padding: 14px 18px;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    margin: 16px 0;
}
.total-box .label { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; }
.total-box .value { font-size: 20px; }

.actions-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

/* ============================================
   PERFIL — avatar / logo upload
============================================ */
.avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: var(--gray-50);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.avatar-preview {
    width: 120px; height: 120px;
    border-radius: 50%;
    background: white;
    border: 2px dashed var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--gray-400);
    font-size: 38px;
}
.avatar-preview img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.avatar-upload input[type=file] { display: none; }

/* ============================================
   TOAST
============================================ */
.toast {
    position: fixed;
    bottom: calc(var(--bottom-nav-h) + 24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--black);
    color: white;
    padding: 12px 20px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ============================================
   LOADING
============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ============================================
   DESKTOP (tablet/pc)
============================================ */
@media (min-width: 768px) {
    .page { padding: 24px; }
    .bottom-nav { display: none; }
    .app { padding-bottom: 0; }
    .app-header { padding: 0 24px; }
    .fab { bottom: 24px; right: 24px; }
}
