/* -------------------------------------------------------------------------
   REUSABLE UI COMPONENTS
   ------------------------------------------------------------------------- */

/* ---------------- BUTTONS ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    user-select: none;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    font-family: var(--font-sans);
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-text, var(--text-inverse, #000000)) !important;
    box-shadow: 0 2px 8px var(--primary-glow);
    border: 1px solid transparent;
}

.btn-primary,
.btn-primary .btn-text,
.btn-primary span {
    color: var(--primary-text, var(--text-inverse, #000000)) !important;
    font-weight: 700;
}

.btn-primary svg {
    color: var(--primary-text, var(--text-inverse, #000000)) !important;
    stroke: currentColor;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    color: var(--primary-text, var(--text-inverse, #000000)) !important;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) .btn-text,
.btn-primary:hover:not(:disabled) span {
    color: var(--primary-text, var(--text-inverse, #000000)) !important;
}

.btn-secondary {
    background: var(--surface-elevated);
    color: var(--text) !important;
    border-color: var(--border);
}

.btn-secondary,
.btn-secondary .btn-text,
.btn-secondary span {
    color: var(--text) !important;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--surface-muted);
    border-color: var(--border-hover);
    color: var(--text) !important;
}

.btn-outline {
    background: transparent;
    color: var(--text) !important;
    border-color: var(--border-strong, var(--border));
}

.btn-outline,
.btn-outline .btn-text,
.btn-outline span {
    color: var(--text) !important;
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface-elevated);
    border-color: var(--primary);
    color: var(--text) !important;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary) !important;
}

.btn-ghost,
.btn-ghost .btn-text,
.btn-ghost span {
    color: var(--text-secondary) !important;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--surface-elevated);
    color: var(--text) !important;
}

.btn-ghost:hover:not(:disabled) .btn-text,
.btn-ghost:hover:not(:disabled) span {
    color: var(--text) !important;
}

.btn-danger {
    background: #DC2626;
    color: #FFFFFF !important;
    border-color: transparent;
}

.btn-danger,
.btn-danger .btn-text,
.btn-danger span {
    color: #FFFFFF !important;
    font-weight: 600;
}

.btn-danger:hover:not(:disabled) {
    background: #B91C1C;
    color: #FFFFFF !important;
}

.btn-icon {
    padding: 8px;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.btn-large {
    padding: 13px 26px;
    font-size: 15px;
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-xs {
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    min-height: 24px;
    border-radius: var(--radius-sm);
}

.btn-full {
    width: 100%;
}

/* ---------------- FORM INPUTS ---------------- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--space-4);
    text-align: left;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 11px 14px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    outline: none;
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-group.has-error .form-input {
    border-color: var(--danger);
    background: var(--danger-soft);
}

.form-error {
    font-size: 12px;
    color: var(--danger);
    margin-top: 2px;
    display: none;
}

.form-group.has-error .form-error {
    display: block;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.input-icon-left {
    padding-left: 40px;
}

.input-icon-right {
    padding-right: 40px;
}

.input-icon-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}

.input-icon-btn:hover {
    color: var(--text);
}

/* ---------------- TOGGLE SWITCH ---------------- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--border);
    transition: var(--transition-base);
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-base);
    border-radius: 50%;
    box-shadow: var(--shadow-xs);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

[data-theme="monochrome"] .toggle-switch input:checked + .toggle-slider {
    background-color: #FFFFFF;
}

[data-theme="monochrome"] .toggle-switch input:checked + .toggle-slider:before {
    background-color: #000000;
}

[data-theme="sandstone"] .toggle-switch input:checked + .toggle-slider {
    background-color: #C8754D;
}

[data-theme="sandstone"] .toggle-switch input:checked + .toggle-slider:before {
    background-color: #FFFFFF;
}

/* ---------------- BADGES & PILLS ---------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-full);
    line-height: 1;
}

.badge-primary {
    background: var(--primary-soft);
    color: var(--primary);
}

.badge-success {
    background: var(--success-soft);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.badge-muted {
    background: var(--surface-elevated);
    color: var(--text-secondary);
}

/* ---------------- AVATARS ---------------- */
.avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    overflow: visible;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
}

