/* ════════════════════════════════════════════════════════════════════════════
   ICHI OS — Unified Design System v4.0
   Shared by all 17 Ichi OS apps. Import once, consistent everywhere.
   
   v4.0: Native-feel SPA transitions, glassmorphism v2, data display system,
   micro-interaction presets, metric cards, position tables, live indicators.
   v3.0: Mobile-native experience — bottom tab bar, iOS safe areas,
   touch-optimized, gesture-ready, collapsible sidebar, PWA enhanced.
   Dark-first with full light theme support.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ──────────────────────────────────────────────────────── */
:root {
  /* Dark theme (default) */
  --bg:           #080a10;
  --bg2:          #0e1118;
  --bg3:          #151822;
  --bg4:          #1c2030;
  --surface:      rgba(18, 22, 32, 0.7);
  --surface-h:    rgba(24, 28, 42, 0.85);
  --border:       rgba(255,255,255,0.06);
  --border-h:     rgba(255,255,255,0.12);
  --text:         #dde3ed;
  --text2:        #7a8499;
  --text3:        #454e63;
  --accent:       #5b8af5;
  --accent-glow:  rgba(91,138,245,0.2);
  --accent2:      #a78bfa;
  --success:      #34d399;
  --danger:       #f87171;
  --warning:      #fbbf24;
  --info:         #38bdf8;
  
  /* v4.0: Extended palette */
  --accent-soft:   rgba(91,138,245,0.08);
  --success-soft:  rgba(52,211,153,0.08);
  --danger-soft:   rgba(248,113,113,0.08);
  --warning-soft:  rgba(251,191,36,0.08);
  --info-soft:     rgba(56,189,248,0.08);
  
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:    0 8px 24px rgba(0,0,0,0.5);
  --shadow-lg:    0 16px 48px rgba(0,0,0,0.6);
  --glow:         0 0 32px rgba(91,138,245,0.12);
  
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    18px;
  --radius-xl:    24px;
  --radius-full:  9999px;
  
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:         'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  
  --topbar-h:     56px;
  --sidebar-w:    260px;
  --sidebar-collapsed: 56px;
  --tabbar-h:     64px;
  
  --transition:   0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-spring: 0.5s cubic-bezier(0.22, 1.2, 0.36, 1);
  /* v4.0: faster transitions for micro-interactions */
  --transition-fast: 0.12s cubic-bezier(0.16, 1, 0.3, 1);

  /* Depth elevation steps */
  --elevation-0:  rgba(0,0,0,0);
  --elevation-1:  0 1px 2px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.04);
  --elevation-2:  0 4px 12px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06);
  --elevation-3:  0 8px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.08);
  --elevation-4:  0 16px 48px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.1);
}

/* ── Light theme ──────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f5f6fa;
  --bg2:          #eef0f5;
  --bg3:          #e4e7f0;
  --bg4:          #d8dce8;
  --surface:      rgba(228, 231, 240, 0.75);
  --surface-h:    rgba(216, 220, 232, 0.9);
  --border:       rgba(0,0,0,0.08);
  --border-h:     rgba(0,0,0,0.15);
  --text:         #1a1d2e;
  --text2:        #5a6178;
  --text3:        #8a91a8;
  --accent:       #4a73e8;
  --accent-glow:  rgba(74,115,232,0.15);
  --accent2:      #8b5cf6;
  --accent-soft:   rgba(74,115,232,0.06);
  --success-soft:  rgba(52,211,153,0.06);
  --danger-soft:   rgba(248,113,113,0.06);
  --warning-soft:  rgba(251,191,36,0.06);
  --info-soft:     rgba(56,189,248,0.06);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.12);
  --shadow-md:    0 8px 24px rgba(0,0,0,0.15);
  --shadow-lg:    0 16px 48px rgba(0,0,0,0.2);
  --glow:         0 0 32px rgba(74,115,232,0.08);
  --elevation-1:  0 1px 2px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
  --elevation-2:  0 4px 12px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.06);
  --elevation-3:  0 8px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.08);
  --elevation-4:  0 16px 48px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.1);
}

/* ── RESET ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: rgba(91,138,245,0.3); color: var(--text); }
html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overscroll-behavior: none;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: auto;
  user-select: auto;
  touch-action: manipulation;
}
input, textarea, [contenteditable], .selectable {
  -webkit-user-select: text;
  user-select: text;
}

/* ── SCROLLBAR ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── TYPOGRAPHY ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
.text-mono { font-family: var(--mono); font-size: 0.8125rem; }
.text-xs   { font-size: 0.75rem; }
.text-sm   { font-size: 0.8125rem; }
.text-base { font-size: 0.9375rem; }
.text-lg   { font-size: 1.125rem; }
.text-xl   { font-size: 1.5rem; }
.text-2xl  { font-size: 2rem; }

/* ── LAYOUT COMPONENTS ──────────────────────────────────────────────────── */

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--elevation-1);
  backdrop-filter: blur(12px);
  transition: all var(--transition);
}
.card:hover {
  border-color: var(--border-h);
  box-shadow: var(--elevation-2);
  transform: translateY(-1px);
}
.card:active { transform: scale(0.99); }
.card-glass {
  background: rgba(18,22,32,0.5);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.875rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
  text-decoration: none; color: inherit;
  white-space: nowrap;
  min-height: 44px;
  position: relative; overflow: hidden;
}
.btn::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 10%, transparent 70%);
  opacity: 0; transition: opacity 0.3s;
}
.btn:active::after { opacity: 1; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-secondary {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg4); border-color: var(--border-h); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--danger); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-xs { padding: 5px 10px; font-size: 0.75rem; border-radius: 6px; min-height: 32px; }
.btn-sm { padding: 7px 14px; font-size: 0.8125rem; min-height: 36px; }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--radius-md); min-height: 52px; }
.btn-icon {
  width: 44px; height: 44px; padding: 0; border-radius: var(--radius-full);
  font-size: 1.25rem;
}

