/* ============================================
   Finnhub — Ultra-Detailed Mobile-First Responsive UI
   10 Breakpoints · Atomic Precision · Touch Optimized
   ============================================ */

:root {
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-hover: #f1f3f5;
    --bg-card: #ffffff;
    --border: #e9ecef;
    --border-light: #f1f3f5;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --green: #4caf50;
    --green-bg: #e8f5e9;
    --green-soft: rgba(76, 175, 80, 0.1);
    --red: #e53935;
    --red-bg: #ffebee;
    --red-soft: rgba(229, 57, 53, 0.1);
    --blue: #2563eb;
    --blue-light: #e8f0fe;
    --blue-soft: rgba(37, 99, 235, 0.08);
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.16);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --font: 'Lora', 'Georgia', 'Times New Roman', serif;
    --font-display: 'DM Serif Display', 'Georgia', serif;
    --space-xs: clamp(2px, 0.5vw, 4px);
    --space-sm: clamp(4px, 1vw, 8px);
    --space-md: clamp(8px, 2vw, 16px);
    --space-lg: clamp(12px, 3vw, 24px);
    --space-xl: clamp(16px, 4vw, 32px);
    --fs-2xs: clamp(8px, 1.8vw, 9px);
    --fs-xs: clamp(9px, 2vw, 10px);
    --fs-sm: clamp(10px, 2.2vw, 11px);
    --fs-base: clamp(12px, 2.5vw, 13px);
    --fs-md: clamp(13px, 2.8vw, 14px);
    --fs-lg: clamp(14px, 3vw, 16px);
    --fs-xl: clamp(16px, 3.5vw, 18px);
    --fs-2xl: clamp(18px, 4vw, 22px);
    --navbar-h: 48px;
    --bottom-nav-h: 0px;
    --pnl-strip-h: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