.avatar-xs { width: 24px; height: 24px; font-size: 10px; }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 44px; height: 44px; font-size: 15px; }
.avatar-lg { width: 56px; height: 56px; font-size: 18px; }
.avatar-xl { width: 88px; height: 88px; font-size: 28px; }

.avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    background-color: var(--text-muted);
}

.avatar-status.online {
    background-color: var(--success);
    animation: pulseOnline 2.5s infinite;
}

.avatar-status.away {
    background-color: var(--warning);
}

.avatar-status.offline {
    background-color: var(--text-muted);
}

/* ---------------- MODALS ---------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 32, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-backdrop.open,
.modal-backdrop.show,
.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
    transform: scale(0.95) translateY(12px);
    transition: transform var(--transition-smooth);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-backdrop.open .modal-card,
.modal-backdrop.show .modal-card,
.modal-backdrop.active .modal-card {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--surface-elevated);
    color: var(--text);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    max-height: 70vh;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
    background: var(--surface-elevated);
}

/* ---------------- TOAST NOTIFICATIONS ---------------- */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    z-index: var(--z-toast);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 12px 18px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    max-width: 420px;
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    pointer-events: auto;
}

.toast.hide {
    animation: toastSlideOut 0.25s forwards;
}

.toast-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--primary); }

.toast-message {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.toast-close {
    color: var(--text-muted);
    padding: 4px;
    margin-left: var(--space-2);
    border-radius: var(--radius-xs);
}

.toast-close:hover {
    color: var(--text);
}

/* ---------------- DROPDOWNS & MENUS ---------------- */
.dropdown-menu {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    min-width: 180px;
    z-index: var(--z-dropdown);
    display: none;
    animation: slideDown 0.18s ease;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    text-align: left;
}

.dropdown-item:hover {
    background: var(--surface-elevated);
    color: var(--text);
}

.dropdown-item.danger {
    color: var(--danger);
}

.dropdown-item.danger:hover {
    background: var(--danger-soft);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ---------------- SKELETONS & SPINNERS ---------------- */
.skeleton {
    background: linear-gradient(90deg, var(--surface-elevated) 25%, var(--border) 50%, var(--surface-elevated) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ---------------- EMPTY STATE ---------------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-10) var(--space-6);
    color: var(--text-secondary);
    height: 100%;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-4);
    color: var(--text-muted);
    background: var(--surface-elevated);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-2);
}

.empty-state-desc {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 320px;
    margin-bottom: var(--space-6);
    line-height: 1.5;
}

/* ---------------- CUSTOM DESKTOP CURSOR (Delegated to animations.css) ---------------- */
.custom-cursor-dot {
    display: none !important;
}

/* ---------------- PROFESSIONAL FRANK ID BADGE & COPY BUTTON ---------------- */
.frank-id-badge {
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    font-weight: 800;
    color: var(--text);
    background: var(--surface-elevated);
    padding: 2px 6px;
    border-radius: var(--radius-xs, 4px);
    border: 1px solid var(--border);
    letter-spacing: 0.6px;
    display: inline-flex;
    align-items: center;
    user-select: all;
    line-height: 1.2;
}

[data-theme="monochrome"] .frank-id-badge {
    color: #FFFFFF;
    background: #181818;
    border-color: #303030;
}

[data-theme="sandstone"] .frank-id-badge {
    color: #76543B;
    background: #F8EFE2;
    border-color: #D8C5AA;
}

.btn-copy-frank-id {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    min-width: 26px;
    min-height: 26px;
    border-radius: var(--radius-xs, 4px);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast, 150ms ease);
    position: relative;
    outline: none;
    line-height: 1;
    flex-shrink: 0;
}