/* Badges / Tags */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.02em;
  line-height: 1.5;
}
.badge-success { background: rgba(52,211,153,0.15); color: var(--success); }
.badge-warning { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-danger  { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-info    { background: rgba(56,189,248,0.15); color: var(--info); }
.badge-accent  { background: rgba(91,138,245,0.15); color: var(--accent); }

/* Inputs */
.input {
  width: 100%; padding: 10px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.875rem; min-height: 44px;
  color: var(--text); outline: none;
  transition: all var(--transition);
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input::placeholder { color: var(--text3); }

/* Toast notifications */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 10000;
  background: var(--surface-h); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 20px;
  box-shadow: var(--elevation-3); backdrop-filter: blur(16px);
  font-size: 0.875rem; max-width: 360px;
  animation: slideInRight 0.3s var(--transition-bounce);
  bottom: max(24px, calc(env(safe-area-inset-bottom, 16px) + 8px));
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── BOTTOM TAB BAR (mobile navigation) ──────────────────────────── */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: space-around;
  height: var(--tabbar-h);
  background: var(--surface-h);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 0 4px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  animation: tabBarIn 0.4s var(--transition-spring);
}
@keyframes tabBarIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.tab-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 12px;
  min-width: 56px; min-height: 48px;
  border-radius: var(--radius-md);
  font-size: 0.625rem; font-weight: 600; color: var(--text2);
  text-decoration: none; transition: all var(--transition);
  position: relative;
}
.tab-item .tab-icon { font-size: 1.375rem; line-height: 1; }
.tab-item.active {
  color: var(--accent);
}
.tab-item.active::before {
  content: ''; position: absolute; top: -1px; left: 50%; transform: translateX(-50%);
  width: 24px; height: 2px; background: var(--accent);
  border-radius: 0 0 2px 2px;
}
.tab-item:active { background: var(--bg3); }

/* ── COLLAPSIBLE SIDEBAR ─────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 8000;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: transform var(--transition-slow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 7999;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.3s ease;
}

/* ── PAGE TRANSITIONS ────────────────────────────────────────────── */
.page-enter {
  animation: pageIn 0.35s var(--transition-slow);
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.page-exit {
  animation: pageOut 0.2s ease forwards;
}
@keyframes pageOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ── MOBILE RESPONSIVE ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html { font-size: 13px; }
  .card { padding: 14px; }
  .hide-mobile { display: none !important; }
  .show-mobile { display: flex !important; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .sidebar-toggle { display: flex !important; }
}
@media (max-width: 640px) {
  .app-container { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .modal { max-width: 100%; border-radius: var(--radius-md); }
  .tab-bar { display: flex; }
  body.has-tab-bar { padding-bottom: var(--tabbar-h); }
  .desktop-nav { display: none !important; }
}
@media (max-width: 480px) {
  html { font-size: 12px; }
  .btn { padding: 8px 16px; font-size: 0.8125rem; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .card { border-radius: 0; border-left: none; border-right: none; }
  .card:first-child { border-top: none; }
  .app-container { padding: 0; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
}
@media (max-width: 360px) {
  html { font-size: 11px; }
  .tab-item { min-width: 44px; padding: 4px 8px; }
}
@media (min-width: 1025px) {
  .tab-bar { display: none; }
  .show-mobile { display: none; }
  .sidebar-toggle { display: none; }
  .sidebar-overlay { display: none; }
}
@media (min-width: 769px) and (max-width: 1024px) {
  .tab-bar { display: none; }
}

/* ── iOS SAFE AREA UTILITIES ──────────────────────────────────────── */
.safe-top    { padding-top: env(safe-area-inset-top, 0); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0); }
.safe-left   { padding-left: env(safe-area-inset-left, 0); }
.safe-right  { padding-right: env(safe-area-inset-right, 0); }
@media (display-mode: standalone) {
  body { padding-top: env(safe-area-inset-top, 0); }
}

/* ── UTILITY CLASSES ────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-xs { gap: 4px; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.p-sm { padding: 8px; }
.p-md { padding: 16px; }
.p-lg { padding: 24px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text2); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── SKELETON LOADING ───────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-text { height: 14px; margin-bottom: 8px; border-radius: 4px; }
.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }
.skeleton-title { height: 20px; width: 40%; margin-bottom: 16px; border-radius: 4px; }
.skeleton-card { height: 80px; margin-bottom: 12px; border-radius: var(--radius-sm); }
.skeleton-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); flex-shrink: 0; }

/* ── EMPTY STATE ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; gap: 12px;
}
.empty-state-icon { font-size: 3rem; opacity: 0.4; margin-bottom: 4px; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--text2); }
.empty-state-desc { font-size: 0.8125rem; color: var(--text3); max-width: 320px; line-height: 1.5; }
.empty-state-action { margin-top: 8px; }

/* ── MODAL / DIALOG ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--elevation-3);
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  animation: modalIn 0.3s var(--transition-bounce);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 12px;
}
.modal-header h3 { font-size: 1.125rem; }
.modal-close {
  background: none; border: none; color: var(--text3); font-size: 1.25rem;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; transition: all var(--transition);
  min-width: 44px; min-height: 44px;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal-body { padding: 12px 24px 20px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 0 24px 20px;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.97); } }

/* ── TOAST ENHANCEMENTS ──────────────────────────────────────────────────── */
.toast-top { bottom: auto; top: 24px; animation: slideInDown 0.3s var(--transition-bounce); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }
.toast-warning { border-left: 3px solid var(--warning); }
@keyframes slideInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-exit { animation: slideOutRight 0.25s ease forwards; }
@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

/* ── TABLE STYLES ────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.ichi-table {
  width: 100%; border-collapse: collapse; font-size: 0.8125rem;
}
.ichi-table th {
  text-align: left; padding: 10px 14px;
  font-weight: 600; font-size: 0.6875rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text2);
  border-bottom: 1px solid var(--border);
}
.ichi-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.ichi-table tr:hover td { background: var(--bg3); }
.ichi-table tr:last-child td { border-bottom: none; }

/* ── STAT CARD ───────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 16px;
  backdrop-filter: blur(8px);
  box-shadow: var(--elevation-1);
  transition: all var(--transition);
}
.stat-card:hover {
  border-color: var(--border-h);
  box-shadow: var(--elevation-2);
  transform: translateY(-1px);
}
.stat-label {
  font-size: 0.6875rem; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.stat-value {
  font-size: 1.5rem; font-weight: 800; font-family: var(--mono);
  letter-spacing: -0.02em; margin-top: 2px;
}
.stat-delta { font-size: 0.75rem; margin-top: 2px; }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ── APP TOPBAR (shared pattern) ─────────────────────────────────────────── */
.app-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; margin-bottom: 24px;
  flex-wrap: wrap; gap: 12px;
  padding-top: max(12px, env(safe-area-inset-top, 0));
}
.app-brand { font-size: 1.125rem; font-weight: 800; }
.app-brand span {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.app-container {
  max-width: 1100px; margin: 0 auto; padding: 20px 24px; min-height: 100dvh;
  padding-bottom: max(20px, calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0) + 16px));
}

/* ── WIDGET GRID (Hub dashboard) ──────────────────────────────────── */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(12px);
  box-shadow: var(--elevation-1);
  transition: all var(--transition);
  cursor: pointer;
  position: relative; overflow: hidden;
}
.widget::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  opacity: 0; transition: opacity var(--transition);
}
.widget:hover {
  border-color: var(--border-h);
  box-shadow: var(--elevation-3);
  transform: translateY(-2px);
}
.widget:hover::before { opacity: 1; }
.widget:active { transform: scale(0.99); }
.widget-icon { font-size: 2rem; margin-bottom: 12px; }
.widget-title { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.widget-desc { font-size: 0.8125rem; color: var(--text2); line-height: 1.4; }
.widget-meta {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  font-size: 0.6875rem; color: var(--text3);
}

/* ── QUICK ACTIONS ROW ────────────────────────────────────────────── */
.quick-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px;
}
.quick-action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.8125rem; font-weight: 600; color: var(--text);
  cursor: pointer; transition: all var(--transition);
  text-decoration: none;
  min-height: 40px;
}
.quick-action:hover { background: var(--bg4); border-color: var(--accent); }
.quick-action:active { transform: scale(0.97); }

