/* ========= Design Tokens ========= */
:root {
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: rgba(37, 99, 235, 0.10);
  --brand-ring: rgba(37, 99, 235, 0.18);
  --up-color: #ef4444;
  --up-soft: rgba(239, 68, 68, 0.10);
  --up-bg: rgba(239, 68, 68, 0.06);
  --down-color: #10b981;
  --down-soft: rgba(16, 185, 129, 0.10);
  --down-bg: rgba(16, 185, 129, 0.06);
  --flat-color: #64748b;
  --bg-app: #f4f6fa;
  --bg-app-grad: radial-gradient(1200px 600px at 100% -10%, rgba(37,99,235,0.06), transparent 60%), radial-gradient(900px 500px at -10% 0%, rgba(239,68,68,0.04), transparent 60%);
  --bg-card: #ffffff;
  --bg-elev: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-overlay: rgba(15, 23, 42, 0.42);
  --text-main: #0b1220;
  --text-secondary: #475569; /* Slate 600: Increased contrast for primary details */
  --text-muted: #64748b;     /* Slate 500: Meets WCAG AA contrast of 4.5:1 on white background */
  --border-color: #e6e8ee;
  --border-strong: #cdd2db;
  --border-soft: #eef0f4;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 8px 24px -10px rgba(15, 23, 42, 0.14), 0 4px 10px -6px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 22px 48px -16px rgba(15, 23, 42, 0.22), 0 10px 22px -10px rgba(15, 23, 42, 0.10);
  --shadow-brand: 0 8px 22px -8px rgba(37, 99, 235, 0.45);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --control-height: 38px;
  --control-radius: 999px;
  --t-fast: 160ms cubic-bezier(.4,0,.2,1);
  --t-base: 240ms cubic-bezier(.4,0,.2,1);
  --t-slow: 320ms cubic-bezier(.4,0,.2,1);
  --spring: cubic-bezier(.34, 1.36, .54, 1);
  --transition: var(--t-base);
}

@media (prefers-color-scheme: dark) {
  /* dark mode intentionally disabled */
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: Inter, Outfit, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-feature-settings: "tnum";
  background-color: var(--bg-app);
  background-image: var(--bg-app-grad);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.5;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container { max-width: 1080px; margin: 0 auto; }

/* ========= Header ========= */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 12px; flex-wrap: wrap; }
.header h1 {
  font-size: clamp(20px, 5vw, 26px); font-weight: 800; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 8px;
  color: var(--text-main);
}
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.status-group {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-card); padding: 0 14px; border-radius: var(--control-radius);
  border: 1px solid var(--border-color); box-shadow: var(--shadow-xs);
  height: var(--control-height); box-sizing: border-box;
}
.tstat { font-size: 12px; font-weight: 700; color: var(--text-secondary); white-space: nowrap; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #10b981; position: relative; flex-shrink: 0;
}
.status-dot.trade { background: #10b981; }
.status-dot.call { background: var(--brand); }
.status-dot.close { background: #94a3b8; }
.status-dot.paused { background: #f59e0b; }

.badge {
  background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 800;
  padding: 0 7px; border-radius: 999px; min-width: 22px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.last-refresh { font-size: 11px; color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.last-refresh:empty { display: none; }

.view-toggle {
  --toggle-pad: 3px;
  display: inline-flex; background: var(--bg-card); padding: var(--toggle-pad); border-radius: var(--control-radius);
  border: 1px solid var(--border-color); box-shadow: var(--shadow-xs); gap: 2px;
  height: var(--control-height); box-sizing: border-box; align-items: center;
}
.view-toggle button {
  border: none; background: transparent;
  width: calc(var(--control-height) - var(--toggle-pad) * 2 - 2px);
  height: calc(var(--control-height) - var(--toggle-pad) * 2 - 2px);
  border-radius: var(--control-radius);
  cursor: pointer; transition: var(--t-base);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted);
}
.view-toggle button svg { width: 16px; height: 16px; fill: currentColor; }
.view-toggle button.active { background: var(--brand-soft); color: var(--brand); }
.view-toggle button:not(.active):hover { color: var(--text-secondary); }
.view-toggle button:active { transform: scale(0.92); }

/* ========= Search ========= */
.add-row { display: flex; margin-bottom: 8px; position: relative; z-index: 100; }
.search-wrap { position: relative; flex: 1; }
.search-wrap::before {
  content: "🔍"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; pointer-events: none; opacity: 0.55;
}
.search-wrap input {
  width: 100%; height: var(--control-height); padding: 0 16px 0 36px;
  border: 1px solid var(--border-color); border-radius: var(--control-radius);
  font-size: 14px; outline: none; background: var(--bg-card); color: var(--text-main);
  box-shadow: var(--shadow-xs); transition: var(--t-base);
}
.search-wrap input::placeholder { color: var(--text-muted); }
.search-wrap input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring), var(--shadow-sm);
}

.dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; background: var(--bg-card);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  overflow: hidden; display: none; z-index: 200;
  border: 1px solid var(--border-color);
}
.dropdown.open { display: block; animation: slideIn .22s var(--spring); }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ditem {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border-soft); transition: background var(--t-fast);
}
.ditem:last-child { border-bottom: none; }
.ditem:hover, .ditem.active { background: var(--bg-subtle); }
.ditem .dc {
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13px; font-weight: 700; color: var(--brand);
  background: var(--brand-soft); padding: 3px 8px; border-radius: 6px;
}
.ditem .dn { flex: 1; font-size: 15px; font-weight: 600; color: var(--text-main); }
.ditem .dm { font-size: 11px; color: var(--text-secondary); background: var(--bg-subtle); padding: 3px 8px; border-radius: 6px; font-weight: 600; }
.dropdown .sh { font-size: 11px !important; color: var(--text-muted) !important; text-align: center; padding: 10px !important; border-top: 1px solid var(--border-soft) !important; background: var(--bg-subtle); }

