/* ============================================
   MenkIQTest - Premium Style System v2.0
   Mobile-First, Premium UI/UX Enhancement
   ============================================ */

:root {
  /* Core Colors - Dark Theme */
  --bg: #0b0f16;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.66);
  --muted2: rgba(255, 255, 255, 0.54);
  
  /* Accent Colors */
  --primary: #4ea1ff;
  --primary-dark: #3b8ae5;
  --primary-light: #6db3ff;
  --danger: #ff4e6a;
  --danger-dark: #e63d56;
  --warn: #ffcc66;
  --warn-dark: #f5b942;
  --ok: #31d18b;
  --ok-dark: #28b575;
  
  /* Additional Premium Colors */
  --purple: #a78bfa;
  --pink: #ec4899;
  --teal: #14b8a6;
  --orange: #fb923c;
  
  /* Border Radius */
  --r: 18px;
  --r2: 22px;
  --r-sm: 12px;
  --r-xs: 8px;
  --r-lg: 28px;
  --r-full: 999px;
  
  /* Shadows - Enhanced */
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
  --shadow2: 0 8px 22px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.20);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 30px 70px rgba(0, 0, 0, 0.55);
  --glow-primary: 0 0 30px rgba(78, 161, 255, 0.25);
  --glow-success: 0 0 30px rgba(49, 209, 139, 0.25);
  --glow-danger: 0 0 30px rgba(255, 78, 106, 0.25);
  
  /* Spacing System */
  --s1: 6px;
  --s2: 10px;
  --s3: 14px;
  --s4: 18px;
  --s5: 24px;
  --s6: 32px;
  --s7: 40px;
  --s8: 48px;
  
  /* Typography */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.4s ease;
  
  /* Layout */
  --header-height: 70px;
  --max-width: 1400px;
  --max-width-narrow: 1050px;
  --max-width-tight: 720px;
}

/* ============================================
   Reset & Base Styles
   ============================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

html, body {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  background: 
    radial-gradient(1200px 700px at 20% -10%, rgba(78, 161, 255, 0.18), transparent 55%),
    radial-gradient(900px 550px at 110% 10%, rgba(49, 209, 139, 0.12), transparent 50%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  position: relative;
}

/* Fix background positioning in RTL */
html[dir="rtl"] body {
  background: 
    radial-gradient(1200px 700px at 80% -10%, rgba(78, 161, 255, 0.18), transparent 55%),
    radial-gradient(900px 550px at -10% 10%, rgba(49, 209, 139, 0.12), transparent 50%),
    var(--bg);
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-light);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--primary-light);
}

pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: var(--s4);
  border-radius: var(--r);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow-x: auto;
  margin: var(--s4) 0;
}

strong {
  font-weight: 700;
  color: var(--text);
}

/* ============================================
   Accessibility
   ============================================ */

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 9999;
}

.skip-link:focus {
  left: var(--s4);
  top: var(--s4);
  width: auto;
  height: auto;
  background: rgba(11, 24, 39, 0.98);
  backdrop-filter: blur(10px);
  border: 2px solid var(--primary);
  padding: 12px 16px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
}

:focus-visible {
  outline: 3px solid rgba(78, 161, 255, 0.6);
  outline-offset: 3px;
  border-radius: var(--r-xs);
}

/* ============================================
   Layout & Containers
   ============================================ */

.container {
  width: min(var(--max-width-narrow), 100%);
  margin: 0 auto;
  padding: var(--s6) var(--s4);
  overflow-x: hidden;
  max-width: 100vw;
}

.container-wide {
  width: min(var(--max-width), 100%);
  margin: 0 auto;
  padding: var(--s6) var(--s4);
  overflow-x: hidden;
  max-width: 100vw;
}

.container-tight {
  width: min(var(--max-width-tight), 100%);
  margin: 0 auto;
  padding: var(--s6) var(--s4);
  overflow-x: hidden;
  max-width: 100vw;
}

/* Main element overflow protection */
main {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  position: relative;
}

section {
  overflow-x: hidden;
  max-width: 100%;
}

