/* ============================================================
   SONORA Material Design 3 Reusable Interactive Components
   ============================================================ */

[data-ripple] {
    position: relative;
    overflow: hidden;
}

.m3-ripple-ink {
    position: absolute;
    border-radius: 50%;
    background: var(--md-ripple);
    transform: scale(0);
    animation: m3-ripple-anim 520ms var(--ease-standard) forwards;
    pointer-events: none;
}

@keyframes m3-ripple-anim {
    to {
        transform: scale(2.8);
        opacity: 0;
    }
}

/* M3 Buttons */
.m3-btn {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    font-family: var(--font-body);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.18s var(--ease-standard), border-color 0.18s var(--ease-standard), transform 0.14s var(--ease-standard), box-shadow 0.18s var(--ease-standard);
}

.m3-btn:active {
    transform: scale(0.98);
}

.m3-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.m3-btn.small {
    height: 34px;
    padding: 0 13px;
    font-size: 12.5px;
}

.m3-btn.small .ms-icon {
    font-size: 17px;
}

.m3-btn.full {
    width: 100%;
}

.m3-btn-filled {
    background: var(--md-primary);
    color: var(--md-on-primary);
}

.m3-btn-filled:hover:not(:disabled) {
    filter: brightness(1.07);
    box-shadow: var(--md-shadow-1);
}

.m3-btn-tonal {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.m3-btn-tonal:hover:not(:disabled) {
    filter: brightness(1.08);
}

.m3-btn-outlined {
    background: transparent;
    color: var(--md-on-surface);
    border-color: var(--md-outline);
}

.m3-btn-outlined:hover:not(:disabled) {
    background: var(--md-surface-container-high);
}

.m3-btn-text {
    background: transparent;
    color: var(--md-primary);
}

.m3-btn-text:hover {
    background: rgba(124, 155, 255, 0.10);
}

.m3-btn-danger {
    background: rgba(239, 68, 68, 0.14);
    color: var(--md-dnd);
    border-color: rgba(239, 68, 68, 0.25);
}

.m3-btn-danger:hover {
    background: rgba(239, 68, 68, 0.22);
}

.m3-icon-btn {
    position: relative;
    overflow: hidden;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    border: 0;
    background: transparent;
    color: var(--md-on-surface-variant);
    cursor: pointer;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    transition: background-color 0.16s, color 0.16s;
}

.m3-icon-btn:hover {
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
}

/* M3 Chips */
.m3-chip {
    position: relative;
    overflow: hidden;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--md-outline-variant);
    background: var(--md-surface-container-low);
    color: var(--md-on-surface-variant);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.18s var(--ease-standard);
}

.m3-chip.small {
    height: 30px;
    padding: 0 11px;
    font-size: 12px;
}

.m3-chip .ms-icon {
    font-size: 16px;
}

.m3-chip:hover {
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
}

.m3-chip.active {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
    border-color: transparent;
    font-weight: 600;
}

/* M3 Toggle Switch */
.m3-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
    cursor: pointer;
}

.m3-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.m3-switch-track {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-full);
    background: var(--md-surface-container-highest);
    border: 1.5px solid var(--md-outline);
    transition: background-color 0.2s var(--ease-standard), border-color 0.2s;
}

.m3-switch-track::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--md-on-surface-variant);
    transition: transform 0.22s var(--ease-emphasized), background-color 0.2s;
}

.m3-switch input:checked + .m3-switch-track {
    background: var(--md-primary);
    border-color: var(--md-primary);
}

.m3-switch input:checked + .m3-switch-track::after {
    transform: translateX(20px);
    background: var(--md-on-primary);
}

/* M3 Inputs & Fields */
.m3-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.m3-field > span,
.field-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--md-on-surface-variant);
}

.field-hint {
    font-size: 11.5px;
    color: var(--md-on-surface-variant);
}

.field-hint.err {
    color: var(--md-dnd);
}

.m3-input,
.m3-textarea {
    width: 100%;
    min-width: 0;
    background: var(--md-surface-container-low);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-sm);
    color: var(--md-on-surface);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.18s, box-shadow 0.18s, background-color 0.18s;
}

.m3-input {
    height: 42px;
}

