/*
 * Tayseer ERP — Vuexy Branding Overrides
 * Burgundy primary color + Cairo Arabic font
 * Also provides legacy design tokens (--clr-*) used by feature CSS.
 */

:root,
[data-bs-theme="light"] {
  /* Bootstrap 5 overrides */
  --bs-primary: #800020;
  --bs-primary-rgb: 128, 0, 32;
  --bs-primary-bg-subtle: rgba(128, 0, 32, 0.08);
  --bs-primary-border-subtle: rgba(128, 0, 32, 0.2);
  --bs-primary-text-emphasis: #5a0016;
  --bs-link-color: #800020;
  --bs-link-color-rgb: 128, 0, 32;
  --bs-link-hover-color: #5a0016;
  --bs-link-hover-color-rgb: 90, 0, 22;
  --bs-font-sans-serif: 'Cairo', sans-serif;
  --bs-body-font-family: 'Cairo', sans-serif;

  /* Legacy design tokens (used by smart-onboarding, system-settings, etc.) */
  --clr-primary-900: #4a0012;
  --clr-primary-800: #600018;
  --clr-primary-700: #70001c;
  --clr-primary: #800020;
  --clr-primary-500: #9a1a3a;
  --clr-primary-400: #b03050;
  --clr-primary-300: #c75070;
  --clr-primary-200: #dd8098;
  --clr-primary-100: #f0c0cc;
  --clr-primary-50: #fdf0f3;
  --clr-accent: #c8a04a;
  --clr-accent-light: #e8d08a;
  --clr-accent-dark: #9a7a2a;
  --clr-bg: #f4f6f9;
  --clr-surface: #ffffff;
  --clr-border: #e0e0e0;
  --clr-text: #2c2c2c;
  --clr-text-muted: #6c757d;
  --clr-text-light: #999;
  --clr-text-on-primary: #ffffff;
  --clr-success: #28a745;
  --clr-warning: #ffc107;
  --clr-danger: #dc3545;
  --clr-info: #17a2b8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 14px;
  --font-size-md: 16px;
  --font-size-lg: 20px;
  --font-size-xl: 26px;
  --transition: all 0.25s ease;
}

body {
  font-family: 'Cairo', sans-serif;
}

/* Primary color for buttons, badges, etc.
   Now driven by tayseer-themes.css via --t-primary variables.
   Kept here only as fallback for pages that don't load themes. */

/* Sidebar dark theme accent — now driven by tayseer-themes.css */

/* App brand styling */
.app-brand .app-brand-text {
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: clamp(0.7rem, 1.1vw + 0.4rem, 0.92rem);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  max-width: calc(100% - 70px);
}
.app-brand .app-brand-logo img {
  border-radius: 6px;
}

/* Navbar user avatar */
.avatar-online::after {
  background-color: var(--bs-success);
}

/* Vuexy active menu indicator line — now driven by tayseer-themes.css */

/* Pagination, nav, form focus — now driven by tayseer-themes.css */

/* Card header consistency */
.card {
  border-radius: 0.5rem;
}

/* Table hover — now driven by tayseer-themes.css */

/* Skip-to-content link — WCAG 2.4.1 */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100000;
  padding: 0.75rem 1.5rem;
  background: var(--bs-primary, #800020);
  color: #fff;
  border-radius: 0 0 0.5rem 0.5rem;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s ease;
}
.skip-to-content:focus {
  top: 0;
  color: #fff;
  outline: 3px solid var(--clr-accent, #c8a04a);
  outline-offset: 2px;
}

/* ═══ AdminLTE → Vuexy Card Shim ═══
   Maps legacy .box / .box-primary to Bootstrap 5 .card styling
   so all 90+ existing views render consistently without per-file edits */
.box,
.box-primary,
.box-default,
.box-info,
.box-success,
.box-warning,
.box-danger {
  background: var(--bs-card-bg, #fff);
  border: var(--bs-card-border-width, 1px) solid var(--bs-card-border-color, rgba(0,0,0,.125));
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,.04);
  border-top: none;
}
.box-header,
.box-header.with-border {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-card-border-color, rgba(0,0,0,.125));
  background: transparent;
}
.box-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: var(--bs-heading-color, inherit);
}
.box-body {
  padding: 1.25rem;
  overflow-x: auto;
}
.box-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--bs-card-border-color, rgba(0,0,0,.125));
  background: var(--bs-tertiary-bg, #f8f9fa);
  border-radius: 0 0 0.5rem 0.5rem;
}
.box-tools {
  display: flex;
  gap: 0.375rem;
  align-items: center;
}
[data-bs-theme="dark"] .box,
[data-bs-theme="dark"] .box-primary {
  background: var(--bs-card-bg, #2b2c40);
  border-color: var(--bs-card-border-color, rgba(255,255,255,.1));
}

/* ═══ Skeleton Loading — ISO 9241-110 (User Expectation) ═══ */
@keyframes ty-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.ty-skeleton {
  position: relative;
  overflow: hidden;
  pointer-events: none;
}
.ty-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 5;
  background: linear-gradient(90deg,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,.04) 40%,
    rgba(0,0,0,.08) 50%,
    rgba(0,0,0,.04) 60%,
    rgba(0,0,0,0) 100%);
  background-size: 200% 100%;
  animation: ty-shimmer 1.5s ease-in-out infinite;
  border-radius: inherit;
}
[data-bs-theme="dark"] .ty-skeleton::after {
  background: linear-gradient(90deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,.06) 40%,
    rgba(255,255,255,.1) 50%,
    rgba(255,255,255,.06) 60%,
    rgba(255,255,255,0) 100%);
  background-size: 200% 100%;
}
.ty-skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: var(--bs-tertiary-bg, #e9ecef);
  margin-bottom: 8px;
}
.ty-skeleton-line.w-75 { width: 75%; }
.ty-skeleton-line.w-50 { width: 50%; }
.ty-skeleton-line.w-40 { width: 40%; }
.ty-skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bs-tertiary-bg, #e9ecef);
}

