@tailwind base;
@tailwind components;
@tailwind utilities;

body {
  margin: 0;
  background: #0a0412;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

/* Safe area insets for notched iPads / phones */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

/* Hide scrollbars but keep scroll */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* Prevent text selection on drag handles */
.drag-handle { touch-action: none; user-select: none; -webkit-user-select: none; }

/* Mobile backdrop */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 9;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Smooth transitions for panels */
@media (prefers-reduced-motion: no-preference) {
  .panel-transition { transition: width 0.15s ease, height 0.15s ease, opacity 0.15s ease; }
}

/* iPad-specific: prevent double-tap zoom on buttons */
button, [role="button"] { touch-action: manipulation; }

/* Textarea on iOS: prevent zoom on focus (iOS zooms in when font < 16px) */
@supports (-webkit-touch-callout: none) {
  textarea, input[type="text"], input[type="search"] {
    font-size: max(16px, 1em) !important;
  }
}

/* Terminal input: kill all focus chrome (outline, ring, box-shadow, border).
   The global `:focus-visible` rule below draws a 2px fuchsia outline on
   everything; on a full-width input that looks like a highlighted bar. */
input.terminal-input,
input.terminal-input:focus,
input.terminal-input:focus-visible,
input.terminal-input:focus-within {
  outline: none !important;
  box-shadow: none !important;
  border: 0 !important;
  background: transparent !important;
  -webkit-appearance: none;
  appearance: none;
}

/* ── Terminal selection/copy on iPad ────────────────────────────────────
   Fake terminal (Terminal tab): output needs explicit text selection +
   the iOS callout (Copy/Define menu). The global `.no-callout` / drag-
   handle rules suppress this unless we override here.                      */
.fake-terminal-output,
.fake-terminal-output * {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}
/* xterm (Runtime tab): the canvas renderer uses a DOM selection-layer
   overlay. We need the rows + selection-layer to be selectable and allow
   the native iPadOS callout. The helper textarea stays hidden.            */
.wc-term .xterm-rows,
.wc-term .xterm-rows *,
.wc-term .xterm-selection-layer,
.wc-term .xterm-screen {
  -webkit-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

/* ── Full-height layout: use dvh (dynamic viewport height) so the app fills  ─
   the real visible area on iPad Safari even when the toolbar is shown/hidden. ─
   Falls back to 100vh on older browsers.                                      */
#root, .app-shell {
  height: 100dvh;
  height: 100vh; /* fallback for browsers without dvh */
  height: 100dvh;
  overflow: hidden;
}

/* Ensure scrollable inner panels handle iOS rubber-band correctly */
.scroll-touch {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Minimum touch target: 44×44px (Apple HIG) */
.touch-target {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Drag handle: larger touch zone on iPad, visible affordance */
.drag-handle-v {
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  min-width: 8px;
}
.drag-handle-h {
  cursor: row-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  min-height: 8px;
}

/* Prevent callout (copy menu) on long-press in non-editable elements */
.no-callout { -webkit-touch-callout: none; }

/* Safe-area bottom padding utility — use on any fixed bottom bar */
.pb-safe { padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); }
.pt-safe { padding-top: max(0px, env(safe-area-inset-top)); }

/* Status bar text on iPad split view / full screen */
@media (display-mode: standalone) {
  .app-shell {
    padding-top: env(safe-area-inset-top);
  }
}

/* Improve tab/button legibility on Retina iPad screens */
@media (-webkit-min-device-pixel-ratio: 2) {
  .font-mono, textarea, .editor-area {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
}

/* iPad landscape: give a bit more horizontal breathing room */
@media (min-width: 1024px) and (orientation: landscape) {
  .chat-panel-width { min-width: 300px; }
}

/* Focus-visible ring for iPad keyboard navigation */
:focus-visible {
  outline: 2px solid #e879f9;
  outline-offset: 2px;
}

/* ──────────────────────────────────────────────────────────────────────
   xterm.js inside the WebContainer terminal pane.

   xterm creates a hidden <textarea> (`.xterm-helper-textarea`) positioned
   at the caret. It MUST stay invisible and not receive the global
   `font-size: max(16px, 1em)` / `:focus-visible` / selection styling we
   apply elsewhere — otherwise it renders as a big tappable "ghost input"
   under the prompt on iPadOS, blocking terminal selection.
   ────────────────────────────────────────────────────────────────────── */
.wc-term .xterm,
.wc-term .xterm-viewport,
.wc-term .xterm-screen {
  width: 100% !important;
  height: 100% !important;
}
.wc-term .xterm-helper-textarea {
  /* Zero-size, zero-opacity, off-screen fallback */
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  opacity: 0 !important;
  z-index: -10 !important;
  /* Undo the global iOS 16px override */
  font-size: 1px !important;
  line-height: 1 !important;
  padding: 0 !important;
  border: 0 !important;
  outline: none !important;
}
.wc-term .xterm-helper-textarea:focus,
.wc-term .xterm-helper-textarea:focus-visible {
  outline: none !important;
}
/* Let touch users select terminal output */
.wc-term .xterm-rows,
.wc-term .xterm-selection-layer {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
/* Viewport shouldn't grow past the pane; fitAddon handles rows */
.wc-term .xterm-viewport {
  overflow-y: auto !important;
  overscroll-behavior: contain;
}