/* ETSP UI Enhancements v2.0 — components layer
 * Loaded AFTER sidebar.css.
 * Implements: P0.2 cost panel, P0.9 skeleton loaders, P0.8 mobile drawer
 *             + bottom tab, P1.8 command palette, toasts, helper utilities.
 * Respects prefers-reduced-motion.
 */

/* ============================================================
 * 0. UTILITIES
 * ============================================================ */

.etsp-sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

.etsp-focus-ring:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ============================================================
 * 1. SKELETON LOADER (P0.9)
 * ============================================================ */

.etsp-skeleton {
    background: linear-gradient(90deg,
        var(--background-hover) 0%,
        rgba(255,255,255,0.04) 50%,
        var(--background-hover) 100%);
    background-size: 200% 100%;
    animation: etsp-shimmer 1.4s ease-in-out infinite;
    border-radius: 6px;
    display: block;
}

.etsp-skeleton-line { height: 12px; margin-bottom: 8px; }
.etsp-skeleton-line.short { width: 40%; }
.etsp-skeleton-line.medium { width: 70%; }
.etsp-skeleton-line.long { width: 100%; }

.etsp-skeleton-card {
    background: var(--background-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.etsp-skeleton-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
}

.etsp-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

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

/* ============================================================
 * 2. COST PANEL (P0.2)
 * ============================================================ */

.etsp-cost-panel {
    background: var(--background-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.etsp-cost-panel.etsp-cost-ok { border-color: rgba(37, 186, 59, 0.4); }
.etsp-cost-panel.etsp-cost-warn { border-color: rgba(255, 165, 2, 0.4); }
.etsp-cost-panel.etsp-cost-block { border-color: rgba(255, 71, 87, 0.4); background: rgba(255, 71, 87, 0.04); }

.etsp-cost-title {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 600;
    color: var(--foreground);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.etsp-cost-row {
    display: flex; justify-content: space-between;
    padding: 4px 0;
    color: var(--foreground-muted);
}

.etsp-cost-row.etsp-cost-total {
    border-top: 1px dashed var(--border);
    margin-top: 6px;
    padding-top: 8px;
    color: var(--foreground);
    font-weight: 600;
    font-size: 1rem;
}

.etsp-cost-row.etsp-cost-balance .balance-value { font-weight: 600; }
.etsp-cost-row.etsp-cost-balance.etsp-balance-ok .balance-value { color: var(--success); }
.etsp-cost-row.etsp-cost-balance.etsp-balance-warn .balance-value { color: var(--warning); }
.etsp-cost-row.etsp-cost-balance.etsp-balance-block .balance-value { color: var(--error); }

.etsp-cost-actions { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.etsp-cost-actions a, .etsp-cost-actions button {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    background: var(--background-hover);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
}

.etsp-cost-panel.etsp-cost-loading {
    opacity: 0.6;
    pointer-events: none;
}

.etsp-cost-panel.etsp-cost-error .etsp-cost-title { color: var(--error); }

/* ============================================================
 * 3. COMMAND PALETTE (P1.8)
 * ============================================================ */

.etsp-cmdk-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
    animation: etsp-fade-in 0.15s ease;
}

.etsp-cmdk-backdrop.etsp-open { display: flex; }

.etsp-cmdk {
    background: var(--background-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,255,200,0.1);
}

.etsp-cmdk-input-wrap {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.etsp-cmdk-input-wrap .etsp-cmdk-icon { color: var(--foreground-muted); font-size: 1.1rem; }

.etsp-cmdk-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--foreground);
    font-size: 1rem;
    outline: none;
}

.etsp-cmdk-input::placeholder { color: var(--foreground-muted); }

.etsp-cmdk-kbd {
    font-size: 0.7rem;
    color: var(--foreground-muted);
    background: var(--background-hover);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
}

.etsp-cmdk-list { list-style: none; margin: 0; padding: 0.5rem; overflow-y: auto; flex: 1; }

.etsp-cmdk-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--foreground-muted);
    padding: 0.75rem 0.75rem 0.4rem;
    font-weight: 600;
}

.etsp-cmdk-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--foreground);
    font-size: 0.9rem;
    transition: background 0.1s;
}

.etsp-cmdk-item:hover, .etsp-cmdk-item.etsp-active {
    background: var(--background-hover);
}

.etsp-cmdk-item.etsp-active {
    box-shadow: inset 2px 0 0 var(--primary);
}

.etsp-cmdk-item-icon { font-size: 1rem; width: 20px; text-align: center; }
.etsp-cmdk-item-label { flex: 1; }
.etsp-cmdk-item-hint { font-size: 0.75rem; color: var(--foreground-muted); }

.etsp-cmdk-empty { padding: 2rem; text-align: center; color: var(--foreground-muted); font-size: 0.9rem; }