/* Pjax loading overlay */
.ty-pjax-loading {
  position: relative;
  min-height: 120px;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.ty-pjax-loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid var(--bs-primary, #800020);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ty-spin 0.7s linear infinite;
  z-index: 10;
}
@keyframes ty-spin {
  to { transform: rotate(360deg); }
}

/* ═══ Toast Notification System ═══ */
.ty-toast-container {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100010;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - 2rem);
}
.ty-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  background: var(--bs-card-bg, #fff);
  box-shadow: 0 8px 24px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  border-right: 4px solid var(--toast-color, #800020);
  animation: ty-toast-in 0.35s cubic-bezier(.2,.8,.3,1);
  transition: opacity 0.3s, transform 0.3s;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--bs-body-color, #333);
}
.ty-toast.ty-toast-out {
  opacity: 0;
  transform: translateX(-20px);
}
@keyframes ty-toast-in {
  from { opacity: 0; transform: translateX(-30px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.ty-toast-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
  background: var(--toast-color, #800020);
  margin-top: 1px;
}
.ty-toast-body { flex: 1; min-width: 0; }
.ty-toast-title {
  font-weight: 700;
  font-size: 0.8125rem;
  margin-bottom: 2px;
}
.ty-toast-msg { font-size: 0.8125rem; opacity: 0.85; }
.ty-toast-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--bs-body-color, #666);
  opacity: 0.5;
  padding: 0 4px;
  line-height: 1;
  margin-top: -2px;
}
.ty-toast-close:hover { opacity: 1; }
.ty-toast-progress {
  position: absolute;
  bottom: 0;
  right: 0;
  height: 3px;
  background: var(--toast-color, #800020);
  border-radius: 0 0 0.5rem 0;
  opacity: 0.4;
  transition: width linear;
}
.ty-toast--success { --toast-color: #28a745; }
.ty-toast--error   { --toast-color: #dc3545; }
.ty-toast--warning { --toast-color: #ffc107; }
.ty-toast--info    { --toast-color: #17a2b8; }

/* ═══ WCAG 2.2 AAA — Enhanced Accessibility ═══ */

/* AAA Touch Target (WCAG 2.5.8): min 44×44px for all interactive elements */
a:not(.dropdown-item):not(.page-link):not(.breadcrumb-item > a):not(.db-link),
button:not(.btn-close):not(.ty-toast-close),
input[type="checkbox"],
input[type="radio"],
select,
.btn,
.nav-link,
.so-step,
[role="tab"],
[role="menuitem"] {
  min-height: 44px;
  min-width: 44px;
}
/* Ensure small icon buttons still meet target area with padding */
.btn-icon, .btn-sm, .btn-xs {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* Checkbox/Radio visual size boost */
input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
}

/* AAA Contrast Safety: boost muted text colors for 7:1 ratio */
.text-muted, .text-body-secondary, .form-text,
.breadcrumb-item + .breadcrumb-item::before,
.db-kpi-label, .db-kpi-sub, .ct-stat-label,
.ocp-status-bar__meta-label {
  color: var(--bs-emphasis-color, #495057) !important;
}
[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-body-secondary,
[data-bs-theme="dark"] .form-text {
  color: var(--bs-secondary-color, #b0b7c3) !important;
}

/* Focus Visible Ring (WCAG 2.4.13 AAA: Focus appearance) */
:focus-visible {
  outline: 3px solid var(--bs-primary, #800020) !important;
  outline-offset: 2px !important;
  border-radius: 4px;
}
[data-bs-theme="dark"] :focus-visible {
  outline-color: var(--bs-primary, #e06080) !important;
}

/* AAA Link Distinction: underline all in-content links */
.db-card-body a:not(.btn):not(.db-link),
.modal-body a:not(.btn),
p a:not(.btn) {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ═══ Microinteractions — Buttons & Cards ═══ */
.btn {
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
  position: relative;
  overflow: hidden;
}
.btn:active:not(:disabled):not(.disabled) {
  transform: scale(0.96);
  transition-duration: 0.08s;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  border-radius: inherit;
}
.btn:hover::after { opacity: 0.06; }
.btn:active::after { opacity: 0.12; }

.card, .db-card, .db-kpi, .ct-stat-card, .ocp-card {
  transition: transform 0.2s cubic-bezier(.4,0,.2,1), box-shadow 0.2s cubic-bezier(.4,0,.2,1);
}
.card:hover, .db-card:hover, .ct-stat-card:hover, .ocp-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
}

.badge, .db-status-pill, .ct-badge {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.badge:hover, .db-status-pill:hover, .ct-badge:hover {
  transform: scale(1.05);
}

@keyframes ty-ripple {
  to { transform: scale(2.5); opacity: 0; }
}

.form-control:focus, .form-select:focus, .select2-container--focus .select2-selection {
  transition: border-color 0.2s, box-shadow 0.2s;
}

a:not(.btn):not(.nav-link):not(.db-kpi) {
  transition: color 0.15s ease;
}

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

/* ═══ Persistent GridView Quick Search ═══ */
.ty-grid-search { padding: 4px 0; }
.ty-grid-search-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bs-body-bg, #f8f9fa);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 8px;
  padding: 6px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ty-grid-search-inner:focus-within {
  border-color: var(--bs-primary, #800020);
  box-shadow: 0 0 0 3px rgba(128,0,32,.12);
}
.ty-grid-search-icon {
  color: var(--bs-secondary-color, #6c757d);
  font-size: 13px;
  flex-shrink: 0;
}
.ty-grid-search-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--bs-body-color, #333);
  flex: 1;
  min-width: 0;
  font-family: inherit;
}
.ty-grid-search-input::placeholder { color: var(--bs-secondary-color, #999); }
.ty-grid-search-count {
  font-size: 11px;
  color: var(--bs-secondary-color, #6c757d);
  white-space: nowrap;
  padding: 2px 8px;
  background: var(--bs-tertiary-bg, #e9ecef);
  border-radius: 10px;
}

/* ═══ Column Visibility Toggle ═══ */
.ty-col-toggle-wrap {
  position: relative;
  display: inline-block;
  margin-right: 4px;
}
.ty-col-toggle-btn {
  padding: 4px 8px !important;
  font-size: 12px;
  border-radius: 6px !important;
}
.ty-col-toggle-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1050;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bs-body-bg, #fff);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 8px 0;
  margin-top: 4px;
}
.ty-col-toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  margin: 0;
}
.ty-col-toggle-item:hover {
  background: var(--bs-tertiary-bg, #f0f0f0);
}
.ty-col-toggle-item input[type="checkbox"] {
  accent-color: var(--bs-primary, #800020);
  width: 14px;
  height: 14px;
}

/* RTL fixes for select2 and kartik widgets */
.select2-container--krajee-bs5 .select2-selection--single .select2-selection__rendered {
  text-align: right;
}

/* ───────────────────────────────────────────
 * Global Flash Messages — ty-flash
 * Used by content.php to render Yii flash messages
 * ─────────────────────────────────────────── */
.ty-flash {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  animation: ty-flash-in .25s ease-out;
}
@keyframes ty-flash-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ty-flash__icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.ty-flash__body { flex: 1; line-height: 1.55; }
.ty-flash__body ul { margin: 4px 0 0; padding-inline-start: 20px; }
.ty-flash__body strong { font-weight: 700; }
.ty-flash__close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: inherit;
  opacity: .55; padding: 0 4px; align-self: flex-start;
  transition: opacity .15s;
}
.ty-flash__close:hover { opacity: 1; }
.ty-flash--success { background: #e9f9ef; color: #166534; border-color: #bbf7d0; }
.ty-flash--success .ty-flash__icon { color: #16a34a; }
.ty-flash--error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.ty-flash--error   .ty-flash__icon { color: #dc2626; }
.ty-flash--warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.ty-flash--warning .ty-flash__icon { color: #d97706; }
.ty-flash--info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.ty-flash--info    .ty-flash__icon { color: #2563eb; }
