/* Components - buttons, icons, alerts, flash, dialogs, notifications. */

/* ========================================
   BUTTONS
    Single source of truth for all buttons.
    Variants: cta (accent), premium, secondary (neutral), good, bad,
    link (inline text-style).
   Modifiers: btn-block, btn-sm.
   Flat, uniform fill. Single frame mechanism: thick transparent
   inset lines on top (light) and bottom (dark), drawn over the
   background to give a 3D bevel. border: 0 removes the native
   button UA border so <a> and <button> render identically.
   Minimum height: every button, including btn-sm, must stay at or
   above --btn-min-height. Never add a modifier that pushes below it.
   The fill and bevel live on ::before so :active can scale only the
   look while the button box (and its click target) stays full size.
   The slot content is wrapped in .btn-inner so the label scales with
   the fill on press, keeping the press effect identical to before.
   ======================================== */

.btn {
    --btn-fill: var(--accent);
    --btn-text: var(--text-inverse);
    --btn-min-height: var(--space-6);

    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-pixel);
    font-size: var(--font-size-xs);
    line-height: var(--line-height-snug);
    padding: var(--space-3) var(--space-6);
    min-height: var(--btn-min-height);
    background: transparent;
    color: var(--btn-text);
    border: 0;
    cursor: pointer;
    text-decoration: none;
    font-weight: 400;
}

.btn::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--btn-fill);
    box-shadow:
        inset 0 4px 0 rgba(255, 255, 255, 0.45),
        inset 0 -4px 0 rgba(0, 0, 0, 0.5);
    transition:
        background-color 0.1s ease,
        transform 0.05s ease;
}

.btn-inner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    transition: transform 0.05s ease;
}

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

.btn:hover::before {
    background-color: color-mix(in oklch, var(--btn-fill), white 10%);
}

.btn:active::before,
.btn:active .btn-inner {
    transform: scale(97%);
}

.btn:focus-visible {
    outline: var(--border-width) solid var(--accent);
    outline-offset: var(--space-0-5);
}

.btn:disabled,
.btn:disabled:hover,
.btn:disabled:active {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.btn:disabled::before,
.btn:disabled:hover::before,
.btn:disabled:active::before,
.btn:disabled .btn-inner,
.btn:disabled:hover .btn-inner,
.btn:disabled:active .btn-inner {
    transform: none;
}

.btn-cta {
    --btn-fill: var(--accent);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.btn-cta::before {
    background:
        radial-gradient(circle, rgba(0, 0, 0, 0.14) 0%, rgba(0, 0, 0, 0) 55%),
        var(--btn-fill);
}

.btn-premium {
    --btn-fill: var(--premium-500);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.btn-premium::before {
    background:
        radial-gradient(circle, rgba(0, 0, 0, 0.14) 0%, rgba(0, 0, 0, 0) 55%),
        var(--btn-fill);
}

.btn-secondary {
    --btn-fill: var(--border);
    --btn-text: var(--text-primary);
}

.btn-good {
    --btn-fill: var(--success-200);
    --btn-text: var(--success-800);
}

.btn-bad {
    --btn-fill: var(--error-200);
    --btn-text: var(--error-800);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
}

.btn-sm .btn-inner {
    gap: var(--space-1);
}

.btn-link {
    --btn-text: var(--accent);

    font-weight: inherit;
}

.btn-link:hover {
    text-decoration: underline;
    text-decoration-thickness: from-font;
    text-underline-offset: var(--space-1);
}

.btn-link::before {
    content: none;
}

.btn-link.is-danger {
    --btn-text: var(--error-text);
}

/* Amount preset grid - toggle cells joined by thin gray gridlines. */
.amount-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--border-width-thin);
    background: var(--border);
    border: var(--border-width-thin) solid var(--border);
    max-width: 360px;
    margin-bottom: var(--space-4);
}

.amount-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--bg);
    border: 0;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    cursor: pointer;
    transition:
        background-color 0.1s ease,
        color 0.1s ease;
}

.amount-cell:hover {
    color: var(--text-primary);
}

.amount-cell .icon {
    display: none;
}

.amount-cell.selected {
    background: var(--design-200);
    color: var(--text-inverse);
}

.amount-cell.selected .icon {
    display: inline-block;
}

.amount-cell:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* ========================================
   PAGINATION (plain, shared with admin)
   ======================================== */

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    margin: var(--space-6) 0 0;
    padding: 0;
    list-style: none;
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--space-8);
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    line-height: var(--line-height-snug);
    color: var(--text-secondary);
    text-decoration: none;
}

a.pagination-link:hover {
    color: var(--text-primary);
}

a.pagination-link:focus-visible {
    outline: var(--border-width) solid var(--accent);
    outline-offset: var(--space-0-5);
}

.pagination-link.is-current {
    color: var(--accent-dark);
    font-weight: 700;
}

.pagination-link.is-disabled {
    color: var(--text-muted);
    opacity: 0.5;
}

