@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400..700&family=Geist+Mono:wght@400..600&display=swap');

/* ==========================================================================
   RADON — UI v2
   One surface language: dark ink, a single luminous accent, hairline borders.
   Tabs fuse with the toolbar below them (active tab = toolbar colour).
   All ids / classes from index.html are preserved.
   ========================================================================== */

/* ── Tokens: light (default) ── */
:root.light, :root {
    /* surfaces */
    --bg-0: #f3f4f8;        /* app background */
    --chrome: #e8eaf1;      /* title bar + tab strip */
    --surface: #ffffff;     /* toolbar + active tab */
    --surface-2: #eff1f6;   /* inputs, hover */
    --surface-3: #e3e6ee;   /* pressed */
    --border: #d6d9e4;

    /* text */
    --text: #14162a;
    --text-dim: #6a6f88;

    /* accents */
    --accent: #5b4bff;
    --accent-soft: rgba(91, 75, 255, 0.12);
    --accent-glow: rgba(91, 75, 255, 0.28);
    --on-accent: #ffffff;
    --good: #0f9f8a;
    --danger: #e0345a;
    --logo: #14162a;

    /* shape + type */
    --radius: 10px;
    --radius-sm: 7px;
    --font-ui: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'Geist Mono', 'Kode Mono', 'Fira Code', ui-monospace, monospace;

    /* layout */
    --nav-height: 44px;
    --nav-width: auto;
    --tab-section-height: 40px;
    --webview-nav-height: 48px;

    /* legacy aliases (other scripts / components may still read these) */
    --primary: var(--accent);
    --primary-good: var(--good);
    --primary-bad: var(--on-accent);
    --background: var(--bg-0);
    --svg: var(--text);
    --bg2: var(--chrome);
    --bg3: var(--surface-2);
    --bg4: var(--bg-0);
    --bg5: var(--surface);
    --term-glow: var(--accent-glow);
    --term-border: var(--border);
    --term-radius: var(--radius);
}

/* ── Tokens: dark ── */
:root.dark {
    --bg-0: #090a0f;
    --chrome: #0d0f16;
    --surface: #151824;
    --surface-2: #1c2031;
    --surface-3: #262b40;
    --border: #272c40;

    --text: #e7e9f4;
    --text-dim: #8b91ab;

    --accent: #9d8cff;
    --accent-soft: rgba(157, 140, 255, 0.14);
    --accent-glow: rgba(157, 140, 255, 0.30);
    --on-accent: #0a0b12;
    --good: #5eead4;
    --danger: #ff6b8a;
    --logo: #c9c2ff;
}

@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --bg-0: #090a0f;
        --chrome: #0d0f16;
        --surface: #151824;
        --surface-2: #1c2031;
        --surface-3: #262b40;
        --border: #272c40;
        --text: #e7e9f4;
        --text-dim: #8b91ab;
        --accent: #9d8cff;
        --accent-soft: rgba(157, 140, 255, 0.14);
        --accent-glow: rgba(157, 140, 255, 0.30);
        --on-accent: #0a0b12;
        --good: #5eead4;
        --danger: #ff6b8a;
        --logo: #c9c2ff;
    }
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; }

html, body, :root {
    display: flex;
    flex-direction: column;
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg-0);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button, input {
    font-family: inherit;
    border: 0;
    outline: none;
}