a, button, [onclick] { touch-action: manipulation; }
::selection { background: var(--blue-light); color: var(--blue); }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (max-width: 768px) {
    .segment-tabs::-webkit-scrollbar, .summary-bar::-webkit-scrollbar { display: none; }
    .segment-tabs, .summary-bar { -ms-overflow-style: none; scrollbar-width: none; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes dotFill { 0% { transform: scale(0); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

.main-app:not(.hidden) { animation: fadeIn 0.3s ease; }

/* ===================== LOADING SCREEN ===================== */
.loading-screen { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 998; padding: var(--space-lg); padding-top: var(--safe-top); }
.loading-container { text-align: center; width: 340px; max-width: 100%; }
.loading-logo { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 2.5vw, 12px); margin-bottom: clamp(24px, 6vw, 32px); }
.loading-logo .brand-logo { width: clamp(36px, 10vw, 44px); height: clamp(36px, 10vw, 44px); object-fit: contain; border-radius: var(--radius-sm); }
.loading-logo h1 { font-family: var(--font-display); font-size: clamp(22px, 5vw, 26px); font-weight: 400; color: var(--text-primary); }
.loading-spinner { display: flex; justify-content: center; margin-bottom: clamp(16px, 4vw, 20px); }
.spinner-ring { width: clamp(32px, 8vw, 40px); height: clamp(32px, 8vw, 40px); border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; }
.loading-status { font-size: var(--fs-md); color: var(--text-secondary); margin-bottom: clamp(12px, 3vw, 16px); font-weight: 500; }
.loading-progress-bar { width: 100%; height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; margin-bottom: clamp(20px, 5vw, 28px); }
.loading-progress-fill { height: 100%; width: 0%; background: var(--blue); border-radius: 4px; transition: width 0.4s ease; }
.loading-steps { display: flex; flex-direction: column; gap: clamp(8px, 2vw, 12px); text-align: left; padding: 0 clamp(4px, 2vw, 8px); }
.loading-step { display: flex; align-items: center; gap: clamp(8px, 2vw, 10px); font-size: var(--fs-base); color: var(--text-muted); transition: color 0.3s; }
.loading-step.active { color: var(--text-primary); }
.loading-step.done { color: var(--green); }
.step-icon { width: 20px; text-align: center; font-size: 14px; flex-shrink: 0; }
.step-icon.spinning { animation: spin 1s linear infinite; color: var(--blue); }
.step-icon.pending { color: var(--text-muted); }
.step-icon.done { color: var(--green); }

/* ===================== PIN SCREEN ===================== */
.pin-screen { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: var(--space-lg); padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }
.pin-container { text-align: center; width: 320px; max-width: 100%; }
.pin-logo { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 2.5vw, 12px); margin-bottom: 8px; }
.pin-logo .brand-logo { width: clamp(36px, 10vw, 44px); height: clamp(36px, 10vw, 44px); object-fit: contain; border-radius: var(--radius-sm); }
.pin-logo h1 { font-family: var(--font-display); font-size: clamp(22px, 5.5vw, 26px); font-weight: 400; color: var(--text-primary); letter-spacing: 0; }
.pin-subtitle { color: var(--text-secondary); font-size: var(--fs-md); margin-bottom: clamp(20px, 5vw, 32px); }
.pin-dots { display: flex; gap: clamp(10px, 3vw, 16px); justify-content: center; margin-bottom: clamp(8px, 2vw, 12px); }
.pin-dots .dot { width: clamp(12px, 3.5vw, 14px); height: clamp(12px, 3.5vw, 14px); border-radius: 50%; border: 2px solid var(--border); background: transparent; transition: all 0.15s ease; }
.pin-dots .dot.filled { background: var(--text-primary); border-color: var(--text-primary); animation: dotFill 0.2s ease; }
.pin-dots .dot.error { border-color: var(--red); background: var(--red); animation: shake 0.4s ease; }
.pin-error { color: var(--red); font-size: var(--fs-base); height: 20px; margin-bottom: clamp(8px, 2vw, 12px); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(6px, 1.5vw, 8px); max-width: 280px; margin: 0 auto; }
.pin-key { width: 100%; aspect-ratio: 1.4; max-height: 64px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); font-size: clamp(20px, 5vw, 22px); font-weight: 500; color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.1s ease; user-select: none; font-family: var(--font); -webkit-tap-highlight-color: transparent; }
.pin-key:hover { background: var(--bg-hover); }
.pin-key:active { background: var(--border); transform: scale(0.95); }
.pin-key-empty { border: none; pointer-events: none; background: transparent !important; }
.pin-key-del { color: var(--text-secondary); }
.pin-key-del svg { width: clamp(20px, 5vw, 24px); height: clamp(20px, 5vw, 24px); }

/* ===================== PROFILE SCREEN ===================== */
.profile-screen { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 999; padding: var(--space-lg); padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }
.profile-container { text-align: center; width: 380px; max-width: 100%; }
.profile-subtitle { color: var(--text-secondary); font-size: var(--fs-lg); margin-bottom: clamp(20px, 5vw, 28px); margin-top: 4px; }
.profile-list { display: flex; flex-direction: column; gap: clamp(6px, 1.5vw, 8px); }
.profile-card { display: flex; align-items: center; gap: clamp(10px, 2.5vw, 14px); padding: clamp(12px, 3vw, 14px) clamp(14px, 3.5vw, 18px); border: 1px solid var(--border); border-radius: var(--radius-lg); cursor: pointer; transition: all 0.15s ease; text-align: left; background: var(--bg); -webkit-tap-highlight-color: transparent; }
.profile-card:hover { border-color: var(--blue); background: var(--blue-light); box-shadow: var(--shadow-sm); }
.profile-card:active { transform: scale(0.98); box-shadow: var(--shadow-xs); }
.profile-card .pc-avatar { width: clamp(38px, 10vw, 44px); height: clamp(38px, 10vw, 44px); border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.profile-card .pc-avatar .material-symbols-rounded { font-size: clamp(22px, 5.5vw, 26px); }
.profile-card .pc-info { flex: 1; }
.profile-card .pc-name { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 400; color: var(--text-primary); }
.profile-card .pc-demat { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 1px; }
.profile-card .pc-arrow { color: var(--text-muted); flex-shrink: 0; transition: transform 0.15s; }
.profile-card:hover .pc-arrow { transform: translateX(2px); color: var(--blue); }

/* ===================== STOCK LOGOS ===================== */
.stock-logo { width: 24px; height: 24px; border-radius: 50%; object-fit: contain; background: var(--bg-secondary); border: 1px solid var(--border); flex-shrink: 0; vertical-align: middle; }
.stock-logo-fallback { width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; vertical-align: middle; font-family: var(--font); }
.instrument-cell { display: flex; align-items: center; gap: 10px; }
.instrument-info { display: flex; flex-direction: column; }
.mhc-logo { width: clamp(28px, 7vw, 34px); height: clamp(28px, 7vw, 34px); border-radius: 50%; object-fit: contain; background: var(--bg-secondary); border: 1px solid var(--border); flex-shrink: 0; }
.mhc-logo-fallback { width: clamp(28px, 7vw, 34px); height: clamp(28px, 7vw, 34px); border-radius: 50%; background: var(--blue); color: #fff; font-size: clamp(10px, 2.5vw, 12px); font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.mhc-top-left { display: flex; align-items: center; gap: clamp(8px, 2vw, 10px); }

/* ===================== NAVBAR ===================== */
.navbar { height: var(--navbar-h); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(12px, 3vw, 20px); padding-left: calc(clamp(12px, 3vw, 20px) + var(--safe-left)); padding-right: calc(clamp(12px, 3vw, 20px) + var(--safe-right)); background: rgba(255,255,255,0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 100; }
.navbar-left { display: flex; align-items: center; gap: clamp(6px, 2vw, 10px); }
.navbar-logo { width: clamp(24px, 6vw, 28px); height: clamp(24px, 6vw, 28px); object-fit: contain; border-radius: var(--radius-sm); }
.navbar-brand { font-family: var(--font-display); font-weight: 400; font-size: clamp(15px, 3.8vw, 17px); letter-spacing: 0; }
.navbar-center { position: absolute; left: 50%; transform: translateX(-50%); }
.navbar-nav { display: flex; gap: 0; }
.nav-link { text-decoration: none; color: var(--text-secondary); font-size: var(--fs-base); font-weight: 500; padding: 14px 18px; border-bottom: 2px solid transparent; transition: all 0.15s ease; }
.nav-link:hover { color: var(--text-primary); }
.nav-link.active { color: var(--blue); border-bottom-color: var(--blue); }
.navbar-right { position: relative; }
.user-badge { display: flex; align-items: center; gap: clamp(4px, 1.5vw, 8px); cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); transition: background 0.15s; -webkit-tap-highlight-color: transparent; }
.user-badge:hover { background: var(--bg-hover); }
.user-avatar { width: clamp(26px, 6.5vw, 28px); height: clamp(26px, 6.5vw, 28px); border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-avatar .material-symbols-rounded { font-size: clamp(16px, 4vw, 18px); }
.user-name { font-size: var(--fs-base); font-weight: 500; }
.member-dropdown { position: absolute; top: 44px; right: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); min-width: 220px; z-index: 200; padding: 6px; animation: scaleIn 0.15s ease; }
.member-item { display: flex; align-items: center; gap: clamp(8px, 2vw, 10px); padding: clamp(8px, 2vw, 10px) clamp(10px, 2.5vw, 12px); border-radius: var(--radius-sm); cursor: pointer; transition: background 0.15s; -webkit-tap-highlight-color: transparent; }
.member-item:hover { background: var(--bg-hover); }
.member-item.active { background: var(--blue-light); }
.member-item .m-avatar { width: clamp(28px, 7vw, 32px); height: clamp(28px, 7vw, 32px); border-radius: 50%; background: var(--blue); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.member-item .m-info { flex: 1; }
.member-item .m-name { font-size: var(--fs-base); font-weight: 500; }
.member-item .m-demat { font-size: var(--fs-sm); color: var(--text-muted); }
.member-all { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* ===================== SUMMARY BAR ===================== */
.summary-bar { display: flex; padding: clamp(12px, 3vw, 16px) clamp(14px, 3.5vw, 24px); padding-left: calc(clamp(14px, 3.5vw, 24px) + var(--safe-left)); padding-right: calc(clamp(14px, 3.5vw, 24px) + var(--safe-right)); gap: clamp(16px, 4vw, 32px); border-bottom: 1px solid var(--border); background: var(--bg); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.summary-item { display: flex; flex-direction: column; min-width: clamp(90px, 22vw, 120px); flex-shrink: 0; }
.summary-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }
.summary-value { font-size: clamp(14px, 3.5vw, 18px); font-weight: 600; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }
.summary-sub { font-size: var(--fs-sm); font-weight: 500; margin-top: 1px; }
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ===================== SEGMENT TABS ===================== */
.segment-tabs { display: flex; gap: 0; padding: 0 clamp(10px, 2.5vw, 24px); padding-left: calc(clamp(10px, 2.5vw, 24px) + var(--safe-left)); padding-right: calc(clamp(10px, 2.5vw, 24px) + var(--safe-right)); border-bottom: 1px solid var(--border); background: var(--bg); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.seg-tab { padding: clamp(8px, 2vw, 12px) clamp(12px, 3vw, 20px); background: none; border: none; border-bottom: 2px solid transparent; font-size: var(--fs-base); font-weight: 500; color: var(--text-secondary); cursor: pointer; font-family: var(--font); display: flex; align-items: center; gap: clamp(4px, 1vw, 6px); transition: all 0.15s; white-space: nowrap; -webkit-tap-highlight-color: transparent; flex-shrink: 0; }
.seg-tab:hover { color: var(--text-primary); }
.seg-tab.active { color: var(--text-primary); border-bottom-color: var(--blue); }
.seg-count { background: var(--bg-secondary); padding: 1px clamp(5px, 1.5vw, 7px); border-radius: 10px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); }
.seg-tab.active .seg-count { background: var(--blue-light); color: var(--blue); }

/* ===================== CONTENT ===================== */
.content { padding: 0 clamp(8px, 2vw, 24px); padding-left: calc(clamp(8px, 2vw, 24px) + var(--safe-left)); padding-right: calc(clamp(8px, 2vw, 24px) + var(--safe-right)); padding-bottom: calc(var(--pnl-strip-h) + var(--bottom-nav-h) + var(--safe-bottom) + 16px); }

/* ===================== HOLDINGS HEADER ===================== */
.holdings-header { display: flex; align-items: center; justify-content: space-between; padding: clamp(10px, 2.5vw, 14px) 0; gap: clamp(8px, 2vw, 12px); }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-secondary); padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2.5vw, 14px); border-radius: var(--radius-md); border: 1px solid var(--border); width: clamp(180px, 40vw, 260px); transition: border-color 0.15s, box-shadow 0.15s; }
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.search-box svg { flex-shrink: 0; }
.search-box input { border: none; background: none; outline: none; font-size: var(--fs-base); font-family: var(--font); color: var(--text-primary); width: 100%; min-width: 0; }
.search-box input::placeholder { color: var(--text-muted); }
.sort-controls select { padding: clamp(6px, 1.5vw, 8px) clamp(8px, 2vw, 12px); border: 1px solid var(--border); border-radius: var(--radius-md); font-size: var(--fs-base); font-family: var(--font); color: var(--text-secondary); background: var(--bg); cursor: pointer; outline: none; transition: border-color 0.15s; -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M2 4l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.sort-controls select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }

/* ===================== HOLDINGS TABLE ===================== */
.holdings-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-md); }
.holdings-table { width: 100%; border-collapse: collapse; }
.holdings-table thead th { text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; padding: clamp(8px, 2vw, 10px) clamp(8px, 2vw, 12px); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); white-space: nowrap; }
.holdings-table tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
.holdings-table tbody tr:hover { background: var(--bg-hover); }
.holdings-table tbody tr:last-child { border-bottom: none; }
.holdings-table td { padding: clamp(10px, 2.5vw, 14px) clamp(8px, 2vw, 12px); font-size: var(--fs-base); }
.col-name { min-width: 180px; }
.col-num { text-align: right !important; min-width: 100px; }
.holdings-table td.col-num { text-align: right; font-variant-numeric: tabular-nums; }
.stock-name { font-weight: 600; font-size: var(--fs-base); color: var(--text-primary); }
.stock-exchange { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 400; }
.pnl-value { font-weight: 600; }
.pnl-percent { font-size: var(--fs-xs); font-weight: 500; }