/* ── STATUS DOT ───────────────────────────────────────────────────── */
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.warning { background: var(--warning); }

/* ── LINK / ANCHOR RESET ─────────────────────────────────────────────────── */
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent2); }

/* ── KEYBOARD SHORTCUT ───────────────────────────────────────────────────── */
kbd {
  display: inline-block; padding: 2px 6px;
  font-family: var(--mono); font-size: 0.6875rem;
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text2);
}

/* ── TOOLTIP ──────────────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--bg4); color: var(--text);
  padding: 4px 10px; border-radius: var(--radius-sm);
  font-size: 0.75rem; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
  margin-bottom: 6px;
}
[data-tooltip]:hover::after { opacity: 1; }

/* ── PROGRESS BAR ─────────────────────────────────────────────────── */
.progress {
  height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px; transition: width 0.6s var(--transition-slow);
}

/* ── SMOOTH ENTRANCE ANIMATIONS ──────────────────────────────────────────── */
.entrance { animation: fadeSlideUp 0.4s var(--transition-bounce); animation-fill-mode: both; }
.entrance-delay-1 { animation-delay: 0.05s; animation-fill-mode: both; }
.entrance-delay-2 { animation-delay: 0.1s; animation-fill-mode: both; }
.entrance-delay-3 { animation-delay: 0.15s; animation-fill-mode: both; }
.entrance-delay-4 { animation-delay: 0.2s; animation-fill-mode: both; }
.entrance-delay-5 { animation-delay: 0.25s; animation-fill-mode: both; }
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
}

