/**
 * Browsper Custom CSS Extensions
 *
 * Custom extensions for Pico CSS 2.1.1 framework.
 *
 * @license MIT
 * @copyright 2026 Browsper
 * @see https://github.com/Gi007i/Browsper
 */

/* =============================================
   SEMANTIC COLOR TOKENS
   ============================================= */
:root {
    --color-success: #2a7d2e;
    --color-danger: #c62828;
    --color-warning: #f57f17;
    --color-info: #1565c0;
    --pico-background-color: #f5f5f5;
}

[data-theme="dark"] {
    --color-success: #66bb6a;
    --color-danger: #ef5350;
    --color-warning: #ffca28;
    --color-info: #42a5f5;
}

/* =============================================
   UTILITIES
   ============================================= */
.hidden { display: none !important; }
.text-negative { color: var(--pico-del-color); }
.text-positive { color: var(--pico-ins-color); }
.nowrap { white-space: nowrap; }

.page-header {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: start;
    align-items: center;
}

/* =============================================
   TABLE VERTICAL ALIGNMENT
   ============================================= */
/* Buttons in tables: remove margin that causes misalignment */
figure table button,
figure table [type="submit"],
figure table [type="button"] {
    margin-top: 0;
    margin-bottom: 0;
}

/* =============================================
   STICKY FOOTER
   ============================================= */
html, body {
    height: 100vh;
}

body > footer {
    position: sticky;
    top: 100vh;
}

/* =============================================
   NAVIGATION
   ============================================= */
.main-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--pico-background-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* =============================================
   BULK ACTIONS BAR
   ============================================= */
.bulk-actions-bar button {
    white-space: nowrap;
}

/* =============================================
   PAGINATION
   ============================================= */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    text-decoration: none;
}

.pagination .current {
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
    border-color: var(--pico-primary);
}

/* =============================================
   PAGE NAVIGATION
   ============================================= */
/* Mobile: Stack layout (title on top, buttons below) */
.page-nav {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-nav h2 {
    text-align: center;
}

.page-nav ul {
    justify-content: center;
}

/* Desktop: Title left, buttons right (horizontal) */
@media (min-width: 768px) {
    .page-nav {
        display: grid;
        grid-template-columns: auto 1fr;
        gap: 1rem;
        align-items: center;
    }

    .page-nav h2 {
        text-align: left;
    }

    .page-nav ul {
        justify-content: flex-start;
        justify-self: end;
    }
}

/* =============================================
   LEGEND
   ============================================= */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
}

/* =============================================
   FORM GROUPS
   ============================================= */
.form-group {
    margin-bottom: var(--pico-spacing);
}

.form-group > label {
    margin-bottom: 0;
}

.form-group > small {
    display: block;
    margin-top: 0;
    color: var(--pico-muted-color);
}

/* =============================================
   TOAST NOTIFICATIONS
   ============================================= */
#toast-container {
    position: fixed;
    top: 80px;
    right: 1rem;
    z-index: 1000;
    max-width: 400px;
    width: calc(100% - 2rem);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

#toast-container:empty {
    display: none;
}

.toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--pico-primary);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.toast-fadeout {
    opacity: 0;
    transform: translateX(100%);
}

.toast span {
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    padding: 0.25rem;
    margin: 0;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: var(--pico-muted-color);
    width: auto;
}

.toast-close:hover {
    color: var(--pico-color);
}

[data-theme="dark"] .toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* =============================================
   ALERT COLOR VARIANTS (used by .toast)
   ============================================= */
.alert-success {
    border-left-color: var(--pico-ins-color);
}

.alert-danger {
    border-left-color: var(--pico-del-color);
}

.alert-warning {
    border-left-color: var(--color-warning);
}

.alert-info {
    border-left-color: var(--pico-primary);
}

/* =============================================
   TABLE SORTING
   ============================================= */
th[data-sort] {
    cursor: pointer;
}

/* =============================================
   FORM VALIDATION ERRORS
   ============================================= */
/* Error messages inside labels should be red when field is invalid */
label [aria-invalid="true"] ~ small,
label:has([aria-invalid="true"]) > small:last-child,
fieldset[aria-invalid="true"] > small {
    color: var(--pico-del-color);
}

/* =============================================
   ENCRYPTION STATE
   ============================================= */
.encrypted-content {
    filter: blur(4px);
    user-select: none;
    transition: filter 0.3s ease;
}

