/* =========================================================
   Estimate View — Public Customer Page
   ========================================================= */

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

:root {
    --blue:        #2563EB;
    --blue-light:  #EFF6FF;
    --green:       #16A34A;
    --green-light: #F0FDF4;
    --yellow:      #D97706;
    --yellow-light:#FFFBEB;
    --red:         #DC2626;
    --red-light:   #FEF2F2;
    --dark:        #0F172A;
    --muted:       #394A51;
    --border:      #E2E8F0;
    --bg:          #F1F5F9;
    --white:       #FFFFFF;
    --radius:      10px;
    --shadow:      rgba(50,50,93,0.15) 0px 2px 5px -1px, rgba(0,0,0,0.1) 0px 1px 3px -1px;
    --font:        'Inter', system-ui, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--dark);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
    padding-bottom: 60px;
}

a { color: var(--blue); text-decoration: none; }

/* ── Top Bar ── */
.estimate-topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* ── Page Wrapper ── */
.estimate-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Card ── */
.est-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* ── Hero Card ── */
.est-hero {
    background: #DFEDFF;
    padding: 32px 36px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.est-hero-left h1 {
    font-size: 42px;
    font-weight: 800;
    color: var(--dark);
    line-height: 1.1;
    letter-spacing: -1px;
}

.est-hero-left .est-id {
    font-size: 14px;
    color: var(--muted);
    margin-top: 6px;
}

.est-hero-left .est-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    margin-top: 10px;
}

.est-hero-right {
    text-align: right;
    flex-shrink: 0;
}

.est-hero-right .company-logo {
    max-height: 60px;
    max-width: 180px;
    object-fit: contain;
    margin-bottom: 10px;
    display: block;
    margin-left: auto;
}

.est-hero-right .company-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
}

.est-hero-right .company-meta {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

/* ── Info Grid (Prepared By / Bill To / Details) ── */
.est-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border-top: 1px solid var(--border);
}

.est-info-col {
    padding: 24px 28px;
    border-right: 1px solid var(--border);
}

.est-info-col:last-child { border-right: none; }

.est-info-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}

.est-info-col .name {
    font-size: 15px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 4px;
}

.est-info-col p {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}

.est-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
    color: var(--muted);
}

.est-detail-row span:last-child {
    font-weight: 600;
    color: var(--dark);
}

.total-row {
    justify-content: flex-end;
    margin-bottom: 3px !important;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border);
}

.est-total-big {
    font-size: 28px;
    font-weight: 800;
    color: var(--blue);
    text-align: right;
    margin-top: 0;
    letter-spacing: -0.5px;
}

.est-deposit-badge {
    display: flex;
    justify-content: center;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--blue);
    background: var(--blue-light);
    border-radius: 20px;
    padding: 3px 10px;
}

.est-deposit-amount {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--blue);
    margin-top: 2px;
}

/* ── Section Title ── */
.est-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: #FAFBFC;
}

/* ── Introduction ── */
.est-intro-body {
    padding: 24px;
}

.est-intro-body p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.est-intro-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.est-intro-images img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity 0.2s;
}

.est-intro-images img:hover { opacity: 0.88; }

/* ── Line Items ── */
.est-line-items { padding: 0; }

.est-group-header {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    background: #F8FAFC;
    padding: 10px 24px;
    border-bottom: 1px solid var(--border);
}

.est-line-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: start;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.est-line-item:last-child { border-bottom: none; }

.est-item-img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.est-item-img-placeholder {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background: #F1F5F9;
    flex-shrink: 0;
}

.est-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
}

.est-item-desc {
    font-size: 13px;
    color: var(--muted);
    margin-top: 3px;
    line-height: 1.5;
}

.est-item-price {
    text-align: right;
    flex-shrink: 0;
}

.est-item-qty {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 2px;
}

.est-item-total {
    font-size: 15px;
    font-weight: 700;
    color: var(--blue);
}

/* ── Totals ── */
.est-totals {
    background: #F8FAFC;
    border-top: 1px solid var(--border);
    padding: 20px 24px;
}

.est-totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 14px;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

.deposit-row > span:nth-child(1) {
    color: var(--dark) !important;
}

.est-totals-row:last-child { border-bottom: none; }

.est-totals-row.options-row {
    color: var(--blue);
    font-weight: 600;
    display: none;
}

.est-totals-row.options-row.visible { display: flex; }

.est-totals-row span:last-child { font-weight: 600; color: var(--dark); }

.est-totals-row.total-row {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
    padding-top: 10px;
    margin-top: 4px;
}

.est-totals-row.total-row span:last-child {
    font-size: 20px;
    color: var(--dark);
}

.est-totals-row.deposit-row span:last-child { color: var(--blue); }

/* ── Optional Add-Ons ── */
.est-optional-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: #FAFBFC;
}

.est-optional-header-left h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
}

.est-optional-header-left p {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

.est-optional-running {
    display: none;
    background: var(--blue);
    color: white;
    font-size: 13px;
    font-weight: 600;
    border-radius: 20px;
    padding: 5px 14px;
    white-space: nowrap;
}

.est-optional-running.visible { display: inline-block; }

.est-optional-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    overflow: hidden;
}

.est-optional-item:last-child { border-bottom: none; }
.est-optional-item:hover { background: #F8FAFC; }
.est-optional-item.selected { background: var(--green-light); }

.est-opt-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    background: white;
}