button {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

button:hover { background: var(--surface-2); }
button:active { background: var(--surface-3); }
button:disabled { cursor: not-allowed; opacity: 0.35; background: none; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

svg { color: var(--text); flex-shrink: 0; }

::selection { background: var(--accent); color: var(--on-accent); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

nav {
    display: flex;
    align-items: center;
    padding: 0;
}

/* ── Title bar ── */
.app-header { flex: none; }

nav.main-nav {
    -webkit-app-region: drag;
    justify-content: space-between;
    height: var(--nav-height);
    width: 100%;
    padding: 0 14px;
    background: var(--chrome);
}

nav .left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-logo { margin: 0; display: flex; }

nav .left svg {
    width: 24px !important;
    height: 24px !important;
}

.app-logo svg path,
.app-logo svg rect { fill: var(--logo); }

.chelsea-market {
    font-family: 'ChelseaMarket-Regular', var(--font-ui);
    font-size: 1.05rem;
    font-weight: 400;
    margin: 0;
    letter-spacing: 0.02em;
    color: var(--text);
}

@font-face {
    font-family: 'ChelseaMarket-Regular';
    src: url('../fonts/ChelseaMarket-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

nav .right {
    display: flex;
    align-items: center;
    gap: 8px;
    -webkit-app-region: no-drag
}

nav .right button, nav .right button svg {
    width: 16px !important; 
}

.status-widget {
    -webkit-app-region: no-drag;
    display: flex;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-dim);
}

button#themeToggle { -webkit-app-region: no-drag; }
#themeToggle svg { color: var(--text) !important; stroke: var(--text) !important; }

.theme-toggle {
    width: 28px;
    height: 28px;
    position: relative;
    border: 1px solid var(--border);
    background: var(--surface);
}
.theme-toggle .icon { width: 14px; height: 14px; position: absolute; transition: opacity 0.2s, transform 0.3s; }
.icon-moon { opacity: 1; transform: rotate(0deg); }
.icon-sun  { opacity: 0; transform: rotate(90deg); }
[data-theme="light"] .icon-moon { opacity: 0; transform: rotate(-90deg); }
[data-theme="light"] .icon-sun  { opacity: 1; transform: rotate(0deg); }

/* ── Tab strip ── */
nav.tab-section {
    flex: none;
    -webkit-app-region: drag;
    width: var(--tab-section-width, 100%);
    height: var(--tab-section-height);
    align-items: flex-end;
    gap: 2px;
    padding: 0 12px;
    background: var(--chrome);
}

.tab, .new-tab { -webkit-app-region: no-drag; }

.tab {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 220px;
    min-width: 0;
    max-width: 220px;
    height: 34px;
    padding: 0 6px 0 12px;
    color: var(--text-dim);
    background: transparent;
    border-radius: var(--radius) var(--radius) 0 0;
    container-type: inline-size;
    font-size: 0.8rem;
    overflow: hidden;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    animation: tabappear 800ms ease;
}

.tab * { animation: tabappearC 800ms ease; }

.tab::before {
    content: '';
    position: absolute;
    top: 0; left: 10px; right: 10px;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tab:hover { background: var(--surface-2); color: var(--text); }

.tab.active {
    background: var(--surface);
    color: var(--text);
}
.tab.active::before { opacity: 1; }

.tab svg { width: 15px; height: 15px; color: currentColor; stroke: currentColor; }

.tab-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: left;
}

.tab.disappearing {
    pointer-events: none;
    animation: tabDisappear 800ms ease forwards;
}
.tab.disappearing * { animation: tabDisappearC 800ms ease forwards; }

.close-btn,
.tab .close-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 6px;
    color: var(--text-dim);
}
.close-btn svg { width: 13px; height: 13px; }
.close-btn:hover {
    background: color-mix(in srgb, var(--danger) 18%, transparent);
    color: var(--danger);
}

/* + button sits after the last tab regardless of DOM order */
.new-tab {
    order: 9999;
    flex: none;
    width: 30px;
    height: 30px;
    margin: 0 0 2px 6px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
}
.new-tab svg { width: 16px; height: 16px; color: currentColor; stroke: currentColor; }
.new-tab:hover { background: var(--surface-2); color: var(--accent); }

/* ── Workspace ── */
#main, .workspace {
    position: relative;
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    background: var(--surface);
}

.webview-tab, .terminal-tab {
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* ── Browser toolbar ── */
.webview-tab#webview-tab {
    height: var(--webview-tab-height, 100%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

nav.webviewNav {
    flex: none;
    width: 100%;
    height: var(--webview-nav-height);
    gap: 8px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

nav.webviewNav .nav-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

nav.webviewNav svg { width: 18px; height: 18px; color: var(--text); stroke: currentColor; }

.backBtn, .forwardBtn, .reloadBtn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
}

/* Address bar */
.address-bar, #searchBarContainer {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 12px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.address-bar:hover { background: var(--surface-3); }

.address-bar:focus-within {
    background: var(--surface-2);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.isSiteSafe { display: flex; align-items: center; }

.security-badge { display: flex; align-items: center; }
.security-badge svg { width: 16px; height: 16px; }
.security-badge.safe   { color: var(--good); }
.security-badge.safe svg   { color: var(--good); }
.security-badge.unsafe { color: var(--danger); display: none; }
.security-badge.unsafe svg { color: var(--danger); }

input#searchBar.searchBar {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.84rem;
}
input#searchBar.searchBar::placeholder { color: var(--text-dim); }

button.goBtn#goBtn {
    width: 34px;
    height: 34px;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
}
button.goBtn#goBtn:hover {
    background: var(--accent);
    filter: brightness(1.1);
    box-shadow: 0 0 16px var(--accent-glow);
    transform: translateY(-1px);
}
button.goBtn#goBtn:active { transform: translateY(0); }
button.goBtn#goBtn svg { color: var(--on-accent); stroke: var(--on-accent); }

.webviewContainer#webviewContainer {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-0);
}

webview#webview.webview {
    display: flex;
    width: 100%;
    height: 100%;
}

/* ── Terminal tab ── */
.terminal-tab#terminal-tab { background: var(--bg-0); }

.terminal-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 36px;
    padding: 0 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.terminal-brand { margin: 0; display: flex; align-items: center; }