/* ============================================
   Header / Topbar
   ============================================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4);
  background: rgba(11, 15, 22, 0.75);
  backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  transition: transform var(--transition-base), background var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.topbar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, 
    rgba(78, 161, 255, 0.05) 0%, 
    transparent 50%, 
    rgba(49, 209, 139, 0.05) 100%);
  opacity: 0;
  transition: opacity var(--transition-slow);
  pointer-events: none;
}

.topbar:hover::before {
  opacity: 1;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 220px;
}

.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, 
    rgba(78, 161, 255, 0.28), 
    rgba(49, 209, 139, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: var(--shadow2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  font-size: 22px;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.logo:hover {
  transform: scale(1.05) rotate(-3deg);
  box-shadow: var(--shadow2), var(--glow-primary), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.titleblock .title {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.3px;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.titleblock .subtitle {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

/* Top Actions */
.top-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ============================================
   Cards
   ============================================ */

.card {
  background: linear-gradient(180deg, 
    rgba(255, 255, 255, 0.085), 
    rgba(255, 255, 255, 0.055));
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: var(--s5);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at 30% 20%, 
    rgba(78, 161, 255, 0.08) 0%, 
    transparent 60%
  );
  opacity: 0;
  transition: opacity var(--transition-slow);
  pointer-events: none;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card:hover::before {
  opacity: 1;
}

.card + .card {
  margin-top: var(--s5);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  margin-bottom: var(--s4);
  flex-wrap: wrap;
}

/* ============================================
   Typography
   ============================================ */

.h1 {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 900;
  letter-spacing: -0.5px;
  margin: 0 0 var(--s3) 0;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.h2 {
  font-size: clamp(20px, 2.5vw, 26px);
  font-weight: 800;
  letter-spacing: -0.3px;
  margin: 0 0 var(--s3) 0;
  line-height: 1.3;
}

.h3 {
  font-size: clamp(18px, 2vw, 22px);
  font-weight: 700;
  letter-spacing: -0.2px;
  margin: 0 0 var(--s2) 0;
  line-height: 1.3;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.small {
  font-size: 13px;
  color: var(--muted2);
  line-height: 1.5;
}

.nowrap {
  white-space: nowrap;
}

.text-center {
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ============================================
   Layout Utilities
   ============================================ */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gap {
  gap: var(--s3);
}

.gap-sm {
  gap: var(--s2);
}

.gap-lg {
  gap: var(--s4);
}

.wrap {
  flex-wrap: wrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--s3);
}

.stat {
  grid-column: span 12;
  padding: var(--s4);
  border-radius: var(--r);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.22);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(255, 255, 255, 0.18);
}

/* ============================================
   Forms
   ============================================ */

.select,
.input,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.select:hover,
.input:hover,
textarea:hover {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.32);
}

.select:focus,
.input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78, 161, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
}

.select::placeholder,
.input::placeholder,
textarea::placeholder {
  color: var(--muted2);
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.checkbox {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  user-select: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--r-xs);
  transition: background var(--transition-fast);
}

.checkbox:hover {
  background: rgba(255, 255, 255, 0.03);
}

.checkbox input {
  margin-top: 3px;
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 12px 20px;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
  transition: width var(--transition-base), height var(--transition-base);
}

.btn:hover::before {
  width: 300px;
  height: 300px;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: linear-gradient(135deg, 
    rgba(78, 161, 255, 0.95), 
    rgba(78, 161, 255, 0.75));
  border-color: rgba(78, 161, 255, 0.6);
  color: #0a1525;
  font-weight: 800;
  box-shadow: var(--shadow-sm);
}

.btn.primary:hover {
  background: linear-gradient(135deg, 
    rgba(78, 161, 255, 1), 
    rgba(78, 161, 255, 0.85));
  box-shadow: var(--shadow2), var(--glow-primary);
  transform: translateY(-3px);
}

.btn.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.18);
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn.danger {
  background: rgba(255, 78, 106, 0.14);
  border-color: rgba(255, 78, 106, 0.5);
  color: rgba(255, 255, 255, 0.95);
}

