/* Global styles for Telegram Web App - HireHub Mobile Web */

:root {
  /* Brand colors */
  --color-primary: #0067C9;
  --color-primary-light: #3584e4;
  --color-primary-dark: #0055A8;
  --color-telegram: #0088cc;
  --color-success: #34C759;
  --color-error: #FF3B30;
  --color-warning: #FF9500;
  
  /* Neutral colors */
  --color-background: #F5F5F5;
  --color-surface: #FFFFFF;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-border: #E5E5EA;
  
  /* Safe areas */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  background-color: var(--color-background);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
}

#root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Responsive container for Telegram and desktop */
@media (min-width: 769px) {
  body {
    background-color: #e8e8e8;
  }
  
  #root {
    max-width: 768px;
    margin: 0 auto;
    background-color: var(--color-surface);
    min-height: 100vh;
    min-height: 100dvh;
    box-shadow: 0 0 60px rgba(0, 103, 201, 0.08), 0 0 20px rgba(0, 0, 0, 0.06);
  }
}

/* Mobile optimizations */
@media (max-width: 768px) {
  body {
    /* Top inset is handled by SafeAreaProvider in RootLayout — do not duplicate here */
    padding-top: 0;
    padding-bottom: 0; /* Tab bar handles bottom safe area */
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
  }
  
  /* Smaller screen optimizations */
  @media (max-width: 375px) {
    html {
      font-size: 14px;
    }
  }
}

/* Input styles for better mobile UX */
input, textarea {
  font-size: 16px !important; /* Prevents iOS zoom on focus */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 12px; /* Match app rounded input style */
  touch-action: auto;
}

input:focus, textarea:focus {
  outline: none;
}

/* Focus-visible ring for keyboard / Telegram web navigation
   Only applies when inputs don't already have a component-level shadow ring */
input:focus-visible:not([data-focused]),
textarea:focus-visible {
  outline: 2px solid rgba(0, 103, 201, 0.5);
  outline-offset: 0;
  border-radius: 12px;
}

/* Button styles */
button {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

button:focus {
  outline: none;
}

button:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid rgba(0, 103, 201, 0.5);
  outline-offset: 2px;
  border-radius: 8px;
}

button:active {
  transform: scale(0.98);
}

/* Prevent text selection for better UX in Telegram */
.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Allow text selection for inputs */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Smooth scrolling */
.smooth-scroll {
  scroll-behavior: smooth;
}

/* Hide scrollbars but keep functionality */
.hide-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
  display: none;
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.3);
}

/* Native-like easing for Mini App (Material-style cubic-bezier) */
:root {
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 320ms;
}

/* Animation utilities - smooth native-like timing */
.fade-in {
  animation: fadeIn var(--duration-normal) var(--ease-out);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.slide-up {
  animation: slideUp var(--duration-normal) var(--ease-out);
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Touch feedback - snappy for native feel */
.touchable {
  transition: opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.touchable:active {
  opacity: 0.7;
  transform: scale(0.98);
}

/* Mini App: smooth press feedback and scroll (native-like) */
body[data-telegram="true"] .touchable,
body[data-telegram="true"] [data-pressable] {
  transition: opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

body[data-telegram="true"] .smooth-scroll {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Bottom tab bar spacing */
.tab-bar-spacer {
  height: calc(70px + var(--safe-area-bottom));
}

/* Fix for iOS keyboard */
@supports (-webkit-touch-callout: none) {
  .keyboard-open body {
    height: 100vh;
    overflow: hidden;
  }
  .keyboard-open body[data-telegram="true"] {
    min-height: var(--tg-viewport-stable-height, 100dvh);
  }
}

/* Telegram Mini App specific */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .telegram-bottom-safe {
    padding-bottom: max(env(safe-area-inset-bottom), 16px);
  }
}

/* When running inside Telegram Mini App: viewport, theme, and native-like behavior */
/* Top inset is applied once in root layout (SafeAreaProvider); do not duplicate with body padding */
body[data-telegram="true"] {
  /* Use stable height so layout does not jump when the keyboard opens */
  height: var(--tg-viewport-stable-height, 100dvh);
  max-height: var(--tg-viewport-stable-height, 100dvh);
  min-height: var(--tg-viewport-stable-height, 100dvh);
  background-color: var(--tg-theme-bg-color, var(--color-background));
  color: var(--tg-theme-text-color, var(--color-text));
  /* Disable callout only; do NOT blanket-disable user-select — users need to copy
     text from job descriptions, company names, etc. UI elements use .no-select. */
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding-top: 0;
}

/* Allow text selection everywhere inside the mini app except explicit .no-select nodes */
body[data-telegram="true"] *:not(.no-select) {
  -webkit-user-select: text;
  user-select: text;
}

/* Buttons and interactive elements should not be selectable */
body[data-telegram="true"] button,
body[data-telegram="true"] [role="button"],
body[data-telegram="true"] [role="tab"],
body[data-telegram="true"] [role="menuitem"] {
  -webkit-user-select: none;
  user-select: none;
}

body[data-telegram="true"] #root {
  height: var(--tg-viewport-stable-height, 100dvh);
  max-height: var(--tg-viewport-stable-height, 100dvh);
  min-height: var(--tg-viewport-stable-height, 100dvh);
  background-color: var(--tg-theme-bg-color, var(--color-surface));
  color: var(--tg-theme-text-color, var(--color-text));
  overscroll-behavior: none;
  contain: layout style;
}