/* ===================== POSITIONS ===================== */
.positions-summary { display: flex; gap: clamp(16px, 4vw, 24px); padding: clamp(12px, 3vw, 16px) 0; }

/* ===================== FUNDS ===================== */
.funds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(240px, 40vw, 280px), 1fr)); gap: clamp(10px, 2.5vw, 16px); padding: clamp(14px, 3.5vw, 20px) 0; }
.fund-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: clamp(12px, 3vw, 18px); transition: box-shadow 0.15s, transform 0.15s; background: var(--bg-card); }
.fund-card:hover { box-shadow: var(--shadow-sm); }
.fund-card:active { transform: scale(0.99); }
.fund-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: clamp(8px, 2vw, 12px); gap: 8px; }
.fund-name { font-size: var(--fs-base); font-weight: 600; color: var(--text-primary); line-height: 1.3; flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.fund-type { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; background: var(--bg-secondary); padding: 2px 8px; border-radius: 4px; height: fit-content; white-space: nowrap; flex-shrink: 0; }
.fund-row { display: flex; justify-content: space-between; padding: clamp(3px, 0.8vw, 4px) 0; font-size: var(--fs-sm); gap: 8px; }
.fund-row-label { color: var(--text-secondary); flex-shrink: 0; }
.fund-row-value { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; word-break: break-word; }
.fund-divider { border: none; border-top: 1px solid var(--border-light); margin: clamp(4px, 1vw, 8px) 0; }

/* ===================== PNL STRIP ===================== */
.pnl-strip { position: fixed; bottom: var(--bottom-nav-h); left: 0; right: 0; height: var(--pnl-strip-h); border-top: 1px solid var(--border); background: rgba(255,255,255,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); display: flex; align-items: center; justify-content: center; gap: clamp(16px, 4vw, 48px); padding: 0 clamp(8px, 2vw, 24px); padding-left: calc(clamp(8px, 2vw, 24px) + var(--safe-left)); padding-right: calc(clamp(8px, 2vw, 24px) + var(--safe-right)); z-index: 100; }
.pnl-item { display: flex; align-items: center; gap: clamp(4px, 1vw, 8px); }
.pnl-item-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 500; }
.pnl-item-value { font-size: clamp(12px, 3vw, 15px); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===================== MOBILE BOTTOM NAV (hidden desktop) ===================== */
.mobile-bottom-nav { display: none; }
.mobile-holding-card { display: none; }
.mobile-cards-container { display: none; }

/* ===================== EMPTY STATE ===================== */
.empty-state { text-align: center; padding: clamp(32px, 10vw, 60px) clamp(16px, 4vw, 20px); color: var(--text-muted); }
.empty-state p { font-size: var(--fs-md); }

/* ===================== PULL TO REFRESH ===================== */
.pull-indicator { text-align: center; padding: 12px; font-size: var(--fs-sm); color: var(--text-muted); transition: opacity 0.2s; display: none; }
.pull-indicator.visible { display: block; animation: fadeIn 0.2s ease; }

/* ===================== TOAST ===================== */
.toast { position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text-primary); color: #fff; padding: 10px 20px; border-radius: var(--radius-xl); font-size: var(--fs-base); font-weight: 500; z-index: 9999; opacity: 0; transition: all 0.3s ease; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow-lg); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== OVERLAY / BACKDROP ===================== */
.overlay-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 190; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.overlay-backdrop.active { opacity: 1; pointer-events: auto; }

/* ==================================================================
   RESPONSIVE: LARGE DESKTOP (min-width: 1200px)
   ================================================================== */
@media (min-width: 1200px) {
    .content { max-width: 1200px; margin: 0 auto; }
    .summary-bar { gap: 40px; padding: 18px 28px; }
    .holdings-table td { padding: 16px 14px; }
}

/* ==================================================================
   RESPONSIVE: TABLET (max-width: 768px)
   ================================================================== */
@media (max-width: 768px) {
    :root { --navbar-h: 50px; --bottom-nav-h: 60px; --pnl-strip-h: 48px; }
    .navbar { height: var(--navbar-h); padding: 0 12px; }
    .navbar-center { display: none; }
    .navbar-right .user-name { display: none; }
    .navbar-right .user-badge > svg { display: none; }
    .mobile-bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,0.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); justify-content: space-around; align-items: center; padding: 4px 0; padding-bottom: max(4px, var(--safe-bottom)); padding-left: var(--safe-left); padding-right: var(--safe-right); z-index: 200; height: var(--bottom-nav-h); }
    .mob-nav-item { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--text-muted); font-size: clamp(9px, 2.2vw, 10px); font-weight: 500; padding: 6px 12px; border-radius: var(--radius-md); transition: color 0.15s, transform 0.1s; -webkit-tap-highlight-color: transparent; min-width: 56px; min-height: 44px; justify-content: center; }
    .mob-nav-item.active { color: var(--blue); }
    .mob-nav-item.active svg { stroke: var(--blue); }
    .mob-nav-item:active { transform: scale(0.92); background: var(--bg-hover); }
    .mob-nav-item svg { width: clamp(18px, 4.5vw, 22px); height: clamp(18px, 4.5vw, 22px); }
    .pnl-strip { bottom: var(--bottom-nav-h); height: var(--pnl-strip-h); gap: 8px; padding: 0 10px; justify-content: space-around; }
    .pnl-item { gap: 3px; flex-direction: column; align-items: center; }
    .pnl-item-label { font-size: clamp(7px, 1.8vw, 9px); letter-spacing: 0.3px; }
    .pnl-item-value { font-size: clamp(11px, 2.8vw, 13px); }
    .summary-bar { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(8px, 2vw, 12px); padding: clamp(10px, 2.5vw, 14px); overflow-x: visible; }
    .summary-item { min-width: unset; padding: clamp(6px, 1.5vw, 8px); background: var(--bg-secondary); border-radius: var(--radius-sm); }
    .summary-value { font-size: clamp(14px, 3.5vw, 16px); }
    .summary-sub { font-size: clamp(10px, 2.5vw, 11px); }
    .segment-tabs { padding: 0 10px; }
    .seg-tab { padding: 10px clamp(10px, 2.5vw, 14px); font-size: clamp(11px, 2.8vw, 13px); }
    .content { padding: 0 clamp(8px, 2vw, 12px); padding-bottom: calc(var(--pnl-strip-h) + var(--bottom-nav-h) + var(--safe-bottom) + 16px); }
    .holdings-header { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
    .search-box { width: 100%; }
    .sort-controls { width: 100%; }
    .sort-controls select { width: 100%; padding: 10px 12px; font-size: var(--fs-md); }
    .funds-grid { grid-template-columns: 1fr; }
    .member-dropdown { position: fixed; top: auto; bottom: var(--bottom-nav-h); left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-xl); max-height: 60vh; overflow-y: auto; padding: 8px; animation: slideUp 0.2s ease; }
    .member-item { padding: clamp(10px, 2.5vw, 12px); min-height: 48px; }
    .member-item .m-avatar { width: clamp(32px, 8vw, 36px); height: clamp(32px, 8vw, 36px); }
    .member-item .m-name { font-size: var(--fs-md); }
    .member-item .m-demat { font-size: var(--fs-sm); }
    .positions-summary { flex-wrap: wrap; gap: 12px; }
}

