/* ui.css — styles for the shared UI primitives in js/ui.js.
   ============================================================================

   Every class here is prefixed `ui-`. That is deliberate: five stylesheets
   already define `.toast` and four define `.modal`, with different positioning,
   colours and durations. A shared `.toast` rule would collide with all of them
   depending on load order. The `ui-` prefix means this file can be loaded on
   every page today without touching a single existing rule.

   Icons are inline SVG, drawn by ui.js. Font Awesome is NOT used here — five
   pages (login, add-user, profile, user-management, reset-password) never load
   it, and a toast that renders an empty box on those pages is worse than none.

   Depends on tokens.css for colour/spacing/radius values.
   ========================================================================== */


/* ============================================================================
   TOASTS
   ========================================================================== */

.ui-toast-container {
    position: fixed;
    top: var(--space-4, 1rem);
    right: var(--space-4, 1rem);
    z-index: var(--z-toast, 2500);
    display: flex;
    flex-direction: column;
    gap: var(--space-2, 0.5rem);
    max-width: min(420px, calc(100vw - 2rem));
    pointer-events: none;   /* container ignores clicks; toasts re-enable them */
}

.ui-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3, 0.75rem);
    padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
    background: var(--surface-default, #fff);
    color: var(--text-strong, #111827);
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-left: 4px solid var(--ui-toast-accent, #6b7280);
    border-radius: var(--radius-md, 8px);
    box-shadow: var(--shadow-lg, 0 12px 32px rgba(16, 24, 40, 0.12));
    font-family: var(--font-sans, system-ui, sans-serif);
    font-size: var(--text-sm, 0.875rem);
    line-height: 1.5;
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 200ms var(--ease, ease), transform 200ms var(--ease, ease);
}

.ui-toast.is-visible {
    opacity: 1;
    transform: translateX(0);
}

/* Leaving state — kept separate so a toast dismissed early animates out too. */
.ui-toast.is-leaving {
    opacity: 0;
    transform: translateX(12px);
}

.ui-toast__icon {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    color: var(--ui-toast-accent, #6b7280);
}

.ui-toast__message {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;   /* long invoice ids / URLs must not overflow */
}

.ui-toast__close {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    border-radius: var(--radius-xs, 4px);
    font: inherit;
    line-height: 1;
}

.ui-toast__close:hover {
    background: var(--surface-hover, #f3f4f6);
    color: var(--text-strong, #111827);
}

.ui-toast--success { --ui-toast-accent: var(--success-600, #0b6e4f); }
.ui-toast--error   { --ui-toast-accent: var(--danger-600,  #b91c1c); }
.ui-toast--warning { --ui-toast-accent: var(--warning-600, #b45309); }
.ui-toast--info    { --ui-toast-accent: var(--info-600,    #2563eb); }


/* ============================================================================
   DIALOGS (confirm / alert)
   ========================================================================== */

.ui-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-top, 1100);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4, 1rem);
    background: var(--surface-overlay, rgba(15, 23, 42, 0.55));
    opacity: 0;
    transition: opacity 150ms var(--ease, ease);
}

.ui-dialog-backdrop.is-visible { opacity: 1; }

.ui-dialog {
    width: 100%;
    max-width: 440px;
    background: var(--surface-default, #fff);
    color: var(--text-default, #374151);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-xl, 0 20px 50px rgba(16, 24, 40, 0.16));
    font-family: var(--font-sans, system-ui, sans-serif);
    transform: translateY(8px) scale(0.98);
    transition: transform 150ms var(--ease, ease);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}

.ui-dialog-backdrop.is-visible .ui-dialog {
    transform: translateY(0) scale(1);
}

.ui-dialog__body {
    padding: var(--space-6, 1.5rem);
    overflow-y: auto;
}

.ui-dialog__title {
    margin: 0 0 var(--space-2, 0.5rem);
    font-size: var(--text-lg, 1.125rem);
    font-weight: var(--weight-semibold, 600);
    color: var(--text-strong, #111827);
    line-height: 1.3;
}

.ui-dialog__message {
    margin: 0;
    font-size: var(--text-sm, 0.875rem);
    line-height: 1.6;
    color: var(--text-default, #374151);
    white-space: pre-line;   /* callers pass multi-line confirmation copy */
    overflow-wrap: anywhere;
}

.ui-dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2, 0.5rem);
    padding: var(--space-4, 1rem) var(--space-6, 1.5rem);
    border-top: 1px solid var(--border-subtle, #e5e7eb);
    background: var(--surface-sunken, #f9fafb);
    border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
    flex-wrap: wrap;
}

.ui-dialog__btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: var(--radius-md, 8px);
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: var(--text-sm, 0.875rem);
    font-weight: var(--weight-semibold, 600);
    line-height: 1.4;
    cursor: pointer;
    min-height: 38px;
    transition: background-color 150ms var(--ease, ease),
                border-color 150ms var(--ease, ease);
}

.ui-dialog__btn--cancel {
    background: var(--surface-default, #fff);
    border-color: var(--border-default, #d1d5db);
    color: var(--text-default, #374151);
}

.ui-dialog__btn--cancel:hover {
    background: var(--surface-hover, #f3f4f6);
    border-color: var(--border-strong, #9ca3af);
}

.ui-dialog__btn--confirm {
    background: var(--primary-900, #1a237e);
    color: #fff;
}

.ui-dialog__btn--confirm:hover { background: var(--primary-800, #283593); }

.ui-dialog__btn--danger { background: var(--danger-600, #b91c1c); color: #fff; }
.ui-dialog__btn--danger:hover { background: var(--danger-700, #991b1b); }


/* ============================================================================
   SHARED
   ========================================================================== */

/* Applied to <body> while a dialog or trapped modal is open, so the page
   behind cannot be scrolled with the wheel. */
.ui-scroll-locked {
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .ui-toast,
    .ui-dialog-backdrop,
    .ui-dialog {
        transition-duration: 1ms;
    }
}

@media print {
    .ui-toast-container,
    .ui-dialog-backdrop { display: none !important; }
}