.terminal-brand img { height: 16px; width: auto; opacity: 0.9; }

.terminal-copyright {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    color: var(--text-dim);
}

.terminal-viewport {
    flex: 1;
    min-height: 0;
    padding: 10px 6px 6px 14px;
    background: var(--bg-0);
    overflow: hidden;
}
.terminal-viewport .xterm { height: 100%; }
.terminal-viewport .xterm-viewport { background: transparent !important; }

/* ── Prompt overlay (command-palette style) ── */
.prompt-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 999;
    align-items: flex-start;
    justify-content: center;
    padding-top: 14vh;
    background: color-mix(in srgb, var(--bg-0) 72%, transparent);
    backdrop-filter: blur(10px);
}

.prompt-box {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(560px, 90%);
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--accent-soft);
    animation: promptIn 0.18s ease-out;
}

.prompt-header { display: flex; align-items: center; gap: 10px; }

.prompt-icon::before {
    content: '❯';
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

.prompt-msg {
    width: 100%;
    margin: 0;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text);
    text-align: left;
}

.prompt-body { display: flex; flex-direction: column; gap: 10px; }

.prompt-input {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.prompt-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt-footer { display: flex; justify-content: flex-end; }

.prompt-submit {
    height: 36px;
    padding: 0 18px;
    background: var(--accent);
    color: var(--on-accent);
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.85rem;
}
.prompt-submit:hover {
    background: var(--accent);
    filter: brightness(1.1);
    box-shadow: 0 0 16px var(--accent-glow);
}

/* ── Custom select ── */
.custom-select-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.select-trigger {
    width: 100%;
    padding: 11px 14px;
    justify-content: space-between;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: left;
    font-size: 0.88rem;
}
.select-trigger:hover { border-color: var(--text-dim); background: var(--surface-2); }
.select-trigger:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }

.select-arrow {
    margin-left: 6px;
    font-size: 9px;
    color: var(--text-dim);
    transition: transform 0.2s ease;
}
.custom-select-container.open .select-arrow { transform: rotate(180deg); color: var(--accent); }

.select-options-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 100%;
    max-height: 200px;
    margin: 0;
    padding: 4px;
    list-style: none;
    overflow-y: auto;
    display: none;
    z-index: 999;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.custom-select-container.open .select-options-list { display: block; }

.select-option {
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.86rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}
.select-option:hover { background: var(--surface-2); }
.select-option.selected { background: var(--accent-soft); color: var(--accent); }
.select-option.selected:hover { background: var(--accent-soft); }

/* ── Loading screen ── */
div#loading-screen.loading-screen {
    position: absolute;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: var(--bg-0);
}

.loading-content {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 0.95rem;
}
.loading-prompt { color: var(--accent); font-weight: 600; }
.loading-text   { color: var(--text-dim); }
.loading-cursor { color: var(--accent); animation: blink 1s step-end infinite; }

div#loading-screen.loading-screen::after {
    content: '';
    width: 140px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent) 0 0 / 200% 100%;
    animation: sweep 1.4s linear infinite;
}

/* ── Container queries (narrow tabs) ── */
@container (max-width: 150px) {
    .tab-name { font-size: 0.75rem; }
}
@container (max-width: 100px) {
    .tab-name { display: none; }
}
@container (max-width: 60px) {
    .tab-name, .tab-icon { display: none; }
    .tab .close-btn { width: 100%; height: 100%; }
}

/* ── Keyframes (names kept for the tab JS) ── */
@keyframes tabappear {
    0%   { max-width: 0; opacity: 0; }
    100% { max-width: 220px; opacity: 1; }
}
@keyframes tabappearC {
    0%   { visibility: hidden; }
    10%  { visibility: visible; }
}
@keyframes tabDisappear {
    0%   { max-width: 220px; opacity: 1; }
    100% { max-width: 0; opacity: 0; padding: 0; }
}
@keyframes tabDisappearC {
    0%   { visibility: visible; }
    90%  { visibility: hidden; }
}
@keyframes promptIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes sweep { to { background-position: -200% 0; } }

/* ── Context menu ── */
.ctx-menu {
    position: fixed;
    z-index: 2000;
    min-width: 190px;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    animation: promptIn 0.12s ease-out;
    outline: none;
}

.ctx-item {
    width: 100%;
    justify-content: space-between;
    gap: 24px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    text-align: left;
    color: var(--text);
}
.ctx-item:hover,
.ctx-item:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    outline: none;
}
.ctx-item.danger:hover,
.ctx-item.danger:focus-visible {
    background: color-mix(in srgb, var(--danger) 15%, transparent);
    color: var(--danger);
}
.ctx-hint {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-dim);
}
.ctx-sep {
    height: 1px;
    margin: 5px 4px;
    background: var(--border);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}