/**
 * ManaVault - UI Polish Layer (v1.0.0)
 * (c) 2024-2026 BTCin Corporate s.r.o.
 *
 * CSS-only improvements loaded LAST.
 * Safe to remove: just delete the <link> tag to revert everything.
 *
 * Fixes:
 *  1. Missing definitions (modal-footer, form-control)
 *  2. Duplicate conflicts (btn-sm, btn-secondary)
 *  3. Transitions on all interactive elements
 *  4. Focus rings for keyboard navigation
 *  5. Modal backdrop blur + smooth animation
 *  6. Table polish (hover, zebra-striping)
 *  7. Dark-theme scrollbars
 *  8. Card hover consistency
 *  9. Badge utility classes (for future JS migration)
 * 10. Button consistency (success, warning padding)
 * 11. Disabled state clarity
 */

/* ==========================================================================
   1. MISSING DEFINITIONS
   ========================================================================== */

/* modal-footer: used in 15+ modals, had NO CSS definition */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
}

/* modal-buttons: legacy alias — same layout */
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
}

/* form-control: used in 5 inputs with NO CSS — mirror form-input */
.form-control {
    padding: 0.875rem 1rem;
    background: var(--secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 1rem;
    font-family: 'Work Sans', sans-serif;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

/* ==========================================================================
   2. FIX DUPLICATE CONFLICTS
   ========================================================================== */

/* btn-sm: was defined twice (1504: 0.5rem 1rem, 3378: 0.35rem 0.7rem)
   Settle on the smaller one for consistency with btn-danger-sm, btn-edit-sm */
.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
}

/* btn-secondary: was defined twice (740: with border, 2044: without)
   Keep border version — more visible on dark backgrounds */
.btn-secondary {
    background: var(--secondary);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--border);
}

/* btn-success & btn-warning: align padding with .btn base */
.btn-success,
.btn-warning {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

/* btn-warning: use dark text that's not pure black */
.btn-warning {
    color: var(--ds-neutral-900, #0F172A);
}

/* ==========================================================================
   3. UNIVERSAL TRANSITIONS
   ========================================================================== */

/* Smooth transitions on all interactive elements */
a,
button,
select,
.btn,
.btn-filter,
.btn-export,
.btn-undo,
.btn-edit-item,
.btn-edit-sm,
.btn-danger-sm,
.menu-item,
.rail-item,
.nav-btn,
.page-btn,
.period-tab,
.shelf-btn,
.tree-node-header,
.search-result-item,
.ecom-order-card {
    transition: all 0.2s ease-out;
}

/* Form inputs — only border + shadow transition (not "all") */
.form-input,
.form-control,
.filter-input,
.filter-select,
select.form-input {
    transition: border-color 0.2s ease-out, box-shadow 0.2s ease-out, background 0.2s ease-out;
}

/* ==========================================================================
   4. FOCUS RINGS (Keyboard Navigation)
   ========================================================================== */

/* Visible focus ring for all interactive elements */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Inputs: use box-shadow instead (looks better inside form fields) */
.form-input:focus-visible,
.form-control:focus-visible,
.filter-input:focus-visible,
.filter-select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle, rgba(8, 145, 178, 0.2));
}

/* Buttons: subtle ring */
.btn:focus-visible,
button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   5. MODAL POLISH
   ========================================================================== */

/* Backdrop blur on modals */
.modal {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background: rgba(0, 0, 0, 0.55);
}

/* Smoother modal-content entrance */
.modal-content {
    animation: uiSlideUp 0.25s ease-out;
}

