/* Draft invoices modal, draft action dropdown and draft details offcanvas (POS + sales list).
   Split from the former public/css/pos.css. Global; order-sensitive (after invoice-modal.css). */

/* ==========================================================================
   DRAFT INVOICES MODAL
   ========================================================================== */
.drafts-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: var(--z-modal-backdrop);
}

.drafts-modal.show {
    display: flex;
}

.drafts-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(6px);
    animation: posFadeIn 0.18s ease both;
}

.drafts-dialog {
    position: relative;
    width: min(820px, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-3xl);
    box-shadow: var(--shadow-dialog);
    padding: 22px;
    animation: modalRise 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.drafts-modal-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 18px;
}

.drafts-modal-header h2 {
    font-size: 22px;
    color: var(--text-gray-dark);
    margin-bottom: 4px;
}

.drafts-list-wrap {
    min-height: 120px;
    overflow: visible !important;
    padding-bottom: 70px;
}

.drafts-table-wrapper {
    overflow: visible !important;
    position: relative;
}

.drafts-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 36px 0;
    color: var(--text-muted);
    font-size: 13px;
}

.drafts-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 13px;
}

.drafts-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: visible !important;
}

.drafts-table th:first-child {
    border-top-left-radius: var(--radius-lg);
}

.drafts-table th:last-child {
    border-top-right-radius: var(--radius-lg);
}

.drafts-table tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-lg);
}

.drafts-table tr:last-child td:last-child {
    border-bottom-right-radius: var(--radius-lg);
}

.drafts-table th {
    background: var(--bg-light);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 14px;
    text-align: left;
}

.drafts-table td {
    padding: 11px 14px;
    font-size: 13px;
    color: var(--text-dark);
    border-top: 1px solid var(--bg-secondary);
    overflow: visible !important;
    position: relative;
}

.drafts-table tr:hover td {
    background: var(--bg-light);
}

.draft-load-link {
    border: none;
    background: transparent;
    padding: 0;
    color: var(--primary-color);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    transition: color var(--transition-fast);
}

.draft-load-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.show-drafts-btn {
    border-color: var(--primary-light-border) !important;
    color: var(--primary-color) !important;
}

.show-drafts-btn:hover {
    background: var(--primary-light) !important;
    border-color: var(--primary-color) !important;
}

/* ==========================================================================
   DRAFT INVOICES — DOCTOR, STATUS & ACTION DROPDOWN STYLES
   ========================================================================== */
.doctor-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.doctor-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary-light, #eff6ff);
    color: var(--primary-color, #4f46e5);
    font-size: 10.5px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: -0.02em;
    border: 1px solid var(--primary-light-border, rgba(79, 70, 229, 0.2));
}

.doctor-name-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
}

.draft-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--radius-full, 9999px);
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.draft-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

tr.draft-row-open,
tr:has(.draft-action-dropdown.open) {
    position: relative;
    z-index: 9999 !important;
}

.draft-action-wrap {
    position: relative;
    display: inline-block;
}

.draft-action-wrap.open-wrap,
.draft-action-wrap:has(.draft-action-dropdown.open) {
    z-index: 10000 !important;
}