.m3-input:focus,
.m3-textarea:focus {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(124, 155, 255, 0.18);
    background: var(--md-surface-container);
}

/* M3 Segmented Control */
.m3-segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--md-surface-container-high);
    border-radius: var(--radius-full);
    margin-bottom: 18px;
}

.seg-btn {
    height: 36px;
    border-radius: var(--radius-full);
    border: 0;
    background: transparent;
    color: var(--md-on-surface-variant);
    font-family: var(--font-body);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease-emphasized);
}

.seg-btn.active {
    background: var(--md-surface-container-low);
    color: var(--md-on-surface);
    box-shadow: var(--md-shadow-1);
}

/* M3 Sliders with Filled Active Trail (--pct) */
.m3-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 99px;
    background: linear-gradient(
        to right,
        var(--md-primary) 0%,
        var(--md-primary) var(--pct, 0%),
        var(--md-surface-container-highest) var(--pct, 0%),
        var(--md-surface-container-highest) 100%
    );
    outline: none;
    cursor: pointer;
    transition: height 0.14s;
}

.m3-slider:hover {
    height: 7px;
}

.m3-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--md-primary);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
    transition: transform 0.14s;
}

.m3-slider:hover::-webkit-slider-thumb {
    transform: scale(1.2);
}

/* ============================================================
   CUSTOM PORTAL M3 SELECT MENU (ZERO NATIVE SELECT, ZERO SCROLL FLASH)
   ============================================================ */
.m3-select {
    position: relative;
    display: inline-block;
    width: 100%;
    min-width: 0;
}

.m3-select.compact {
    width: 100%;
}

.m3-select-trigger {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 42px;
    padding: 0 12px 0 14px;
    border-radius: var(--radius-sm);
    background: var(--md-surface-container-low);
    border: 1px solid var(--md-outline);
    color: var(--md-on-surface);
    font-family: var(--font-body);
    font-size: 13.5px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    transition: border-color 0.18s, background-color 0.18s, box-shadow 0.18s;
}

.m3-select.compact .m3-select-trigger {
    height: 34px;
    border-radius: var(--radius-full);
    padding: 0 10px 0 12px;
    background: var(--md-surface-container-high);
    border-color: var(--md-outline-variant);
    font-size: 12.5px;
}

.m3-select-trigger:hover {
    background: var(--md-surface-container-high);
}

.m3-select.open .m3-select-trigger {
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(124, 155, 255, 0.16);
}

.m3-select-value {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.m3-select-value span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.m3-select-chevron {
    font-size: 18px;
    color: var(--md-on-surface-variant);
    transition: transform 0.22s var(--ease-emphasized);
    flex-shrink: 0;
}

.m3-select.open .m3-select-chevron {
    transform: rotate(180deg);
}

.m3-select-menu-portal {
    position: fixed;
    z-index: 700;
    max-width: min(310px, calc(100vw - 20px));
    max-height: 280px;
    overflow-y: auto;
    padding: 6px;
    border-radius: var(--radius-md);
    background: var(--md-surface-container-high);
    border: 1px solid var(--md-outline);
    box-shadow: var(--md-shadow-3);
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.16s var(--ease-standard), transform 0.2s var(--ease-emphasized);
}

.m3-select-menu-portal.open {
    opacity: 1;
    transform: scale(1);
}

.m3-select-option {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--md-on-surface);
    padding: 9px 11px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-body);
    transition: background-color 0.14s;
}

.m3-select-option:hover {
    background: var(--md-surface-container-highest);
}

.m3-select-option.selected {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}

.m3-opt-texts {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.m3-opt-label {
    font-size: 13.5px;
    font-weight: 600;
}

.m3-opt-sub {
    font-size: 11.5px;
    color: var(--md-on-surface-variant);
}

.m3-select-option.selected .m3-opt-sub {
    color: inherit;
    opacity: 0.85;
}

.m3-opt-check {
    font-size: 18px;
    opacity: 0;
}

.m3-select-option.selected .m3-opt-check {
    opacity: 1;
}

.status-dot-sm {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================================
   ANIMATED MODALS (ENTER + EXIT SPRINGS, ZERO OVERFLOW X)
   ============================================================ */
.m3-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--md-scrim);
    backdrop-filter: blur(10px);
    display: none;
    place-items: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.22s var(--ease-standard);
}