/* ========= Toolbar / Chips ========= */
.toolbar {
  position: sticky; top: max(0px, env(safe-area-inset-top));
  z-index: 80;
  display: flex; align-items: center; gap: 6px; margin: 0 -4px 6px;
  padding: 4px 4px; flex-wrap: nowrap;
  background: rgba(244, 246, 250, 0.78); /* High-end frosted glass background blending with app bg */
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid rgba(230, 232, 238, 0.4);
}
.toolbar > button, .toolbar .sort-toggle {
  padding: 0 10px; border-radius: 999px; border: 1px solid var(--border-color);
  background: var(--bg-card); font-size: 12px; font-weight: 700; color: var(--text-secondary);
  cursor: pointer; transition: var(--t-base); white-space: nowrap; flex-shrink: 0;
  height: 28px; display: inline-flex; align-items: center; justify-content: center;
}
.toolbar > button:active { transform: scale(0.96); }
.toolbar > button.active, #defaultBtn.active { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-brand); }

.sort-toggle { min-width: 32px; font-weight: 800; }
.sort-toggle.active-desc { color: var(--up-color); border-color: var(--up-color); background: var(--up-bg); }
.sort-toggle.active-asc { color: var(--down-color); border-color: var(--down-color); background: var(--down-bg); }

.chips-wrap {
  display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none;
  padding: 2px 0; flex: 1; min-width: 0;
  /* Default: no mask when no scrollable overflow */
  mask-image: none;
  -webkit-mask-image: none;
  transition: mask-image 0.2s, -webkit-mask-image 0.2s;
}

/* Has left overflow: fade out left side */
.chips-wrap.fade-left {
  mask-image: linear-gradient(to right, transparent, #000 12px, #000);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12px, #000);
}

/* Has right overflow: fade out right side */
.chips-wrap.fade-right {
  mask-image: linear-gradient(to right, #000, #000 calc(100% - 12px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000, #000 calc(100% - 12px), transparent);
}

/* Has both overflows: fade out both sides */
.chips-wrap.fade-left.fade-right {
  mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent);
}
.chips-wrap::-webkit-scrollbar { display: none; }
.gchip {
  padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-secondary);
  cursor: pointer; transition: var(--t-base); flex-shrink: 0; white-space: nowrap;
  height: 28px; display: inline-flex; align-items: center; gap: 4px;
}
.gchip:hover { border-color: var(--border-strong); color: var(--text-main); }
.gchip.active { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-brand); }
.gchip .chg { font-weight: 800; margin-left: 0; font-variant-numeric: tabular-nums; font-size: 10px; letter-spacing: -0.01em; }
.gchip.up:not(.active) { border-color: rgba(239,68,68,0.28); background: var(--up-bg); color: var(--text-main); }
.gchip.down:not(.active) { border-color: rgba(16,185,129,0.28); background: var(--down-bg); color: var(--text-main); }
.gchip.up .chg { color: var(--up-color); }
.gchip.down .chg { color: var(--down-color); }
.gchip.active .chg { color: rgba(255,255,255,0.95); }
.gbtn { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }

/* ========= Market Bar / Indices ========= */
.market-bar-wrap {
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
  /* Default: no mask when no scrollable overflow */
  mask-image: none;
  -webkit-mask-image: none;
  transition: mask-image 0.2s, -webkit-mask-image 0.2s;
}

.market-bar-wrap.fade-left {
  mask-image: linear-gradient(to right, transparent, #000 16px, #000);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 16px, #000);
}

.market-bar-wrap.fade-right {
  mask-image: linear-gradient(to right, #000, #000 calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000, #000 calc(100% - 16px), transparent);
}

.market-bar-wrap.fade-left.fade-right {
  mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}

.market-bar {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 2px 4px;
  width: 100%;
}
.market-bar::-webkit-scrollbar {
  display: none;
}

.mcard {
  --theme-color: var(--flat-color);
  position: relative;
  height: 64px;
  min-width: 150px;
  flex: 1 0 150px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: transform var(--t-base) var(--spring), box-shadow var(--t-base), border-color var(--t-base);
}

.mcard:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--border-strong);
}

/* Left side accent indicator bar */
.mcard::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  transition: top var(--t-base), bottom var(--t-base), background-color var(--t-base);
  background-color: var(--theme-color);
}
.mcard:hover::before {
  top: 0;
  bottom: 0;
}

.mcard.up {
  --theme-color: var(--up-color);
}
.mcard.down {
  --theme-color: var(--down-color);
}
.mcard.flat {
  --theme-color: var(--flat-color);
}

@keyframes pulse-up-accent {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 1px var(--up-color)); }
  50% { opacity: 0.75; filter: drop-shadow(0 0 4px var(--up-color)); }
}
@keyframes pulse-down-accent {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 1px var(--down-color)); }
  50% { opacity: 0.75; filter: drop-shadow(0 0 4px var(--down-color)); }
}

.mcard.up::before {
  animation: pulse-up-accent 3s ease-in-out infinite;
}
.mcard.down::before {
  animation: pulse-down-accent 3s ease-in-out infinite;
}

.mcard-sparkline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28px;
  pointer-events: none;
  opacity: 0.18;
  transition: opacity var(--t-base);
  z-index: 1;
}
.mcard:hover .mcard-sparkline {
  opacity: 0.45;
}
.mcard-sparkline svg {
  width: 100%;
  height: 100%;
  display: block;
}

.mcard-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  z-index: 2;
  position: relative;
}
.mcard-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mcard-code {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

.mcard-body {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 2;
  position: relative;
}
.mprice {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.mchange {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
}
.mchg-pct {
  font-size: 11px;
  font-weight: 800;
}
.mchg-val {
  font-size: 9px;
  color: var(--text-secondary);
  opacity: 0.85;
}

.mcard :is(.mprice, .mchg-pct) {
  color: var(--theme-color);
}

@media (min-width: 768px) {
  .market-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(156px, 1fr));
    overflow-x: visible;
  }
}