/* ── HARDWARE-ACCELERATED ANIMATIONS ───────────────────────────────── */
.gpu { will-change: transform; transform: translateZ(0); }

/* ── RESPONSIVE VISIBILITY ─────────────────────────────────────────── */
.show-mobile { display: none !important; }
@media (max-width: 768px) {
  .show-mobile { display: flex !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   V4.0 — NEW COMPONENTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── v4.0: SHELL TRANSITIONS (SPA-like navigation) ──────────────────────── */
.shell-view {
  position: absolute; inset: 0;
  opacity: 0; transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s var(--transition);
  pointer-events: none;
  overflow-y: auto;
}
.shell-view.active {
  opacity: 1; transform: translateY(0);
  pointer-events: auto;
}
.shell-view.exiting {
  opacity: 0; transform: translateY(-6px);
}
/* v4.0: Shell iframe container */
.shell-iframe-wrap {
  position: relative; width: 100%; height: 100%;
}
.shell-iframe-wrap iframe {
  width: 100%; height: 100%; border: none; background: var(--bg);
  opacity: 0; transition: opacity 0.3s ease;
}
.shell-iframe-wrap iframe.loaded { opacity: 1; }
.shell-iframe-wrap .iframe-loader {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; transition: opacity 0.2s;
}
.shell-iframe-wrap .iframe-loader.hidden { opacity: 0; }

/* ── v4.0: GLASS PANEL (rich glassmorphism) ─────────────────────────────── */
.panel-glass {
  background: linear-gradient(135deg, 
    rgba(18,22,32,0.75) 0%, 
    rgba(24,28,42,0.65) 100%);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-lg);
  box-shadow: 
    0 8px 32px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.04);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.panel-glass:hover {
  border-color: rgba(255,255,255,0.1);
  box-shadow: 
    0 12px 40px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ── v4.0: METRIC CARD (for dashboard stats) ────────────────────────────── */
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--elevation-1);
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.metric-card::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 80px; height: 80px;
  background: radial-gradient(circle at top right, var(--accent-soft), transparent 70%);
  opacity: 0; transition: opacity var(--transition);
}
.metric-card:hover::after { opacity: 1; }
.metric-card:hover {
  border-color: var(--border-h);
  transform: translateY(-1px);
  box-shadow: var(--elevation-2);
}
.metric-label {
  font-size: 0.625rem; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px;
}
.metric-value {
  font-size: 1.75rem; font-weight: 800; font-family: var(--mono);
  letter-spacing: -0.03em; color: var(--text);
}
.metric-value.gain { color: var(--success); }
.metric-value.loss { color: var(--danger); }
.metric-sub {
  font-size: 0.6875rem; color: var(--text2); margin-top: 4px;
  font-family: var(--mono);
}
.metric-icon {
  position: absolute; top: 14px; right: 16px;
  font-size: 1.5rem; opacity: 0.2;
}

