@import "./theme.css";

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

html,
body,
#root {
    height: 100%;
    overflow: hidden;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    user-select: none;
}

.app {
    position: relative;
    height: 100%;
}

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

input,
textarea {
    font-family: var(--font-ui);
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    outline: none;
    font-size: 13px;
    transition:
        border-color var(--duration-normal) var(--ease-in-out),
        box-shadow var(--duration-normal) var(--ease-in-out);
}

input:focus,
textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary) 12%, transparent);
}

button {
    font-family: var(--font-ui);
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 13px;
    transition:
        color var(--duration-fast) var(--ease-in-out),
        background var(--duration-fast) var(--ease-in-out);
}

button:hover {
    color: var(--text-primary);
}

button:active:not(:disabled) {
    transform: scale(0.97);
}

/* Focus mode: hide chrome */
.app.focus-mode .chrome {
    display: none;
}

/* ═══════════════════════════════════════
   Loading progress bar
   ═══════════════════════════════════════ */

.chrome {
    position: relative;
    -webkit-app-region: no-drag;
}

.loading-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--accent-primary) 30%,
        var(--accent-secondary) 70%,
        transparent
    );
    background-size: 300% 100%;
    animation:
        loading-bar-enter var(--duration-normal) var(--ease-out-expo) both,
        loading-bar-shimmer 1.6s ease-in-out infinite;
    z-index: 10;
    transition: opacity 300ms var(--ease-in-out);
}

.loading-bar.closing {
    opacity: 0;
}

@keyframes loading-bar-enter {
    from {
        opacity: 0;
        transform: scaleX(0.3);
        transform-origin: left;
    }
    to {
        opacity: 1;
        transform: scaleX(1);
        transform-origin: left;
    }
}

@keyframes loading-bar-shimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

/* ═══════════════════════════════════════
   Find bar (Ctrl+F)
   ═══════════════════════════════════════ */

.find-bar {
    position: absolute;
    top: calc(32px + var(--tab-height) + var(--address-bar-height) + 4px);
    right: 14px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border-visible);
    border-radius: var(--radius-lg);
    background: linear-gradient(
        180deg,
        var(--glass-gradient-start),
        var(--glass-gradient-end)
    );
    box-shadow:
        0 4px 12px var(--shadow-color),
        0 16px 40px var(--shadow-color);
    backdrop-filter: blur(16px);
    animation: toast-enter var(--duration-enter) var(--ease-out-expo) both;
}

.find-bar-input {
    width: 200px;
    height: 28px;
    padding: 0 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color var(--duration-fast) var(--ease-in-out);
}

.find-bar-input:focus {
    border-color: var(--accent-primary);
}

.find-bar-count {
    color: var(--text-muted);
    font-size: 11px;
    font-family: var(--font-mono);
    white-space: nowrap;
    min-width: 60px;
    text-align: center;
}

.find-bar-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast), color var(--duration-fast);
}

.find-bar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.find-bar-close {
    font-size: 16px;
    color: var(--text-muted);
}

.find-bar-close:hover {
    color: var(--text-primary);
}

/* ═══════════════════════════════════════
   Scroll fade indicators
   ═══════════════════════════════════════ */

.scroll-fade {
    position: relative;
}

.scroll-fade::before,
.scroll-fade::after {
    content: '';
    position: absolute;
    left: 0;
    right: 5px;
    height: 24px;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-in-out);
}

.scroll-fade::before {
    top: 0;
    background: linear-gradient(
        to bottom,
        var(--bg-secondary),
        transparent
    );
}

.scroll-fade::after {
    bottom: 0;
    background: linear-gradient(
        to top,
        var(--bg-secondary),
        transparent
    );
}

.scroll-fade.fade-top::before {
    opacity: 1;
}

.scroll-fade.fade-bottom::after {
    opacity: 1;
}

/* ═══════════════════════════════════════
   Custom tooltips — CSS-only via [data-tooltip]
   ═══════════════════════════════════════ */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    min-height: 24px;
    width: max-content;
    max-width: min(240px, calc(100vw - 24px));
    padding: 6px 10px;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    background-clip: padding-box;
    border: 1px solid var(--border-visible);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.45;
    letter-spacing: 0;
    text-align: center;
    white-space: normal;
    overflow-wrap: break-word;
    pointer-events: none;
    opacity: 0;
    z-index: 2147483647;
    box-shadow:
        0 8px 24px var(--shadow-color-strong),
        0 0 0 1px color-mix(in srgb, var(--bg-primary) 70%, transparent);
    transition:
        opacity var(--duration-normal) var(--ease-in-out),
        transform var(--duration-normal) var(--ease-out-expo);
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    transition-delay: 400ms;
}

/* Position variant — tooltip below */
[data-tooltip-pos="bottom"]::after {
    bottom: auto;
    top: calc(100% + 6px);
    transform: translateX(-50%) translateY(-4px);
}

[data-tooltip-pos="bottom"]:hover::after {
    transform: translateX(-50%) translateY(0);
}

/* Position variant — tooltip to the left */
[data-tooltip-pos="left"]::after {
    bottom: auto;
    left: auto;
    right: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%) translateX(4px);
}

[data-tooltip-pos="left"]:hover::after {
    transform: translateY(-50%) translateX(0);
}

@keyframes badge-enter {
    from {
        opacity: 0;
        transform: scale(0);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