/* ========= Card View ========= */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; align-items: start; }
.card {
  background: var(--bg-card); border-radius: var(--radius-lg); padding: 18px 18px 18px 22px;
  position: relative; transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
  border: 1px solid var(--border-color); box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: 14px;
  overflow: hidden;
  align-self: start;
}
.card::before {
  content: ''; position: absolute; top: 10px; bottom: 10px; left: 0; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--theme-color, var(--border-color));
  opacity: 0.9;
  transition: top var(--t-base), bottom var(--t-base), opacity var(--t-base);
}
.card:hover::before { top: 0; bottom: 0; opacity: 1; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }

.card .del {
  position: absolute; top: 14px; right: 18px; width: 28px; height: 28px; border-radius: 8px;
  background: transparent; color: var(--text-muted); border: none; cursor: pointer;
  transition: var(--t-base); display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1; opacity: 0.55;
}
.card:hover .del { opacity: 1; }
.card .del:hover { background: var(--up-soft); color: var(--up-color); opacity: 1; }
.card .del:active { transform: scale(0.92); }
.card .del.confirm {
  background: var(--up-color); color: #fff; width: auto; padding: 0 12px;
  font-size: 11px; font-weight: 800; animation: pop 200ms var(--spring); opacity: 1;
}
@keyframes pop { from { transform: scale(0.85); } to { transform: scale(1); } }

.card-header { padding-right: 36px; padding-left: 0; }
.card .name {
  font-size: 17px; font-weight: 800; color: var(--text-main);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  letter-spacing: -0.01em;
}
.card .code-meta {
  font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}

.gtag {
  font-size: 10px; padding: 3px 8px; border-radius: 6px;
  background: var(--brand-soft); color: var(--brand);
  font-weight: 700; vertical-align: middle; cursor: pointer;
  transition: var(--t-base); white-space: nowrap; line-height: 1.4;
}
.gtag:hover { background: var(--brand); color: #fff; }
.gtag.empty {
  background: transparent; color: var(--text-muted);
  border: 1px dashed var(--border-strong); font-weight: 600;
}
.gtag.empty:hover { background: var(--brand-soft); color: var(--brand); border-style: solid; border-color: var(--brand); }
.gtag.empty.add-mini {
  padding: 0; width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1; font-weight: 700;
  border-style: dashed;
}
.gtag.empty.add-mini:hover { border-style: solid; }

.stock-name { cursor: pointer; transition: color var(--t-fast); }
.stock-name:hover { color: var(--brand); }

.price-box {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  cursor: pointer; user-select: none; -webkit-user-select: none; position: relative;
  border-radius: 8px; padding: 4px 20px 4px 4px; margin: -4px; transition: background var(--t-fast);
}
.price {
  font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em; line-height: 1; color: var(--text-main);
}
.change-box { text-align: right; display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.chg-pct {
  font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em; line-height: 1;
}
.chg-val { font-size: 11px; font-weight: 600; opacity: 0.7; font-variant-numeric: tabular-nums; margin-top: 5px; }

.detail-grid {
  display: grid; 
  grid-template-columns: 1.18fr 1fr 1fr; /* Slightly wider first column to protect volume digits from truncation */
  gap: 8px 10px;
  padding-top: 14px; border-top: 1px dashed var(--border-color);
}
.detail-item {
  display: flex; align-items: baseline; justify-content: flex-start; gap: 6px; /* Group labels & values tightly for optimal legibility */
  min-width: 0;
}
.detail-item .label { font-size: 11px; color: var(--text-muted); font-weight: 700; margin-bottom: 0; letter-spacing: 0.02em; flex-shrink: 0; }
.detail-item .value {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text-main); letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ========= Row / List View ========= */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--bg-card); border-radius: var(--radius-md);
  border: 1px solid var(--border-color); padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  transition: var(--t-base); position: relative; overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.row::before {
  content: ''; position: absolute; left: 0; top: 12%; bottom: 12%; width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--theme-color, var(--border-color));
  transition: var(--t-base);
}
.row:hover::before { top: 0; bottom: 0; }