.est-optional-item.selected .est-opt-checkbox {
    background: var(--green);
    border-color: var(--green);
}

.est-opt-checkmark {
    display: none;
    color: white;
}

.est-optional-item.selected .est-opt-checkmark { display: block; }

.est-opt-body { flex: 1; }

.est-opt-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
}

.est-opt-desc {
    font-size: 13px;
    color: var(--muted);
    margin-top: 3px;
}

.est-opt-price { text-align: right; flex-shrink: 0; }

.est-opt-amount {
    font-size: 15px;
    font-weight: 700;
    color: var(--blue);
}

/* ADDED watermark */
.est-added-stamp {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    font-size: 36px;
    font-weight: 900;
    color: var(--green);
    opacity: 0;
    letter-spacing: 4px;
    pointer-events: none;
    transition: opacity 0.2s;
    text-transform: uppercase;
}

.est-optional-item.selected .est-added-stamp { opacity: 0.12; }

/* ── Contract ── */
.est-contract-body {
    padding: 20px 24px;
}

.est-contract-text {
    background: #F8FAFC;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.7;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

/* ── Deposit Info ── */
.est-deposit-info {
    padding: 24px;
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.est-deposit-icon {
    width: 44px;
    height: 44px;
    background: var(--blue-light);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--blue);
}

.est-deposit-info-text h4 {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 6px;
}

.est-deposit-info-text p {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
}

.est-deposit-info-text .deposit-highlight {
    color: var(--blue);
    font-weight: 600;
}

/* ── Signature ── */
.est-signature-body { padding: 24px; }

.est-sig-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 10px;
}

.est-sig-canvas-wrapper {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: white;
}

.est-sig-hint {
    text-align: center;
    padding: 12px;
    font-size: 13px;
    color: #656E7B;
    border-bottom: 1px solid var(--border);
    pointer-events: none;
}

#signature-canvas {
    display: block;
    width: 100%;
    height: 200px;
    touch-action: none;
}

.est-sig-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

/* ── Action Buttons ── */
.est-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

.btn-est {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    font-family: var(--font);
}

.btn-est:hover { opacity: 0.88; }
.btn-est:active { transform: scale(0.98); }

.btn-est:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-approve  { background: #16A34A; color: white; }
.btn-deposit  { background: var(--blue); color: white; }
.btn-changes  { background: var(--yellow-light); color: var(--yellow); border: 1px solid #FDE68A; }
.btn-decline  { background: var(--red-light); color: var(--red); border: 1px solid #FECACA; }
.btn-clear    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-submit   { background: var(--blue); color: white; }

/* ── Inline Action Forms (changes/decline) ── */
.est-inline-action {
    display: none;
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: #FAFBFC;
}

.est-inline-action.visible { display: block; }

.est-inline-action label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.est-inline-action textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--dark);
    resize: vertical;
    min-height: 100px;
    outline: none;
    transition: border-color 0.15s;
}

.est-inline-action textarea:focus { border-color: var(--blue); }

.est-inline-btn-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

/* ── Status States ── */
.est-status-banner {
    padding: 20px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
}

.est-status-banner.approved  { background: var(--green-light);  color: var(--green); }
.est-status-banner.declined  { background: var(--red-light);    color: var(--red); }
.est-status-banner.expired   { background: #FFF7ED; color: #C2410C; }
.est-status-banner.converted { background: var(--blue-light);   color: var(--blue); }

.est-status-banner svg { flex-shrink: 0; }

/* ── Toast ── */
.est-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--dark);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s;
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
}

.est-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .est-hero { flex-direction: column-reverse; }
    .est-hero-right { text-align: left; }
    .est-hero-right .company-logo { margin-left: 0; }
    .est-info-grid { grid-template-columns: 1fr; }
    .est-info-col { border-right: none; border-bottom: 1px solid var(--border); }
    .est-info-col:last-child { border-bottom: none; }
    .est-line-item { grid-template-columns: 1fr auto; }
    .est-item-img, .est-item-img-placeholder { display: none; }
    .est-actions { justify-content: stretch; }
    .btn-est { flex: 1; justify-content: center; }
}

/* ── Loading Overlay ── */
.est-loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}

.est-loading-overlay.visible {
    display: flex;
}

.est-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #E2E8F0;
    border-top-color: #6366F1;
    border-radius: 50%;
    animation: est-spin 0.8s linear infinite;
}

.est-loading-message {
    font-size: 15px;
    font-weight: 500;
    color: #475569;
}

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

.est-meta-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.est-meta-notice {
    font-size: 13px;
    color: #94A3B8;
    margin-bottom: 5px;
}

#est-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
    display: flex;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
}
#est-lightbox.visible {
    opacity: 1;
    visibility: visible;
}

.est-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
}

.est-lightbox-content {
    position: relative;
    z-index: 1;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#est-lightbox-img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.est-lightbox-counter {
    color: white;
    font-size: 14px;
    opacity: 0.8;
}

.est-lightbox-close,
.est-lightbox-prev,
.est-lightbox-next {
    position: absolute;
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background 0.2s;
}
.est-lightbox-close:hover,
.est-lightbox-prev:hover,
.est-lightbox-next:hover { background: rgba(255,255,255,0.3); }

.est-lightbox-close { top: 50px; right: 60px; }
.est-lightbox-prev  { left: 60px; top: 50%; transform: translateY(-50%); }
.est-lightbox-next  { right: 60px; top: 50%; transform: translateY(-50%); }