/* ==================================================================
   RESPONSIVE: LARGE PHONE (max-width: 600px) — Cards
   ================================================================== */
@media (max-width: 600px) {
    :root { --navbar-h: 48px; --bottom-nav-h: 56px; --pnl-strip-h: 44px; }
    .holdings-table-wrap { display: none !important; }
    .mobile-holding-card { display: block; }
    .mobile-cards-container { display: flex; flex-direction: column; gap: 0; }
    .mobile-holding-card { padding: clamp(12px, 3vw, 16px) clamp(2px, 1vw, 6px); border-bottom: 1px solid var(--border-light); transition: background 0.1s; animation: fadeInUp 0.25s ease both; }
    .mobile-holding-card:nth-child(1) { animation-delay: 0.02s; }
    .mobile-holding-card:nth-child(2) { animation-delay: 0.04s; }
    .mobile-holding-card:nth-child(3) { animation-delay: 0.06s; }
    .mobile-holding-card:nth-child(4) { animation-delay: 0.08s; }
    .mobile-holding-card:nth-child(5) { animation-delay: 0.10s; }
    .mobile-holding-card:nth-child(n+6) { animation-delay: 0.12s; }
    .mobile-holding-card:active { background: var(--bg-hover); }
    .mobile-holding-card:last-child { border-bottom: none; }
    .mhc-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: clamp(6px, 1.5vw, 10px); gap: 8px; }
    .mhc-name { font-weight: 600; font-size: clamp(13px, 3.3vw, 15px); color: var(--text-primary); line-height: 1.3; }
    .mhc-exchange { font-size: clamp(10px, 2.5vw, 11px); color: var(--text-muted); margin-top: 1px; }
    .mhc-pnl { text-align: right; flex-shrink: 0; }
    .mhc-pnl-val { font-weight: 700; font-size: clamp(13px, 3.3vw, 15px); display: block; font-variant-numeric: tabular-nums; line-height: 1.3; }
    .mhc-pnl-pct { font-size: clamp(10px, 2.5vw, 11px); font-weight: 500; }
    .mhc-bottom { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(4px, 1vw, 8px); padding: clamp(6px, 1.5vw, 8px) 0; }
    .mhc-stat { display: flex; flex-direction: column; gap: 1px; }
    .mhc-stat-label { font-size: clamp(8px, 2vw, 10px); text-transform: uppercase; letter-spacing: 0.3px; color: var(--text-muted); font-weight: 500; }
    .mhc-stat-value { font-size: clamp(11px, 2.8vw, 13px); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-primary); }
    .mhc-day { display: flex; justify-content: space-between; align-items: center; margin-top: clamp(4px, 1vw, 6px); padding-top: clamp(4px, 1vw, 6px); border-top: 1px dashed var(--border); }
    .mhc-day-label { font-size: clamp(8px, 2vw, 10px); text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.3px; font-weight: 500; }
    .mhc-day-value { font-size: clamp(11px, 2.8vw, 12px); font-weight: 600; font-variant-numeric: tabular-nums; }
    .mhc-pnl-val.positive { background: var(--green-soft); padding: 2px 6px; border-radius: 4px; }
    .mhc-pnl-val.negative { background: var(--red-soft); padding: 2px 6px; border-radius: 4px; }
    .pnl-strip { height: var(--pnl-strip-h); gap: 4px; padding: 0 6px; bottom: var(--bottom-nav-h); }
    .pnl-item { flex-direction: row; gap: 3px; }
    .pnl-item-label { font-size: clamp(7px, 1.8vw, 8px); }
    .pnl-item-value { font-size: clamp(10px, 2.5vw, 11px); }
    .summary-bar { grid-template-columns: 1fr 1fr; gap: clamp(6px, 1.5vw, 8px); padding: clamp(8px, 2vw, 12px) clamp(8px, 2vw, 10px); }
    .summary-item { padding: clamp(8px, 2vw, 10px); background: var(--bg-secondary); border-radius: var(--radius-sm); }
    .summary-label { font-size: clamp(8px, 2vw, 10px); }
    .summary-value { font-size: clamp(13px, 3.3vw, 15px); }
    .summary-sub { font-size: clamp(9px, 2.3vw, 10px); }
    .pin-container { width: 100%; padding: 0 clamp(16px, 4vw, 24px); }
    .pin-pad { max-width: 100%; gap: clamp(6px, 1.5vw, 10px); }
    .pin-key { height: clamp(52px, 13vw, 60px); font-size: clamp(20px, 5vw, 24px); border-radius: var(--radius-lg); }
    .pin-logo h1 { font-size: clamp(20px, 5vw, 24px); }
    .pin-dots .dot { width: clamp(14px, 3.5vw, 16px); height: clamp(14px, 3.5vw, 16px); }
    .mobile-bottom-nav { height: var(--bottom-nav-h); padding: 2px 0; padding-bottom: max(2px, var(--safe-bottom)); }
    .mob-nav-item { padding: 4px 8px; min-width: 52px; min-height: 40px; font-size: clamp(8px, 2vw, 9px); }
    .mob-nav-item svg { width: clamp(16px, 4vw, 20px); height: clamp(16px, 4vw, 20px); }
    .content { padding-bottom: calc(var(--pnl-strip-h) + var(--bottom-nav-h) + var(--safe-bottom) + 12px); }
    .fund-card { padding: clamp(10px, 2.5vw, 14px); }
    .fund-row { font-size: clamp(10px, 2.5vw, 12px); padding: clamp(2px, 0.6vw, 3px) 0; }
    .fund-name { font-size: clamp(11px, 2.8vw, 13px); }
    .positions-summary { flex-direction: column; gap: 8px; }
}

