/* ==============================================
   MODULES - Feature-specific styles
   ============================================== */

/* ---- History List ---- */
.modal-container--history {
    max-width: 920px;
    width: min(96vw, 920px);
    overflow: hidden;
}

#history-tab-quotes,
#history-tab-customers,
#history-tab-approvals {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.history-modal-title h3 {
    margin-bottom: 4px;
}

.history-modal-title p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    font-weight: 400;
}

.history-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(140px, 1fr)) auto;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
    background: linear-gradient(135deg, #fffaf4 0%, #ffffff 65%);
}

.history-current-card {
    border: 1px solid rgba(234,148,54,0.22);
    border-radius: 14px;
    padding: 10px 12px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
}

.history-current-card__label,
.history-summary__label {
    display: block;
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
    margin-bottom: 4px;
}

.history-current-card strong {
    color: var(--brand-primary);
    font-size: var(--font-size-md);
    direction: ltr;
    display: inline-block;
}

.history-toolbar__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.history-summary {
    display: flex;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid #edf1f7;
    background: #f8fafc;
}

.history-summary > div {
    min-width: 120px;
    padding: 8px 10px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #edf1f7;
}

.history-summary__value {
    color: var(--text-primary);
    font-weight: 800;
    direction: ltr;
    display: inline-block;
}

.history-list {
    background: #f8fafc;
}

.history-loading {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    background: #fff;
    border-radius: 14px;
    border: 1px dashed var(--border-color);
}

.history-search {
    padding: 10px 18px;
    border-bottom: 1px solid #edf1f7;
    background: #fff;
}

.history-search input {
    width: 100%;
}

.history-item {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    margin-bottom: 10px;
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
    background: #fff;
    overflow: hidden;
}

.history-item:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(234,148,54,0.34);
    transform: translateY(-2px);
}

.history-item__body {
    padding: 14px 16px 10px;
    flex: 1;
}

.history-item__topline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.history-item__topline h4 {
    font-size: var(--font-size-md);
    color: var(--brand-primary);
    margin: 0;
}

.history-item__client {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.history-item__meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

.history-item__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
    gap: 10px;
}

.history-item__total {
    font-weight: 800;
    color: var(--text-primary);
    direction: ltr;
    font-size: 15px;
    white-space: nowrap;
}

.history-version-badge,
.history-owner-badge {
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.75rem;
    font-weight: 700;
}

.history-version-badge {
    background: rgba(234,148,54,0.12);
    color: var(--brand-primary);
}

.history-owner-badge {
    background: #e8f4fd;
    color: #1a6494;
}

.history-edited-badge {
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #fef3e2;
    color: #a85a00;
}

.history-status-badge {
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
}

.history-status-badge--draft {
    background: #f3f4f6;
    color: #6b7280;
    border-color: #e5e7eb;
}

.history-status-badge--sent {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.history-status-badge--approved {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0;
}

.history-status-badge--execution {
    background: rgba(234,148,54,0.12);
    color: var(--brand-primary);
    border-color: rgba(234,148,54,0.35);
}

.history-item__actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

@media (max-width: 720px) {
    .history-toolbar {
        grid-template-columns: 1fr;
    }

    .history-toolbar__actions {
        justify-content: stretch;
    }

    .history-toolbar__actions .btn {
        flex: 1;
    }

    .history-item__footer {
        flex-direction: column;
        align-items: stretch;
    }

    .history-item__actions {
        justify-content: stretch;
    }

    .history-item__actions .btn {
        flex: 1;
    }
}

/* ---- History tabs ---- */
.history-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    padding: 0 16px;
    gap: 4px;
    flex-shrink: 0;
}

.history-tab {
    padding: 11px 18px;
    border: none;
    border-bottom: 2.5px solid transparent;
    background: none;
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.history-tab.active {
    color: var(--brand-primary);
    border-bottom-color: var(--brand-primary);
}

.history-tab:hover:not(.active) {
    color: var(--text-primary);
}

/* ---- Customer cards (in history modal customers tab) ---- */
.customer-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 10px;
    background: #fff;
    transition: box-shadow var(--transition), border-color var(--transition);
}

.customer-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(234,148,54,0.3);
}

