/**
 * AI Editor - Base Styles
 * Variables, resets, typography, layout grid, scrollbars, responsive
 */

/* ============================================
   CSS VARIABLES
   ============================================ */

:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --bg-hover: #3c3c3c;
    --bg-active: #094771;
    
    --text-primary: #cccccc;
    --text-secondary: #9e9e9e;   /* AA 4.5:1+ on bg-tertiary #2d2d30 */
    --text-muted: #8e8e8e;       /* AA 4.5:1+ on bg-secondary #252526 */
    
    --accent: #0e7dca;
    --accent-hover: #1a8fe0;
    --success: #4ec9b0;
    --warning: #dcdcaa;
    --error: #f14c4c;
    --danger: #c93a3a;
    
    --border: #3c3c3c;
    --border-light: #474747;
    
    --font-mono: 'Fira Code', 'Consolas', 'Monaco', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* ---- Three independent font size axes (controlled by settings sliders) ---- */
    --ui-font-size: 13px;       /* Informational: header, sidebar labels, modals, status */
    --editor-font-size: 14px;   /* Code editor content */
    --chat-font-size: 13px;     /* Chat panel messages and controls */
    
    /* ---- UI-derived sizes (sidebar, header, modals, components) ---- */
    --font-xs: calc(var(--ui-font-size) - 3px);   /* ~10px at 13 */
    --font-sm: calc(var(--ui-font-size) - 2px);   /* ~11px at 13 */
    --font-md: calc(var(--ui-font-size) - 1px);   /* ~12px at 13 */
    --font-base: var(--ui-font-size);              /* ~13px at 13 */
    --font-lg: calc(var(--ui-font-size) + 1px);    /* ~14px at 13 */
    --font-xl: calc(var(--ui-font-size) + 3px);    /* ~16px at 13 */
    --font-2xl: calc(var(--ui-font-size) + 7px);   /* ~20px at 13 */
    
    /* ---- Chat-derived sizes (chat panel only) ---- */
    --chat-xs: calc(var(--chat-font-size) - 3px);
    --chat-sm: calc(var(--chat-font-size) - 2px);
    --chat-md: calc(var(--chat-font-size) - 1px);
    --chat-base: var(--chat-font-size);
    --chat-lg: calc(var(--chat-font-size) + 1px);
    --chat-xl: calc(var(--chat-font-size) + 3px);
    --chat-2xl: calc(var(--chat-font-size) + 7px);
    
    /* ---- Layout dimensions (scale with UI font) ---- */
    --header-height: calc(var(--ui-font-size) * 3.1);  /* ~40px at 13, ~50px at 16 */
    --sidebar-width: 260px;
    --chat-width: 350px;
    --input-height: 120px;
    --banner-height: 0px;       /* Set > 0 to show header/footer banners */
}

/* ============================================
   RESET & BASE
   ============================================ */

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-base);
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ============================================
   LAYOUT
   ============================================ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;          /* dynamic viewport: excludes mobile browser chrome */
}

/* ---- Header ---- */

.app-header {
    height: var(--header-height);
    min-height: 36px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    flex-shrink: 0;
    font-size: var(--font-base);
}

.app-header h1 {
    font-size: var(--font-lg);
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* ---- Main content grid ---- */

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    contain: layout style;       /* P1-CLS: prevent children from shifting ancestor layout */
    min-height: 0;               /* P1-CLS: flex child won't push container beyond bounds */
}

/* ---- Banners (opt-in header/footer areas) ----
   Set --banner-height > 0 and add elements with these classes to activate.
   Useful for announcement bars, environment indicators, status footers. */

.app-banner-top,
.app-banner-bottom {
    height: var(--banner-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    flex-shrink: 0;
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

.app-banner-bottom {
    border-bottom: none;
    border-top: 1px solid var(--border);
}

/* Hidden when banner height is 0 */
.app-banner-top:empty,
.app-banner-bottom:empty {
    display: none;
}

/* ============================================
   SCROLLBARS
   ============================================ */

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 5px;
}

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

/* ============================================
   PANEL VISIBILITY & RESIZE
   ============================================ */

.sidebar.hidden {
    display: none;
}

.chat-panel.hidden {
    display: none;
}

.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--accent);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px;
    right: -3px;
}

/* Prevent text selection and iframe capture during drag */
body.resizing {
    cursor: col-resize !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

body.resizing iframe,
body.resizing .cm-editor {
    pointer-events: none;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Screen-reader only — visually hidden but accessible */
.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;
}

/* Skip navigation link */
.skip-nav {
    position: absolute;
    top: -100%;
    left: 1rem;
    z-index: 10000;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: white;
    border-radius: 0 0 4px 4px;
    text-decoration: none;
    font-size: var(--font-sm);
    transition: top 0.15s ease;
}
.skip-nav:focus {
    top: 0;
}

/* Focus-visible: keyboard users get a clear ring, mouse users don't */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Suppress outline on mouse focus */
:focus:not(:focus-visible) {
    outline: none;
}

/* Buttons, inputs, selects — tighter focus ring */
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-radius: 2px;
}

/* Tab items focus ring */
.editor-tab:focus-visible,
.settings-tab:focus-visible,
.file-tree-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Modal close buttons — circular focus ring */
.modal-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 50%;
}

/* ============================================
   RESPONSIVE — laptop vs desktop
   ============================================ */

/* Narrower screens: tighten panel defaults */
@media (max-width: 1200px) {
    :root {
        --sidebar-width: 220px;
        --chat-width: 300px;
    }
}

/* ============================================
   REDUCED MOTION — respect OS preference
   ============================================ */
@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;
    }
}
