/* ============================================================
 * Zotreus mobile-app skin — Material 3 inspired
 * Loaded after style.css. Activates on viewport ≤ 820px.
 * ============================================================ */

@media (max-width: 820px) {

  :root {
    --m3-primary:   #6f8eff;
    --m3-on-prim:   #ffffff;
    --m3-surface:   #11151c;
    --m3-surface-2: #181d26;
    --m3-surface-3: #20262f;
    --m3-outline:   #2a323d;
    --m3-on-surf:   #e7ecf1;
    --m3-on-surf-2: #aeb6c2;
    --m3-on-surf-3: #7d8a9c;
    --m3-success:   #4ade80;
    --m3-error:     #f87171;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 2px 6px rgba(0,0,0,.45);
    --shadow-fab: 0 6px 16px rgba(0,0,0,.55);
  }

  body {
    background: #0a0d12;
    padding-bottom: 64px; /* room for bottom nav */
  }

  /* ---------- TOP APP BAR ---------- */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    background: var(--m3-surface);
    border-bottom: 1px solid var(--m3-outline);
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    height: 56px;
  }
  .brand { gap: 12px; flex: 1; min-width: 0; }
  .brand h1 { font-size: 17px !important; font-weight: 600; letter-spacing: 0.1px; display: block !important; }
  .brand .ticker { display: none; }
  .logo {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    flex: 0 0 26px !important;
  }
  .logo svg { width: 26px !important; height: 26px !important; display: block; }

  .topbar-right { gap: 6px; flex: 0 0 auto; }
  .status { display: none; } /* status moves to a tiny dot in app bar later if needed */
  .balance-pill {
    background: transparent;
    border: 1px solid var(--m3-outline);
    color: var(--m3-on-surf-2);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    height: 32px;
  }
  .balance-pill .balance-label { display: none; }
  .balance-pill b { font-size: 13px; color: var(--m3-on-surf); }
  .signin-link, .signup-btn {
    height: 36px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0 16px;
    font-size: 13px;
    font-weight: 500;
  }
  .signup-btn { background: var(--m3-primary); color: var(--m3-on-prim); }

  .user-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--m3-surface-2);
    border: 1px solid var(--m3-outline);
    color: var(--m3-on-surf);
    font-size: 14px;
  }
  .user-btn svg { display: none; }
  .user-dropdown {
    position: fixed;
    top: 60px;
    right: 12px;
    left: auto;
    min-width: 200px;
    background: var(--m3-surface-3);
    border: 1px solid var(--m3-outline);
    border-radius: 12px;
    box-shadow: var(--shadow-2);
    overflow: hidden;
  }
  .user-dropdown a {
    padding: 14px 16px;
    font-size: 14px;
    color: var(--m3-on-surf);
  }

  /* ---------- TOP TABS (HIDE on mobile, replaced by bottom nav) ---------- */
  .tabs { display: none !important; }

  /* Search bar — surface card under app bar */
  main { padding: 14px 12px 24px; }

  /* ---------- BOTTOM NAVIGATION (Android style) ---------- */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--m3-surface);
    border-top: 1px solid var(--m3-outline);
    display: flex;
    z-index: 90;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .bottom-nav button {
    flex: 1;
    background: none;
    border: none;
    color: var(--m3-on-surf-3);
    font-size: 11px;
    font-weight: 500;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    padding: 6px 4px;
    transition: color 0.15s ease;
    position: relative;
  }
  .bottom-nav button:active { background: rgba(111, 142, 255, 0.08); }
  .bottom-nav button.active { color: var(--m3-primary); }
  .bottom-nav .nav-icon-wrap {
    width: 56px;
    height: 28px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
  }
  .bottom-nav button.active .nav-icon-wrap { background: rgba(111, 142, 255, 0.18); }
  .bottom-nav svg { width: 20px; height: 20px; display: block; }

  /* ---------- ASSET LIST AS CARDS (replaces tables on mobile) ---------- */
  .market-table {
    display: block;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }
  .market-table thead { display: none; }
  .market-table, .table-wrap {
    background: transparent;
    border: none;
    padding: 0;
  }
  .market-table tbody { display: block; }
  .market-table tbody tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: center;
    background: var(--m3-surface);
    border: 1px solid var(--m3-outline);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-1);
  }
  .market-table tbody tr:hover { background: var(--m3-surface-2); }
  .market-table tbody td {
    display: contents;
    border: none;
    padding: 0;
  }
  /* Hide ALL cells, then re-show via specific selectors as positioned grid items */
  .market-table tbody td { display: none; }

  /* Crypto card layout */
  #crypto-table tbody tr {
    grid-template-areas:
      "icon  name  price"
      "icon  meta  delta";
    grid-template-columns: 36px 1fr auto;
    gap: 14px;
  }
  #crypto-table td:nth-child(2) {
    display: flex; grid-area: icon; align-items: center;
  }
  #crypto-table td:nth-child(2) .asset-cell { display: contents; }
  #crypto-table td:nth-child(2) .asset-cell img {
    grid-area: icon; width: 36px; height: 36px;
  }
  #crypto-table td:nth-child(2) .asset-cell > div {
    grid-column: name / span 1;
    grid-row: 1; display: flex; flex-direction: column;
    padding-left: 4px;
  }
  #crypto-table td:nth-child(2) .asset-cell .name { font-size: 15px; font-weight: 500; color: var(--m3-on-surf); }
  #crypto-table td:nth-child(2) .asset-cell .symbol {
    margin-left: 0; font-size: 12px; color: var(--m3-on-surf-3);
    text-transform: uppercase; letter-spacing: 0.5px;
  }
  /* Price (col 3) */
  #crypto-table td:nth-child(3) {
    display: block; grid-area: price; text-align: right;
    font-size: 15px; font-weight: 600; color: var(--m3-on-surf);
  }
  /* 24h % (col 6) */
  #crypto-table td:nth-child(6) {
    display: block; grid-area: delta; text-align: right; font-size: 12px;
  }

  /* Stocks card layout */
  #stocks-table tbody tr {
    grid-template-areas:
      "sym  name  price"
      "sym  meta  delta";
    grid-template-columns: 56px 1fr auto;
  }
  #stocks-table td:nth-child(1) {
    display: flex; grid-area: sym; align-items: center; justify-content: center;
    background: var(--m3-surface-2);
    width: 44px; height: 44px;
    border-radius: 50%;
    font-weight: 700; font-size: 11px;
    letter-spacing: 0.3px; color: var(--m3-primary);
  }
  #stocks-table td:nth-child(2) {
    display: block; grid-area: name; font-size: 14px;
    color: var(--m3-on-surf); font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #stocks-table td:nth-child(3) {
    display: block; grid-area: price; text-align: right;
    font-size: 15px; font-weight: 600; color: var(--m3-on-surf);
  }
  #stocks-table td:nth-child(6) {
    display: block; grid-area: delta; text-align: right; font-size: 12px;
  }

  /* Watchlist + holdings stay tabular but condensed */
  #watchlist-table, #history-table, #rules-table, #holdings-table {
    display: table;
    table-layout: fixed;
    width: 100%;
  }
  #watchlist-table thead, #history-table thead, #rules-table thead, #holdings-table thead { display: table-header-group; }
  #watchlist-table tbody, #history-table tbody, #rules-table tbody, #holdings-table tbody { display: table-row-group; }
  #watchlist-table tr, #history-table tr, #rules-table tr, #holdings-table tr {
    display: table-row;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  #watchlist-table td, #history-table td, #rules-table td, #holdings-table td {
    display: table-cell !important;
    padding: 10px 8px !important;
    border-bottom: 1px solid var(--m3-outline) !important;
    background: var(--m3-surface);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #watchlist-table th, #history-table th, #rules-table th, #holdings-table th {
    background: var(--m3-surface-2) !important;
    font-size: 10px !important;
    padding: 8px 6px !important;
  }
  #watchlist-table tr:first-child td, #history-table tr:first-child td, #rules-table tr:first-child td, #holdings-table tr:first-child td {
    border-top: 1px solid var(--m3-outline);
  }
  /* Round corners on first/last cells of watchlist-style tables */
  #watchlist-table, #history-table, #rules-table, #holdings-table {
    border: 1px solid var(--m3-outline);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-1);
  }

  /* ---------- HIDE NON-ESSENTIAL COLUMNS ON MOBILE ---------- */
  /* Holdings: keep Asset, Quantity, Value (PHP), P&L; hide Type/AvgBuy/Current/PnLpct/Action */
  #holdings-table th:nth-child(2),
  #holdings-table td:nth-child(2),
  #holdings-table th:nth-child(4),
  #holdings-table td:nth-child(4),
  #holdings-table th:nth-child(5),
  #holdings-table td:nth-child(5),
  #holdings-table th:nth-child(8),
  #holdings-table td:nth-child(8),
  #holdings-table th:nth-child(9),
  #holdings-table td:nth-child(9) {
    display: none !important;
  }

  /* Rules: keep Asset, Take Profit, Stop Loss, Cancel; hide Quantity/Status */
  #rules-table th:nth-child(2),
  #rules-table td:nth-child(2),
  #rules-table th:nth-child(5),
  #rules-table td:nth-child(5) {
    display: none !important;
  }

  /* History: keep When, Side, Asset, Total, P&L; hide Quantity/Price USD */
  #history-table th:nth-child(4),
  #history-table td:nth-child(4),
  #history-table th:nth-child(5),
  #history-table td:nth-child(5) {
    display: none !important;
  }

  /* Allow tables to scroll horizontally as a fallback if anything overflows */
  .table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Mobile modal hardening: ensure flex display when not hidden */
  .modal:not([hidden]) { display: flex !important; }

  /* Search */
  .search-fab {
    display: block;
    margin: 0 0 12px;
  }
  #search {
    height: 44px;
    padding: 0 16px 0 44px;
    background: var(--m3-surface-2) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23aeb6c2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 14px 50%;
    border: 1px solid var(--m3-outline);
    border-radius: 999px;
    font-size: 14px;
  }

  /* Refresh as round icon button */
  .refresh {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--m3-surface-2);
    border: 1px solid var(--m3-outline);
  }

  /* Summary cards — Material 3 chips */
  .summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .summary-card {
    background: var(--m3-surface);
    border: 1px solid var(--m3-outline);
    border-radius: 14px;
    padding: 14px 14px;
    box-shadow: var(--shadow-1);
  }
  .summary-card .label {
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--m3-on-surf-3);
    font-weight: 500;
  }
  .summary-card .value {
    font-size: 18px;
    font-weight: 600;
    margin-top: 4px;
    letter-spacing: -0.3px;
  }

  .panel-h3 {
    font-size: 12px;
    margin: 18px 4px 8px;
    color: var(--m3-on-surf-3);
    text-transform: none;
    letter-spacing: 0.1px;
  }

  /* ---------- BOTTOM SHEET MODAL ---------- */
  .modal {
    align-items: flex-end !important;
    padding: 0 !important;
    background: rgba(0,0,0,0.55) !important;
  }
  .modal-card {
    max-width: none !important;
    max-height: 92vh !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 8px 20px 28px !important;
    border: none !important;
    background: var(--m3-surface-3) !important;
    box-shadow: 0 -8px 24px rgba(0,0,0,.45);
    animation: sheet-up 0.22s cubic-bezier(.2,.7,.2,1);
  }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .modal-card::before {
    content: "";
    display: block;
    width: 36px; height: 4px;
    background: var(--m3-outline);
    border-radius: 2px;
    margin: 0 auto 18px;
  }
  .modal-close {
    top: 14px; right: 14px;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--m3-surface-2);
    color: var(--m3-on-surf);
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
  }
  .detail-header h2 { font-size: 20px; }
  .detail-price { font-size: 28px; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Trade form chunkier on mobile */
  .trade-modal-tabs button {
    height: 44px; font-size: 13px;
  }
  .trade-form input { height: 50px; font-size: 16px; padding: 12px 16px; }
  .trade-form .submit-btn { height: 52px; border-radius: 999px; font-size: 15px; }
  .trade-form .quick button { height: 32px; padding: 0 14px; border-radius: 999px; }

  /* ---------- FAB (Add Funds) — neon variant matching +New Rule ---------- */
  .fab {
    position: fixed;
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
    z-index: 85;
    height: 56px;
    padding: 0 24px 0 20px;
    background: rgba(15, 20, 28, 0.95);
    color: #cfd8ff;
    border: 1.5px solid;
    border-image: linear-gradient(135deg, #5fa8ff 0%, #b46aff 100%) 1;
    border-radius: 16px;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
      0 0 0 1px rgba(95, 168, 255, 0.22),
      0 0 28px rgba(111, 142, 255, 0.45),
      0 14px 28px rgba(0, 0, 0, 0.55),
      inset 0 0 22px rgba(95, 168, 255, 0.10);
    transition: transform 0.18s cubic-bezier(.2,.7,.2,1), box-shadow 0.22s ease, color 0.18s ease;
    animation: fab-pulse 3.2s ease-in-out infinite;
  }
  @keyframes fab-pulse {
    0%, 100% { box-shadow: 0 0 0 1px rgba(95, 168, 255, 0.22),
                           0 0 24px rgba(111, 142, 255, 0.42),
                           0 14px 28px rgba(0, 0, 0, 0.55),
                           inset 0 0 22px rgba(95, 168, 255, 0.10); }
    50%      { box-shadow: 0 0 0 1px rgba(95, 168, 255, 0.40),
                           0 0 38px rgba(180, 106, 255, 0.55),
                           0 18px 32px rgba(0, 0, 0, 0.60),
                           inset 0 0 26px rgba(180, 106, 255, 0.14); }
  }
  .fab::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.16) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: fab-sheen 4.2s linear infinite;
    pointer-events: none;
    border-radius: inherit;
  }
  @keyframes fab-sheen {
    0%   { background-position: 220% 0; }
    100% { background-position: -220% 0; }
  }
  .fab svg {
    width: 20px;
    height: 20px;
    color: #5fa8ff;
    filter: drop-shadow(0 0 8px rgba(95, 168, 255, 0.8));
    position: relative;
    z-index: 1;
  }
  .fab > *:not(svg) {
    position: relative;
    z-index: 1;
    background: linear-gradient(120deg, #ffffff 0%, #cfd8ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
  @media (hover: hover) {
    .fab:hover {
      transform: translateY(-2px);
      color: #ffffff;
    }
  }
  .fab:active {
    transform: scale(0.97);
    animation-play-state: paused;
  }

  /* Notify modal as bottom sheet too */
  .notify-card {
    border-radius: 24px 24px 0 0 !important;
    max-width: none !important;
    width: 100% !important;
    margin-bottom: 0 !important;
    padding: 24px 22px 28px !important;
  }
  #notify-root.open { align-items: flex-end !important; padding: 0 !important; }

  /* Hide footer on mobile (already removed but defensive) */
  footer { display: none; }
}

/* ============ DESKTOP: hide bottom nav and FAB ============ */
@media (min-width: 821px) {
  .bottom-nav { display: none; }
  .fab { display: none; }
}

/* ============================================================
 * Native polish — ripple, pull-to-refresh, splash, skeletons,
 * sheet drag. Active across all viewports unless scoped.
 * ============================================================ */

/* ---------- MATERIAL RIPPLE ---------- */
.ripple-host { overflow: hidden; }
.ripple-ink {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: currentColor;
  opacity: 0.22;
  transform: scale(0);
  animation: ripple-grow 520ms cubic-bezier(.2,.7,.2,1) forwards;
}
@keyframes ripple-grow {
  to { transform: scale(2.4); opacity: 0; }
}

/* ---------- PULL-TO-REFRESH ---------- */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  z-index: 95;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--m3-surface-3, #20262f);
  border: 1px solid var(--m3-outline, #2a323d);
  box-shadow: 0 4px 12px rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--m3-primary, #6f8eff);
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
  will-change: transform, opacity;
}
.ptr-indicator svg { width: 22px; height: 22px; }
.ptr-indicator.visible { opacity: 1; }
.ptr-indicator.refreshing svg { animation: ptr-spin 0.9s linear infinite; }
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

/* ---------- SPLASH SCREEN ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(circle at 50% 40%, #1a2233 0%, #0a0d12 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  transition: opacity 360ms ease;
}
#splash.fade-out { opacity: 0; pointer-events: none; }
#splash .splash-logo {
  width: 96px; height: 96px;
  display: grid; place-items: center;
  border-radius: 28px;
  background: linear-gradient(135deg, #6f8eff 0%, #b46aff 100%);
  box-shadow: 0 12px 40px rgba(111, 142, 255, .35), inset 0 1px 0 rgba(255,255,255,.18);
  animation: splash-pulse 1.6s ease-in-out infinite;
}
#splash .splash-logo svg { width: 56px; height: 56px; color: #fff; }
#splash .splash-name {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: #e7ecf1;
}
#splash .splash-tagline {
  font-size: 12px;
  color: #7d8a9c;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
@keyframes splash-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ---------- SKELETON LOADERS ---------- */
.skeleton-list { padding: 0; margin: 0; list-style: none; }
.skeleton-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--m3-surface, #11151c);
  border: 1px solid var(--m3-outline, #2a323d);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}
.skeleton-row .sk-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
}
.skeleton-row .sk-line {
  height: 12px;
  border-radius: 6px;
}
.skeleton-row .sk-line + .sk-line { margin-top: 8px; width: 60%; }
.skeleton-row .sk-right {
  width: 70px; height: 14px;
  border-radius: 6px;
  justify-self: end;
}
.sk-shimmer {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.10) 50%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 200% 100%;
  animation: sk-shine 1.4s linear infinite;
}
@keyframes sk-shine {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ---------- BOTTOM-SHEET DRAG-DOWN ---------- */
@media (max-width: 820px) {
  .modal-card {
    touch-action: pan-y;
    will-change: transform;
  }
  .modal-card.dragging {
    transition: none !important;
    animation: none !important;
  }
  .modal-card.snapping {
    transition: transform 240ms cubic-bezier(.2,.7,.2,1);
  }
  .modal-card::before {
    cursor: grab;
  }
}