.customer-card__info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.customer-card__name {
    font-weight: 700;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.customer-card__meta {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.customer-card__legal {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed var(--border-color);
}

.customer-card__legal span {
    color: var(--brand-secondary);
}

.customer-card__actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* ---- Contact exists note ---- */
.contact-exists-note {
    font-size: var(--font-size-xs);
    color: #16a34a;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f0fdf4;
    border-radius: 999px;
    border: 1px solid #bbf7d0;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    background: #fff;
    border-radius: 14px;
    border: 1px dashed var(--border-color);
}

.empty-state__icon {
    font-size: 52px;
    margin-bottom: var(--space-md);
}

.empty-state__title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.empty-state__text {
    font-size: var(--font-size-sm);
}

/* ---- Loading Spinner ---- */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
}

.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--brand-violet);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    left: var(--space-lg);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    background: #2f2f2f;
    color: white;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: var(--font-size-sm);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    border: 1px solid rgba(255,255,255,0.12);
}

.toast--success { background: #10B981; }
.toast--error   { background: #EF4444; }
/* WAS var(--brand-primary) #EA9436: white on it measures 2.39:1, below the 4.5:1 floor — the
   least readable toast in the app, and the one now carrying an Undo button. #8A4E10 is the
   darker brand tone already proven on the active category chip: white on it measures 6.61:1. */
.toast--warning { background: #8A4E10; color: #fff; }
/* 'info' was already being passed by the history CSV export but had no rule,
   so those toasts rendered on the bare dark default. */
.toast--info    { background: #1A6494; }

/* An actionable toast — today only the Undo offered after a quote line is deleted. The button is
   a real control inside the live region, so it must be reachable, hittable and visibly focused. */
.toast--action {
    display: flex;
    align-items: center;
    gap: 14px;
}

.toast__text { flex: 1 1 auto; }

/* 44px, not the 24px WCAG floor. This is a timed, one-shot, hard-to-retry control on a device
   where touch is the primary input — a near-miss costs the rep the undo, not just a second tap. */
.toast__action {
    flex: none;
    min-height: 44px;
    min-width: 64px;
    padding: 4px 16px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}

.toast__action:hover { background: rgba(255, 255, 255, 0.16); border-color: #fff; }

/* White on the toast's own dark ground clears 3:1 in every toast colour, unlike the app-wide
   brand-orange ring, which does not. */
.toast__action:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ---- Inline field validation (final-export required fields) ---- */
.field-invalid {
    border-color: #EF4444 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18);
}

.field-error-text {
    color: #EF4444;
    font-size: var(--font-size-xs);
    margin-top: 4px;
}

@keyframes slideIn {
    from { transform: translateX(-20px); opacity: 0; }
    to   { transform: translateX(0);      opacity: 1; }
}

/* ---- PDF Preview (isolated iframe — P18) ---- */
#pdf-preview-content { padding: 0; overflow: auto; }
.pdf-preview-frame { width: 100%; height: 72vh; border: 0; background: #e5e7eb; display: block; }

/* ---- Fonts CSS (Phase 2 - offline) ---- */
@font-face {
    font-family: 'Alexandria';
    src: url('../assets/fonts/Alexandria-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: block;
}

/* ---- Signed-out backstop ----------------------------------------------------
   WHY: every overlay in this app lives OUTSIDE <main id="app-main-shell">, so the
   auth gate — which only hides that shell — cannot hide any of them, and
   `.modal { position: fixed; inset: 0; z-index: 999 }` puts each one squarely over
   the login form. Eight of twelve stayed up through a user change, one of them the
   full rendered quotation (client details, line items, prices, totals, bank details).

   App._closeOutgoingUserSurfaces() closes them properly — settling the promises that
   two of them hold, which CSS cannot do — and this is the SECOND line of defence
   behind it, not a replacement: if teardown ever misses a surface again, the surface
   is still not painted over the next rep's login screen. Keyed on the class, not on a
   list of ids, so a new modal is covered the day it is written.

   App._enforceAuthGate() puts is-signed-out on <body> whenever nobody is signed in. */
body.is-signed-out .modal,
body.is-signed-out #products-editor-page,
body.is-signed-out #customer-dropdown {
    display: none !important;
}
