/* Kosis – Custom Styles */

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

/* Prevent iOS rubber-band scrolling on workspace */
html, body { overscroll-behavior: none; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* Animations */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse-dot { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-15px); } to { opacity: 1; transform: translateX(0); } }
@keyframes logoGlow { 0%, 100% { filter: drop-shadow(0 0 4px rgba(88,166,255,0.3)); } 50% { filter: drop-shadow(0 0 12px rgba(88,166,255,0.6)); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.msg-animate { animation: fadeInUp 0.25s ease-out; }
.step-animate { animation: slideIn 0.25s ease-out; }
.typing-dot { animation: pulse-dot 1.4s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
.logo-glow { animation: logoGlow 3s ease-in-out infinite; }
.model-badge { transition: all 0.2s ease; }
.model-badge:hover { transform: scale(1.03); }

/* Chat markdown */
.chat-md h1, .chat-md h2, .chat-md h3 { font-weight: 600; margin: 0.6em 0 0.3em; }
.chat-md h1 { font-size: 1.2em; } .chat-md h2 { font-size: 1.1em; } .chat-md h3 { font-size: 1em; }
.chat-md p { margin: 0.3em 0; line-height: 1.65; }
.chat-md ul, .chat-md ol { margin: 0.3em 0; padding-left: 1.5em; }
.chat-md li { margin: 0.15em 0; }
.chat-md code { background: #1c2128; padding: 0.1em 0.35em; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: 0.85em; color: #f0883e; }
.chat-md pre { background: #0d1117; border: 1px solid #30363d; border-radius: 6px; padding: 0.8em; margin: 0.6em 0; overflow-x: auto; position: relative; }
.chat-md pre code { background: transparent; color: #e6edf3; padding: 0; font-size: 0.82em; line-height: 1.55; }
.chat-md blockquote { border-left: 3px solid #58a6ff; padding-left: 0.8em; margin: 0.5em 0; color: #8b949e; }
.chat-md a { color: #58a6ff; text-decoration: none; }
.chat-md a:hover { text-decoration: underline; }
.chat-md table { border-collapse: collapse; margin: 0.6em 0; width: 100%; }
.chat-md th, .chat-md td { border: 1px solid #30363d; padding: 0.4em 0.6em; text-align: left; font-size: 0.9em; }
.chat-md th { background: #161b22; font-weight: 600; }

/* Process steps */
.process-step { border-left: 2px solid #30363d; padding-left: 0.8em; margin: 0.2em 0; transition: all 0.3s ease; }
.process-step.running { border-left-color: #58a6ff; }
.process-step.done { border-left-color: #3fb950; }
.process-step.error { border-left-color: #f85149; }

/* File tree (Desktop) */
.file-tree-item { transition: background 0.15s ease; }
.file-tree-item:hover { background: rgba(48, 54, 61, 0.5); }
.file-tree-item.active { background: rgba(88, 166, 255, 0.1); }

/* Split-screen resize handle (future enhancement) */
.resize-handle { width: 3px; background: transparent; cursor: col-resize; transition: background 0.2s; }
.resize-handle:hover { background: #58a6ff; }

/* Preview iframe */
iframe { background: white; }

/* Terminal */
#terminal-output pre {
  font-family: 'JetBrains Mono', monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Panel tabs */
.panel-tab { transition: all 0.15s ease; }

/* ============================================
   MOBILE STYLES (max-width: 900px)
   ============================================ */

/* --- Mobile Bottom Navigation --- */
.mobile-bottom-nav {
  display: flex;
  align-items: stretch;
  height: 56px;
  background: #161b22;
  border-top: 1px solid #30363d;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: #8b949e;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  padding: 4px 0;
}

.mobile-nav-item i { font-size: 16px; transition: transform 0.2s ease; }
.mobile-nav-item span { font-size: 10px; line-height: 1; }

.mobile-nav-item.active {
  color: #58a6ff;
}
.mobile-nav-item.active i {
  transform: scale(1.1);
}

.mobile-nav-item:active {
  background: rgba(88, 166, 255, 0.08);
}

/* Active indicator dot under tab */
.mobile-nav-item.active::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  background: #58a6ff;
  border-radius: 1px;
}

/* Green dot for preview ready */
.mobile-nav-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 6px;
  height: 6px;
  background: #3fb950;
  border-radius: 50%;
  border: 1.5px solid #161b22;
}

/* Streaming pulse badge on chat tab */
.mobile-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 6px;
  height: 6px;
  background: #58a6ff;
  border-radius: 50%;
  animation: pulse-dot 1.4s infinite;
}

/* --- Mobile More Menu (Bottom Sheet) --- */
.mobile-more-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  transition: background 0.3s ease;
}
.mobile-more-overlay.active {
  background: rgba(0, 0, 0, 0.5);
  pointer-events: all;
}

.mobile-more-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #161b22;
  border-top: 1px solid #30363d;
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 70vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mobile-more-overlay.active .mobile-more-sheet {
  transform: translateY(0);
}

.mobile-more-handle {
  width: 36px;
  height: 4px;
  background: #30363d;
  border-radius: 2px;
  margin: 10px auto 4px;
}

/* --- Mobile File Tree Items --- */
.mobile-file-item {
  transition: background 0.12s ease;
  border-bottom: 1px solid rgba(48, 54, 61, 0.3);
}
.mobile-file-item:last-child { border-bottom: none; }
.mobile-file-item:active { background: rgba(48, 54, 61, 0.6); }

/* --- Mobile Workspace --- */
.mobile-workspace {
  /* Use dynamic viewport height for mobile browsers */
  height: 100dvh;
  touch-action: pan-y;
}

.mobile-header {
  -webkit-user-select: none;
  user-select: none;
}

/* --- Mobile Chat Adjustments --- */
@media (max-width: 900px) {
  /* Chat markdown on mobile – slightly smaller */
  .chat-md pre { font-size: 0.78em; padding: 0.6em; }
  .chat-md code { font-size: 0.82em; }

  /* Process steps on mobile */
  .process-step { padding-left: 0.6em; }

  /* Textarea safe area */
  #chat-input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  /* Hide desktop scrollbar on mobile for cleaner look */
  ::-webkit-scrollbar { width: 0; height: 0; }
}

/* --- Safe area support for notched devices --- */
@supports (padding: max(0px)) {
  .mobile-bottom-nav {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    height: calc(56px + env(safe-area-inset-bottom, 0px));
  }
}

/* --- Desktop: ensure split-screen is visible --- */
@media (min-width: 901px) {
  .mobile-bottom-nav { display: none !important; }
  .mobile-more-overlay { display: none !important; }
  .mobile-workspace { height: 100vh; }
}

/* Monaco Editor container */
#monaco-container {
  width: 100%;
  height: 100%;
  min-height: 200px;
}
#monaco-container .monaco-editor {
  border-radius: 0;
}

/* Upload dropzone animation */
#upload-dropzone.drag-over {
  border-color: #58a6ff;
  background: rgba(88, 166, 255, 0.05);
}

/* Token dashboard chart */
#daily-chart {
  max-height: 200px;
}

/* Handoff modal animation */
#handoff-modal > div,
#upload-modal > div {
  animation: fadeInUp 0.2s ease-out;
}

/* ============================================
   PHASE 7: WORKFLOW CREATOR STYLES
   ============================================ */

/* Workflow Node styles */
.wf-node {
  transition: filter 0.15s ease;
}
.wf-node:hover {
  filter: brightness(1.1);
}
.wf-node:hover [data-glow] {
  opacity: 0.4 !important;
}
.wf-node-selected [data-glow] {
  opacity: 0.6 !important;
}

/* Node Palette drag */
.wf-palette-node {
  transition: all 0.15s ease;
}
.wf-palette-node:active {
  transform: scale(0.95);
  opacity: 0.7;
}

/* Canvas animations */
@keyframes nodeAppear {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
.wf-node {
  animation: nodeAppear 0.2s ease-out;
}

/* Connection glow animation */
@keyframes connectionPulse {
  0%, 100% { stroke-opacity: 0.3; }
  50% { stroke-opacity: 0.7; }
}

/* Prompt badge shimmer */
@keyframes promptShimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

/* Canvas grid pattern with zoom */
#wf-canvas-container {
  background-color: #080c14;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(88,166,255,0.03) 0%, transparent 50%),
    linear-gradient(rgba(48,54,61,0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(48,54,61,0.15) 1px, transparent 1px);
  background-size: 100% 100%, 20px 20px, 20px 20px;
}

/* Port hover glow */
[data-port-type]:hover {
  box-shadow: 0 0 8px rgba(88,166,255,0.6);
}

/* Inspector panel glass effect */
#wf-inspector-panel {
  background: linear-gradient(180deg, rgba(22,27,34,0.95) 0%, rgba(13,17,23,0.98) 100%);
  backdrop-filter: blur(12px);
}

/* Generated code styling */
#wf-generated-code {
  tab-size: 2;
  font-variant-ligatures: contextual;
}

/* Workflow designer scrollbar */
#wf-inspector-panel::-webkit-scrollbar { width: 4px; }
#wf-inspector-panel::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