.btn.danger:hover {
  background: rgba(255, 78, 106, 0.22);
  border-color: rgba(255, 78, 106, 0.65);
  box-shadow: var(--shadow-sm), var(--glow-danger);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================
   Badges & Pills
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--r-full);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: var(--r-full);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.pill.ok {
  border-color: rgba(49, 209, 139, 0.4);
  background: rgba(49, 209, 139, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

.pill.danger {
  border-color: rgba(255, 78, 106, 0.4);
  background: rgba(255, 78, 106, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

.pill.warn {
  border-color: rgba(255, 204, 102, 0.4);
  background: rgba(255, 204, 102, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

/* ============================================
   Alerts / Notices
   ============================================ */

.notice {
  border-radius: var(--r);
  padding: 14px 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  margin-bottom: var(--s4);
  line-height: 1.6;
}

.notice.success {
  border-color: rgba(49, 209, 139, 0.4);
  background: rgba(49, 209, 139, 0.12);
}

.notice.danger {
  border-color: rgba(255, 78, 106, 0.4);
  background: rgba(255, 78, 106, 0.12);
}

.notice.warn {
  border-color: rgba(255, 204, 102, 0.4);
  background: rgba(255, 204, 102, 0.12);
}

.notice.info {
  border-color: rgba(78, 161, 255, 0.4);
  background: rgba(78, 161, 255, 0.12);
}

/* ============================================
   Dividers
   ============================================ */

.divider {
  height: 1px;
  background: linear-gradient(90deg, 
    transparent, 
    rgba(255, 255, 255, 0.12), 
    transparent);
  margin: var(--s4) 0;
}

/* ============================================
   App-Specific Components
   ============================================ */

.app-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s4);
  padding-bottom: var(--s4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: var(--s4);
}

/* HUD */
.hud {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
}

.hud-item {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.22);
  min-width: 120px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.hud-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(255, 255, 255, 0.2);
}

.hud-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-value {
  font-weight: 900;
  font-size: 18px;
  margin-top: 4px;
  letter-spacing: -0.3px;
}

/* Content */
.content {
  padding: var(--s3) 0;
}

/* Options */
.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 14px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.opt:hover {
  background: rgba(0, 0, 0, 0.28);
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateX(4px);
}

.opt input {
  margin-top: 3px;
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.opt .opt-text {
  line-height: 1.6;
  flex: 1;
}

.opt.is-selected {
  border-color: rgba(78, 161, 255, 0.6);
  background: rgba(78, 161, 255, 0.12);
  box-shadow: 0 0 20px rgba(78, 161, 255, 0.15);
}

/* Footer Actions */
.footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s3);
  margin-top: var(--s5);
  flex-wrap: wrap;
}

/* ============================================
   KPI Grid
   ============================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s3);
}

.kpi {
  padding: var(--s4);
  border-radius: var(--r);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(135deg, 
    rgba(0, 0, 0, 0.25), 
    rgba(0, 0, 0, 0.15));
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: 60px;
  background: radial-gradient(circle, rgba(78, 161, 255, 0.15), transparent 70%);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.kpi:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow2);
  border-color: rgba(255, 255, 255, 0.2);
}

.kpi:hover::before {
  opacity: 1;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-weight: 900;
  font-size: 24px;
  margin-top: 8px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================
   Tables
   ============================================ */

.table-wrap {
  overflow: auto;
  border-radius: var(--r);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.2);
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.table th,
.table td {
  text-align: left;
  padding: 14px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
}

.table th {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
  background: rgba(0, 0, 0, 0.15);
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* ============================================
   Form Grid
   ============================================ */

.form-grid {
  display: grid;
  gap: var(--s4);
  max-width: 540px;
}

.field {
  display: flex;
  flex-direction: column;
}

.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
}

/* ============================================
   Footer
   ============================================ */

.footnote {
  padding: var(--s6) var(--s4);
  color: var(--muted2);
  text-align: center;
  font-size: 13.5px;
  line-height: 1.7;
}

/* ============================================
   RTL Support
   ============================================ */

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .top-actions {
  justify-content: flex-start;
}

html[dir="rtl"] .table th,
html[dir="rtl"] .table td {
  text-align: right;
}

html[dir="rtl"] .opt:hover {
  transform: translateX(-4px);
}

/* Fix all hover transforms to prevent horizontal overflow in RTL */
html[dir="rtl"] .stat:hover {
  transform: translateY(-2px) translateX(0);
}

html[dir="rtl"] .card:hover {
  transform: translateY(-2px) translateX(0);
}

html[dir="rtl"] .kpi:hover {
  transform: translateY(-4px) translateX(0);
}

html[dir="rtl"] .hud-item:hover {
  transform: translateY(-2px) translateX(0);
}

/* Fix pseudo-element gradient positioning in RTL */
html[dir="rtl"] .card::before {
  background: radial-gradient(
    circle at 70% 20%, 
    rgba(78, 161, 255, 0.08) 0%, 
    transparent 60%
  );
}

html[dir="rtl"] .kpi::before {
  right: auto;
  left: 0;
}

html[dir="rtl"] .topbar::before {
  background: linear-gradient(90deg, 
    rgba(49, 209, 139, 0.05) 0%, 
    transparent 50%, 
    rgba(78, 161, 255, 0.05) 100%);
}

/* Fix checkbox and button alignment in RTL */
html[dir="rtl"] .checkbox {
  flex-direction: row-reverse;
}

html[dir="rtl"] .checkbox input {
  margin-left: 10px;
  margin-right: 0;
}

html[dir="rtl"] .btn {
  flex-direction: row-reverse;
}

/* Fix brand alignment in RTL */
html[dir="rtl"] .brand {
  flex-direction: row-reverse;
}

/* Prevent overflow from transforms */
html[dir="rtl"] .container,
html[dir="rtl"] .container-wide,
html[dir="rtl"] .container-tight {
  overflow-x: hidden;
}

/* Additional overflow protection */
html[dir="rtl"] main {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

html[dir="rtl"] section {
  overflow-x: hidden;
}


/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

@media (max-width: 820px) {
  .container,
  .container-wide,
  .container-tight {
    padding: var(--s5) var(--s3);
  }

  .card {
    padding: var(--s4);
  }

  .topbar {
    padding: var(--s3);
  }

  .brand {
    min-width: auto;
  }

  .logo {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .titleblock .title {
    font-size: 16px;
  }

  .hud {
    flex-direction: column;
    align-items: stretch;
  }

  .hud-item {
    min-width: 0;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi {
    padding: var(--s3);
  }

  .kpi-value {
    font-size: 20px;
  }

  .top-actions {
    gap: var(--s2);
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .table th,
  .table td {
    padding: 12px 10px;
    font-size: 13px;
  }

  .footer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .footer-actions .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  :root {
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s5: 20px;
    --s6: 28px;
  }

  .container,
  .container-wide,
  .container-tight {
    padding: var(--s5) var(--s2);
  }

  .card {
    padding: var(--s3);
    border-radius: var(--r);
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .h1 {
    font-size: 22px;
  }

  .h2 {
    font-size: 18px;
  }

  .titleblock .title {
    font-size: 15px;
  }

  .titleblock .subtitle {
    font-size: 11px;
  }
}

/* ============================================
   Motion Safety
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  body {
    background: white;
    color: black;
  }

  .topbar,
  .skip-link,
  .btn,
  .footer-actions {
    display: none;
  }

  .card {
    border: 1px solid #ddd;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .table {
    border: 1px solid #ddd;
  }

  .table th,
  .table td {
    border: 1px solid #ddd;
  }
}

/* ============================================
   Custom Scrollbar (Webkit)
   ============================================ */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  border: 2px solid rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   Selection
   ============================================ */

::selection {
  background: rgba(78, 161, 255, 0.3);
  color: var(--text);
}

::-moz-selection {
  background: rgba(78, 161, 255, 0.3);
  color: var(--text);
}

/* ============================================
   Utility Classes
   ============================================ */

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--s1) !important; }
.mb-2 { margin-bottom: var(--s2) !important; }
.mb-3 { margin-bottom: var(--s3) !important; }
.mb-4 { margin-bottom: var(--s4) !important; }
.mb-5 { margin-bottom: var(--s5) !important; }
.mb-6 { margin-bottom: var(--s6) !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--s1) !important; }
.mt-2 { margin-top: var(--s2) !important; }
.mt-3 { margin-top: var(--s3) !important; }
.mt-4 { margin-top: var(--s4) !important; }
.mt-5 { margin-top: var(--s5) !important; }
.mt-6 { margin-top: var(--s6) !important; }

.p-0 { padding: 0 !important; }
.p-1 { padding: var(--s1) !important; }
.p-2 { padding: var(--s2) !important; }
.p-3 { padding: var(--s3) !important; }
.p-4 { padding: var(--s4) !important; }
.p-5 { padding: var(--s5) !important; }
.p-6 { padding: var(--s6) !important; }

.text-left { text-align: left !important; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }

.font-bold { font-weight: 700 !important; }
.font-black { font-weight: 900 !important; }

.opacity-50 { opacity: 0.5 !important; }
.opacity-75 { opacity: 0.75 !important; }

.pointer { cursor: pointer !important; }
.no-select { user-select: none !important; }