.btn-copy-frank-id:hover {
    color: var(--primary, #2563EB);
    border-color: var(--primary, #2563EB);
    background: var(--primary-soft, rgba(37, 99, 235, 0.12));
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.2);
}

.btn-copy-frank-id:active {
    transform: scale(0.95);
}

.btn-copy-frank-id:focus-visible {
    outline: 2px solid var(--primary, #2563EB);
    outline-offset: 2px;
}

.btn-copy-frank-id.copied {
    color: var(--success, #10B981) !important;
    border-color: var(--success, #10B981) !important;
    background: var(--success-soft, rgba(16, 185, 129, 0.12)) !important;
}

/* Touch target for mobile accessibility (minimum 40-44px tap area) */
@media (max-width: 768px) {
    .btn-copy-frank-id::after {
        content: '';
        position: absolute;
        top: -9px;
        bottom: -9px;
        left: -9px;
        right: -9px;
        min-width: 44px;
        min-height: 44px;
    }
}

/* -------------------------------------------------------------------------
   FRANK MULTILINGUAL (i18n) SELECTOR & DROPDOWN COMPONENT
   ------------------------------------------------------------------------- */
.lang-selector-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    min-height: 38px;
    box-sizing: border-box;
}

.lang-btn:hover,
.lang-btn:focus-visible {
    color: var(--text);
    border-color: var(--theme-border, var(--border));
    background: var(--bg-hover, rgba(255, 255, 255, 0.06));
    outline: none;
}

.lang-btn[aria-expanded="true"] {
    color: var(--text);
    border-color: var(--primary);
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
}

.lang-btn .lang-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.lang-btn .current-lang-label {
    display: inline-block;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
}

.lang-btn .chevron-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.lang-btn[aria-expanded="true"] .chevron-icon {
    transform: rotate(180deg);
}

/* Language Dropdown Menu */
.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 140px;
    max-width: min(200px, 90vw);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
    padding: 6px;
    z-index: var(--z-dropdown);
    display: none;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    box-sizing: border-box;
}

[data-theme="sandstone"] .lang-dropdown-menu {
    background: #FFF8EA;
    border-color: #D9BE98;
    box-shadow: 0 10px 30px rgba(118, 84, 59, 0.15), 0 0 0 1px rgba(118, 84, 59, 0.08);
}

.lang-dropdown-menu.show {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.lang-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 12px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition-fast), color var(--transition-fast);
    font-family: inherit;
    box-sizing: border-box;
}

.lang-option:hover,
.lang-option:focus-visible {
    color: var(--text);
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
    outline: none;
}

[data-theme="sandstone"] .lang-option:hover,
[data-theme="sandstone"] .lang-option:focus-visible {
    background: rgba(118, 84, 59, 0.08);
    color: #2D2319;
}

.lang-option.active {
    color: var(--primary);
    font-weight: 700;
    background: var(--primary-glow, rgba(255, 255, 255, 0.06));
}

[data-theme="sandstone"] .lang-option.active {
    background: rgba(200, 117, 77, 0.12);
    color: #C8754D;
}

.lang-option::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: transparent;
    transition: background var(--transition-fast);
    flex-shrink: 0;
    margin-left: 8px;
}

.lang-option.active::after {
    background: currentColor;
}

/* Mobile specific styling inside navigation menus */
.mobile-lang-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 0;
    border-top: 1px solid var(--border);
    margin-top: 14px;
    width: 100%;
}

.mobile-lang-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.mobile-lang-selector {
    width: 100%;
}

.mobile-lang-selector .lang-btn {
    width: 100%;
    justify-content: space-between;
}

.mobile-lang-selector .lang-dropdown-menu {
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
}



/* -------------------------------------------------------------------------
   GLOBAL APPLICATION STARTUP & LOADING SCREEN
   Universal splash and auth check loader supporting Sandstone & Monochrome
   ------------------------------------------------------------------------- */
.app-loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #080B24;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s ease;
}

[data-theme="sandstone"] .app-loading-screen {
    background: #1C1917;
}

.app-loading-screen.fade-out {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.frank-logo-anim-stage.splash {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    text-align: center;
}

.frank-anim-wordmark {
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

[data-theme="sandstone"] .frank-anim-wordmark {
    background: linear-gradient(135deg, #FDFBF7 0%, #E7E5E4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}


/* Instant startup cloak to prevent visual flashing during session validation */
html.app-checking-session body > *:not(.app-loading-screen):not(#appLoadingScreen) {
    display: none !important;
}