/* ==================================================================
   RESPONSIVE: MEDIUM PHONE (max-width: 480px)
   ================================================================== */
@media (max-width: 480px) {
    .summary-bar { gap: 6px; padding: 8px; }
    .summary-item { padding: 8px; }
    .mhc-bottom { gap: 4px; }
    .pnl-item-label { font-size: clamp(6px, 1.6vw, 8px); }
    .pnl-item-value { font-size: clamp(9px, 2.3vw, 11px); }
    .navbar { padding: 0 10px; }
    .navbar-logo { width: 24px; height: 24px; }
    .navbar-brand { font-size: clamp(14px, 3.5vw, 16px); }
    .fund-card-header { flex-direction: column; gap: 4px; }
    .fund-name { max-width: 100%; }
}

/* ==================================================================
   RESPONSIVE: SMALL PHONE (max-width: 414px)
   ================================================================== */
@media (max-width: 414px) {
    .mobile-holding-card { padding: 10px 2px; }
    .mhc-name { font-size: clamp(12px, 3vw, 13px); }
    .mhc-pnl-val { font-size: clamp(12px, 3vw, 13px); }
    .mhc-stat-value { font-size: clamp(10px, 2.5vw, 12px); }
    .mhc-stat-label { font-size: clamp(7px, 1.8vw, 9px); }
    .mhc-day-value { font-size: clamp(10px, 2.5vw, 11px); }
    .seg-tab { padding: 8px clamp(8px, 2vw, 12px); font-size: clamp(10px, 2.5vw, 12px); }
    .seg-count { padding: 0px 5px; font-size: clamp(8px, 2vw, 10px); }
    .profile-card { padding: 10px 12px; gap: 10px; }
    .profile-card .pc-avatar { width: 36px; height: 36px; }
    .profile-card .pc-name { font-size: clamp(13px, 3.3vw, 14px); }
    .profile-card .pc-demat { font-size: clamp(9px, 2.3vw, 10px); }
}