.row-main { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-info { flex: 1; min-width: 0; }
.row-name {
  font-size: 15px; font-weight: 700; color: var(--text-main);
  display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; min-width: 0;
  letter-spacing: -0.01em; overflow: hidden;
}
/* Stock name has priority but ellipsis-clips if extremely long */
.row-name .stock-name {
  flex-shrink: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
/* Compact group chip for row view — first group + optional "+N" counter */
.row-name .row-gtag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; max-width: 62%;
  flex-shrink: 1; min-width: 0;
}
.row-name .row-gtag .rg-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.row-name .row-gtag .rg-extra {
  flex-shrink: 0; font-size: 9px; font-weight: 800;
  padding: 0 5px; border-radius: 999px; line-height: 1.5;
  background: rgba(255,255,255,0.6); color: var(--brand);
}
.row-name .row-gtag:hover .rg-extra { background: rgba(255,255,255,0.85); }
.row-name .row-gtag.empty { padding: 3px 8px; }
.row-meta { font-size: 11px; color: var(--text-secondary); font-weight: 600; margin-top: 3px; display: flex; gap: 6px; align-items: center; font-variant-numeric: tabular-nums; }
.row-meta .market { background: var(--bg-subtle); padding: 1px 6px; border-radius: 4px; color: var(--text-secondary); font-size: 10px; }

.row-price {
  width: 110px; text-align: right; font-size: 18px; font-weight: 800;
  font-variant-numeric: tabular-nums; flex-shrink: 0; letter-spacing: -0.02em;
}
.row-change { width: 100px; text-align: right; flex-shrink: 0; }
.row-chg-pct { font-size: 15px; font-weight: 800; display: block; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.row-chg-val { font-size: 11px; font-weight: 600; opacity: 0.7; display: block; font-variant-numeric: tabular-nums; margin-top: 2px; }

.row-extra { display: flex; gap: 0; margin-left: 16px; color: var(--text-secondary); font-size: 12px; }
.row-extra span { width: 86px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-extra b { color: var(--text-main); font-weight: 700; margin-left: 4px; }

.row-action {
  width: 32px; height: 32px; flex-shrink: 0; position: relative; z-index: 10;
}
.row-action button {
  position: absolute; right: 0; top: 0; height: 100%;
  width: 32px; border: none; background: transparent;
  color: var(--text-muted); cursor: pointer; border-radius: 8px; transition: var(--t-base);
  display: inline-flex; align-items: center; justify-content: center;
  pointer-events: none;
  white-space: nowrap;
}
.row-action:hover button { background: var(--up-soft); color: var(--up-color); }
.row-action.confirm button {
  background: var(--up-color) !important; color: #fff !important;
  width: auto; padding: 0 12px; font-size: 11px; font-weight: 800;
  animation: pop 200ms var(--spring);
}

/* ========= Colors & Animations ========= */
.up { --theme-color: var(--up-color); }
.down { --theme-color: var(--down-color); }
.flat { --theme-color: var(--flat-color); }

:is(.up, .down) :is(.price, .chg-pct, .chg-val, .row-price, .row-chg-pct, .row-chg-val) {
  color: var(--theme-color);
}


button:focus-visible, [role="button"]:focus-visible, .ditem:focus-visible, .gchip:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.toast-action:focus-visible { outline-color: #fff; outline-offset: 1px; }

/* ========= Responsive ========= */
@media (max-width: 900px) {
  .row-extra { display: none; }
}

@media (max-width: 640px) {
  body { padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }

  :root {
    --control-height: 34px;
  }

  .header {
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    grid-template-areas: "title status . toggle auth";
    gap: 6px 8px;
    align-items: center;
    margin-bottom: 6px;
  }
  .header h1 {
    grid-area: title;
    font-size: 20px;
    margin: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
  }
  .header h1 span[aria-hidden="true"] {
    display: none;
  }
  .header-right {
    display: contents;
  }
  .status-group {
    grid-area: status;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    height: auto;
    gap: 5px;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
  }
  .status-group .badge {
    height: 16px;
    min-width: 16px;
    font-size: 9px;
    padding: 0 4px;
    border-radius: 999px;
  }
  .tstat { font-size: 11px; }
  .last-refresh { display: none; }
  .view-toggle {
    grid-area: toggle;
    justify-self: end;
  }
  .auth-btn {
    grid-area: auth;
    justify-self: end;
    padding: 0;
    width: var(--control-height);
    height: var(--control-height);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .auth-btn .auth-text {
    display: none;
  }
  .auth-btn .auth-icon svg {
    width: 16px;
    height: 16px;
  }

  .grid { grid-template-columns: 1fr; gap: 12px; }
  .add-row { margin-bottom: 8px; }
  .search-wrap input { height: var(--control-height); padding: 0 16px 0 36px; font-size: 14px; }

  .market-bar-wrap { margin-bottom: 6px; }
  .market-bar { gap: 8px; }
  .mcard { min-width: 156px; flex: 1 0 156px; padding: 6px 10px; }
  .mcard-name { font-size: 12px; }
  .mprice { font-size: 14.5px; white-space: nowrap; }
  .mchange { font-size: 10px; flex-shrink: 0; }
  .mchg-pct { font-size: 10px; }
  .mchg-val { font-size: 8.5px; }

  .toolbar {
    padding: 3px 4px;
    gap: 4px;
    margin-bottom: 6px;
    top: max(0px, env(safe-area-inset-top));
    background: rgba(244, 246, 250, 0.85); /* Frosted glass toolbar for mobile */
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid rgba(230, 232, 238, 0.4);
  }
  .toolbar > button, .gchip, .sort-toggle { font-size: 11px; height: 25px; padding: 0 8px; gap: 3px; }
  .gchip .chg { font-size: 9.5px; }
  .gchip .chip-counts { font-size: 7.5px; line-height: 1; }
  .gbtn { padding: 0 8px; }

  .card { padding: 14px 14px 14px 18px; gap: 12px; border-radius: var(--radius-md); }
  .card-header { padding-left: 0; padding-right: 32px; }
  .card .name { font-size: 16px; }
  .price { font-size: 28px; letter-spacing: -0.025em; } /* Raised card price on mobile to 28px */
  .chg-pct { font-size: 14px; }
  .chg-val { font-size: 10px; margin-top: 4px; }
  .detail-grid { padding-top: 12px; gap: 8px 10px; grid-template-columns: 1.15fr 1fr 1fr; }
  .detail-item .label { font-size: 10px; }
  .detail-item .value { font-size: 12px; }
  .card .del { width: 28px; height: 28px; top: 10px; right: 14px; opacity: 0.55; }
  .card .del:active { opacity: 1; }
  .card .drag-handle.card-handle {
    left: 2px; width: 12px; height: 40px; opacity: 0.5;
  }
  .card .drag-handle.card-handle::before { inset: -16px -14px; }
  .card::before { top: 8px; bottom: 8px; width: 3px; opacity: 0.95; }

  .row { padding: 12px 10px 12px 8px; gap: 8px; border-radius: var(--radius-md); }
  .row-main { gap: 8px; }
  .row-name { font-size: 14px; gap: 5px; }
  .row-name .row-gtag { padding: 2px 7px; font-size: 9px; max-width: 58%; gap: 3px; }
  .row-name .row-gtag .rg-extra { font-size: 8px; padding: 0 4px; }
  .row-name .row-gtag.empty { padding: 2px 7px; font-size: 9px; }
  .row-meta { font-size: 10px; margin-top: 2px; }
  .row-price { width: 78px; font-size: 16px; }
  .row-change { width: 72px; }
  .row-chg-pct { font-size: 13px; }
  .row-chg-val { font-size: 10px; }
  .row-action { width: 28px; height: 28px; }
  .row-action button { width: 28px; font-size: 13px; }
}

@media (max-width: 380px) {
  .header h1 { font-size: 19px; }
  .price { font-size: 26px; }
  .row-price { width: 70px; font-size: 15px; }
  .row-change { width: 66px; }
}

@media (hover: none) {
  .card:hover { transform: none; }
  .row:hover::before { top: 12%; bottom: 12%; }
}

/* ========= Util & Toast ========= */
.vh { display: none !important; }

.toast {
  position: fixed; bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px)); left: 50%;
  transform: translateX(-50%) translateY(160px);
  background: #1e293b; color: #fff; padding: 13px 20px; border-radius: 14px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  transition: transform .35s var(--spring), opacity .25s ease;
  z-index: 2000; opacity: 0;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  border: 1px solid rgba(255,255,255,0.06);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--down-color); }
.toast-action {
  background: rgba(255,255,255,0.18); border: none; color: #fff;
  font-weight: 700; font-size: 13px; padding: 7px 14px; border-radius: 10px;
  cursor: pointer; transition: background var(--t-fast); flex-shrink: 0;
}
.toast-action:hover { background: rgba(255,255,255,0.30); }

/* ========= Overlays & Sheets ========= */
.bs-overlay, .gm-overlay, .ga-overlay {
  position: fixed; inset: 0; background: var(--bg-overlay);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 900; display: none;
}
.bs-overlay.open, .gm-overlay.open, .ga-overlay.open { display: block; animation: fadeIn .25s ease; }
.gm-overlay { z-index: 920; }
.ga-overlay { z-index: 940; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.bs-panel, .gm-panel, .ga-panel {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-card);
  border-radius: 24px 24px 0 0; z-index: 910; transform: translateY(100%);
  transition: transform .35s var(--spring);
  padding: 0 0 max(40px, calc(env(safe-area-inset-bottom) + 16px));
  box-shadow: 0 -16px 40px -8px rgba(0,0,0,0.18);
  max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--border-color); border-bottom: none;
}
.gm-panel { z-index: 930; }
.ga-panel { z-index: 950; }
.bs-panel.open, .gm-panel.open, .ga-panel.open { transform: translateY(0); }

@media (min-width: 640px) {
  .bs-panel, .gm-panel, .ga-panel {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, calc(-50% + 100vh));
    width: min(480px, 92vw);
    max-height: 80vh;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    padding: 12px 0 8px;
  }
  .bs-panel.open, .gm-panel.open, .ga-panel.open {
    transform: translate(-50%, -50%);
  }
  .bs-handle, .gm-handle, .ga-handle {
    display: none;
  }
  .bs-title, .gm-title, .ga-title {
    padding: 14px 24px 16px;
  }
}