.decrypted-content {
    filter: none;
    user-select: auto;
}

/* =============================================
   FEATURE WARNING BANNER
   ============================================= */
.feature-warning-banner {
    background: #b71c1c;
    color: #fff;
    padding: 1rem;
    text-align: center;
    font-weight: bold;
}

/* =============================================
   RECOVERY KEY GRID
   ============================================= */
.recovery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    font-family: monospace;
}

.recovery-word {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    font-size: 0.875rem;
}

.recovery-word-num {
    color: var(--pico-muted-color);
    margin-right: 0.4rem;
}

/* =============================================
   BACKUP CODES
   ============================================= */
.backup-codes-warning {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-left: 4px solid var(--color-warning);
    background: var(--pico-card-background-color);
}

.backup-codes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.backup-code {
    display: block;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    font-size: 0.9rem;
}

/* =============================================
   CONNECTION INDICATOR
   ============================================= */
.indicator-active {
    background: var(--color-success);
}

.indicator-idle {
    background: var(--pico-muted-color);
}

/* =============================================
   DRAG AND DROP
   ============================================= */
.dragging {
    opacity: 0.4;
}

/* =============================================
   LAYOUT CONTAINERS
   ============================================= */
.container-narrow { max-width: 420px; margin: 4rem auto; }
.container-medium { max-width: 480px; margin: 4rem auto; }
.container-wide { max-width: 520px; margin: 3rem auto; }

/* =============================================
   FLEX UTILITIES
   ============================================= */
.flex-row { display: flex; gap: 0.5rem; }
.flex-row-wrap { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.flex-row-wrap-end { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; }
.flex-row-end { display: flex; gap: 0.5rem; justify-content: flex-end; }
.flex-row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.flex-row-center {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.flex-row-center-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.flex-1 { flex: 1; }

/* =============================================
   TEXT UTILITIES
   ============================================= */
.text-small { font-size: 0.875rem; }
.text-center { text-align: center; }
.text-muted { color: var(--pico-muted-color); }
.text-mono { font-family: monospace; }
.text-wrap-all { word-break: break-all; white-space: pre-wrap; }

/* =============================================
   SPACING UTILITIES
   ============================================= */
.mt-0 { margin-top: 0; }
.mt-05 { margin-top: 0.5rem; }
.mt-1 { margin-top: 1rem; }
.mt-15 { margin-top: 1.5rem; }
.mt-2 { margin-top: 2rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 1rem; }
.mb-15 { margin-bottom: 1.5rem; }
.mb-2 { margin-bottom: 2rem; }
.m-0 { margin: 0; }

/* =============================================
   GRID UTILITIES
   ============================================= */
.grid-auto-fit-sm {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.grid-auto-fit-md {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}

/* =============================================
   LIST UTILITIES
   ============================================= */
.list-plain {
    list-style: none;
    padding: 0;
}

/* =============================================
   FAVORITES
   ============================================= */
.favorite-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.favorite-actions {
    display: flex;
    gap: 0.25rem;
}

.drag-handle {
    cursor: grab;
    color: var(--pico-muted-color);
}

/* =============================================
   SEARCH INPUT
   ============================================= */
.search-input {
    flex: 1;
    min-width: 200px;
}

.search-label {
    flex: 1;
    min-width: 200px;
}

/* =============================================
   PAGINATION LAYOUT
   ============================================= */
.pagination-bar {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

/* =============================================
   BROWSER SESSION
   ============================================= */
.browser-frame {
    width: 100%;
    height: 75vh;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
}

.connection-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-success);
}

.no-session-article {
    max-width: 480px;
    margin: 6rem auto;
    text-align: center;
}

/* =============================================
   TOTP SETUP
   ============================================= */
.totp-qr-container {
    text-align: center;
    margin: 1.5rem 0;
}

.totp-qr-image {
    max-width: 220px;
    width: 100%;
    border: 4px solid var(--pico-background-color);
}

/* =============================================
   CODE DISPLAY
   ============================================= */
.code-display {
    font-size: 1.1rem;
    padding: 0.5rem;
    background: var(--pico-code-background-color, #f4f4f4);
    border-radius: 4px;
}

/* =============================================
   STATUS COLORS IN TABLES
   ============================================= */
.status-negative { color: var(--pico-del-color, #c0392b); }
.status-positive { color: var(--pico-ins-color, #27ae60); }