/* ==================================================================
   RESPONSIVE: EXTRA SMALL PHONE (max-width: 390px)
   ================================================================== */
@media (max-width: 390px) {
    .summary-bar { gap: 5px; padding: 6px; }
    .summary-item { padding: 6px 8px; }
    .summary-label { font-size: clamp(7px, 1.8vw, 9px); }
    .summary-value { font-size: clamp(12px, 3vw, 14px); }
    .mhc-logo, .mhc-logo-fallback { width: 26px; height: 26px; }
    .mhc-top-left { gap: 6px; }
    .member-dropdown { left: 4px; right: 4px; padding: 6px; }
    .member-item { padding: 10px 8px; }
}

/* ==================================================================
   RESPONSIVE: VERY SMALL PHONE (max-width: 360px)
   ================================================================== */
@media (max-width: 360px) {
    :root { --bottom-nav-h: 52px; --pnl-strip-h: 38px; }
    .summary-bar { grid-template-columns: 1fr; gap: 4px; padding: 6px; }
    .summary-item { flex-direction: row; justify-content: space-between; align-items: center; padding: 6px 8px; }
    .summary-sub { display: none; }
    .mhc-bottom { grid-template-columns: repeat(3, 1fr); gap: 2px; }
    .mhc-stat-label { font-size: clamp(6px, 1.5vw, 8px); }
    .mhc-stat-value { font-size: clamp(9px, 2.3vw, 11px); }
    .pin-key { height: clamp(44px, 11vw, 52px); font-size: clamp(18px, 4.5vw, 20px); }
    .pin-pad { gap: 5px; }
    .pin-dots .dot { width: 12px; height: 12px; }
    .pin-dots { gap: 8px; }
    .fund-card { padding: 10px; }
    .fund-row { font-size: clamp(9px, 2.3vw, 11px); }
    .mob-nav-item { min-width: 44px; min-height: 36px; padding: 3px 6px; font-size: clamp(7px, 1.8vw, 8px); }
    .mob-nav-item svg { width: 16px; height: 16px; }
    .pnl-strip { height: var(--pnl-strip-h); gap: 2px; }
    .pnl-item { gap: 2px; }
}