/* ── v4.0: DATA ROW (key-value pairs) ───────────────────────────────────── */
.data-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}
.data-row:last-child { border-bottom: none; }
.data-key { color: var(--text2); }
.data-val { font-weight: 600; font-family: var(--mono); font-size: 0.8125rem; }
.data-val.up { color: var(--success); }
.data-val.down { color: var(--danger); }
.data-val.accent { color: var(--accent); }

/* ── v4.0: POSITION ROW (trading positions) ─────────────────────────────── */
.position-row {
  display: grid; grid-template-columns: 80px 60px 1fr 90px 80px;
  align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: all var(--transition);
  font-size: 0.8125rem;
}
.position-row:hover {
  border-color: var(--border-h);
  box-shadow: var(--elevation-1);
  transform: translateX(2px);
}
.position-symbol { font-weight: 700; font-family: var(--mono); }
.position-type { font-size: 0.6875rem; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.position-type.buy { background: var(--success-soft); color: var(--success); }
.position-type.sell { background: var(--danger-soft); color: var(--danger); }
.position-entry { font-size: 0.75rem; color: var(--text2); font-family: var(--mono); }
.position-pl { font-weight: 700; font-family: var(--mono); text-align: right; }
.position-pl.up { color: var(--success); }
.position-pl.down { color: var(--danger); }
.position-actions { text-align: right; }
@media (max-width: 640px) {
  .position-row { grid-template-columns: 70px 50px 1fr 70px; }
  .position-actions { display: none; }
}
@media (max-width: 400px) {
  .position-row { grid-template-columns: 1fr 1fr; gap: 4px; }
  .position-entry, .position-actions { display: none; }
}

/* ── v4.0: SECTION HEADER ────────────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title {
  font-size: 0.8125rem; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.section-count {
  font-size: 0.6875rem; color: var(--text3);
  background: var(--bg3); padding: 2px 8px; border-radius: var(--radius-full);
}

/* ── v4.0: LIVE PULSE (animated status indicator) ────────────────────────── */
.live-pulse {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  position: relative;
}
.live-pulse::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--success);
  animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* ── v4.0: GLASS BADGE ──────────────────────────────────────────────────── */
.glass-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-full);
  font-size: 0.6875rem; font-weight: 600; color: var(--text2);
  backdrop-filter: blur(8px);
}