.bs-handle, .gm-handle, .ga-handle {
  width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong);
  margin: 12px auto; opacity: 0.6;
}

.bs-title, .gm-title, .ga-title {
  font-size: 17px; font-weight: 800; padding: 6px 24px 16px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border-soft); margin-bottom: 8px;
  letter-spacing: -0.01em; color: var(--text-main);
}

.gm-title button#addGroupBtn {
  border: none; background: var(--brand-soft); color: var(--brand);
  padding: 7px 14px; border-radius: 10px; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: var(--t-base);
}
.gm-title button#addGroupBtn:hover { background: var(--brand); color: #fff; }

.bs-item, .gm-item, .ga-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  cursor: pointer; transition: var(--t-base); color: var(--text-main);
}
.bs-item:hover, .gm-item:hover, .ga-item:hover { background: var(--bg-subtle); }
.bs-item:active, .gm-item:active, .ga-item:active { background: var(--border-soft); }

.bs-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border-color); }
.bs-item .bslabel, .gm-item .gname2, .ga-label { flex: 1; font-size: 15px; font-weight: 600; color: var(--text-main); }
.bs-item .bscount, .gm-item .gcount { font-size: 12px; color: var(--text-muted); font-weight: 700; }
.bs-item .check { color: var(--brand); font-size: 16px; font-weight: 800; }

.gm-item .actions { display: flex; gap: 6px; }
.gm-item .actions button {
  border: none; background: var(--bg-subtle); width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; font-size: 13px; transition: var(--t-base); color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
.gm-item .actions button:hover { background: var(--border-color); color: var(--text-main); }
.gm-item .actions button.danger:hover { background: var(--up-soft); color: var(--up-color); }
.gm-item .icon { font-size: 18px; }

/* Multi-Group Sheet items */
.bs-list { padding: 12px 0 4px; }
.bs-item {
  margin: 4px 14px; border-radius: 14px; padding: 14px 18px;
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-subtle); border: 1px solid transparent;
}
.bs-item:hover { background: var(--bg-elev); border-color: var(--border-color); }
.bs-item.active { background: var(--brand-soft); border-color: var(--brand-ring); }