@keyframes uiSlideUp {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal header: consistent spacing */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

/* Modal close button hover */
.modal-close {
    transition: all 0.15s ease-out;
    border-radius: var(--radius-sm, 4px);
    line-height: 1;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    transform: scale(1.1);
}

/* ==========================================================================
   6. TABLE POLISH
   ========================================================================== */

/* Zebra striping */
.data-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Row hover — more visible */
.data-table tbody tr:hover {
    background: rgba(8, 145, 178, 0.08);
}

/* Table header — slightly more contrast */
.data-table thead th {
    border-bottom: 2px solid var(--border);
}

/* Mini table hover */
.mini-table tbody tr:hover {
    background: rgba(8, 145, 178, 0.06);
}

/* ==========================================================================
   7. DARK-THEME SCROLLBARS
   ========================================================================== */

/* Webkit scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg, #0A0E1A);
}

::-webkit-scrollbar-thumb {
    background: var(--border, #334155);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #94A3B8);
}

/* Firefox scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border, #334155) var(--bg, #0A0E1A);
}

/* Modal content scrollbar — slightly lighter for contrast */
.modal-content::-webkit-scrollbar-track {
    background: var(--card, #1A1F2E);
}

/* ==========================================================================
   8. CARD HOVER
   ========================================================================== */

/* Consistent hover lift on interactive cards */
.product-form-card,
.data-section,
.ecom-order-card,
.export-module-card {
    transition: box-shadow 0.2s ease-out, border-color 0.2s ease-out;
}

.ecom-order-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.export-module-card:hover {
    border-color: var(--accent);
}

/* Stat cards — lift + accent glow on hover */
.stat-card {
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out, border-color 0.2s ease-out;
    border: 1px solid var(--border);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(8, 145, 178, 0.12), 0 4px 8px rgba(0, 0, 0, 0.2);
    border-color: var(--accent);
}

/* Cards: accent top border for visual hierarchy */
.product-form-card,
.data-section {
    border-top: 2px solid var(--accent);
}

/* ==========================================================================
   9. BADGE UTILITY CLASSES (for future JS migration)
   ========================================================================== */

/* Base badge */
.badge,
.badge-success,
.badge-warning,
.badge-danger,
.badge-info,
.badge-muted,
.badge-accent,
.badge-purple,
.badge-amazon {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: white;
    line-height: 1.4;
}

.badge-success { background: #27ae60; }
.badge-warning { background: #f39c12; }
.badge-danger  { background: #e74c3c; }
.badge-info    { background: #3498db; }
.badge-muted   { background: #95a5a6; }
.badge-accent  { background: #09B1BA; }
.badge-purple  { background: #9b59b6; }
.badge-orange  { background: #e67e22; }
.badge-amazon  { background: #FF9900; color: #000; text-decoration: none; }

/* Small badge variant */
.badge-sm {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}

/* Pill variant (round counters) */
.badge-pill {
    border-radius: 12px;
    padding: 0.2rem 0.6rem;
    font-size: 0.85rem;
}

/* Subtle variants (semi-transparent bg, colored text) */
.badge-success-subtle { background: rgba(16, 185, 129, 0.13); color: #10B981; }
.badge-warning-subtle { background: rgba(245, 158, 11, 0.13); color: #F59E0B; }
.badge-danger-subtle  { background: rgba(239, 68, 68, 0.13); color: #EF4444; }
.badge-info-subtle    { background: rgba(8, 145, 178, 0.13); color: #0891B2; }
.badge-muted-subtle   { background: rgba(148, 163, 184, 0.13); color: #94A3B8; }
.badge-accent-subtle  { background: rgba(8, 145, 178, 0.13); color: #0891B2; }
.badge-purple-subtle  { background: rgba(139, 92, 246, 0.13); color: #8B5CF6; }
.badge-orange-subtle  { background: rgba(230, 126, 34, 0.13); color: #E67E22; }

/* ==========================================================================
   10. DISABLED STATE CLARITY
   ========================================================================== */

button:disabled,
.btn:disabled,
select:disabled,
input:disabled,
textarea:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==========================================================================
   11. MISC POLISH
   ========================================================================== */

/* Smoother page title */
.page-title {
    letter-spacing: -0.01em;
}

/* Navigation menu item — active indicator smoother */
.menu-item.active {
    transition: all 0.2s ease-out;
}

/* Rail item hover */
.rail-item:hover {
    background: rgba(8, 145, 178, 0.12);
}

/* Tree node hover */
.tree-node-header:hover {
    background: rgba(8, 145, 178, 0.06);
    border-radius: var(--radius-md, 8px);
}

/* Pagination buttons */
.page-btn {
    border-radius: var(--radius-md, 8px);
}

.page-btn:hover:not(:disabled):not(.active) {
    background: var(--secondary);
    border-color: var(--accent);
}

/* Selection styling */
::selection {
    background: rgba(8, 145, 178, 0.3);
    color: var(--text);
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* ==========================================================================
   12. PHASE 3 — BADGE VISUAL UPGRADE
   ========================================================================== */

/* Badge base: add subtle border + better vertical alignment */
.badge,
.badge-success,
.badge-warning,
.badge-danger,
.badge-info,
.badge-muted,
.badge-accent,
.badge-purple,
.badge-orange,
.badge-amazon {
    vertical-align: middle;
    white-space: nowrap;
    letter-spacing: 0.01em;
    border: 1px solid transparent;
}

/* Modern badge look: semi-transparent bg + colored text (glassmorphism-lite) */
.badge-success { background: rgba(39, 174, 96, 0.18); color: #4ade80; border-color: rgba(39, 174, 96, 0.3); }
.badge-warning { background: rgba(243, 156, 18, 0.18); color: #fbbf24; border-color: rgba(243, 156, 18, 0.3); }
.badge-danger  { background: rgba(231, 76, 60, 0.18); color: #f87171; border-color: rgba(231, 76, 60, 0.3); }
.badge-info    { background: rgba(52, 152, 219, 0.18); color: #60a5fa; border-color: rgba(52, 152, 219, 0.3); }
.badge-muted   { background: rgba(148, 163, 184, 0.15); color: #94A3B8; border-color: rgba(148, 163, 184, 0.2); }
.badge-accent  { background: rgba(9, 177, 186, 0.18); color: #22d3ee; border-color: rgba(9, 177, 186, 0.3); }
.badge-purple  { background: rgba(155, 89, 182, 0.18); color: #c084fc; border-color: rgba(155, 89, 182, 0.3); }
.badge-orange  { background: rgba(230, 126, 34, 0.18); color: #fb923c; border-color: rgba(230, 126, 34, 0.3); }
.badge-amazon  { background: rgba(255, 153, 0, 0.18); color: #FF9900; border-color: rgba(255, 153, 0, 0.3); text-decoration: none; }

/* Subtle variants: add matching border for definition */
.badge-success-subtle { border-color: rgba(16, 185, 129, 0.2); }
.badge-warning-subtle { border-color: rgba(245, 158, 11, 0.2); }
.badge-danger-subtle  { border-color: rgba(239, 68, 68, 0.2); }
.badge-info-subtle    { border-color: rgba(8, 145, 178, 0.2); }
.badge-muted-subtle   { border-color: rgba(148, 163, 184, 0.15); }
.badge-accent-subtle  { border-color: rgba(8, 145, 178, 0.2); }
.badge-purple-subtle  { border-color: rgba(139, 92, 246, 0.2); }
.badge-orange-subtle  { border-color: rgba(230, 126, 34, 0.2); }

/* Subtle variants: base properties */
.badge-success-subtle,
.badge-warning-subtle,
.badge-danger-subtle,
.badge-info-subtle,
.badge-muted-subtle,
.badge-accent-subtle,
.badge-purple-subtle,
.badge-orange-subtle {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

/* ==========================================================================
   13. PHASE 3 — TABLE ENHANCEMENTS
   ========================================================================== */

/* Better table header — accent underline + uppercase muted text */
.data-table thead th {
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 2px solid var(--accent);
    color: var(--accent);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.75rem 1rem;
}

/* Sticky header shadow indicator */
.data-table thead {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

/* Tighter cell padding */
.data-table td {
    vertical-align: middle;
    padding: 0.65rem 1rem;
    font-size: 0.88rem;
}

/* Row hover: accent left border + glow */
.data-table tbody tr:hover {
    background: rgba(8, 145, 178, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
}

/* Alternating rows — subtle */
.data-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.015);
}

.data-table tbody tr:nth-child(even):hover {
    background: rgba(8, 145, 178, 0.08);
}

/* Clickable row cursor */
.data-table tbody tr[onclick] {
    cursor: pointer;
}

/* Table cell text truncation helper */
.data-table td .truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Monospace cells (LPN, SKU, codes) */
.data-table td code,
.data-table td .mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ==========================================================================
   14. PHASE 3 — EMPTY STATE & LOADING
   ========================================================================== */

/* Empty table rows - nicer centered text */
.data-table td[colspan] {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-style: italic;
}

/* Shimmer loading animation (for JS to add class "shimmer" to elements) */
.shimmer {
    background: linear-gradient(
        90deg,
        var(--secondary) 25%,
        rgba(255,255,255,0.05) 50%,
        var(--secondary) 75%
    );
    background-size: 200% 100%;
    animation: shimmerSlide 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes shimmerSlide {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Loading overlay for sections */
.loading-overlay {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading-overlay::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(10, 14, 26, 0.4);
    border-radius: inherit;
}

/* ==========================================================================
   15. PHASE 3 — TOAST & NOTIFICATION POLISH
   ========================================================================== */

/* Toast container (if using showNotification/showToast) */
.toast,
.notification {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    animation: toastSlideIn 0.3s ease-out;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Success/error toast accents */
.toast-success,
.notification-success {
    border-left: 4px solid var(--success);
}

.toast-error,
.notification-error {
    border-left: 4px solid var(--danger);
}

.toast-warning,
.notification-warning {
    border-left: 4px solid var(--warning);
}

/* ==========================================================================
   16. PHASE 3 — FORM IMPROVEMENTS
   ========================================================================== */

/* Consistent select styling */
.form-input,
.form-control,
.filter-input,
.filter-select {
    appearance: none;
    -webkit-appearance: none;
}

select.form-input,
select.form-control,
select.filter-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

/* Input placeholder styling */
.form-input::placeholder,
.form-control::placeholder,
.filter-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

/* Textarea auto-height helper */
textarea.form-input,
textarea.form-control {
    min-height: 80px;
    resize: vertical;
}

/* ==========================================================================
   17. PHASE 3 — DATA DENSITY & SPACING
   ========================================================================== */

/* Tighter spacing for dense data views (aukro, ecommerce tables) */
.data-table.compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.data-table.compact th {
    padding: 0.5rem 0.75rem;
    font-size: 0.7rem;
}

/* Data section spacing */
.data-section + .data-section {
    margin-top: 1.5rem;
}

/* Filter bar consistency */
.filter-bar,
.table-filters,
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

/* ==========================================================================
   18. PHASE 3 — MICRO-INTERACTIONS
   ========================================================================== */

/* Button press effect */
.btn:active:not(:disabled),
button:active:not(:disabled) {
    transform: scale(0.97);
}

/* Link underline on hover */
a:not(.btn):not(.badge-amazon):not(.rail-item):not(.menu-item):hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Image thumbnails in tables */
.data-table img,
.data-table .thumb {
    border-radius: 4px;
    object-fit: cover;
    transition: transform 0.2s ease-out;
}

.data-table img:hover,
.data-table .thumb:hover {
    transform: scale(1.08);
}

/* Sortable table header cursor */
.data-table th[data-sort],
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th[data-sort]:hover,
.data-table th.sortable:hover {
    color: var(--accent);
}

/* ==========================================================================
   19. PHASE 3 — POSITION & STATUS BADGE POLISH
   ========================================================================== */

/* Position badge (warehouse locations) */
.position-badge {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    background: var(--secondary);
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid var(--border);
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* Amazon link badge: ensure it looks good as <a> */
a.badge-amazon {
    text-decoration: none;
    font-weight: 600;
}

a.badge-amazon:hover {
    filter: brightness(1.1);
    text-decoration: none;
}

/* ==========================================================================
   20. PHASE 3 — MODAL IMPROVEMENTS
   ========================================================================== */

/* Modal content: better max-height and overflow */
.modal-content {
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

/* Modal title consistency */
.modal-header h2,
.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* Modal form spacing */
.modal-content .form-group + .form-group {
    margin-top: 1rem;
}

/* Modal actions sticky footer */
.modal-content > .modal-footer:last-child,
.modal-content > .modal-buttons:last-child {
    position: sticky;
    bottom: 0;
    background: var(--card);
    padding-bottom: 0.5rem;
    z-index: 1;
}

/* ==========================================================================
   KEEP LAST — Reduced Motion
   ========================================================================== */

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    html {
        scroll-behavior: auto;
    }
}

/* Touch devices: disable hover to prevent sticky states */
@media (hover: none) and (pointer: coarse) {
    .ecom-order-card:hover,
    .export-module-card:hover,
    .stat-card:hover,
    .tree-node-header:hover {
        transform: none !important;
        box-shadow: inherit !important;
    }
    .data-table tbody tr:hover,
    .data-table tbody tr:nth-child(even):hover,
    .mini-table tbody tr:hover {
        background: inherit !important;
    }
    .rail-item:hover,
    .page-btn:hover:not(:disabled):not(.active),
    .modal-close:hover,
    .btn-secondary:hover:not(:disabled) {
        filter: none !important;
        transform: none !important;
    }
    .data-table img:hover,
    .data-table .thumb:hover {
        transform: none !important;
    }
    .data-table th[data-sort]:hover,
    .data-table th.sortable:hover {
        color: inherit !important;
    }
    a.badge-amazon:hover {
        filter: none !important;
    }
    a:not(.btn):not(.badge-amazon):not(.rail-item):not(.menu-item):hover {
        text-decoration: none !important;
    }
}

/* ==========================================================================
   HOME-TENANT-ONLY (btcin) — Vinted, Reloot, First Minute features
   ========================================================================== */
body:not(.is-home-tenant) .home-tenant-only {
    display: none !important;
}
