:root {
    --bg: #0f1117;
    --bg2: #1a1d27;
    --bg3: #242834;
    --border: #2e3240;
    --text: #e1e4eb;
    --text2: #9ca3af;
    --green: #22c55e;
    --green-bg: rgba(34,197,94,0.12);
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.12);
    --blue: #3b82f6;
    --blue-bg: rgba(59,130,246,0.12);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245,158,11,0.12);
    --purple: #a855f7;
    --radius: 10px;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sticky top bar */
#top-freeze {
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--bg2);
}

/* Header */
.header {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.header h1 span { color: var(--blue); }
.header-actions { display: flex; gap: 10px; align-items: center; }
.last-updated { font-size: 12px; color: var(--text2); }

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
}
.tab {
    padding: 12px 24px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text2);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

/* Range bars (30D and 52W) */
.range-bar-wrap { margin-top: 4px; }
.range-bar-track {
    width: 100%;
    height: 4px;
    background: var(--bg3);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}
.range-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}
.range-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: var(--text2);
    margin-top: 1px;
    line-height: 1;
}

/* Quick filter chips */
.filter-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.filter-chip {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text2);
    transition: all 0.15s;
    white-space: nowrap;
    user-select: none;
}
.filter-chip:hover { color: var(--text); border-color: var(--blue); }
.filter-chip.chip-active { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); }
.filter-chip.chip-green  { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.filter-chip.chip-red    { background: var(--red-bg);   color: var(--red);   border-color: var(--red);   }
.filter-chip.chip-yellow { background: var(--yellow-bg);color: var(--yellow);border-color: var(--yellow); }

/* Row selected highlight */
.stock-main-row { cursor: pointer; transition: background 0.15s; }
.stock-main-row:hover { background: rgba(255,255,255,0.03); }

/* Main Content */
.content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Cards */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Summary Cards */
.summary-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.summary-card {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}
.summary-label {
    font-size: 12px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.summary-value {
    font-size: 24px;
    font-weight: 700;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { background: var(--border); }
.btn-primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}
.btn-primary:hover { opacity: 0.9; }
.btn-danger {
    color: var(--red);
    border-color: transparent;
    background: transparent;
    padding: 4px 8px;
}
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Form */
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}
.form-group label {
    font-size: 12px;
    color: var(--text2);
    font-weight: 500;
}
.form-group input, .form-group select {
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus {
    border-color: var(--blue);
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: min(350px, 92vw);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    display: none;
}
.autocomplete-dropdown.show { display: block; }
.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg3); }
.autocomplete-item .symbol {
    font-weight: 600;
    color: var(--blue);
    min-width: 100px;
}
.autocomplete-item .name {
    color: var(--text2);
    flex: 1;
    margin-left: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.autocomplete-item .exchange {
    font-size: 11px;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--text2);
    margin-left: 8px;
}

/* Tables — default wrapper with mobile horizontal scroll */
.table-wrap {
    margin: 0 -20px;
    padding: 0 20px;
}
@media (max-width: 1200px) {
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Dashboard spreadsheet-style scroll container:
   Both axes scroll, thead sticks to top of container, fixed height.
   Used only for the stock dashboard table (wide 20D/30D data). */
.table-scroll-box {
    margin: 0 -20px;
    overflow: auto;
    max-height: calc(100vh - 180px);
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.table-scroll-box thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--bg2);
}
/* First column (Stock name) stays frozen when scrolling horizontally */
.table-scroll-box td:first-child,
.table-scroll-box th:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg2);
}
.table-scroll-box thead th:first-child {
    z-index: 4; /* corner cell: sticky both axes */
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    text-align: left;
    padding: 6px 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg2);
}

/* Dashboard controls bar — sticky inside .card (below #top-freeze) */
#dash-sticky-bar {
    position: sticky;
    top: var(--top-freeze-h, 99px);
    z-index: 90;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px 12px;
}

