/* ============================================================
   webapp/styles.css — Editor Inline Panamá (Mini App SPA)
   Theme: Telegram-inspired dark, mobile-first, premium feel.
   ============================================================ */

:root {
    /* Color palette (Telegram-inspired) */
    --bg-primary: #0e1621;
    --bg-secondary: #17212b;
    --bg-tertiary: #1e2c39;
    --bg-elevated: #232e3c;
    --bg-overlay: rgba(14, 22, 33, 0.92);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.72);
    --text-muted: rgba(255, 255, 255, 0.48);
    --text-inverse: #0e1621;

    --accent: #3390ec;             /* Telegram blue */
    --accent-hover: #4fa8f3;
    --accent-active: #2483d4;
    --accent-soft: rgba(51, 144, 236, 0.16);

    --success: #4dcb6d;
    --warning: #f5b942;
    --error: #e53935;
    --locked: #f5b942;

    /* Spacing scale (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Radii */
    --r-sm: 0.375rem;
    --r-md: 0.625rem;
    --r-lg: 0.875rem;
    --r-xl: 1.25rem;

    /* Shadows */
    --shadow-1: 0 2px 8px rgba(0, 0, 0, 0.18);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.32);
    --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.48);

    /* Transitions */
    --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-med: 220ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-slow: 360ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* === BASE ============================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
                 "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-top: env(safe-area-inset-top, 0);
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border: none;
    background: transparent;
    color: inherit;
}

input {
    font-family: inherit;
    font-size: inherit;
}

/* === HEADER ========================================== */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(180deg,
        var(--bg-secondary) 0%,
        var(--bg-primary) 100%);
    padding: var(--space-4);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0));
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-1);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.header-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background-color var(--t-med);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 0 0.25rem rgba(77, 203, 109, 0.3);
    animation: pulse-success 2.5s ease-in-out infinite;
}

.status-dot.error {
    background: var(--error);
}

@keyframes pulse-success {
    0%, 100% { box-shadow: 0 0 0 0 rgba(77, 203, 109, 0.4); }
    50% { box-shadow: 0 0 0 0.5rem rgba(77, 203, 109, 0); }
}

.header-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: var(--space-1) var(--space-3);
    border-radius: 999px;
    border: 1px solid var(--border);
}

#proxy-video {
    width: 100%;
    border-radius: var(--r-lg);
    background: #000;
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-2);
    max-height: 40vh;
}

.header-actions {
    display: flex;
    gap: var(--space-2);
}

/* === BUTTONS ========================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--r-md);
    font-weight: 600;
    font-size: 0.9375rem;
    transition: all var(--t-fast);
    user-select: none;
    border: 1px solid transparent;
    flex: 1;
}

.btn-emoji {
    font-size: 1.1em;
    line-height: 1;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(51, 144, 236, 0.32);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(51, 144, 236, 0.4);
}

.btn-primary:active {
    background: var(--accent-active);
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

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

.btn-danger {
    background: rgba(229, 57, 53, 0.16);
    color: var(--error);
}

.btn-danger:hover {
    background: rgba(229, 57, 53, 0.24);
}

/* === TIMELINE ======================================== */

.timeline-container {
    padding: var(--space-4);
    padding-bottom: var(--space-8);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: var(--space-4);
}

.timeline-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.blocks-count {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.blocks-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.block-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--space-4);
    transition: all var(--t-fast);
    position: relative;
    overflow: hidden;
}

.block-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-strong);
}

.block-card.locked {
    border-color: var(--locked);
    box-shadow: 0 0 0 1px var(--locked-soft, rgba(245, 185, 66, 0.16));
}

.block-card.locked::before {
    content: "🔒";
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    opacity: 0.6;
    font-size: 0.875rem;
}

.block-card.optimistic {
    opacity: 0.6;
    pointer-events: none;
}

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.block-info {
    flex: 1;
    min-width: 0;
}

