/* ============================================================
   PRESUPUESTOS.CSS — Flomay  (basado en administracion.css)
   ============================================================ */

* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Segoe UI', Arial, sans-serif;
    transition: background-color var(--transition-speed),
                color var(--transition-speed),
                border-color var(--transition-speed),
                box-shadow var(--transition-speed);
}

:root {
    --transition-speed: 0.3s;
    --bg-dark: #f0f2f5;
    --bg-darker: #ffffff;
    --text-light: #1a1b1e;
    --text-gray: #4b5563;
    --primary-blue: #3b82f6;
    --accent-dark: #2563eb;
    --shadow-color: rgba(0,0,0,0.1);
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #e5e9f2 100%);
    min-height: 100vh;
}

/* ── HEADER ──────────────────────────────────── */
header {
    background-color: var(--bg-darker);
    padding: 1rem 2rem;
    display: flex; justify-content: space-between; align-items: center;
    height: 60px;
    box-shadow: 0 5px 20px rgba(0,0,0,.3);
    position: relative; z-index: 10;
}
.logo-container { display: flex; align-items: center; gap: 1rem; }
.logo-image { height: 40px; width: auto; object-fit: contain; }
.logo { color: var(--text-light); font-weight: bold; font-size: 1.2rem; }
.search-bar { display: flex; align-items: center; flex: 1; max-width: 400px; margin: 0 2rem; }
.search-bar input {
    padding: .8rem; border: none; border-radius: 20px;
    width: 100%; background: rgba(255,255,255,.05);
    color: var(--text-light);
    box-shadow: inset 0 2px 5px rgba(0,0,0,.1);
    transition: all .3s ease;
}
.search-bar input:focus { outline: none; box-shadow: 0 0 15px rgba(59,130,246,.3); }
.user-info { display: flex; align-items: center; gap: 1rem; }
.logout-button {
    background-color: transparent; border: 1px solid var(--primary-blue);
    color: var(--primary-blue); padding: .5rem 1rem; border-radius: 20px;
    cursor: pointer; display: flex; align-items: center; gap: .5rem;
    transition: all .3s ease;
}
.logout-button:hover { background-color: var(--primary-blue); color: white; }
#userName { font-weight: 500; color: var(--text-light); }

/* ── MAIN CONTAINER ──────────────────────────── */
.admin-container { max-width: 1200px; margin: 2rem auto; padding: 0 1rem 80px; }

/* ── ADMIN SECTION ───────────────────────────── */
.admin-section {
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(10px);
    box-shadow: 0 5px 20px rgba(0,0,0,.05);
    border-radius: 15px;
    border: 1px solid rgba(255,255,255,.8);
    padding: 2rem; margin-bottom: 2rem;
    transition: transform .3s ease, box-shadow .3s ease;
}
.admin-section:hover { box-shadow: 0 8px 25px rgba(0,0,0,.08); transform: translateY(-2px); }

.section-title {
    display: flex; align-items: center; gap: 10px;
    color: var(--text-light); font-size: 1.3rem;
    margin-bottom: 1.5rem; padding-bottom: .5rem;
    border-bottom: 2px solid var(--primary-blue);
}
.section-title i { color: var(--primary-blue); }

/* Badge de número de presupuesto */
.num-badge {
    background: var(--primary-blue); color: white;
    padding: 3px 12px; border-radius: 20px; font-size: .82rem;
    font-weight: 600; margin-left: auto;
}

/* ── CONTROLES BAR ───────────────────────────── */
.controls-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; }
.controls-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.controls-left select {
    padding: .5rem 1rem; border: 1px solid #e2e8f0; border-radius: 8px;
    font-size: .9rem; color: var(--text-light); background: white;
    outline: none; cursor: pointer;
}

/* Botones principales */
.sync-button, .tool-button {
    background: var(--primary-blue); color: white;
    border: none; padding: 10px 18px; border-radius: 6px;
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 10px;
    transition: all .2s ease; font-weight: 500;
    box-shadow: 0 4px 6px rgba(59,130,246,.2);
    text-transform: uppercase; font-size: .85rem; letter-spacing: .5px;
}
.sync-button:hover, .tool-button:hover { background: var(--accent-dark); transform: translateY(-2px); box-shadow: 0 6px 10px rgba(59,130,246,.3); }
.sync-button:active, .tool-button:active { transform: scale(.97); }