.pagination-gap {
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* ========================================
   ICONS
   ======================================== */

.icon {
    width: 1em;
    height: 1em;
    display: inline-block;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

/* ========================================
   TOASTS (Sonner-style, <dialog>, no JS)
   Full-width panel at the top on narrow
   screens, bottom-right corner on wide
   screens. Rendered with the modern <dialog>
   element + <form method="dialog"> so the close
   button works natively without JavaScript.
   ======================================== */

.toast {
    position: fixed;
    z-index: var(--z-toast);
    top: var(--space-5);
    left: 0;
    right: 0;
    width: 100%;
    padding: var(--space-4) var(--space-5);
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--accent-light);
    color: var(--text-primary);
    border: none;
    box-shadow: var(--shadow-modal);
    border-radius: 0;
    overflow: hidden;
}

.toast:nth-of-type(2) {
    top: calc(var(--space-5) + 76px);
}

.toast::backdrop {
    background: transparent;
}

.toast[open] {
    animation: toast-in 0.2s ease-out;
}

.toast-icon {
    flex-shrink: 0;
    margin-top: 0.1em;
    color: var(--text-primary);
}

.toast-icon .icon {
    width: 1.25em;
    height: 1.25em;
}

.toast-text {
    flex: 1;
    min-width: 0;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.toast-text p {
    margin: 0;
    color: var(--text-primary);
}

.toast-text p + p {
    margin-top: var(--space-1);
}

.toast-close-form {
    flex-shrink: 0;
    margin-left: auto;
}

.toast-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-1);
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
}

.toast-close:hover {
    opacity: 0.7;
}

.toast-close .icon {
    width: 1.1rem;
    height: 1.1rem;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-in-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (min-width: 768px) {
    .toast {
        top: auto;
        left: auto;
        right: var(--space-5);
        bottom: var(--space-5);
        width: min(440px, calc(100vw - var(--space-8)));
    }

    .toast:nth-of-type(2) {
        top: auto;
        bottom: calc(var(--space-5) + 76px);
    }

    .toast[open] {
        animation-name: toast-in-up;
    }
}

/* ========================================
   NATIVE CONFIRM DIALOG (popover, no JS)
   ======================================== */

.confirm-dialog {
    border: none;
    border-top: var(--border-width-accent) solid var(--error-border);
    padding: var(--space-6);
    max-width: 380px;
    width: calc(100% - var(--space-8));
    background: var(--bg-alt);
    color: var(--text-primary);
}

.confirm-dialog[popover] {
    inset: 0;
    margin: auto;
}

.confirm-dialog::backdrop {
    background: color-mix(in srgb, var(--accent-light) 15%, transparent);
}

.confirm-dialog-title {
    margin: 0 0 var(--space-3);
    font-family: var(--font-pixel);
    font-size: var(--font-size-base);
    line-height: var(--line-height-snug);
    color: var(--text-primary);
    text-wrap: balance;
}

.confirm-dialog-text {
    margin: 0 0 var(--space-6);
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    text-wrap: pretty;
}

.confirm-dialog-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    flex-wrap: wrap;
}

.inline-form {
    display: inline;
}

/* ========================================
   NOTIFICATIONS (popover drawer, no JS)
   ======================================== */

.notif-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--icon-gap);
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.notif-trigger:hover {
    color: var(--text-primary);
}

.notif-trigger .icon {
    width: 1.25rem;
    height: 1.25rem;
}

.notif-count {
    font-family: var(--font-pixel);
    font-size: var(--font-size-2xs);
    color: var(--accent-dark);
    line-height: var(--line-height-none);
}

.notif-panel {
    position: fixed;
    inset: 0 0 0 auto;
    margin: 0;
    width: min(420px, 100%);
    height: 100vh;
    height: 100dvh;
    border: none;
    padding: 0;
    background: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
}

.notif-panel:popover-open {
    display: flex;
    flex-direction: column;
    animation: notif-slide-in 0.2s ease-out;
}

.notif-panel::backdrop {
    background: color-mix(in srgb, var(--accent-light) 15%, transparent);
}

@keyframes notif-slide-in {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.notif-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: var(--border-width) solid var(--border);
    flex-shrink: 0;
}

.notif-title {
    font-family: var(--font-pixel);
    font-size: var(--font-size-xs);
    color: var(--text-primary);
}

.notif-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.notif-close:hover {
    color: var(--text-primary);
}

.notif-close .icon {
    width: 1.25rem;
    height: 1.25rem;
}

.notif-body {
    flex: 1;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: var(--border-width-thin) solid var(--border-light);
}

.notif-item.is-unread {
    background: var(--bg-alt);
}

.notif-icon {
    flex-shrink: 0;
    margin-top: 0.15em;
    color: var(--text-muted);
}

.notif-icon .icon {
    width: 1.2em;
    height: 1.2em;
}

.notif-kind-warning .notif-icon {
    color: var(--warning-500);
}

.notif-kind-important .notif-icon {
    color: var(--error-500);
}

.notif-kind-billing .notif-icon {
    color: var(--accent-dark);
}

.notif-kind-system .notif-icon {
    color: var(--text-secondary);
}

.notif-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-0-5);
}

.notif-text {
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--text-secondary);
    text-decoration: none;
    overflow-wrap: anywhere;
    text-wrap: pretty;
}

a.notif-text {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a.notif-text:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
}

.notif-item.is-unread .notif-text {
    color: var(--text-primary);
    font-weight: 700;
}

.notif-item.is-unread a.notif-text {
    color: var(--accent-dark);
}

.notif-item.is-unread a.notif-text:hover {
    color: var(--accent);
}

.notif-time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.notif-delete {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-1);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.notif-delete:hover {
    color: var(--error-text);
}

.notif-delete .icon {
    width: 1rem;
    height: 1rem;
}

.notif-empty {
    padding: var(--space-6) var(--space-5);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.notif-foot {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: var(--border-width) solid var(--border);
    flex-shrink: 0;
}

.notif-foot form {
    flex: 1;
}