.bs-item .dot-outer {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  transition: var(--t-base); flex-shrink: 0; background: var(--bg-card);
}
.bs-item.active .dot-outer { border-color: var(--brand); background: var(--brand); }
.bs-item .dot-inner {
  width: 14px; height: 14px; display: inline-flex; align-items: center; justify-content: center;
  color: transparent; font-size: 13px; font-weight: 900; transition: var(--t-base);
}
.bs-item.active .dot-inner { color: #fff; }
.bs-item.active .dot-inner::after { content: '✓'; }

.bs-item .bslabel { flex: 1; font-size: 15px; font-weight: 700; color: var(--text-main); }
.bs-item .bscount { font-size: 11px; font-weight: 700; color: var(--text-muted); background: var(--bg-card); padding: 3px 9px; border-radius: 999px; }
.bs-item.active .bscount { background: var(--bg-card); color: var(--brand); }

.bs-new {
  margin: 12px 14px 4px; padding: 16px; border-radius: 14px;
  background: var(--bg-subtle); border: 2px dashed var(--border-strong); color: var(--brand);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 800; cursor: pointer; transition: var(--t-base);
}
.bs-new:hover { background: var(--brand-soft); border-color: var(--brand); border-style: solid; }
.bs-new svg { width: 18px; height: 18px; fill: currentColor; }

.bs-footer { padding: 12px 14px 0; display: flex; gap: 12px; }
.bs-confirm {
  flex: 1; padding: 15px; background: var(--brand); color: #fff; border: none;
  border-radius: 14px; font-size: 15px; font-weight: 800; cursor: pointer;
  transition: var(--t-base); box-shadow: var(--shadow-brand);
  letter-spacing: 0.02em;
}
.bs-confirm:disabled { background: var(--bg-subtle); color: var(--text-muted); cursor: not-allowed; box-shadow: none; }
.bs-confirm:not(:disabled):hover { background: var(--brand-hover); transform: translateY(-1px); }
.bs-confirm:not(:disabled):active { transform: translateY(0); }

.gm-chg { font-size: 13px; font-weight: 800; margin-left: auto; margin-right: 12px; font-variant-numeric: tabular-nums; }
.gm-chg.up { color: var(--up-color); }
.gm-chg.down { color: var(--down-color); }
.gm-chg.flat { color: var(--text-muted); }

.bs-cancel, .ga-cancel {
  margin: 6px 14px 8px;
  padding: 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 12px;
  transition: background var(--t-base), color var(--t-base);
}
.bs-cancel:hover, .ga-cancel:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.ga-icon { font-size: 18px; width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; background: var(--bg-subtle); border-radius: 12px; flex-shrink: 0; }
.ga-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }
.ga-item.danger { color: var(--up-color); }
.ga-item.danger .ga-icon { background: var(--up-soft); color: var(--up-color); }

/* ========= Dialog ========= */
.dlg-overlay {
  position: fixed; inset: 0; background: var(--bg-overlay);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 980; display: none;
}
.dlg-overlay.open { display: block; animation: fadeIn .2s ease; }
.dlg-panel {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-card);
  border-radius: 24px 24px 0 0; z-index: 990; transform: translateY(100%);
  transition: transform .35s var(--spring);
  padding: 0 0 max(24px, calc(env(safe-area-inset-bottom) + 16px));
  box-shadow: 0 -16px 40px -8px rgba(0,0,0,0.2);
  border: 1px solid var(--border-color); border-bottom: none;
}
.dlg-panel.open { transform: translateY(0); }
.dlg-panel::before {
  content: ''; display: block; width: 40px; height: 4px;
  border-radius: 2px; background: var(--border-strong); margin: 12px auto 8px; opacity: 0.6;
}
@media (min-width: 640px) {
  .dlg-panel {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, calc(-50% + 100vh));
    width: min(440px, 92vw);
    border-radius: 18px;
    border: 1px solid var(--border-color);
  }
  .dlg-panel.open { transform: translate(-50%, -50%); }
}
.dlg-title { font-size: 17px; font-weight: 800; padding: 4px 24px 8px; color: var(--text-main); letter-spacing: -0.01em; }
.dlg-body { font-size: 14px; color: var(--text-secondary); padding: 0 24px 12px; line-height: 1.55; }
.dlg-input {
  display: block; width: calc(100% - 48px); margin: 4px 24px 16px;
  padding: 13px 16px; border: 1px solid var(--border-color); border-radius: 12px;
  font-size: 16px; outline: none; background: var(--bg-card); transition: var(--t-base);
  font-family: inherit; color: var(--text-main);
}
.dlg-input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.dlg-actions { display: flex; gap: 10px; padding: 4px 24px 0; }
.dlg-actions button {
  flex: 1; padding: 13px; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer; transition: var(--t-base);
  font-family: inherit;
}
.dlg-cancel { background: var(--bg-subtle); color: var(--text-main); }
.dlg-cancel:hover { background: var(--border-color); }
.dlg-ok { background: var(--brand); color: #fff; box-shadow: var(--shadow-brand); }
.dlg-ok:hover { background: var(--brand-hover); }
.dlg-ok.danger { background: var(--up-color); box-shadow: 0 8px 22px -8px rgba(239,68,68,0.5); }
.dlg-ok.danger:hover { background: #dc2626; }

/* ========= Empty State ========= */
.empty-view {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 100px 20px; text-align: center;
}
.empty-icon {
  font-size: 56px; margin-bottom: 18px; line-height: 1; opacity: 1;
  width: 96px; height: 96px; border-radius: 28px;
  background: linear-gradient(135deg, var(--brand-soft), var(--up-soft));
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
}
.empty-title { font-size: 19px; font-weight: 800; margin-bottom: 8px; color: var(--text-main); letter-spacing: -0.01em; }
.empty-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 22px; max-width: 320px; line-height: 1.6; opacity: 1; }
.empty-cta {
  border: none; background: var(--brand); color: #fff;
  padding: 13px 24px; border-radius: 12px; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: var(--t-base); box-shadow: var(--shadow-brand);
  font-family: inherit;
}
.empty-cta:hover { background: var(--brand-hover); transform: translateY(-1px); }
.empty-cta:active { transform: translateY(0); }

/* ========= Footer ========= */
.footer {
  margin-top: 60px; padding: 32px 0 12px;
  border-top: 1px solid var(--border-soft);
  text-align: center; color: var(--text-muted);
}
.footer p { font-size: 12px; margin-bottom: 8px; font-weight: 600; }
.footer .disclaimer { font-size: 11px; opacity: 0.75; line-height: 1.65; max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* ========= Refresh Spinner ========= */
@keyframes spin { to { transform: rotate(360deg); } }

/* ========= Stronger Flash on Price Change ========= */
@keyframes flashUp {
  0% { background-color: rgba(239, 68, 68, 0.30); }
  40% { background-color: rgba(239, 68, 68, 0.18); }
  100% { background-color: transparent; }
}
@keyframes flashDown {
  0% { background-color: rgba(16, 185, 129, 0.30); }
  40% { background-color: rgba(16, 185, 129, 0.18); }
  100% { background-color: transparent; }
}
.flashUp { animation: flashUp 1.4s ease-out; }
.flashDown { animation: flashDown 1.4s ease-out; }

/* Subtle pulse on price element when tweening */
.price.tweening, .row-price.tweening { transition: color 0.6s; }

/* ========= Offline / Error Banner ========= */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--up-color); color: #fff;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  font-size: 13px; font-weight: 700; text-align: center; letter-spacing: 0.02em;
  z-index: 3000; transform: translateY(-110%);
  transition: transform 0.35s var(--spring);
  box-shadow: 0 4px 14px -4px rgba(239,68,68,0.4);
}
.offline-banner.show { transform: translateY(0); }
.offline-banner.warn { background: #f59e0b; box-shadow: 0 4px 14px -4px rgba(245,158,11,0.4); }

/* ========= Pull-to-Refresh Indicator ========= */
.ptr-indicator {
  position: fixed; top: -52px; left: 50%;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand); z-index: 1500;
  transform: translateX(-50%);
  transition: top 0.32s var(--spring);
  pointer-events: none;
}
.ptr-indicator svg { width: 20px; height: 20px; fill: currentColor; transition: transform 0.15s; }
.ptr-indicator.dragging { transition: none; }
.ptr-indicator.refreshing svg { animation: spin 0.9s linear infinite; }