/* ==================================================================
   RESPONSIVE: ULTRA SMALL (max-width: 320px)
   ================================================================== */
@media (max-width: 320px) {
    :root { --bottom-nav-h: 48px; --pnl-strip-h: 34px; }
    .navbar { height: 44px; padding: 0 8px; }
    .navbar-logo { width: 22px; height: 22px; }
    .navbar-brand { font-size: 13px; }
    .mobile-holding-card { padding: 8px 0; }
    .mhc-name { font-size: 11px; }
    .mhc-pnl-val { font-size: 11px; }
    .mhc-exchange { font-size: 9px; }
    .mhc-stat-label { font-size: 6px; letter-spacing: 0.2px; }
    .mhc-stat-value { font-size: 9px; }
    .mhc-day-label { font-size: 7px; }
    .mhc-day-value { font-size: 9px; }
    .pnl-strip { display: none; }
    .content { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 10px); }
    .summary-item { padding: 4px 6px; }
    .summary-label { font-size: 7px; }
    .summary-value { font-size: 11px; }
    .seg-tab { padding: 6px 8px; font-size: 10px; }
    .seg-count { font-size: 8px; padding: 0 4px; }
    .fund-card { padding: 8px; }
    .fund-name { font-size: 10px; }
    .fund-row { font-size: 9px; }
    .pin-key { height: 42px; font-size: 18px; border-radius: 8px; }
    .pin-container { padding: 0 12px; }
    .pin-logo h1 { font-size: 18px; }
    .pin-subtitle { font-size: 12px; margin-bottom: 16px; }
    .loading-logo h1 { font-size: 18px; }
    .loading-logo .brand-logo { width: 32px; height: 32px; }
    .profile-card { padding: 8px 10px; gap: 8px; }
    .profile-card .pc-avatar { width: 32px; height: 32px; }
    .profile-card .pc-avatar .material-symbols-rounded { font-size: 18px; }
    .profile-card .pc-name { font-size: 12px; }
    .profile-card .pc-demat { font-size: 9px; }
    .profile-subtitle { font-size: 12px; margin-bottom: 16px; }
}

