/**
 * hamboorg.city - Shared Styles
 * Focus states, Dark mode, Skeleton loaders, Accessibility
 */

/* ============================================
   FOCUS STATES - Accessibility
   ============================================ */

/* Remove default outline, add custom focus-visible */
*:focus {
  outline: none;
}

*:focus-visible {
  outline: 3px solid var(--focus-ring, #C0612B);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Buttons */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid var(--focus-ring, #C0612B);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(192, 97, 43, 0.15);
}

/* Links */
a:focus-visible {
  outline: 2px solid var(--focus-ring, #C0612B);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Form inputs */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--focus-ring, #C0612B) !important;
  box-shadow: 0 0 0 3px rgba(192, 97, 43, 0.15);
}

/* Toggle switches */
.toggle input:focus-visible + .toggle-slider {
  outline: 3px solid var(--focus-ring, #C0612B);
  outline-offset: 2px;
}

/* Cards and interactive elements */
.card:focus-visible,
.specialist-card:focus-visible,
.article-card:focus-visible {
  outline: 3px solid var(--focus-ring, #C0612B);
  outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-dark, #2A1F14);
  color: var(--text-inv, #FFFBF5);
  padding: 12px 24px;
  border-radius: 0 0 8px 8px;
  z-index: 10000;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

/* ============================================
   DARK MODE
   ============================================ */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1512;
    --bg-warm: #231C16;
    --bg-card: #2A2219;
    --bg-dark: #0F0D0A;
    --amber: #E07A3A;
    --amber-hover: #F08A4A;
    --amber-light: #4A3020;
    --sage: #6BA580;
    --sage-bg: #1E2A22;
    --sage-deep: #8BC4A0;
    --text: #F5EDE5;
    --text-mid: #B5A89A;
    --text-soft: #7A7068;
    --text-inv: #1A1512;
    --border: rgba(245, 237, 229, 0.1);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --urgent: #E05A4A;
    --urgent-bg: #2A1A18;
    --focus-ring: #E07A3A;
  }

  /* Specific dark mode overrides */
  body {
    color-scheme: dark;
  }

  /* Images - slightly reduce brightness */
  img:not([src*=".svg"]) {
    filter: brightness(0.9);
  }

  /* Code blocks */
  pre, code {
    background: var(--bg-dark);
  }

  /* Inputs */
  input, textarea, select {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--text-soft);
  }

  /* Modal overlay */
  .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
  }

  /* Topbar adjustments */
  .topbar {
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
  }

  /* Cards */
  .stat, .section, .card {
    background: var(--bg-card);
    border-color: var(--border);
  }

  /* Toggle slider inactive state */
  .toggle-slider {
    background-color: var(--text-soft);
  }

  /* Scrollbar */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

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

  ::-webkit-scrollbar-thumb {
    background: var(--text-soft);
    border-radius: 4px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--text-mid);
  }
}

/* Manual dark mode toggle class (for future toggle button) */
.dark-mode {
  --bg: #1A1512;
  --bg-warm: #231C16;
  --bg-card: #2A2219;
  --bg-dark: #0F0D0A;
  --amber: #E07A3A;
  --amber-hover: #F08A4A;
  --amber-light: #4A3020;
  --sage: #6BA580;
  --sage-bg: #1E2A22;
  --sage-deep: #8BC4A0;
  --text: #F5EDE5;
  --text-mid: #B5A89A;
  --text-soft: #7A7068;
  --text-inv: #1A1512;
  --border: rgba(245, 237, 229, 0.1);
  --urgent: #E05A4A;
  --urgent-bg: #2A1A18;
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    rgba(255, 255, 255, 0.1) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

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

/* Skeleton variants */
.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: 4px;
}

.skeleton-text:last-child {
  width: 70%;
}

.skeleton-title {
  height: 1.5em;
  width: 60%;
  margin-bottom: 1em;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-card {
  height: 120px;
  border-radius: var(--r-md, 16px);
}

.skeleton-button {
  height: 44px;
  width: 120px;
  border-radius: var(--r-full, 999px);
}

.skeleton-image {
  aspect-ratio: 16/9;
  border-radius: var(--r-md, 16px);
}

/* Skeleton card component */
.skeleton-specialist-card {
  padding: 20px;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 24px);
}

.skeleton-specialist-card .skeleton-header {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.skeleton-specialist-card .skeleton-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

@media (max-width: 480px) {
  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-card, #fff);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 400px;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast.hiding {
  transform: translateX(120%);
  opacity: 0;
}

.toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--text);
}

