/* ── Variables ───────────────────────────────────────── */
:root {
    --accent-red: #c44536;
    --gradient-red: linear-gradient(135deg, #c44536, #d95f4e);
    --dark-bg: #0a0a0a;
    --dark-card: #111111;
    --dark-card-border: rgba(255, 255, 255, 0.07);
    --text-secondary: #a0a0a0;
    --text-muted: #5a5a5a;
}

/* ── Base ────────────────────────────────────────────── */
body {
    font-family: 'Raleway', sans-serif;
    background: var(--dark-bg);
    min-height: 100vh;
    padding: 80px 20px 60px;
}

/* ── Background decorations ──────────────────────────── */
.page-bg-glow {
    position: fixed;
    top: 0;
    right: 0;
    width: 65vw;
    height: 65vh;
    background: radial-gradient(ellipse at 75% 15%, rgba(196, 69, 54, 0.08) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.page-bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
    -webkit-mask-image: radial-gradient(ellipse at center, black 5%, transparent 75%);
    mask-image: radial-gradient(ellipse at center, black 5%, transparent 75%);
}

/* ── Navbar ──────────────────────────────────────────── */
.navbar {
    background-color: rgba(10, 10, 10, 0.95) !important;
    backdrop-filter: blur(10px);
    padding: 1rem 0;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.navbar-brand {
    display: flex;
    align-items: center;
}

.navbar-logo-icon {
    height: 40px;
    width: 40px;
    padding: 5px;
    background: var(--gradient-red);
    border-radius: 10px;
    margin-right: 0.75rem;
    object-fit: contain;
}

.navbar-logo-text {
    height: 40px;
}

/* ── Page container ──────────────────────────────────── */
.presup-container {
    max-width: 960px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* ── Header ──────────────────────────────────────────── */
.presup-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.presup-eyebrow {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--accent-red);
    background: rgba(196, 69, 54, 0.1);
    border: 1px solid rgba(196, 69, 54, 0.25);
    border-radius: 20px;
    padding: 0.35rem 1rem;
    margin-bottom: 1rem;
}

.presup-title {
    color: #fff;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.presup-title .gradient-text {
    background: linear-gradient(135deg, #c44536, #e07b6e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.presup-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* ── Toolbar ─────────────────────────────────────────── */
.presup-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.presup-filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filter-select {
    min-width: 180px;
}

.btn-new-presup {
    flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn-primary {
    background: var(--gradient-red) !important;
    border: none !important;
    color: white !important;
    font-weight: 600;
    border-radius: 50px;
    padding: 0.65rem 1.5rem;
    box-shadow: 0 4px 16px rgba(196, 69, 54, 0.3);
    transition: all 0.25s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(196, 69, 54, 0.45);
}

.btn-outline-crm {
    background: transparent !important;
    border: 1px solid var(--dark-card-border) !important;
    color: var(--text-secondary) !important;
    border-radius: 50px;
    font-weight: 500;
    padding: 0.65rem 1.5rem;
    transition: all 0.2s;
}

.btn-outline-crm:hover {
    border-color: rgba(255, 255, 255, 0.15) !important;
    color: #fff !important;
}

.btn-wa {
    background: #158c34;
    border: none;
    color: #fff;
    font-weight: 600;
    border-radius: 50px;
    padding: 0.65rem 1.5rem;
    transition: all 0.25s;
}

.btn-wa:hover {
    background: #1db445;
    transform: translateY(-1px);
}

/* ── States ──────────────────────────────────────────── */
.pstate {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.pstate-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    font-size: 2rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--dark-card-border);
    color: var(--text-muted);
}

.pstate-icon--error {
    background: rgba(196, 69, 54, 0.1);
    border-color: rgba(196, 69, 54, 0.2);
    color: var(--accent-red);
}

.pstate .spinner-border {
    width: 48px;
    height: 48px;
    border-width: 3px;
    border-color: rgba(196, 69, 54, 0.2);
    border-top-color: var(--accent-red);
    margin-bottom: 1rem;
}

.pstate h3 {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.pstate p {
    font-size: 0.9rem;
    max-width: 340px;
    margin: 0;
}

/* ── Budget list ─────────────────────────────────────── */
.budget-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ── Budget card ─────────────────────────────────────── */
.budget-card {
    background: var(--dark-card);
    border: 1px solid var(--dark-card-border);
    border-radius: 14px;
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-bottom: 25px;
}

.budget-card:hover {
    border-color: rgba(196, 69, 54, 0.3);
    box-shadow: 0 4px 20px rgba(196, 69, 54, 0.08);
}

.budget-card-left {
    flex: 1;
    min-width: 0;
}

.budget-number {
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.2rem;
}

.budget-client {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.budget-date {
    font-size: 0.77rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    margin-right: 1rem;
}

.budget-card-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.budget-total {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    text-align: right;
}

.budget-actions {
    display: flex;
    gap: 0.4rem;
}

/* ── Action buttons on cards ─────────────────────────── */
.btn-action {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--dark-card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.btn-action--edit:hover {
    border-color: rgba(37, 99, 235, 0.4);
    color: #60a5fa;
}

.btn-action--preview:hover {
    border-color: rgba(196, 69, 54, 0.4);
    color: var(--accent-red);
}

.btn-action--delete:hover {
    border-color: rgba(196, 69, 54, 0.4);
    color: #e07b6e;
}

/* ── Status badges ───────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 0.28rem 0.8rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: capitalize;
    flex-shrink: 0;
}

.badge-borrador {
    background: rgba(74, 74, 74, 0.3);
    border: 1px solid rgba(74, 74, 74, 0.5);
    color: #9ca3af;
}

.badge-enviado {
    background: rgba(37, 99, 235, 0.15);
    border: 1px solid rgba(37, 99, 235, 0.3);
    color: #60a5fa;
}

.badge-aceptado {
    background: rgba(22, 163, 74, 0.15);
    border: 1px solid rgba(22, 163, 74, 0.3);
    color: #4ade80;
}

.badge-rechazado {
    background: rgba(196, 69, 54, 0.15);
    border: 1px solid rgba(196, 69, 54, 0.3);
    color: #e07b6e;
}

/* ── CRM Modal ───────────────────────────────────────── */
.crm-modal {
    background: #0e0e0e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
}

.crm-modal-header {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--dark-card-border);
    padding: 1.25rem 1.5rem;
}

.crm-modal-header .modal-title {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
}

.crm-modal-body {
    padding: 1.5rem;
}

.crm-modal-footer {
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--dark-card-border);
    padding: 1rem 1.5rem;
}

/* ── Form sections ───────────────────────────────────── */
.crm-form-section {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--dark-card-border);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
}

.crm-form-section-title {
    color: var(--text-muted);
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.crm-form-section-title i {
    color: var(--accent-red);
}

/* ── Form inputs ─────────────────────────────────────── */
.crm-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    display: block;
}

.crm-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #fff;
    padding: 0.6rem 0.85rem;
    font-size: 0.88rem;
    font-family: 'Raleway', sans-serif;
    transition: border-color 0.2s;
}

.crm-input:focus {
    outline: none;
    border-color: rgba(196, 69, 54, 0.45);
    background: rgba(255, 255, 255, 0.06);
}

.crm-input::placeholder {
    color: var(--text-muted);
}

.crm-select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%235a5a5a' d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 14px;
    padding-right: 2.25rem;
    cursor: pointer;
}

.crm-select option {
    background: #1a1a1a;
    color: #fff;
}

.crm-textarea {
    resize: vertical;
    min-height: 90px;
}

.crm-field-error {
    color: #e07b6e;
    font-size: 0.78rem;
    margin-top: 0.25rem;
    min-height: 1.1em;
}

/* ── Client search ───────────────────────────────────── */
.client-search-wrap {
    position: relative;
    margin-bottom: 0.75rem;
    z-index: 1060;
}

.client-search-wrap i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.82rem;
    z-index: 1;
}

.client-search-wrap input {
    padding-left: 2.5rem;
}

.client-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    z-index: 1070;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.client-option {
    padding: 0.65rem 1rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    transition: background 0.15s;
}

.client-option:hover {
    background: rgba(196, 69, 54, 0.1);
}

.client-option + .client-option {
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.option-name {
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
}

.option-vehicle {
    color: var(--text-muted);
    font-size: 0.77rem;
}

.selected-client-chip {
    display: flex;
    align-items: center;
    background: rgba(196, 69, 54, 0.1);
    border: 1px solid rgba(196, 69, 54, 0.25);
    border-radius: 8px;
    padding: 0.5rem 0.85rem;
    color: #e07b6e;
    font-size: 0.85rem;
    font-weight: 600;
    gap: 0.5rem;
}

.chip-remove {
    background: none;
    border: none;
    color: #e07b6e;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    opacity: 0.7;
    font-size: 0.8rem;
    line-height: 1;
}

.chip-remove:hover {
    opacity: 1;
}

/* ── Items table ─────────────────────────────────────── */
.items-table-wrap {
    overflow-x: auto;
    margin-bottom: 0.5rem;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 420px;
}

.items-table thead th {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--dark-card-border);
}

.items-table tbody tr + tr {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.items-table tbody td {
    padding: 0.4rem 0.5rem;
    vertical-align: middle;
}

.items-table .col-num {
    width: 90px;
    text-align: right;
}

.items-table .col-act {
    width: 36px;
}

.items-table .item-desc {
    border-radius: 6px;
    padding: 0.45rem 0.65rem;
    font-size: 0.83rem;
}

.items-table .item-qty,
.items-table .item-price {
    border-radius: 6px;
    padding: 0.45rem 0.55rem;
    font-size: 0.83rem;
    text-align: right;
}

.item-subtotal {
    color: var(--text-secondary);
    font-size: 0.83rem;
    text-align: right;
    white-space: nowrap;
}

.btn-remove-item {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    transition: all 0.15s;
}

.btn-remove-item:hover {
    background: rgba(196, 69, 54, 0.15);
    color: #e07b6e;
}

.btn-add-item {
    background: rgba(196, 69, 54, 0.1);
    border: 1px solid rgba(196, 69, 54, 0.25);
    color: var(--accent-red);
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.35rem 0.8rem;
    cursor: pointer;
    font-family: 'Raleway', sans-serif;
    transition: all 0.15s;
}

.btn-add-item:hover {
    background: rgba(196, 69, 54, 0.2);
}

.no-items-msg {
    color: var(--text-muted);
    font-size: 0.82rem;
    text-align: center;
    padding: 0.5rem 0;
    font-style: italic;
}

.no-items-msg.text-danger {
    color: #e07b6e !important;
    font-style: normal;
    font-weight: 600;
}

/* ── Totals box ──────────────────────────────────────── */
.totals-box {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--dark-card-border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.totals-total {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
}

/* ── Delete button in modal footer ──────────────────── */
.btn-delete-presup {
    background: rgba(196, 69, 54, 0.12) !important;
    border: 1px solid rgba(196, 69, 54, 0.3) !important;
    color: #e07b6e !important;
    border-radius: 50px;
    font-weight: 600;
    padding: 0.55rem 1.25rem;
    transition: all 0.2s;
    margin-right: auto;
    display: inline-flex;
    align-items: center;
}

.btn-delete-presup:hover {
    background: rgba(196, 69, 54, 0.25) !important;
    border-color: rgba(196, 69, 54, 0.5) !important;
    color: #f09888 !important;
}

/* ── Preview sheet ───────────────────────────────────── */
.preview-sheet {
    background: #f9f9f9;
    color: #111;
    padding: 2rem 2.25rem;
    font-family: 'Raleway', sans-serif;
    min-height: 400px;
    overflow-x: hidden;
}

.preview-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #c44536;
}

.preview-num {
    font-size: 1.4rem;
    font-weight: 800;
    color: #111;
}

.preview-dates {
    font-size: 0.82rem;
    color: #555;
    margin-top: 0.25rem;
    display: flex;
    gap: 1rem;
}

.preview-client {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: #f0f0f0;
    border-radius: 6px;
    font-size: 0.88rem;
    color: #333;
}

.preview-client p {
    margin: 0.2rem 0;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.preview-table thead th {
    background: #c44536;
    color: #fff;
    padding: 0.55rem 0.75rem;
    text-align: left;
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-table tbody .row-even { background: #fff; }
.preview-table tbody .row-odd  { background: #f4f4f4; }

.preview-table tbody td,
.preview-table tfoot td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e0e0e0;
    color: #222;
}

.preview-table tfoot td {
    border-top: 2px solid #ddd;
    border-bottom: none;
}

.preview-total-row td {
    background: #f0f0f0;
    font-size: 0.95rem;
    border-top: 2px solid #c44536 !important;
    color: #111;
}

.preview-notes {
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background: #f0f0f0;
    border-left: 3px solid #c44536;
    font-size: 0.83rem;
    color: #444;
    border-radius: 0 6px 6px 0;
}

/* ── Auth Loader (from auth.css pattern) ─────────────── */
#authLoader {
    position: fixed;
    inset: 0;
    background: var(--dark-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}

#authLoader.hidden {
    opacity: 0;
    pointer-events: none;
}

.auth-loader-spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(196, 69, 54, 0.2);
    border-top-color: var(--accent-red);
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

.auth-loader-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 576px) {
    .presup-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-new-presup {
        order: -1;
        text-align: center;
    }

    .budget-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .budget-card-right {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
    }

    .budget-card-right .budget-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .budget-total {
        font-size: 1.1rem;
    }

    .presup-title {
        font-size: 1.9rem;
    }

    .preview-sheet {
        padding: 1rem 0.85rem;
    }

    .preview-dates {
        flex-direction: column;
        gap: 0.2rem;
    }

    .preview-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    #previewModal .modal-dialog {
        margin: 0.75rem !important;
        max-width: calc(100% - 1.5rem) !important;
    }

    #previewModal .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    #previewModal .modal-footer .btn {
        width: 100%;
    }
}