@media (max-width: 480px) {
    #dash-sticky-bar { padding: 10px 14px; }
}
tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr:hover { background: var(--bg3); }

/* Lot rows */
.stock-main-row { border-left: 3px solid transparent; }
.lot-row {
    border-left: 3px solid var(--blue);
    animation: fadeIn 0.2s ease;
}
.lot-row td {
    padding: 6px 12px !important;
    font-size: 12px !important;
    border-bottom: 1px solid rgba(46,50,64,0.6);
}
.lot-toggle { transition: transform 0.15s; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Day Selector */
.day-selector {
    display: flex;
    gap: 4px;
    background: var(--bg);
    padding: 3px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.day-selector .btn {
    border: none;
    background: transparent;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
}
.day-selector .day-active {
    background: var(--blue);
    color: #fff;
}

.profit { color: var(--green); }
.loss { color: var(--red); }
.neutral { color: var(--text2); }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }

/* Indicator Cards */
.indicators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.indicator-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
}
.indicator-label {
    font-size: 10px;
    color: var(--text2);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.indicator-value {
    font-size: 16px;
    font-weight: 700;
}

/* Watchlist Stock Card */
.watchlist-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.watchlist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.watchlist-header h3 {
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.watchlist-header .price {
    font-size: 20px;
    font-weight: 700;
}

/* Loader */
.loader {
    text-align: center;
    padding: 40px;
    color: var(--text2);
}
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 13px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    animation: slideIn 0.3s ease;
    min-width: 250px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    animation: fadeInModal 0.15s ease;
}
@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-body {
    padding: 20px;
}
.modal-body .form-group {
    margin-bottom: 12px;
}
.modal-body .form-group input {
    width: 100%;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text2);
}
.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text);
}

/* Import tab */
.import-preview-table { width:100%; border-collapse:collapse; margin-top:8px; font-size:13px; }
.import-preview-table th { background:var(--bg2); padding:8px 10px; text-align:left; font-weight:600; color:var(--text2); border-bottom:1px solid var(--border); white-space:nowrap; }
.import-preview-table td { padding:7px 10px; border-bottom:1px solid var(--border); vertical-align:middle; }
.import-preview-table tr.row-unmatched { background:rgba(239,68,68,0.06); }
.import-preview-table tr.row-skip td { opacity:0.4; }
.import-match-ok  { color:var(--green); font-size:12px; font-weight:600; }
.import-match-no  { color:var(--red);   font-size:12px; font-weight:600; }
.import-edit { background:var(--bg2); border:1px solid var(--border); border-radius:4px; color:var(--text); padding:3px 6px; font-size:12px; width:110px; }
.import-summary { display:flex; gap:16px; align-items:center; flex-wrap:wrap; padding:10px 0; font-size:13px; color:var(--text2); }
.import-summary strong { color:var(--text); }
.skip-chk { cursor:pointer; width:14px; height:14px; accent-color:var(--accent); }

/* Sync tab — override sticky thead for scrollable preview tables */
#sync-preview thead th,
#sync-content .table-wrap[style*="max-height"] thead th {
    position: static;
}

/* Trades charge detail — constrain within cell */
#trades-content td table { max-width: 220px; }

/* Group sub-boxes — override sticky thead inside scrollable cards */
.groww-group-card thead th,
#ts-postsale .card thead th { position: static; }

/* Section headers — wrap on mobile */
.trade-section-header { flex-wrap: wrap !important; row-gap: 6px; }

/* Groww group card */
.groww-group-card { border-left: 3px solid var(--blue); }
.groww-group-header:hover { opacity: 0.85; }

/* Import row unmatched (reuse for groww) */
tr.row-unmatched { background: rgba(239,68,68,0.06); }

/* ── Responsive ─────────────────────────────────────────── */