.btn-new    { background: linear-gradient(135deg, #059669, #10b981); box-shadow: 0 4px 6px rgba(16,185,129,.25); }
.btn-new:hover { background: linear-gradient(135deg, #047857, #059669) !important; }
.btn-save   { background: linear-gradient(135deg, #059669, #10b981); box-shadow: 0 4px 6px rgba(16,185,129,.25); }
.btn-save:hover { background: linear-gradient(135deg, #047857, #059669) !important; }
.btn-pdf    { background: linear-gradient(135deg, #dc2626, #ef4444); box-shadow: 0 4px 6px rgba(239,68,68,.25); }
.btn-pdf:hover { background: linear-gradient(135deg, #b91c1c, #dc2626) !important; }
.btn-email  { background: linear-gradient(135deg, #1e3a5f, var(--accent-dark)); box-shadow: 0 4px 6px rgba(37,99,235,.25); }
.btn-email:hover { background: linear-gradient(135deg, #1e3a5f, #1d4ed8) !important; }
.btn-back   { background: #6b7280; box-shadow: none; }
.btn-back:hover { background: #4b5563 !important; }
.btn-manual { background: linear-gradient(135deg, #ea580c, #f97316); box-shadow: 0 4px 6px rgba(249,115,22,.25); }
.btn-manual:hover { background: linear-gradient(135deg, #c2410c, #ea580c) !important; }

.tool-button:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* Stats */
.stats-row { display: flex; gap: 10px; }
.stat-chip {
    background: white; border: 1px solid #e2e8f0;
    border-radius: 20px; padding: 6px 14px;
    display: flex; align-items: center; gap: 7px;
    font-size: .82rem; color: var(--text-gray);
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.stat-chip b { font-size: 1rem; color: var(--text-light); }
.stat-chip.enviado  b { color: #2563eb; }
.stat-chip.aceptado b { color: #059669; }

/* ── GRID DE PRESUPUESTOS ────────────────────── */
.pres-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.empty-state {
    grid-column: 1 / -1; text-align: center; padding: 50px 20px;
    color: var(--text-gray);
}
.empty-state i { font-size: 3rem; opacity: .25; display: block; margin-bottom: 12px; }

/* Tarjeta de presupuesto */
.pres-card {
    background: white; border-radius: 12px;
    border: 1px solid rgba(0,0,0,.06); border-left: 4px solid var(--primary-blue);
    padding: 16px; cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    transition: all .3s ease; position: relative; overflow: hidden;
}
.pres-card::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 4px;
    background: var(--primary-blue); opacity: 0; transition: opacity .3s;
}
.pres-card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(59,130,246,.15); }
.pres-card:hover::before { opacity: 1; }
.pres-card.active { border-left-color: #f97316; background: #fff7f0; }

.pc-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.pc-num { font-size: .75rem; color: var(--text-gray); }
.pc-badge {
    padding: 2px 9px; border-radius: 20px; font-size: .7rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
}
.badge-borrador  { background: #f1f5f9; color: #64748b; }
.badge-enviado   { background: #dbeafe; color: #1d4ed8; }
.badge-aceptado  { background: #d1fae5; color: #065f46; }
.badge-rechazado { background: #fee2e2; color: #991b1b; }

.pc-cliente { font-weight: 700; font-size: .95rem; color: var(--text-light); margin-bottom: 8px; }
.pc-bottom { display: flex; justify-content: space-between; align-items: center; }
.pc-fecha { font-size: .76rem; color: var(--text-gray); }
.pc-total { font-weight: 700; font-size: 1rem; color: var(--primary-blue); }
.pc-actions { display: flex; gap: 6px; margin-top: 10px; }
.pc-btn {
    flex: 1; padding: 6px; border: none; border-radius: 6px;
    font-size: .75rem; cursor: pointer; font-weight: 600;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    transition: all .2s;
}
.pc-btn-edit { background: #eff6ff; color: var(--primary-blue); }
.pc-btn-edit:hover { background: #dbeafe; }
.pc-btn-pdf { background: #fef2f2; color: #dc2626; }
.pc-btn-pdf:hover { background: #fee2e2; }
.pc-btn-del { background: #f1f5f9; color: #6b7280; }
.pc-btn-del:hover { background: #e2e8f0; }

/* ── FORMULARIO ──────────────────────────────── */
.form-action-bar {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 14px 16px;
    background: #f8fafc; border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.form-card {
    background: white; border-radius: 10px;
    border: 1px solid #e2e8f0; padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.form-card-title {
    font-size: .88rem; font-weight: 700; color: var(--primary-blue);
    text-transform: uppercase; letter-spacing: .5px;
    padding-bottom: 10px; margin-bottom: 16px;
    border-bottom: 2px solid #e2e8f0;
    display: flex; align-items: center; gap: 7px;
}

/* Grid de campos */
.form-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
}
.fg { display: flex; flex-direction: column; }
.fg.span2 { grid-column: span 2; }
.fg label {
    font-size: .78rem; font-weight: 700; color: var(--text-gray);
    text-transform: uppercase; letter-spacing: .3px; margin-bottom: 5px;
}
.fg input, .fg select, .fg textarea {
    padding: 9px 12px; border: 1.5px solid #e2e8f0; border-radius: 8px;
    font-size: .9rem; color: var(--text-light); background: #f8fafc;
    outline: none; transition: all .2s ease; font-family: inherit;
}
.fg input:focus, .fg select:focus, .fg textarea:focus {
    border-color: var(--primary-blue); background: white;
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

/* Autocomplete */
.autocomplete-wrapper { position: relative; }
.autocomplete-wrapper input {
    width: 100%; padding: 9px 14px; border: 1.5px solid #e2e8f0;
    border-radius: 8px; font-size: .9rem; background: #f8fafc; outline: none;
    transition: all .2s;
}
.autocomplete-wrapper input:focus {
    border-color: var(--primary-blue); background: white;
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.sug-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: white; border: 1px solid #e2e8f0; border-radius: 8px;
    max-height: 260px; overflow-y: auto; z-index: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,.12); display: none;
}
.sug-dropdown.open { display: block; }
.sug-item {
    padding: 10px 14px; cursor: pointer;
    border-bottom: 1px solid #f1f5f9; transition: background .15s;
}
.sug-item:last-child { border-bottom: none; }
.sug-item:hover { background: #eff6ff; }
.sug-name { font-weight: 600; font-size: .88rem; color: var(--text-light); }
.sug-sub  { font-size: .76rem; color: var(--text-gray); }
.sug-precio { font-weight: 700; color: var(--primary-blue); font-size: .82rem; white-space: nowrap; }
.sug-precio-esp { color: #059669; }
.sug-precio-tag { font-size: .65rem; display: block; }

/* Caja de cliente seleccionado */
.cliente-box {
    margin-top: 8px; background: #eff6ff;
    border: 1px solid #bfdbfe; border-radius: 8px; padding: 10px 14px;
}
.cb-name { font-weight: 700; color: var(--accent-dark); font-size: .92rem; }
.cb-nif  { font-size: .77rem; color: var(--text-gray); margin-top: 1px; }
.cb-dir  { font-size: .82rem; color: var(--text-light); margin-top: 3px; }
.cb-change {
    margin-top: 6px; background: none; border: 1px solid #93c5fd;
    color: var(--accent-dark); border-radius: 6px; padding: 3px 10px;
    font-size: .78rem; cursor: pointer; transition: background .2s;
}
.cb-change:hover { background: #dbeafe; }

/* Barra añadir artículo */
.add-art-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }

/* Tabla de líneas */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid #e2e8f0; }
.lineas-tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.lineas-tbl thead { background: linear-gradient(135deg, var(--primary-blue), var(--accent-dark)); }
.lineas-tbl thead th {
    color: white; padding: 10px 8px; font-weight: 600;
    font-size: .77rem; text-transform: uppercase; letter-spacing: .3px;
    white-space: nowrap;
}
.lineas-tbl thead th:first-child { border-radius: 8px 0 0 0; }
.lineas-tbl thead th:last-child  { border-radius: 0 8px 0 0; }
.lineas-tbl tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .15s; }
.lineas-tbl tbody tr:hover { background: #f8fafc; }
.lineas-tbl tbody td { padding: 0; vertical-align: middle; }

/* Celdas editables inline */
.cel-input {
    width: 100%; padding: 8px 7px; border: 2px solid transparent;
    background: transparent; font-size: .84rem; color: var(--text-light);
    outline: none; font-family: inherit; transition: all .15s;
    border-radius: 0;
}
.cel-input:focus {
    border-color: var(--primary-blue); background: #eff6ff; border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(59,130,246,.15);
}
.cel-input.right { text-align: right; }
.cel-total { font-weight: 700; color: var(--primary-blue); padding: 8px 7px; text-align: right; white-space: nowrap; }
.tc-cod   { width: 75px; }
.tc-desc  { min-width: 190px; }
.tc-num   { width: 80px; }
.tc-env   { width: 80px; }
.tc-price { width: 110px; }
.tc-total { color: white !important; }
.tc-act   { width: 50px; text-align: center !important; }

/* ── BULTOS ── */
.tc-bultos { width: 72px; background: rgba(249,115,22,.12) !important; }

/* Input bultos en tabla */
.tc-bultos-inp {
    background: #fff7ed;
    border-bottom: 2px solid #f97316 !important;
}
.tc-bultos-inp:focus {
    background: #fff7ed !important;
    border-color: #ea580c !important;
    box-shadow: 0 0 0 2px rgba(249,115,22,.2) !important;
}
/* Celda cantidad cuando se calcula por bultos */
.cel-calc {
    background: #d1fae5 !important;
    border-color: #10b981 !important;
    color: #065f46 !important;
    font-weight: 700 !important;
}

.empty-row { text-align: center; padding: 30px; color: var(--text-gray); font-style: italic; }
.empty-row i { color: var(--primary-blue); margin-right: 6px; }

.manual-tag {
    display: inline-block; background: #fff7ed; color: #ea580c;
    border: 1px solid #fed7aa; border-radius: 3px;
    font-size: .64rem; padding: 1px 4px; margin-left: 3px; font-weight: 700;
}

.btn-del-linea {
    background: none; border: none; color: #ef4444;
    cursor: pointer; padding: 6px 8px; border-radius: 5px;
    font-size: .9rem; transition: background .15s; display: block; margin: auto;
}
.btn-del-linea:hover { background: #fee2e2; }

.table-hint {
    font-size: .76rem; color: var(--text-gray); margin-top: 8px;
    display: flex; align-items: center; gap: 5px;
}
.table-hint i { color: var(--primary-blue); }

/* ── BOTTOM GRID ─────────────────────────────── */
.bottom-grid {
    display: grid; grid-template-columns: 1fr 300px; gap: 16px; margin-bottom: 8px;
}
.bottom-grid .form-card { margin-bottom: 0; }
.bottom-grid textarea {
    width: 100%; padding: 10px 12px; border: 1.5px solid #e2e8f0;
    border-radius: 8px; font-size: .88rem; resize: vertical;
    font-family: inherit; outline: none; background: #f8fafc; transition: all .2s;
}
.bottom-grid textarea:focus { border-color: var(--primary-blue); background: white; box-shadow: 0 0 0 3px rgba(59,130,246,.1); }

/* Totales */
.totales-card {
    background: linear-gradient(145deg, #1e3a5f 0%, #2563eb 100%);
    border-radius: 10px; padding: 20px;
    box-shadow: 0 6px 20px rgba(37,99,235,.3);
}
.tot-title {
    color: rgba(255,255,255,.9); font-weight: 700; font-size: .88rem;
    text-transform: uppercase; letter-spacing: .5px;
    border-bottom: 1px solid rgba(255,255,255,.2); padding-bottom: 10px; margin-bottom: 14px;
    display: flex; align-items: center; gap: 7px;
}
.tot-rows { display: flex; flex-direction: column; gap: 10px; }
.tot-row {
    display: flex; justify-content: space-between; align-items: center;
    color: rgba(255,255,255,.85); font-size: .88rem;
}
.tot-row select {
    background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3);
    color: white; border-radius: 5px; padding: 2px 6px; font-size: .76rem;
    cursor: pointer; outline: none;
}
.tot-final {
    border-top: 2px solid rgba(255,255,255,.3); padding-top: 10px; margin-top: 4px;
    font-size: 1.1rem; font-weight: 700; color: white;
}
.tot-final span:last-child { font-size: 1.2rem; }

/* ── MODALES ─────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
    align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: white; border-radius: 15px;
    width: 90%; max-width: 540px; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: mIn .22s ease;
}
@keyframes mIn { from { opacity:0; transform:translateY(-18px) scale(.97); } to { opacity:1; transform:translateY(0) scale(1); } }
.modal-head {
    background: linear-gradient(135deg, var(--primary-blue), var(--accent-dark));
    padding: 16px 20px; border-radius: 15px 15px 0 0;
    display: flex; align-items: center; justify-content: space-between;
}
.modal-head span { color: white; font-weight: 600; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.modal-head button {
    background: rgba(255,255,255,.18); border: none; color: white;
    width: 28px; height: 28px; border-radius: 50%; font-size: 1rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background .2s;
}
.modal-head button:hover { background: rgba(255,255,255,.3); }
.modal-body { padding: 20px; }
.modal-foot {
    padding: 14px 20px; border-top: 1px solid #e2e8f0;
    display: flex; justify-content: flex-end; gap: 10px;
}

.modal-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.modal-grid .fg.span2 { grid-column: span 2; }
.modal-grid .fg label {
    font-size: .78rem; font-weight: 700; color: var(--text-gray);
    text-transform: uppercase; letter-spacing: .3px; margin-bottom: 4px; display: block;
}
.modal-grid .fg input {
    width: 100%; padding: 9px 12px; border: 1.5px solid #e2e8f0;
    border-radius: 8px; font-size: .9rem; background: #f8fafc; outline: none;
    transition: all .2s;
}
.modal-grid .fg input:focus {
    border-color: var(--primary-blue); background: white;
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.preview-box {
    background: #eff6ff; border: 1px solid #bfdbfe;
    border-radius: 8px; padding: 10px 14px; margin-top: 8px;
    font-size: .9rem; color: var(--accent-dark);
    display: flex; align-items: center; gap: 7px;
}
.preview-box strong { font-size: 1.05rem; }

/* ── TOAST ───────────────────────────────────── */
.toast {
    position: fixed; bottom: 72px; right: 20px;
    background: #1e293b; color: white; padding: 11px 20px;
    border-radius: 10px; font-size: .88rem; z-index: 9999;
    opacity: 0; transform: translateY(8px);
    transition: .3s ease; pointer-events: none;
    display: flex; align-items: center; gap: 8px;
    box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #059669; }
.toast.error   { background: #dc2626; }
.toast.warning { background: #d97706; }

/* Spinner */
.spinner {
    display: inline-block; width: 15px; height: 15px;
    border: 2px solid rgba(255,255,255,.4); border-top-color: white;
    border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── NAV ─────────────────────────────────────── */
.navigation-bar {
    position: fixed; bottom: 0; left: 0; right: 0; height: 50px;
    background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
    display: flex; justify-content: center; align-items: center; gap: 40px;
    box-shadow: 0 -2px 10px rgba(0,0,0,.1); z-index: 100;
    padding: 5px 0; border-top: 1px solid rgba(0,0,0,.1);
}
.nav-item {
    color: var(--text-gray); text-decoration: none;
    display: flex; flex-direction: column; align-items: center;
    font-size: .9em; transition: color .3s ease;
}
.nav-item:hover, .nav-item.active { color: var(--primary-blue); }
.nav-item i { font-size: 1.5em; }

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 900px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .fg.span2 { grid-column: span 2; }
    .bottom-grid { grid-template-columns: 1fr; }
    .totales-card { order: -1; }
}
@media (max-width: 768px) {
    header { padding: .5rem 1rem; height: auto; flex-direction: column; gap: .5rem; }
    .search-bar { width: 100%; margin: .5rem 0; }
    .admin-section { padding: 1rem; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .modal-grid { grid-template-columns: 1fr; }
    .modal-grid .fg.span2 { grid-column: span 1; }
    .navigation-bar { gap: 20px; }
}
@media (max-width: 480px) {
    .form-grid { grid-template-columns: 1fr; }
    .fg.span2 { grid-column: span 1; }
    .controls-bar { flex-direction: column; align-items: flex-start; }
    .pres-grid { grid-template-columns: 1fr; }
}
@supports (-webkit-touch-callout: none) {
    .navigation-bar { padding-bottom: max(5px, env(safe-area-inset-bottom)); }
}