.block-index {
    font-size: 0.6875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.block-srt {
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin-top: var(--space-1);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.block-clips {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.clip-thumb {
    aspect-ratio: 16 / 9;
    border-radius: var(--r-sm);
    background: var(--bg-elevated);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.6875rem;
    border: 1px solid var(--border);
    padding: var(--space-1);
    text-align: center;
    overflow: hidden;
}

.clip-thumb-id {
    font-family: "SF Mono", Menlo, monospace;
    font-size: 0.625rem;
    color: var(--text-muted);
    display: block;
    max-width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.clip-thumb-dur {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.block-actions {
    display: flex;
    gap: var(--space-2);
}

.block-action-btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all var(--t-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
}

.block-action-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.block-action-btn.is-locked {
    background: rgba(245, 185, 66, 0.16);
    border-color: var(--locked);
    color: var(--locked);
}

.block-action-btn.is-locked:hover {
    background: rgba(245, 185, 66, 0.24);
}

.block-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* === EMPTY STATE ==================================== */

.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-muted);
}

.empty-emoji {
    font-size: 2.5rem;
    display: block;
    margin-bottom: var(--space-3);
    opacity: 0.6;
}

.empty-text {
    font-size: 0.875rem;
}

/* === DRAWER (search overlay lateral) ================ */

.drawer {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    visibility: hidden;
}

.drawer.is-open {
    pointer-events: auto;
    visibility: visible;
}

.drawer-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity var(--t-med);
}

.drawer.is-open .drawer-overlay {
    opacity: 1;
}

.drawer-panel {
    position: absolute;
    inset: 0;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--t-slow);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.drawer.is-open .drawer-panel {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.drawer-title {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drawer-close {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--bg-elevated);
    font-size: 1.5rem;
    color: var(--text-secondary);
    transition: all var(--t-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.drawer-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.drawer-search {
    padding: var(--space-4);
    display: flex;
    gap: var(--space-3);
    align-items: center;
    border-bottom: 1px solid var(--border);
}

#search-input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--r-md);
    font-size: 1rem;
    transition: all var(--t-fast);
    outline: none;
}

#search-input::placeholder {
    color: var(--text-muted);
}

#search-input:focus {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

.spinner[hidden] {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.search-mode-info {
    padding: var(--space-2) var(--space-4);
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    line-height: 1.4;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    -webkit-overflow-scrolling: touch;
}

.result-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
    transition: all var(--t-fast);
    cursor: pointer;
}

.result-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
}

.result-card.is-selected {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.result-rank {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    padding: 2px 0.5rem;
    border-radius: 999px;
    margin-bottom: var(--space-2);
}

.result-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.result-id {
    font-family: "SF Mono", Menlo, monospace;
}

.result-desc {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.drawer-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border);
    display: flex;
    gap: var(--space-2);
}

/* === TOASTS ========================================== */

.toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0) + var(--space-4));
    right: var(--space-4);
    left: var(--space-4);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-3);
    border: 1px solid var(--border-strong);
    font-size: 0.875rem;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity var(--t-med), transform var(--t-med);
    pointer-events: auto;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast.is-error {
    border-color: var(--error);
    background: rgba(229, 57, 53, 0.16);
}

.toast.is-success {
    border-color: var(--success);
    background: rgba(77, 203, 109, 0.16);
}

/* === SKELETON (loading) ============================== */

@keyframes shimmer {
    0% { background-position: -300px 0; }
    100% { background-position: 300px 0; }
}

.skeleton {
    background-color: var(--bg-elevated);
    background-image: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--bg-tertiary) 50%,
        var(--bg-elevated) 100%);
    background-size: 600px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--r-sm);
}

/* === RESPONSIVE (tablet+) =========================== */

@media (min-width: 768px) {
    html, body { font-size: 16px; }
    #proxy-video { max-height: 50vh; }
    .drawer-panel {
        inset: 0 25% 0 0;          /* desktop: drawer ocupa 75% del ancho */
        transform: translateX(0);
        transition: none;          /* desktop: drawer siempre visible al lado */
        box-shadow: var(--shadow-3);
    }
    .drawer.is-open .drawer-overlay {
        opacity: 0.5;
        pointer-events: auto;
    }
}