/* ============================================================
 * 4. TOAST NOTIFICATIONS
 * ============================================================ */

.etsp-toast-container {
    position: fixed;
    top: 1rem; right: 1rem;
    z-index: 4000;
    display: flex; flex-direction: column; gap: 0.5rem;
    max-width: 360px;
    pointer-events: none;
}

.etsp-toast {
    background: var(--background-card);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--foreground);
    font-size: 0.9rem;
    box-shadow: 0 6px 24px rgba(0,0,0,0.3);
    pointer-events: auto;
    animation: etsp-slide-in 0.25s ease;
    display: flex; align-items: flex-start; gap: 0.5rem;
}

.etsp-toast.etsp-toast-success { border-left-color: var(--success); }
.etsp-toast.etsp-toast-error { border-left-color: var(--error); }
.etsp-toast.etsp-toast-warning { border-left-color: var(--warning); }
.etsp-toast.etsp-toast-info { border-left-color: var(--primary); }

.etsp-toast-icon { font-size: 1rem; line-height: 1.2; }
.etsp-toast-body { flex: 1; }
.etsp-toast-title { font-weight: 600; margin-bottom: 2px; }
.etsp-toast-msg { color: var(--foreground-muted); font-size: 0.85rem; }
.etsp-toast-close { background: none; border: none; color: var(--foreground-muted); cursor: pointer; padding: 0; font-size: 1.1rem; line-height: 1; }

.etsp-toast.etsp-leaving { animation: etsp-slide-out 0.2s ease forwards; }

@keyframes etsp-slide-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes etsp-slide-out { to { transform: translateX(120%); opacity: 0; } }
@keyframes etsp-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
 * 5. MOBILE DRAWER BACKDROP + BOTTOM TAB BAR (P0.8)
 * ============================================================ */

.etsp-drawer-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 90;
    animation: etsp-fade-in 0.2s ease;
}

.etsp-drawer-backdrop.etsp-open { display: block; }

.etsp-bottom-tab {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    padding: 6px max(8px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    z-index: 95;
    justify-content: space-around;
}

.etsp-bottom-tab a {
    flex: 1;
    display: flex; flex-direction: column; align-items: center;
    gap: 2px;
    color: var(--foreground-muted);
    text-decoration: none;
    padding: 6px 4px;
    font-size: 0.65rem;
    font-weight: 500;
    border-radius: 6px;
    transition: color 0.15s;
}

.etsp-bottom-tab a:hover { color: var(--foreground); }
.etsp-bottom-tab a.active { color: var(--primary); }
.etsp-bottom-tab a .etsp-tab-icon { font-size: 1.15rem; line-height: 1; }
.etsp-bottom-tab a.etsp-tab-fab {
    background: var(--primary);
    color: #000;
    border-radius: 50%;
    width: 48px; height: 48px;
    flex: 0 0 auto;
    align-self: flex-start;
    margin-top: -16px;
    padding: 0;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,255,200,0.4);
}
.etsp-bottom-tab a.etsp-tab-fab .etsp-tab-icon { font-size: 1.5rem; font-weight: 700; }
.etsp-bottom-tab a.etsp-tab-fab .etsp-tab-label { display: none; }

@media (max-width: 768px) {
    .etsp-bottom-tab { display: flex; }
    .app-layout { padding-bottom: 64px; }
    body { padding-bottom: 64px; }
}

/* ============================================================
 * 6. ACTIVITY FEED (P1.2)
 * ============================================================ */

.etsp-activity-feed { list-style: none; padding: 0; margin: 0; }
.etsp-activity-item {
    display: flex; gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.etsp-activity-item:last-child { border-bottom: none; }
.etsp-activity-icon {
    width: 32px; height: 32px;
    background: var(--background-hover);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; flex-shrink: 0;
}
.etsp-activity-body { flex: 1; min-width: 0; }
.etsp-activity-title { color: var(--foreground); }
.etsp-activity-meta { color: var(--foreground-muted); font-size: 0.75rem; margin-top: 2px; }

/* ============================================================
 * 7. ACCESSIBILITY: REDUCED MOTION
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .etsp-skeleton { animation: none; background: var(--background-hover); }
    .etsp-toast { animation: none; }
    .etsp-cmdk-backdrop { animation: none; }
    * { scroll-behavior: auto !important; }
}

/* ============================================================
 * 8. EMPTY STATE TEMPLATES (P0.10)
 * ============================================================ */

.etsp-template-chips {
    display: flex; flex-wrap: wrap; gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.etsp-template-chip {
    background: var(--background-hover);
    border: 1px solid var(--border);
    color: var(--foreground);
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 0.4rem;
}

.etsp-template-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}