/* ── v4.0: CHIP/TAG INPUT ────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.6875rem; font-weight: 500; color: var(--text2);
  transition: all var(--transition-fast);
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip .chip-x { cursor: pointer; opacity: 0.5; font-size: 0.75rem; margin-left: 2px; }
.chip .chip-x:hover { opacity: 1; color: var(--danger); }

/* ── v4.0: DASHBOARD GRID (2-col adaptive) ───────────────────────────────── */
.dash-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px; align-items: start;
}
@media (max-width: 768px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── v4.0: PANEL (content section) ───────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 20px;
  box-shadow: var(--elevation-1);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.panel-title {
  font-size: 0.875rem; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.panel-title .icon { font-size: 1.125rem; }

/* ── v4.0: MICRO-INTERACTION PRESETS ─────────────────────────────────────── */
.hover-lift { transition: transform var(--transition-fast), box-shadow var(--transition-fast); }
.hover-lift:hover { transform: translateY(-2px); box-shadow: var(--elevation-2); }
.press-scale { transition: transform var(--transition-fast); }
.press-scale:active { transform: scale(0.97); }
.hover-glow { transition: box-shadow var(--transition); }
.hover-glow:hover { box-shadow: 0 0 20px var(--accent-glow); }
.shimmer-line {
  position: relative; overflow: hidden;
}
.shimmer-line::after {
  content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: shimmer-sweep 3s ease-in-out infinite;
}
@keyframes shimmer-sweep {
  0% { left: -100%; }
  50% { left: 100%; }
  100% { left: 100%; }
}

/* ── v4.0: CONNECTION BADGE ─────────────────────────────────────────────── */
.conn-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem; font-weight: 600;
}
.conn-badge.online { background: var(--success-soft); color: var(--success); }
.conn-badge.offline { background: var(--danger-soft); color: var(--danger); }
.conn-badge.loading { background: var(--warning-soft); color: var(--warning); }

/* ── v4.0: TABS (horizontal) ─────────────────────────────────────────────── */
.tabs-row {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.tab-btn {
  padding: 8px 18px;
  background: transparent; border: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 0.8125rem; font-weight: 500; color: var(--text2);
  cursor: pointer; transition: all var(--transition-fast);
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); background: var(--bg3); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

/* ── v4.0: SEARCH BAR ────────────────────────────────────────────────────── */
.search-bar {
  position: relative; max-width: 480px;
}
.search-bar input {
  width: 100%; padding: 10px 16px 10px 40px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font); font-size: 0.875rem; color: var(--text);
  outline: none; transition: all var(--transition);
  min-height: 44px;
}
.search-bar input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-bar input::placeholder { color: var(--text3); }
.search-bar::before {
  content: '🔍'; position: absolute; left: 14px; top: 50%;
  transform: translateY(-50%); font-size: 0.8125rem; opacity: 0.5;
}

/* ── v4.0: NOTIFICATION DOT ──────────────────────────────────────────────── */
.notif-dot {
  position: relative;
}
.notif-dot::after {
  content: attr(data-count);
  position: absolute; top: -4px; right: -8px;
  min-width: 18px; height: 18px;
  background: var(--danger); color: #fff;
  border-radius: var(--radius-full);
  font-size: 0.625rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.notif-dot[data-count="0"]::after { display: none; }

/* ── v4.0: SKELETON DASHBOARD (matched to dashboard layout) ──────────────── */
.skeleton-dash {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.skeleton-dash .skeleton { height: 90px; border-radius: var(--radius-md); }
@media (max-width: 768px) { .skeleton-dash { grid-template-columns: repeat(2, 1fr); } }

/* ── v4.0: SKELETON PANEL (panel with title + rows) ──────────────────────── */
.skeleton-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 20px;
}
.skeleton-panel .skeleton-title { margin-bottom: 16px; }
.skeleton-panel .skeleton-text { margin-bottom: 10px; }

/* ── v4.0: QUICK STAT STRIP ──────────────────────────────────────────────── */
.quick-stats {
  display: flex; gap: 12px; flex-wrap: wrap;
}
.quick-stat {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  transition: all var(--transition-fast);
}
.quick-stat:hover { border-color: var(--accent); }
.quick-stat .qs-icon { font-size: 1rem; }
.quick-stat .qs-val { font-weight: 700; font-family: var(--mono); }

/* ── v4.0: PAGE HEADER ───────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 20px;
}
.page-header h1 {
  font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em;
  display: flex; align-items: center; gap: 8px;
}
.page-header p {
  font-size: 0.8125rem; color: var(--text2); margin-top: 4px;
}

/* ── v4.0: GRADIENT TEXT ─────────────────────────────────────────────────── */
.gradient-text {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── v4.0: DIVIDER ───────────────────────────────────────────────────────── */
.divider {
  height: 1px; background: var(--border); margin: 16px 0;
}
.divider-soft {
  height: 1px; 
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 16px 0;
}

/* ── v4.0: TOGGLE SWITCH ─────────────────────────────────────────────────── */
.toggle-switch {
  position: relative; width: 44px; height: 24px;
  background: var(--bg4); border-radius: 12px;
  cursor: pointer; transition: background var(--transition-fast);
  border: 1px solid var(--border);
}
.toggle-switch.active { background: var(--accent); border-color: var(--accent); }
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  transition: transform var(--transition-fast);
}
.toggle-switch.active::after { transform: translateX(20px); }