/* ==================================================================
   LANDSCAPE MODE
   ================================================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .pin-screen, .profile-screen, .loading-screen { overflow-y: auto; align-items: flex-start; padding-top: 20px; }
    .pin-key { height: 44px; aspect-ratio: auto; }
    .pin-dots { margin-bottom: 6px; }
    .pin-subtitle { margin-bottom: 12px; }
    .pin-logo { margin-bottom: 4px; }
    .pin-logo h1 { font-size: 20px; }
    .pin-logo .brand-logo { width: 32px; height: 32px; }
    .mobile-bottom-nav { height: 48px; padding-bottom: 2px; }
    .mob-nav-item span { display: none; }
    .mob-nav-item { min-height: 36px; }
    .summary-bar { display: flex; overflow-x: auto; gap: 16px; padding: 8px 10px; }
    .summary-item { min-width: 100px; padding: 4px 8px; flex-shrink: 0; }
    .pnl-strip { height: 36px; }
    .content { padding-bottom: calc(36px + 48px + 10px); }
    .profile-card { padding: 8px 12px; }
    .profile-card .pc-avatar { width: 32px; height: 32px; }
}

/* Tablet landscape — re-show desktop nav */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .navbar-center { display: block; }
    .mobile-bottom-nav { display: none; }
    :root { --bottom-nav-h: 0px; }
    .member-dropdown { position: absolute; top: 44px; bottom: auto; left: auto; right: 0; border-radius: var(--radius-md); }
    .pnl-strip { bottom: 0; }
}

/* ==================================================================
   ACCESSIBILITY
   ================================================================== */
@media (prefers-contrast: high) {
    :root { --border: #000; --text-muted: #555; --bg-secondary: #eee; }
    .mobile-holding-card { border-bottom-width: 2px; }
    .fund-card { border-width: 2px; }
}

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

/* Hover-capable devices only */
@media (hover: hover) and (pointer: fine) {
    .mobile-holding-card:hover { background: var(--bg-hover); }
    .fund-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
    .profile-card:hover .pc-arrow { transform: translateX(4px); }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    .fund-card:hover { box-shadow: none; transform: none; }
    .profile-card:hover { box-shadow: none; }
    .seg-tab { min-height: 44px; }
    .member-item { min-height: 48px; }
    .search-box input { min-height: 36px; font-size: 16px; }
    .sort-controls select { min-height: 44px; font-size: 16px; }
}

/* Print */
@media print {
    .navbar, .pnl-strip, .mobile-bottom-nav, .segment-tabs, .holdings-header { display: none !important; }
    .content { padding: 0; }
    .mobile-holding-card { display: block; page-break-inside: avoid; }
    .holdings-table-wrap { display: block !important; }
    body { font-size: 11px; }
}