/* ========= Sparkline (inline expand) ========= */
.price-box:hover { background: var(--bg-subtle); }
.price-box::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.25;
  transition: opacity var(--t-base), transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
@media (hover: hover) {
  .card:hover .price-box::after { opacity: 0.6; }
}
.card:has(.sparkline-wrap.expanded) .price-box::after {
  opacity: 0.8;
  transform: translateY(-50%) rotate(180deg);
}
.card .sparkline-wrap.expanded { opacity: 1; }
.sparkline-wrap {
  height: 0; opacity: 0; overflow: hidden; margin: 0;
  transition: height 0.32s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.22s ease, margin-top 0.32s cubic-bezier(0.25, 1, 0.5, 1);
}
.sparkline-wrap.expanded { height: 96px; opacity: 1; margin-top: 4px; }
.sparkline-wrap svg { width: 100%; height: 76px; display: block; }
.spk-meta {
  display: flex; justify-content: space-between; font-size: 10px;
  color: var(--text-muted); padding: 2px 2px 0; font-variant-numeric: tabular-nums;
}
.spk-loading, .spk-empty {
  height: 76px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-muted); font-weight: 600;
}

/* ========= Group Chip — red/green counts (vertically stacked) ========= */
.gchip .chip-counts {
  display: inline-flex; flex-direction: column; gap: 0; margin-left: 0;
  font-size: 8px; font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
  padding-left: 0; border-left: none;
  opacity: 0.9;
}
.gchip.active .chip-counts { opacity: 0.95; }
.gchip .cc-up { color: var(--up-color); }
.gchip .cc-down { color: var(--down-color); }
.gchip.active .cc-up, .gchip.active .cc-down { color: rgba(255,255,255,0.95); }

/* ========= Drag-to-Reorder ========= */
.drag-handle {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 32px; flex-shrink: 0;
  border-radius: 4px; color: var(--text-muted);
  opacity: 0.4; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: opacity var(--t-fast), background var(--t-fast), color var(--t-fast);
}
/* Invisible expanded hit-area for touch — keeps the visual minimal without sacrificing tap accuracy */
.drag-handle::before {
  content: ''; position: absolute; inset: -12px -10px;
}
.drag-handle svg { width: 6px; height: 18px; fill: currentColor; pointer-events: none; }
.drag-handle:hover { opacity: 0.85; color: var(--text-secondary); background: transparent; }
.drag-handle:active, body.dragging-active .drag-handle { cursor: grabbing; }
.card .drag-handle {
  position: absolute; top: 14px; left: 10px; z-index: 3;
  width: 14px; height: 32px;
}
.card .drag-handle.card-handle {
  top: 50%; left: 4px; transform: translateY(-50%);
  width: 14px; height: 44px; border-radius: 4px;
  opacity: 0.35;
}
.card .drag-handle.card-handle svg { width: 6px; height: 18px; }
.card .drag-handle.card-handle::before { inset: -14px -12px; }
.card .drag-handle.card-handle:hover { background: transparent; }
.card:hover .drag-handle.card-handle { opacity: 0.75; }
.row-main > .drag-handle { margin-right: -2px; margin-left: -4px; }

@media (pointer: coarse) {
  /* Touch devices: slightly more visible handle so it's easier to find — but still slim */
  .drag-handle { opacity: 0.55; }
  .row-main > .drag-handle { width: 14px; height: 36px; }
  .row-main > .drag-handle svg { width: 6px; height: 20px; }
  .card .drag-handle.card-handle { opacity: 0.55; }
}

.pre-drag {
  transform: scale(0.985);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 6px 20px -8px rgba(15,23,42,0.18);
}
.drag-source {
  opacity: 0 !important;
  transition: opacity 0.12s ease;
}
.drag-ghost {
  position: fixed !important; z-index: 5000 !important;
  pointer-events: none !important;
  box-shadow: 0 22px 48px -8px rgba(15,23,42,0.35), 0 0 0 2px var(--brand-ring) !important;
  transform: scale(1.025);
  opacity: 0.97;
  border-radius: var(--radius-lg) !important;
  background: var(--bg-card) !important;
}
.drag-ghost::before { display: none !important; }
.drag-ghost .drag-handle { cursor: grabbing; opacity: 1; color: var(--brand); }
body.dragging-active {
  cursor: grabbing;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  overflow: hidden;
}
body.dragging-active * { touch-action: none !important; }

