/* components.css — populated by Plan 06-09 (toast, modal, buttons, spinner, states)
 * and Plan 06-10 (avatar). All values reference tokens in tokens.css.
 * Scope: UI-07 (toast), UI-09 (modal + empty/error states), UI-01 spinner.
 */

/* -- Toast ---------------------------------------------------- */
#toast-root {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 240px;
    max-width: 320px;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-border);
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    opacity: 1;
    transform: translateY(0);
    transition: opacity 200ms ease, transform 200ms ease;
}
.toast--success { border-left-color: var(--color-success); }
.toast--error   { border-left-color: var(--color-danger);  }
.toast--warn    { border-left-color: var(--color-warning); }
.toast--info    { border-left-color: var(--color-accent);  }
.toast--leaving { opacity: 0; transform: translateY(-12px); }

.toast__message {
    flex: 1;
    line-height: var(--line-height-normal);
}
.toast__close,
.toast__action {
    flex: 0 0 auto;
    background: transparent;
    border: 0;
    color: var(--color-text-secondary);
    font-size: var(--font-size-base);
    min-height: 24px;
    min-width: 24px;
    padding: 0 var(--space-2);
    cursor: pointer;
}
.toast__close:hover,
.toast__action:hover { color: var(--color-text); }
.toast__action {
    color: var(--color-accent);
    font-weight: var(--font-weight-semibold);
}

/* Mobile: stack at bottom, full-width per 06-UI-SPEC §Toast */
@media (max-width: 639px) {
    #toast-root {
        top: auto;
        bottom: var(--space-4);
        right: var(--space-4);
        left: var(--space-4);
        align-items: stretch;
    }
    .toast { max-width: none; }
}

/* -- Modal ---------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal-dialog {
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    padding: var(--space-6);
    width: 100%;
    max-width: 480px;
}

.modal-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    margin-bottom: var(--space-3);
}
.modal-message {
    color: var(--color-text);
    line-height: var(--line-height-normal);
    margin-bottom: var(--space-6);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* -- Buttons -------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 var(--space-4);
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.btn:focus-visible {
    outline: 2px solid var(--color-accent-subtle);
    outline-offset: 2px;
}
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.btn--primary {
    background: var(--btn-bg);
    color: var(--btn-text);
}
.btn--primary:hover { background: var(--btn-bg-hover); }

.btn--ghost {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border-strong);
}
.btn--ghost:hover { background: var(--color-bg-subtle); }

.btn--danger {
    background: var(--color-danger);
    color: #fff;
}
.btn--danger:hover { background: var(--color-danger-hover); }

/* -- Spinner (UI-01 loading indicator) ----------------------- */
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Initial loading wrapper on the shell before app.js boots */
.initial-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--color-text-secondary);
}

/* -- Empty / Error States (UI-09) ---------------------------- */
.state-empty,
.state-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-4);
    text-align: center;
    color: var(--color-text-secondary);
}
.state-empty h1,
.state-error h1 {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-3);
    color: var(--color-text);
}
.state-empty p,
.state-error p {
    margin-bottom: var(--space-4);
    max-width: 400px;
}

/* -- Stub views (Phase 7/8/9 will replace) ------------------- */
.stub {
    padding: var(--space-6);
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: 8px;
}
.stub h1 { font-size: var(--font-size-xl); margin-bottom: var(--space-2); }
.stub p  { color: var(--color-text-secondary); }
.stub__param {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: var(--font-size-sm);
    background: var(--color-bg-subtle);
    padding: var(--space-1) var(--space-2);
    border-radius: 4px;
    display: inline-block;
    margin-top: var(--space-2);
}

/* -- Avatar (Plan 06-10, UI-04, 06-UI-SPEC §Avatar Component) --- */
/* Circular avatar primitive. Sizes (24/32/40) and per-fallback
 * background color are set inline on the element by createAvatar()
 * because they are data-driven (size arg + hashCode(displayName)).
 * Phase-9 SEC-01 note: style-src 'unsafe-inline' required OR switch
 * to 8 pre-defined classes (.avatar--color-0 through .avatar--color-7)
 * to close the inline-style hole. */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    vertical-align: middle;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    overflow: hidden;
}

.avatar--fallback {
    color: #ffffff;
    user-select: none;
    /* background is set inline per createAvatar's deterministic PALETTE color */
}

.avatar--image {
    object-fit: cover;
}