.draft-action-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border-medium, #cbd5e1);
    border-radius: var(--radius-md, 6px);
    background: var(--bg-card, #ffffff);
    color: var(--text-dark, #334155);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.draft-action-toggle:hover {
    background: var(--bg-light, #f8fafc);
    border-color: var(--primary-color, #4f46e5);
    color: var(--primary-color, #4f46e5);
}

.draft-action-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 165px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: var(--radius-lg, 10px);
    box-shadow:
        0 14px 35px -4px rgba(0, 0, 0, 0.2),
        0 8px 16px -4px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 10001 !important;
    animation: modalRise 0.15s cubic-bezier(0.2, 0, 0.2, 1) both;
}

.draft-action-dropdown.open {
    display: flex;
    flex-direction: column;
}

.draft-action-dropdown.dropup {
    top: auto;
    bottom: calc(100% + 4px);
    animation: modalDropupRise 0.15s cubic-bezier(0.2, 0, 0.2, 1) both;
}

@keyframes modalDropupRise {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.draft-action-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md, 6px);
    color: var(--text-dark, #334155);
    font-size: 12px;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease;
}

.draft-action-item:hover {
    background: var(--bg-light, #f1f5f9);
    color: var(--primary-color, #4f46e5);
}

.draft-action-item.load-action {
    color: var(--primary-color, #4f46e5);
    font-weight: 600;
}

.draft-action-item.load-action:hover {
    background: var(--primary-light, #eef2ff);
}

.draft-action-divider {
    height: 1px;
    background: var(--border-light, #f1f5f9);
    margin: 4px 0;
}

.draft-action-spinner {
    display: none;
    width: 12px;
    height: 12px;
    border: 2px solid var(--primary-light-border, rgba(79, 70, 229, 0.3));
    border-top-color: var(--primary-color, #4f46e5);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.draft-action-item.loading .draft-action-spinner {
    display: inline-block;
}

/* Shared table-row action dropdown (reference: Sales Return "Actions") -------
   Extra modifiers so every table can reuse the same component. */
.draft-action-item.danger,
.draft-action-item.danger i {
    color: var(--danger-color, #dc2626);
}

.draft-action-item.danger:hover {
    background: var(--danger-light, #fef2f2);
    color: var(--danger-color, #dc2626);
}

.draft-action-item:disabled,
.draft-action-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.draft-action-item:focus-visible,
.draft-action-toggle:focus-visible {
    outline: 2px solid var(--primary-color, #4f46e5);
    outline-offset: 1px;
}

.draft-action-item i {
    width: 14px;
    text-align: center;
    font-size: 12px;
}

/* Menu moved to <body> while open so table wrappers never clip it. */
.draft-action-dropdown.draft-action-portal {
    position: fixed;
    right: auto;
    bottom: auto;
}

[data-theme="dark"] .draft-action-item.danger:hover {
    background: rgba(220, 38, 38, 0.15);
}

/* ==========================================================================
   DRAFT INVOICE SHOW OFFCANVAS / MODAL
   ========================================================================== */
.draft-invoice-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10050;
}

.draft-invoice-modal.show,
.draft-invoice-modal.open {
    display: flex;
}

.draft-invoice-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(6px);
}

.draft-invoice-dialog {
    position: relative;
    width: min(840px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: var(--radius-2xl, 16px);
    box-shadow: var(--shadow-dialog, 0 25px 50px -12px rgba(0, 0, 0, 0.25));
    padding: 24px;
    animation: modalRise 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.draft-invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    gap: 16px;
}

.draft-invoice-eyebrow {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-color, #4f46e5);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.draft-invoice-title {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
}

.draft-invoice-date {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

.draft-invoice-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.draft-invoice-btn-print {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border-medium, #cbd5e1);
    border-radius: var(--radius-md, 6px);
    background: var(--bg-card, #ffffff);
    color: var(--text-dark, #334155);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.draft-invoice-btn-print:hover {
    background: var(--bg-light, #f8fafc);
    border-color: var(--primary-color, #4f46e5);
    color: var(--primary-color, #4f46e5);
}

.draft-invoice-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 0;
    color: var(--text-muted, #64748b);
    font-size: 13.5px;
}

.draft-invoice-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 0;
    text-align: center;
}

.draft-invoice-content {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-top: 18px;
}

.draft-invoice-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.draft-invoice-card {
    background: var(--bg-light, #f8fafc);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: var(--radius-lg, 10px);
    padding: 10px 12px;
}

.draft-invoice-card span {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #64748b);
    margin-bottom: 4px;
}

.draft-invoice-card strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    word-break: break-word;
}

.draft-invoice-notes {
    grid-column: 1 / -1;
    background: rgba(245, 158, 11, 0.08);
    border: 1px dashed rgba(245, 158, 11, 0.35);
    border-radius: var(--radius-lg, 10px);
    padding: 10px 14px;
}

.draft-invoice-notes span {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #d97706;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.draft-invoice-notes strong {
    font-size: 12.5px;
    color: var(--text-primary, #0f172a);
    font-weight: 500;
}

.draft-invoice-table-wrap {
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: var(--radius-lg, 10px);
    overflow-x: auto;
}

.draft-invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.draft-invoice-table th {
    background: var(--bg-light, #f8fafc);
    color: var(--text-muted, #64748b);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.draft-invoice-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light, #f1f5f9);
    color: var(--text-dark, #334155);
}

.draft-invoice-table tr:last-child td {
    border-bottom: none;
}

.draft-invoice-prod-name {
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    display: flex;
    align-items: center;
    gap: 6px;
}

.draft-invoice-prod-sku {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    margin-top: 2px;
}

.draft-invoice-unit-badge {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: var(--radius-sm, 4px);
    background: var(--bg-secondary, #e2e8f0);
    color: var(--text-muted, #475569);
    font-weight: 600;
}

.draft-invoice-summary-wrap {
    display: flex;
    justify-content: flex-end;
}

.draft-invoice-summary {
    width: min(340px, 100%);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.draft-invoice-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted, #64748b);
}

.draft-invoice-summary-row strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
}

.draft-invoice-grand-row {
    border-top: 2px solid var(--border-color, #e2e8f0);
    padding-top: 10px;
    margin-top: 4px;
}

.draft-invoice-grand-row span,
.draft-invoice-grand-row strong {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-color, #4f46e5);
}

.draft-invoice-discount-val {
    color: #dc2626 !important;
}

.draft-invoice-tax-val {
    color: var(--primary-color, #4f46e5) !important;
}

.draft-invoice-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #e2e8f0);
}

.draft-invoice-btn-cancel {
    padding: 8px 16px;
    height: 38px;
    border: 1px solid var(--border-medium, #cbd5e1);
    border-radius: var(--radius-lg, 8px);
    background: var(--bg-card, #ffffff);
    color: var(--text-dark, #334155);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.draft-invoice-btn-cancel:hover {
    background: var(--bg-light, #f8fafc);
}

.draft-invoice-btn-load {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    height: 38px;
    border: none;
    border-radius: var(--radius-lg, 8px);
    background: var(--primary-color, #4f46e5);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background 0.15s ease,
        transform 0.1s ease;
}

.draft-invoice-btn-load:hover {
    background: var(--primary-hover, #4338ca);
}

/* ── Dark Theme Overrides for Drafts ── */
[data-theme="dark"] .doctor-avatar {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border-color: rgba(99, 102, 241, 0.3);
}

[data-theme="dark"] .doctor-name-text {
    color: var(--text-primary);
}

[data-theme="dark"] .draft-status-badge {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .draft-action-toggle {
    background: var(--bg-card);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

[data-theme="dark"] .draft-action-toggle:hover {
    background: var(--bg-light);
    border-color: var(--primary-color);
}

[data-theme="dark"] .draft-action-dropdown {
    background: var(--bg-card);
    border-color: var(--border-medium);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .draft-action-item {
    color: var(--text-primary);
}

[data-theme="dark"] .draft-action-item:hover {
    background: var(--bg-light);
}

[data-theme="dark"] .draft-action-divider {
    background: var(--border-medium);
}

[data-theme="dark"] .draft-invoice-dialog {
    background: var(--bg-card);
    border-color: var(--border-medium);
}

[data-theme="dark"] .draft-invoice-title {
    color: var(--text-primary);
}

[data-theme="dark"] .draft-invoice-card {
    background: var(--bg-light);
    border-color: var(--border-medium);
}

[data-theme="dark"] .draft-invoice-card strong {
    color: var(--text-primary);
}

[data-theme="dark"] .draft-invoice-notes {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .draft-invoice-notes strong {
    color: #fbbf24;
}

[data-theme="dark"] .draft-invoice-table th {
    background: var(--bg-light);
    border-color: var(--border-medium);
    color: var(--text-muted);
}

[data-theme="dark"] .draft-invoice-table td {
    border-color: var(--border-medium);
    color: var(--text-primary);
}

[data-theme="dark"] .draft-invoice-prod-name {
    color: var(--text-primary);
}

[data-theme="dark"] .draft-invoice-unit-badge {
    background: var(--bg-secondary);
    color: var(--text-muted);
}

[data-theme="dark"] .draft-invoice-btn-cancel,
[data-theme="dark"] .draft-invoice-btn-print {
    background: var(--bg-light);
    border-color: var(--border-medium);
    color: var(--text-primary);
}