/* Tablet (≤ 768px) */
@media (max-width: 768px) {
    .header        { padding: 12px 16px; }
    .tabs          { padding: 0 16px; }
    .content       { padding: 16px; }
    .form-row      { flex-direction: column; }
    .form-group    { width: 100%; }
    .summary-row   { grid-template-columns: 1fr 1fr; }
    .card-title    { flex-wrap: wrap; row-gap: 8px; }
    .modal-content { margin: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
    /* Group-by selector wrapping */
    .day-selector { margin-left: 0 !important; margin-top: 4px; }
    /* Trades charge detail */
    #trades-content td table { max-width: 180px; font-size: 9px; }
}

/* Phone (≤ 480px) */
@media (max-width: 480px) {
    /* Watchlist */
    .watchlist-header        { flex-wrap: wrap; gap: 8px; }
    .watchlist-header .price { font-size: 16px; }
    .indicators-grid         { grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); gap: 7px; }
    .indicator-value         { font-size: 13px; }

    /* Header — two-row layout on mobile */
    .header             { padding: 10px 14px; gap: 6px; flex-wrap: wrap; }
    .header h1          { font-size: 15px; letter-spacing: 0; white-space: nowrap; flex: 1 0 auto; }
    .header h1 span + span { display: none; }          /* hide "(TYP)" label */
    .header-actions     { flex: 0 0 100%; justify-content: flex-end; gap: 6px; }
    .refresh-wrap       { display: none; }             /* Refresh Data — not needed on mobile */
    #live-refresh-label { display: none; }             /* "Off-hours · Xs" — not needed on mobile */
    #btn-refresh-master,
    #btn-refresh-mf     { display: none; }
    #user-display       { display: none; }

    /* Tab bar — horizontal scroll, no wrap */
    .tabs {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab {
        padding: 10px 14px;
        font-size: 12px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Content + Cards */
    .content           { padding: 10px; }
    .card              { padding: 12px; margin-bottom: 12px; }
    .card-title        { font-size: 13px; margin-bottom: 8px; flex-wrap: wrap; row-gap: 8px; }

    /* Summary cards — 2 per row */
    .summary-row       { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
    .summary-card      { padding: 10px 12px; }
    .summary-value     { font-size: 16px; }
    .summary-label     { font-size: 10px; margin-bottom: 4px; }

    /* Table scroll area flush to card edge */
    .table-wrap        { margin: 0 -12px; padding: 0 12px; }

    /* Buttons — slightly tighter */
    .btn               { padding: 6px 11px; font-size: 12px; }

    /* Forms on mobile */
    .form-row          { flex-direction: column; gap: 10px; }
    .form-group        { width: 100% !important; min-width: unset !important; }
    .form-control      { font-size: 14px; padding: 9px 11px; }
    select.form-control { font-size: 14px; }

    /* Trades filter bar */
    .filter-chips      { gap: 5px; }
    .filter-chip       { font-size: 10px; padding: 3px 8px; }

    /* Modal — full-width on phone */
    .modal-overlay     { padding: 8px; align-items: flex-end; }
    .modal-content     { max-height: 85vh; overflow-y: auto; border-radius: 12px 12px 0 0; }

    /* Day selector buttons */
    .day-selector .btn { padding: 4px 8px; font-size: 11px; }

    /* Toast — bottom */
    .toast-container   { top: auto; bottom: 14px; right: 10px; left: 10px; align-items: stretch; }
    .toast             { min-width: unset; width: 100%; font-size: 12px; padding: 10px 14px; }

    /* Safe area for iOS/Android nav bar */
    .content           { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* Small phones (≤ 360px) */
@media (max-width: 360px) {
    .header h1         { font-size: 13px; }
    .tab               { padding: 8px 9px; font-size: 11px; }
    .summary-value     { font-size: 14px; }
    .summary-card      { padding: 8px 10px; }
    .content           { padding: 8px; }
    .filter-chip       { font-size: 9px; padding: 3px 6px; }
}

/* ── Action buttons in tables (Buy / Sell / Remove) ──────────────────────── */
.btn-act {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 5px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: background 0.12s, opacity 0.12s;
    white-space: nowrap;
    line-height: 1;
}
.btn-act-buy  { color: var(--green);  border-color: var(--green); }
.btn-act-sell { color: var(--yellow); border-color: var(--yellow); }
.btn-act-del  { color: var(--red);    border-color: transparent; }
.btn-act:hover { filter: brightness(1.15); }
.btn-act-del:hover { background: var(--red-bg); border-color: var(--red); }
@media (max-width: 480px) {
    .btn-act { padding: 3px 6px; font-size: 10px; }
}

/* ── Refresh data dropdown button ─────────────────────────────────────────── */
.refresh-wrap { position: relative; }

/* ── Profile Switcher Dropdown ──────────────────────────────────────────── */
.profile-wrap { position: relative; }
.profile-trigger {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--border); background: var(--bg2);
    color: var(--text); font-size: 12px; font-weight: 600;
    transition: border-color .15s, background .15s;
}
.profile-trigger:hover { border-color: var(--blue); background: var(--bg3); }
.profile-trigger .profile-caret {
    font-size: 10px; opacity: .6; margin-left: 2px;
}
.profile-dd {
    display: none; position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; z-index: 300; min-width: 210px;
    box-shadow: 0 8px 30px rgba(0,0,0,.35);
    padding: 6px 0; overflow: visible;
}
.profile-dd.open { display: block; }
.profile-dd-section { padding: 4px 6px; }
.profile-dd-divider { height: 1px; background: var(--border); margin: 4px 8px; }
.profile-dd-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
    color: var(--text2); padding: 6px 12px 4px; font-weight: 600;
}
.profile-dd-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 6px; margin: 1px 6px;
    cursor: pointer; transition: background .1s; border: none;
    background: none; width: calc(100% - 12px); text-align: left;
    font-size: 13px; color: var(--text);
}
.profile-dd-item:hover { background: var(--bg3); }
.profile-dd-item.active { background: var(--bg3); font-weight: 600; }
.profile-dd-item .pi-check {
    width: 16px; font-size: 13px; text-align: center; flex-shrink: 0;
    color: var(--blue); font-weight: 700;
}
.profile-dd-item .pi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-dd-item .pi-del {
    opacity: 0; font-size: 15px; color: var(--text2); background: none;
    border: none; cursor: pointer; padding: 0 2px; line-height: 1; transition: opacity .15s, color .15s;
}
.profile-dd-item:hover .pi-del { opacity: .7; }
.profile-dd-item .pi-del:hover { color: var(--red); opacity: 1; }
.profile-dd-action {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 6px; margin: 1px 6px;
    cursor: pointer; transition: background .1s; border: none;
    background: none; width: calc(100% - 12px); text-align: left;
    font-size: 12px; color: var(--text2);
}
.profile-dd-action:hover { background: var(--bg3); color: var(--text); }
.profile-dd-action.danger { color: var(--red); opacity: .8; }
.profile-dd-action.danger:hover { opacity: 1; background: rgba(239,68,68,.08); }
.profile-dd-action .pi-icon { width: 16px; text-align: center; flex-shrink: 0; font-size: 14px; }
.refresh-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 300;
    min-width: 170px;
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
    overflow: hidden;
}
.refresh-menu.open { display: block; }
.refresh-menu button {
    display: block;
    width: 100%;
    padding: 9px 14px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background .13s;
}
.refresh-menu button:hover { background: var(--bg3); }
.refresh-menu button + button { border-top: 1px solid var(--border); }

/* ── Broker selector button group (Sync tab) ──────────────────────────────── */
.broker-btn-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.broker-btn-group .broker-btn {
    padding: 5px 14px;
    border: none;
    border-right: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background .13s, color .13s;
}
.broker-btn-group .broker-btn:last-child { border-right: none; }
.broker-btn-group .broker-btn.active { background: var(--blue); color: #fff; }
.broker-btn-group .broker-btn:not(.active):hover { color: var(--text); background: var(--border); }

/* ── Trade section header ─────────────────────────────────────────────────── */
.trade-section-hdr {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 10px 14px;
    background: var(--bg2);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: background 0.13s;
}
.trade-section-hdr:hover { background: var(--bg3); }
.trade-section-hdr .tsh-chevron { color: var(--blue); font-size: 14px; flex-shrink: 0; }
.trade-section-hdr .tsh-title   { font-size: 15px; font-weight: 700; }
.trade-section-hdr .tsh-sub     { font-size: 12px; color: var(--text2); }

/* ── Round-trip table ─────────────────────────────────────────────────────── */
.rt-progress-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    vertical-align: middle;
    transition: width 0.4s;
}
.rt-progress-track {
    display: inline-block;
    width: 60px;
    height: 6px;
    background: var(--bg3);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

/* ── Summary card flush variant (reduced bottom margin) ──────────────────── */
.summary-row-flush { margin-bottom: 12px !important; }

/* ── Sync paste area collapsed state ──────────────────────────────────────── */
#sync-paste-area.collapsed {
    height: 36px;
    min-height: 36px;
    resize: none;
    overflow: hidden;
    color: var(--text2);
    font-size: 12px;
}

/* ── Cell highlight for current-price cells ───────────────────────────────── */
.cell-cp { background: var(--blue-bg) !important; }

/* ── Skeleton Loading ────────────────────────────────────────────────────── */
@keyframes skeleton-shimmer {
    0%   { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}
.skeleton-cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 20px;
}
.skeleton-table { margin-bottom: 16px; }
.skeleton-row {
    display: flex; gap: 12px; padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.skeleton-cell {
    height: 14px; border-radius: 4px;
    background: linear-gradient(90deg, var(--bg3) 25%, rgba(255,255,255,0.06) 37%, var(--bg3) 63%);
    background-size: 200px 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton-card {
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 20px;
}
.skeleton-line {
    height: 12px; border-radius: 4px; margin-bottom: 10px;
    background: linear-gradient(90deg, var(--border) 25%, rgba(255,255,255,0.06) 37%, var(--border) 63%);
    background-size: 200px 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton-line.lg { height: 24px; margin-bottom: 0; }
.skeleton-chart {
    height: 200px; border-radius: 8px; margin-top: 16px;
    background: linear-gradient(90deg, var(--bg3) 25%, rgba(255,255,255,0.06) 37%, var(--bg3) 63%);
    background-size: 400px 100%;
    animation: skeleton-shimmer 1.6s ease infinite;
}

/* ── Confirm Modal ───────────────────────────────────────────────────────── */
.modal-confirm { max-width: 420px; }
.btn-danger-solid {
    background: var(--red); border-color: var(--red); color: #fff;
}
.btn-danger-solid:hover { opacity: 0.9; }

/* ── Enhanced Toast ──────────────────────────────────────────────────────── */
.toast {
    display: flex; align-items: center; gap: 10px; justify-content: space-between;
}
.toast-msg { flex: 1; }
.toast-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.toast-close {
    background: none; border: none; color: var(--text2); cursor: pointer;
    font-size: 16px; padding: 0 2px; line-height: 1; opacity: 0.6;
    transition: opacity 0.15s;
}
.toast-close:hover { opacity: 1; }
.toast-retry {
    background: none; border: 1px solid var(--blue); color: var(--blue);
    padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
    cursor: pointer; transition: background 0.15s;
}
.toast-retry:hover { background: var(--blue-bg); }

/* ── Autocomplete keyboard highlight ─────────────────────────────────────── */
.autocomplete-item.ac-highlight {
    background: var(--bg3);
    outline: 1px solid var(--blue);
    outline-offset: -1px;
}

/* ── Focus visible (accessibility) ───────────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
button:focus-visible, .btn:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}

/* ── Theme toggle button ─────────────────────────────────────────────────── */
.theme-toggle {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    padding: 5px 8px; cursor: pointer; font-size: 16px; line-height: 1;
    color: var(--text2); transition: color 0.2s, border-color 0.2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text2); }

/* ── Inline form errors ──────────────────────────────────────────────────── */
.form-error {
    color: var(--red); font-size: 11px; margin-top: 3px; display: none;
}
.form-group.has-error input,
.form-group.has-error select {
    border-color: var(--red);
    box-shadow: 0 0 0 2px rgba(239,68,68,0.15);
}
.form-group.has-error .form-error { display: block; }

/* ── Utility classes (reduce inline styles in JS) ────────────────────────── */
.text-muted  { color: var(--text2); }
.text-blue   { color: var(--blue); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-xs     { font-size: 10px; }
.text-sm     { font-size: 11px; }
.text-base   { font-size: 12px; }
.text-md     { font-size: 13px; }
.text-lg     { font-size: 14px; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.fw-bold     { font-weight: 600; }
.fw-heavy    { font-weight: 700; }
.nowrap      { white-space: nowrap; }
.gap-xs      { gap: 3px; }
.gap-sm      { gap: 6px; }
.gap-md      { gap: 10px; }
.gap-lg      { gap: 16px; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* ── Light Mode ──────────────────────────────────────────────────────────── */
[data-theme="light"] {
    --bg: #f5f6f8;
    --bg2: #ffffff;
    --bg3: #eef0f4;
    --border: #d1d5db;
    --text: #1a1d27;
    --text2: #6b7280;
    --green: #16a34a;
    --green-bg: rgba(22,163,74,0.10);
    --red: #dc2626;
    --red-bg: rgba(220,38,38,0.08);
    --blue: #2563eb;
    --blue-bg: rgba(37,99,235,0.08);
    --yellow: #d97706;
    --yellow-bg: rgba(217,119,6,0.08);
    --purple: #7c3aed;
    --shadow: 0 1px 6px rgba(0,0,0,0.08);
}
[data-theme="light"] .header,
[data-theme="light"] #top-freeze { background: var(--bg2); }
[data-theme="light"] .table-scroll-box td:first-child,
[data-theme="light"] .table-scroll-box th:first-child,
[data-theme="light"] .table-scroll-box thead th { background: var(--bg2); }
[data-theme="light"] .stock-main-row:hover { background: rgba(0,0,0,0.03); }
[data-theme="light"] .autocomplete-dropdown { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
[data-theme="light"] .toast { box-shadow: 0 2px 12px rgba(0,0,0,0.12); }
[data-theme="light"] .modal-overlay { background: rgba(0,0,0,0.4); }
[data-theme="light"] .modal-box { box-shadow: 0 16px 48px rgba(0,0,0,0.15); }
[data-theme="light"] .btn-act-buy  { color: #16a34a; border-color: #16a34a; }
[data-theme="light"] .btn-act-sell { color: #d97706; border-color: #d97706; }

/* ── Print Stylesheet ────────────────────────────────────────────────────── */
@media print {
    :root {
        --bg: #fff !important;
        --bg2: #fff !important;
        --bg3: #f3f4f6 !important;
        --border: #d1d5db !important;
        --text: #000 !important;
        --text2: #4b5563 !important;
        --shadow: none !important;
    }
    body { background: #fff !important; color: #000 !important; }
    .header, .tabs, #top-freeze, .toast-container,
    .modal-overlay, .btn-act, .header-actions,
    .day-selector, #dash-sticky-bar { display: none !important; }
    .content { max-width: 100% !important; margin: 0 !important; padding: 10px !important; }
    .card { box-shadow: none !important; border: 1px solid #d1d5db !important; page-break-inside: avoid; }
    .tab-content { display: none !important; }
    .tab-content.active { display: block !important; }
    table { font-size: 11px !important; }
    thead th { background: #f3f4f6 !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .profit { color: #16a34a !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .loss   { color: #dc2626 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .summary-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    @page { margin: 1cm; }
}