/* ========= Swipe-to-Reveal (rows only) ========= */
.row-slot {
  position: relative; overflow: hidden;
  border-radius: var(--radius-md);
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.card {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.row-slot .row {
  background: var(--bg-card);
  transition: transform 0.32s var(--spring);
  will-change: transform;
}
.row-slot.swiping .row { transition: none; }
.row-slot.revealed .row { transform: translateX(-156px); }
.row-actions-bg {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 156px; display: flex; align-items: stretch;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-base), visibility var(--t-base);
}
.row-slot.revealed .row-actions-bg, .row-slot.swiping .row-actions-bg {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transition: none;
}
.sw-act {
  border: none; cursor: pointer; font-size: 13px; font-weight: 800; color: #fff;
  flex: 1; transition: filter var(--t-fast);
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0.02em;
}
.sw-act.group { background: var(--brand); }
.sw-act.del { background: var(--up-color); }
.sw-act:active { filter: brightness(0.9); }

/* On wide screens (mouse-only), swipe actions are not useful — keep them but compact */
@media (hover: hover) and (pointer: fine) {
  .row-slot { touch-action: auto; }
}

/* ========= Account UI & Glassmorphism Panel ========= */

.auth-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand-soft);
  border: 1px solid rgba(37, 99, 235, 0.2);
  padding: 0 16px; border-radius: var(--control-radius);
  box-shadow: var(--shadow-xs), 0 2px 8px rgba(37, 99, 235, 0.08);
  cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 13px; font-weight: 700; color: var(--brand);
  height: var(--control-height); outline: none; font-family: inherit;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-sizing: border-box;
}
.auth-btn:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
  box-shadow: var(--shadow-brand);
  transform: translateY(-1.5px);
}
.auth-btn:active {
  transform: translateY(0.5px) scale(0.96);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}
.auth-icon {
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.25s ease;
}
.auth-icon svg {
  width: 14px; height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
.auth-btn:hover .auth-icon {
  transform: scale(1.15) rotate(-5deg);
}
.auth-text {
  max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: 0.02em;
}

.up-content {
  padding: 18px 24px 8px;
  animation: fadeIn 0.25s ease;
}

/* Tabs for Login / Register */
.auth-tabs {
  display: flex; background: var(--bg-subtle); padding: 4px; border-radius: 12px;
  margin-bottom: 20px; gap: 4px;
  border: 1px solid var(--border-soft);
}
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 10px; border-radius: 9px;
  cursor: pointer; font-size: 14px; font-weight: 700; color: var(--text-secondary);
  transition: var(--t-base);
}
.auth-tab.active {
  background: var(--bg-card); color: var(--brand);
  box-shadow: var(--shadow-sm);
}

/* Auth Form */
.auth-form {
  display: flex; flex-direction: column; gap: 12px;
}
.up-input {
  width: 100%; padding: 13px 16px; border: 1px solid var(--border-color);
  border-radius: 12px; font-size: 15px; outline: none; background: var(--bg-card);
  color: var(--text-main); transition: var(--t-base);
  font-family: inherit;
}
.up-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring);
}
.auth-submit-btn {
  margin-top: 6px; padding: 14px; background: var(--brand); color: #fff;
  border: none; border-radius: 12px; font-size: 15px; font-weight: 800;
  cursor: pointer; transition: var(--t-base); box-shadow: var(--shadow-brand);
  font-family: inherit;
}
.auth-submit-btn:hover { background: var(--brand-hover); }
.auth-submit-btn:active { transform: scale(0.98); }

/* User Info Card (Logged in view) */
.user-info-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-subtle); border-radius: var(--radius-lg);
  padding: 16px 20px; border: 1px solid var(--border-soft);
  margin-bottom: 20px;
}
.user-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  color: #fff; font-size: 20px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  text-transform: uppercase;
}
.user-details {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.user-name {
  font-size: 17px; font-weight: 800; color: var(--text-main);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sync-info {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.sync-badge {
  font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px;
  background: var(--brand-soft); color: var(--brand);
  text-transform: uppercase;
  transition: all var(--t-fast);
}
.sync-badge.synced { background: var(--down-soft); color: var(--down-color); }
.sync-badge.pending { background: var(--brand-soft); color: var(--brand); animation: pulseSync 1.2s infinite alternate; }
.sync-badge.error { background: var(--up-soft); color: var(--up-color); }
.sync-badge.offline { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border-color); }
.sync-time { font-size: 11px; color: var(--text-muted); font-weight: 600; }

@keyframes pulseSync {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

/* Actions in User Panel */
.up-actions {
  display: flex; flex-direction: column; gap: 10px;
}
.up-action-btn {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer; transition: var(--t-base);
  font-family: inherit; text-align: center;
  background: var(--bg-subtle); color: var(--text-main);
}
.up-action-btn:hover { background: var(--border-color); }
.up-action-btn:active { transform: scale(0.98); }
.up-action-btn.danger {
  background: var(--up-soft); color: var(--up-color);
}
.up-action-btn.danger:hover { background: var(--up-color); color: #fff; }

/* ========= Guest Banner & Auth Tip Card ========= */
.guest-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--brand-soft); border: 1px solid rgba(37, 99, 235, 0.15);
  padding: 8px 14px; border-radius: var(--radius-md);
  margin-bottom: 8px; box-shadow: var(--shadow-xs);
  animation: slideIn .22s var(--spring);
}
.guest-banner .banner-icon { font-size: 14px; }
.guest-banner .banner-text { flex: 1; font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.guest-banner .banner-text strong { color: var(--brand); font-weight: 700; }
.guest-banner .banner-action-btn {
  border: none; background: var(--brand); color: #fff;
  font-size: 11px; font-weight: 700; padding: 5px 12px; border-radius: var(--control-radius);
  cursor: pointer; transition: var(--t-base); box-shadow: var(--shadow-brand);
}
.guest-banner .banner-action-btn:hover { background: var(--brand-hover); }
.guest-banner .banner-close {
  border: none; background: transparent; color: var(--text-muted);
  font-size: 16px; font-weight: 700; cursor: pointer; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--t-fast);
}
.guest-banner .banner-close:hover { color: var(--text-main); }

@media (max-width: 640px) {
  .guest-banner {
    flex-wrap: wrap; padding: 10px 12px; gap: 8px 10px;
  }
  .guest-banner .banner-text { width: 100%; flex: none; font-size: 11.5px; }
  .guest-banner .banner-action-btn { margin-left: auto; }
}