.toast-message {
  font-size: 14px;
  color: var(--text-mid);
  word-wrap: break-word;
}

.toast-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  font-size: 18px;
}

.toast-close:hover {
  background: var(--border);
  color: var(--text);
}

/* Toast variants */
.toast.toast-success {
  border-left: 4px solid var(--sage, #5E9472);
}

.toast.toast-success .toast-icon {
  color: var(--sage, #5E9472);
}

.toast.toast-error {
  border-left: 4px solid var(--urgent, #BF4D3E);
}

.toast.toast-error .toast-icon {
  color: var(--urgent, #BF4D3E);
}

.toast.toast-warning {
  border-left: 4px solid var(--amber, #C0612B);
}

.toast.toast-warning .toast-icon {
  color: var(--amber, #C0612B);
}

.toast.toast-info {
  border-left: 4px solid #3B82F6;
}

.toast.toast-info .toast-icon {
  color: #3B82F6;
}

/* ============================================
   REDUCED MOTION
   ============================================ */

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

  .skeleton {
    animation: none;
    background: var(--border);
  }
}

/* ============================================
   SCREEN READER ONLY
   ============================================ */

.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;
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
  :root {
    --border: rgba(0, 0, 0, 0.3);
  }

  button, .btn, a {
    text-decoration: underline;
  }

  *:focus-visible {
    outline-width: 4px;
  }
}

/* ============================================
   RTL (RIGHT-TO-LEFT) SUPPORT
   Arabic (ar), Persian (fa)
   ============================================ */

/* RTL base - applied when html[dir="rtl"] or .rtl class */
[dir="rtl"],
.rtl {
  direction: rtl;
  text-align: right;
}

/* ---- Logical Properties Overrides for RTL ---- */

/* Skip link - mirror position */
[dir="rtl"] .skip-link {
  left: auto;
  right: 50%;
  transform: translateX(50%);
}

/* Toast container - flip to left side */
[dir="rtl"] .toast-container {
  right: auto;
  left: 24px;
}

@media (max-width: 480px) {
  [dir="rtl"] .toast-container {
    left: 16px;
    right: 16px;
  }
}

/* Toast animation - slide from left */
[dir="rtl"] .toast {
  transform: translateX(-120%);
  border-left: none;
  border-right: 4px solid var(--border);
}

[dir="rtl"] .toast.show {
  transform: translateX(0);
}

[dir="rtl"] .toast.hiding {
  transform: translateX(-120%);
}

/* Toast variants - RTL border */
[dir="rtl"] .toast.toast-success {
  border-left: none;
  border-right: 4px solid var(--sage, #5E9472);
}

[dir="rtl"] .toast.toast-error {
  border-left: none;
  border-right: 4px solid var(--urgent, #BF4D3E);
}

[dir="rtl"] .toast.toast-warning {
  border-left: none;
  border-right: 4px solid var(--amber, #C0612B);
}

[dir="rtl"] .toast.toast-info {
  border-left: none;
  border-right: 4px solid #3B82F6;
}

/* Skeleton loading - reverse animation direction */
[dir="rtl"] .skeleton {
  animation-name: skeleton-loading-rtl;
}

@keyframes skeleton-loading-rtl {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ---- Common Layout Patterns - RTL Flip ---- */

/* Flex row reverse for RTL */
[dir="rtl"] .flex-row,
[dir="rtl"] .topbar,
[dir="rtl"] .nav-links,
[dir="rtl"] .search-container,
[dir="rtl"] .filter-bar {
  flex-direction: row-reverse;
}

/* Icon positions */
[dir="rtl"] .icon-left {
  margin-left: 8px;
  margin-right: 0;
}

[dir="rtl"] .icon-right {
  margin-right: 8px;
  margin-left: 0;
}

/* Input with icon */
[dir="rtl"] .input-with-icon input {
  padding-left: 16px;
  padding-right: 48px;
}

[dir="rtl"] .input-with-icon .input-icon {
  left: auto;
  right: 16px;
}

/* Checkboxes and radio - label on left */
[dir="rtl"] .checkbox-label,
[dir="rtl"] .radio-label {
  flex-direction: row-reverse;
}

[dir="rtl"] .checkbox-label input,
[dir="rtl"] .radio-label input {
  margin-right: 0;
  margin-left: 8px;
}

/* Cards with left accent */
[dir="rtl"] .card-accent-left {
  border-left: none;
  border-right: 4px solid var(--amber);
}

/* Breadcrumbs - reverse arrows */
[dir="rtl"] .breadcrumb-separator {
  transform: rotate(180deg);
}

/* Lists with bullets/icons */
[dir="rtl"] ul:not(.no-rtl-flip),
[dir="rtl"] ol:not(.no-rtl-flip) {
  padding-left: 0;
  padding-right: 1.5em;
}

/* Dropdown menus - align right */
[dir="rtl"] .dropdown-menu {
  left: auto;
  right: 0;
}

/* Modal close button */
[dir="rtl"] .modal-close {
  left: 20px;
  right: auto;
}

/* Progress bars - reverse direction */
[dir="rtl"] .progress-fill {
  transform-origin: right;
}

/* Margins and paddings - use logical properties */
[dir="rtl"] .ml-auto { margin-left: 0; margin-right: auto; }
[dir="rtl"] .mr-auto { margin-right: 0; margin-left: auto; }
[dir="rtl"] .pl-4 { padding-left: 0; padding-right: 1rem; }
[dir="rtl"] .pr-4 { padding-right: 0; padding-left: 1rem; }
[dir="rtl"] .ml-2 { margin-left: 0; margin-right: 0.5rem; }
[dir="rtl"] .mr-2 { margin-right: 0; margin-left: 0.5rem; }

/* Text alignment utilities */
[dir="rtl"] .text-left { text-align: right; }
[dir="rtl"] .text-right { text-align: left; }

/* Float utilities */
[dir="rtl"] .float-left { float: right; }
[dir="rtl"] .float-right { float: left; }

/* Border radius - swap for RTL */
[dir="rtl"] .rounded-l {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-top-right-radius: var(--r-md, 8px);
  border-bottom-right-radius: var(--r-md, 8px);
}

[dir="rtl"] .rounded-r {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: var(--r-md, 8px);
  border-bottom-left-radius: var(--r-md, 8px);
}

/* ---- Specific Components ---- */

/* Language selector flags */
[dir="rtl"] .lang-btn .flag {
  margin-right: 0;
  margin-left: 8px;
}

/* Navigation items */
[dir="rtl"] .nav-item .nav-icon {
  margin-right: 0;
  margin-left: 12px;
}

/* Search input with button */
[dir="rtl"] .search-box {
  flex-direction: row-reverse;
}

[dir="rtl"] .search-box input {
  border-radius: 0 var(--r-full, 999px) var(--r-full, 999px) 0;
}

[dir="rtl"] .search-box button {
  border-radius: var(--r-full, 999px) 0 0 var(--r-full, 999px);
}

/* Specialist/Article cards */
[dir="rtl"] .specialist-card,
[dir="rtl"] .article-card {
  text-align: right;
}

[dir="rtl"] .specialist-card .card-header,
[dir="rtl"] .article-card .article-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .specialist-info {
  margin-left: 0;
  margin-right: 16px;
}

/* Tags/Badges */
[dir="rtl"] .tag-list,
[dir="rtl"] .badge-list {
  flex-direction: row-reverse;
}

/* Form labels */
[dir="rtl"] .form-group label {
  text-align: right;
}

/* Toggle switches */
[dir="rtl"] .toggle {
  flex-direction: row-reverse;
}

[dir="rtl"] .toggle-label {
  margin-right: 0;
  margin-left: 12px;
}

/* Back button / navigation arrows */
[dir="rtl"] .back-btn svg,
[dir="rtl"] .nav-arrow-left {
  transform: rotate(180deg);
}

[dir="rtl"] .nav-arrow-right {
  transform: rotate(180deg);
}

/* Steps / Wizard indicators */
[dir="rtl"] .steps-indicator {
  flex-direction: row-reverse;
}

[dir="rtl"] .step-connector {
  transform: rotate(180deg);
}

/* Verified badge position */
[dir="rtl"] .verified-badge {
  left: 12px;
  right: auto;
}

/* Notification dot position */
[dir="rtl"] .notification-dot {
  left: 0;
  right: auto;
}

/* ---- Icons that should flip in RTL ---- */
[dir="rtl"] .icon-flip-rtl {
  transform: scaleX(-1);
}

/* Icons that should NOT flip (globally recognizable) */
/* Phone, email, clock, calendar, etc. stay the same */
.icon-no-flip {
  transform: none !important;
}

/* ---- RTL-aware Grid ---- */
[dir="rtl"] .grid-cols-auto {
  direction: rtl;
}

/* ---- Animations for RTL ---- */
[dir="rtl"] .slide-in-left {
  animation-name: slide-in-right-rtl;
}

[dir="rtl"] .slide-in-right {
  animation-name: slide-in-left-rtl;
}

@keyframes slide-in-right-rtl {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slide-in-left-rtl {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
