/* base.css — Reset, body, layout shell, icon helpers, status dots, pre/code */

/* Backward-compatible aliases — map old variable names to new semantic tokens from tokens.css.
   New code should use the semantic token names directly (--surface-primary, --accent-default, etc.).
   These aliases exist so existing CSS rules using var(--bg-primary), var(--accent), etc. continue to work. */
:root {
    --bg-primary: var(--surface-primary);
    --bg-secondary: var(--surface-secondary);
    --bg-tertiary: var(--surface-tertiary);
    --accent: var(--accent-default);
    --success: var(--status-success);
    --error: var(--status-error);
    --warning: var(--status-warning);
    --border: var(--border-default);
}

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

html {
    overflow-x: hidden;
    width: 100%;
    overscroll-behavior: none; /* Disable pull-to-refresh */
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    width: 100%;
    overscroll-behavior: none; /* Disable pull-to-refresh */
    touch-action: pan-x pan-y; /* Allow normal scrolling but prevent browser gestures */
    position: relative;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    max-height: 100vh;
    max-height: 100dvh;
}

/* Icon helpers */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

/* Status dots (replace emoji dots) */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background-color: var(--border); }
.dot.dot-on { background-color: var(--success); }
.dot.dot-idle { background-color: var(--text-muted); }
.dot.dot-error { background-color: var(--error); }

.main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.desktop-only {
    display: block;
}

/* Ensure pre-formatted text and code blocks wrap properly */
pre, code {
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

/* ── PWA Window Controls Overlay ── */
/* When installed as PWA with window-controls-overlay display mode,
   the tab bar extends into the title bar for a native terminal feel. */
@media (display-mode: window-controls-overlay) {
    .session-tabs-bar {
        padding-top: env(titlebar-area-y, 0);
        padding-left: env(titlebar-area-x, 10px);
        padding-right: calc(100% - env(titlebar-area-width, 100%) - env(titlebar-area-x, 0px) + 10px);
        -webkit-app-region: drag;
    }
    .session-tabs-bar button,
    .session-tabs-bar .session-tab {
        -webkit-app-region: no-drag;
    }
}

/* Fullscreen PWA: maximize terminal space */
@media (display-mode: standalone), (display-mode: window-controls-overlay) {
    body {
        overscroll-behavior: none;
    }
}

/* ── Accessibility ── */

/* Focus-visible ring for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--accent-default);
    outline-offset: 2px;
}

/* Remove outline for mouse/touch interactions */
:focus:not(:focus-visible) {
    outline: none;
}

/* Skip-to-content link (hidden until focused via Tab) */
.skip-to-content {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-max);
    padding: 8px 16px;
    background-color: var(--accent-default);
    color: var(--text-inverse, #fff);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: top var(--duration-fast) var(--ease-default, cubic-bezier(0.4, 0, 0.2, 1));
}

.skip-to-content:focus {
    top: 8px;
}

/* Live region for screen reader announcements */
.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;
}

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