.m3-modal-backdrop.is-open {
    display: grid;
    opacity: 1;
}

.m3-modal-backdrop.is-closing {
    display: grid;
    opacity: 0;
}

.m3-modal-dialog {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 32px);
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--md-surface-container);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-xl);
    box-shadow: var(--md-shadow-3);
    padding: 24px;
    transform: translateY(20px) scale(0.94);
    opacity: 0;
    transition: transform 0.28s var(--ease-emphasized), opacity 0.22s var(--ease-standard);
}

.m3-modal-backdrop.is-open .m3-modal-dialog {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.m3-modal-backdrop.is-closing .m3-modal-dialog {
    transform: translateY(14px) scale(0.95);
    opacity: 0;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.modal-header h2 {
    font-size: 20px;
    margin-bottom: 3px;
}

.modal-header p {
    font-size: 13px;
    color: var(--md-on-surface-variant);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.form-error {
    color: var(--md-dnd);
    font-size: 13px;
    min-height: 18px;
    margin-bottom: 8px;
}

.m3-switch:not(:has(input)) {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 44px;
    height: 24px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.24);
    border: 1px solid rgba(148, 163, 184, 0.34);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .18s ease, border-color .18s ease;
}

.m3-switch:not(:has(input)) .m3-switch-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--md-on-surface-variant);
    transition: transform .18s ease, background .18s ease;
}

.m3-switch:not(:has(input)).is-on {
    background: var(--md-primary);
    border-color: var(--md-primary);
}

.m3-switch:not(:has(input)).is-on .m3-switch-thumb {
    transform: translateX(20px);
    background: #fff;
}

/* ============================================================
   AVATARS, ANCHORED AVATAR DECORATIONS, EQUALIZER & BADGES
   ============================================================ */
.avatar-decor-host {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    border-radius: 50%;
    flex-shrink: 0;
}

.avatar-decor-canvas {
    position: absolute;
    top: -26%;
    left: -26%;
    width: 152%;
    height: 152%;
    pointer-events: none;
    z-index: 6;
}

.avatar-circle {
    position: relative;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1;
    color: #fff;
    overflow: hidden;
    flex-shrink: 0;
    user-select: none;
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-presence-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    border-radius: 50%;
    vertical-align: middle;
    flex-shrink: 0;
}

.presence-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2.5px solid var(--md-surface-container-low);
    z-index: 8;
}

.presence-dot.online { background: var(--md-online); }
.presence-dot.dnd { background: var(--md-dnd); }
.presence-dot.offline { background: var(--md-offline); }

.unread-badge {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--md-crimson);
    color: var(--md-crimson-text);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(229, 57, 53, 0.42);
}

/* Equalizer Bars */
.eq-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 13px;
}

.eq-bars i {
    display: block;
    width: 3px;
    border-radius: 2px;
    background: var(--md-online);
    animation: eq-bounce 0.9s ease-in-out infinite alternate;
}

.eq-bars i:nth-child(1) { height: 6px; animation-delay: 0s; }
.eq-bars i:nth-child(2) { height: 12px; animation-delay: 0.25s; }
.eq-bars i:nth-child(3) { height: 8px; animation-delay: 0.45s; }

@keyframes eq-bounce {
    0% { transform: scaleY(0.35); }
    100% { transform: scaleY(1); }
}

/* Toasts / Snackbars */
.toast-host {
    position: fixed;
    top: 18px;
    right: 20px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.m3-toast {
    pointer-events: auto;
    background: var(--md-surface-container-high);
    border: 1px solid var(--md-outline);
    border-radius: var(--radius-md);
    box-shadow: var(--md-shadow-2);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toast-in 0.28s var(--ease-emphasized);
    cursor: pointer;
}

.m3-toast.out {
    animation: toast-out 0.2s var(--ease-standard) forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(24px) scale(0.96); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(20px) scale(0.96); }
}

.toast-copy {
    min-width: 0;
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toast-body {
    font-size: 12.5px;
    color: var(--md-on-surface-variant);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
