/* Custom styles for Portfolio Manager Dashboard */

/* ============================================================
   SHIMMER SKELETON — loading placeholder for heavy containers
   ============================================================ */
@keyframes shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position:  600px 0; }
}

.skeleton-line {
    background: linear-gradient(90deg, #1e2d42 25%, #2a3f5a 50%, #1e2d42 75%);
    background-size: 600px 100%;
    animation: shimmer 1.4s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Pre-built skeleton blocks of different sizes */
.skeleton-title  { height: 18px; width: 40%; }
.skeleton-row-lg { height: 14px; width: 95%; }
.skeleton-row-md { height: 14px; width: 70%; }
.skeleton-row-sm { height: 14px; width: 50%; }
.skeleton-table  { height: 12px; width: 100%; margin-bottom: 4px; }

/* Wrapper: shows skeleton, hides content while loading */
.skeleton-wrapper { padding: 8px 0; }

/* Dash _dash-loading class is set while any callback Output
   targeting the same container is in-flight.
   We use it to show a skeleton placeholder inside dcc.Loading. */
._dash-loading .skeleton-wrapper { display: block !important; }
._dash-loading > *:not(.skeleton-wrapper) { visibility: hidden; }

/* ============================================================
   COMPACT DatePickerSingle — match 28px button/input height
   ============================================================ */
.compact-datepicker .DateInput,
.compact-datepicker .SingleDatePickerInput {
    height: 28px !important;
}
.compact-datepicker .DateInput_input {
    height: 28px !important;
    padding: 2px 8px !important;
    font-size: 12px !important;
    line-height: 24px !important;
}
.compact-datepicker .SingleDatePickerInput__withBorder {
    border-radius: 4px !important;
}

/* Marquee animation for auto-scrolling pills */
@keyframes marquee {
    0% { 
        transform: translateX(0); 
    }
    100% { 
        transform: translateX(-50%); 
    }
}

.marquee-container {
    animation: marquee 60s linear infinite;
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 12px;
    flex-shrink: 0;
    white-space: nowrap;
    width: auto;
}

.marquee-container:hover {
    animation-play-state: paused;
}

/* ============================================================
   COMPACT DATATABLE ROWS
   Root cause: Dash DataTable bundle injects:
     .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr {
       min-height: 30px; height: 30px;
     }
   We must override this with equal or higher specificity + !important.
   ============================================================ */

/* Override the 30px row height baked into Dash DataTable bundle */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr {
    min-height: 0 !important;
    height: auto !important;
}

/* Lock padding, font-size, line-height — overrides Bootstrap 5 and DataTable bundle */
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-cell {
    padding: 1px 5px !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
}
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th.dash-header {
    padding: 3px 5px !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
}

/* Zero out inner content div padding and min-height */
.dash-spreadsheet .dash-cell-value,
.dash-spreadsheet .dash-cell-value-container {
    padding: 0 !important;
    line-height: 1.2 !important;
    min-height: 0 !important;
}

/* Markdown cells: remove default element margins/padding that bloat row height */
/* Covers: <p>, <ul>, <li>, <ol>, <a> etc. from Markdown parser rendering */
.dash-spreadsheet .cell-markdown p,
.dash-spreadsheet .cell-markdown ul,
.dash-spreadsheet .cell-markdown ol,
.dash-spreadsheet .cell-markdown li {
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.2 !important;
    list-style: none !important;
}

/* ================================================================
   DESIGN SYSTEM STYLES (from main_layout.py _CSS_STYLES)
   ================================================================ */

/* BASE RESET */
body { font-size: 12px !important; }
.container-fluid { max-width: 100% !important; }

/* KPI CARDS (metric row) */
.kpi-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: box-shadow 0.15s, transform 0.15s;
    height: 100%;
}
.kpi-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.10);
    transform: translateY(-1px);
}

/* SHARED PANEL STYLE (all tabs) */
.mm-panel {
    border: 1px solid #dbeafe !important;
    border-radius: 14px !important;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05) !important;
    overflow: hidden;
    transition: box-shadow 0.15s;
}
.mm-panel:hover {
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.09) !important;
}
.mm-panel .card-header {
    padding: 8px 14px !important;
    background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%) !important;
    border-bottom: 1px solid #dbeafe !important;
    display: flex;
    align-items: center;
}
.mm-panel .card-body {
    padding: 10px 12px !important;
}

/* TYPOGRAPHY */
.mm-section-title  { font-size: 12px; font-weight: 700; color: #0f172a; }
.mm-section-subtitle { font-size: 10px; color: #64748b; }
h6 { font-size: 12px !important; margin-bottom: 4px !important; }
.text-xs  { font-size: 11px !important; }
.text-sm  { font-size: 12px !important; }
.text-base{ font-size: 13px !important; }

/* SPACING COMPACTION */
.row       { margin-bottom: 0 !important; }
.mb-4      { margin-bottom: 8px !important; }
.mb-3      { margin-bottom: 6px !important; }
.mb-2      { margin-bottom: 4px !important; }
.mt-4      { margin-top: 8px !important; }
.mt-3      { margin-top: 6px !important; }

/* BUTTONS */
.btn {
    transition: all 0.15s ease;
    font-size: 11px !important;
    border-radius: 8px !important;
}
.btn-sm { padding: 2px 8px !important; font-size: 10px !important; }
.btn:hover  { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.btn:active { transform: translateY(0); }

/* STATUS BADGES */
.status-badge   { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.status-success { background: #dcfce7; color: #166534; }
.status-danger  { background: #fee2e2; color: #991b1b; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-info    { background: #dbeafe; color: #1e40af; }

/* COMPACT TABS */
.tab--selected, .tab { padding: 4px 8px !important; font-size: 10px !important; }
.tab-content { padding: 0 !important; margin-top: 0 !important; }
.tab-content > .row,
.tab-content > div > .row {
    margin-top: 0 !important;
}
.mm-compact-tabs .nav       { gap: 4px; flex-wrap: wrap; }
.mm-compact-tabs .nav-item  { margin-bottom: 0 !important; }
.mm-compact-tabs .nav-link  {
    padding: 3px 8px !important; font-size: 10px !important;
    line-height: 1.05 !important; border-radius: 6px !important;
}
.mm-compact-tabs .nav-link.active { padding: 3px 8px !important; }

/* DATE PICKERS */
.DateInput_input, .DateInput_input__input,
.DatePickerInput input, .DateInput_input__display_text {
    font-size: 10px !important; line-height: 1 !important; padding: 2px 4px !important;
}
.DateRangePickerInput_calendarIcon { transform: scale(0.85); }

/* FORM INPUTS */
.form-control {
    padding: 3px 8px !important; font-size: 11px !important; height: auto !important;
    border-radius: 8px !important; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15) !important;
}

/* DROPDOWNS */
.Select-control   { height: 28px !important; border-radius: 8px !important; }
.Select-value, .Select-placeholder { line-height: 26px !important; font-size: 11px !important; }
.Select-input > input { font-size: 11px !important; }

/* GENERIC CARDS (non mm-panel) */
.card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
    border-radius: 10px !important;
    transition: box-shadow 0.15s;
    margin-bottom: 4px !important;
}
.card:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.09); }
.card-header {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
    padding: 6px 12px !important;
    font-size: 11px !important;
    border-radius: 10px 10px 0 0 !important;
}
.card-body { padding: 8px 10px !important; }

/* TOAST */
.toast { animation: slideIn 0.3s ease; border-radius: 10px !important; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* PLOTLY */
.js-plotly-plot .plotly .main-svg { overflow: visible; }

/* MONEY MANAGEMENT TAB */
.mm-workspace { display: flex; flex-direction: column; gap: 8px; }
.mm-workspace .mt-2 { margin-top: 0 !important; }

.mm-panel-header-wrap {
    display: flex; align-items: flex-start;
    justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.mm-step-pill-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mm-step-pill {
    display: inline-flex; align-items: center; padding: 4px 10px;
    border-radius: 999px; border: 1px solid #bfdbfe; background: #ffffff;
    color: #1d4ed8; font-size: 10px; font-weight: 600; line-height: 1;
}

.mm-step-card {
    border: 1px solid #e2e8f0 !important; border-radius: 12px !important;
    overflow: hidden; background: #ffffff;
}
.mm-step-card .card-header {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%) !important;
    border-bottom: 1px solid #e2e8f0 !important;
    padding: 6px 10px !important; font-size: 11px !important;
}
.mm-step-card .card-body { padding: 8px 10px !important; }

.mm-workspace .form-label {
    margin-bottom: 2px !important; font-weight: 600;
    color: #334155; font-size: 10px;
}
.mm-workspace .form-control,
.mm-workspace .form-select,
.mm-workspace .Select-control {
    min-height: 30px !important; border-radius: 8px !important;
    border-color: #cbd5e1 !important; box-shadow: none !important;
    font-size: 11px !important;
    padding-top: 3px !important;
    padding-bottom: 3px !important;
}
.mm-workspace .form-control:focus,
.mm-workspace .form-select:focus {
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12) !important;
}
.mm-workspace .nav-tabs .nav-link {
    padding: 6px 12px !important; font-size: 11px !important;
    border-top-left-radius: 10px !important; border-top-right-radius: 10px !important;
}
.mm-workspace .accordion-button {
    padding: 8px 12px !important; font-size: 11px !important; background: #f8fafc !important;
}
.mm-workspace .accordion-body { padding: 8px 10px !important; }

.mm-workspace .mb-3 { margin-bottom: 8px !important; }
.mm-workspace .mb-2 { margin-bottom: 6px !important; }
.mm-workspace .small { font-size: 10px !important; }

.mm-action-bar {
    border: 1px solid #e2e8f0; border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    padding: 10px 12px;
}
.mm-toolbar-heading {
    font-size: 11px; font-weight: 700; color: #0f172a;
    text-transform: uppercase; letter-spacing: 0.03em;
}
.mm-action-note { display: block; margin-top: 2px; font-size: 11px; color: #64748b; }
.mm-toolbar-actions,
.mm-archive-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.mm-toolbar-button { min-width: 190px; }

.mm-archive-toolbar {
    display: flex; align-items: center;
    justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%); margin-bottom: 10px;
}
.mm-archive-meta   { font-size: 11px; color: #475569; margin: 0; }
.mm-archive-status .alert { margin-bottom: 0 !important; }

/* ============================================================
   MOBILE / RESPONSIVE
   ============================================================ */

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Plotly charts fill container width */
.content-col .js-plotly-plot,
.content-col .plot-container.plotly {
    width: 100% !important;
    max-width: 100%;
}

/* DataTables: horizontal scroll on narrow screens */
.dash-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Main tab bar: horizontal row + scroll (mobile_breakpoint=0 in layout) */
.tab-parent {
    width: 100%;
    max-width: 100%;
}

#main-tabs.main-tabs-scrollable,
#main-tabs.tab-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    height: auto !important;
    min-height: 34px;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

#main-tabs .tab {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: max-content;
    white-space: nowrap;
    padding: 6px 10px !important;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    #main-tabs .tab {
        padding: 4px 8px !important;
    }
}

/* KPI metrics wrap on smaller screens */
.kpi-metrics-row {
    flex-wrap: wrap !important;
}
.kpi-metric-col {
    flex: 1 1 18% !important;
    min-width: 120px;
}

/* Sidebar filters: always visible on desktop */
@media (min-width: 992px) {
    #mobile-filters-collapse,
    #mobile-filters-collapse.collapse:not(.show) {
        display: block !important;
        height: auto !important;
        visibility: visible !important;
    }
}

/* Tablet */
@media (max-width: 991.98px) {
    .app-container {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .kpi-metric-col {
        flex: 1 1 30% !important;
        min-width: 140px;
    }

    .mm-toolbar-button {
        min-width: 0 !important;
        flex: 1 1 auto;
    }

    .mm-panel-header-wrap {
        flex-direction: column;
        align-items: stretch !important;
    }

    .mm-toolbar-actions,
    .mm-archive-actions {
        justify-content: flex-start !important;
    }
}

/* Smartphone */
@media (max-width: 767.98px) {
    body {
        font-size: 13px !important;
    }

    .app-container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Header stacks vertically */
    .app-header-top {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px;
    }

    .app-header-title-group {
        flex-wrap: wrap;
        gap: 4px;
    }

    .app-header-title {
        font-size: 14px !important;
        white-space: normal !important;
        margin-right: 0 !important;
    }

    .app-header-actions {
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        gap: 6px;
    }

    .app-header-timestamp {
        display: none;
    }

    .app-header-pills {
        flex-wrap: wrap;
        width: 100%;
    }

    .app-header-pills .form-control,
    .app-header-pills input {
        flex: 1 1 80px;
        min-width: 70px;
        width: auto !important;
        margin-left: 0 !important;
    }

    /* Marquee + VIX stack */
    .app-header-marquee-row {
        flex-direction: column !important;
    }

    .app-header-marquee-row > div:first-child {
        padding-right: 0 !important;
        margin-right: 0 !important;
        border-right: none !important;
        border-bottom: 1px solid #e2e8f0;
        padding-bottom: 6px;
        margin-bottom: 6px;
    }

    .app-vix-charts {
        flex-wrap: wrap !important;
        justify-content: center;
        width: 100%;
    }

    /* KPI: 2 per row */
    .kpi-metric-col {
        flex: 1 1 45% !important;
        min-width: 0;
    }
}

/* ============================================================
   HIDE DASH PLACEHOLDER CHARACTERS
   Hide elements that show "{ }" placeholder text from SSR
   ============================================================ */
._dash-undo-redo, #_dash-location, #_dash-app-content > div:first-child:empty {
    display: none !important;
}

    #main-tabs .tab {
        font-size: 11px !important;
        min-height: 40px;
        display: inline-flex !important;
        align-items: center;
    }

    /* Touch-friendly buttons */
    .btn, .btn-sm {
        min-height: 36px;
        padding: 6px 12px !important;
    }

    .app-mobile-filters-btn {
        min-height: 40px;
    }

    /* Card headers with controls wrap */
    .mm-panel .card-header .row {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px;
    }

    .mm-panel .card-header .row .col-auto,
    .mm-panel .card-header .row [class*="col-"] {
        width: 100%;
        max-width: 100%;
    }

    .mm-panel .card-header .flex-nowrap {
        flex-wrap: wrap !important;
    }

    /* Watchlist add form: 2 columns */
    .wl-add-form > [class*="col"] {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Toast full width */
    #notification-toast {
        width: calc(100vw - 32px) !important;
        max-width: 360px;
        right: 16px !important;
        left: 16px !important;
    }

    /* Money management toolbar */
    .mm-action-bar,
    .mm-archive-toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }

    .mm-toolbar-actions .btn,
    .mm-archive-actions .btn {
        width: 100%;
    }
}

/* Very small phones */
@media (max-width: 399.98px) {
    .kpi-metric-col {
        flex: 1 1 100% !important;
    }

    .app-header-pills {
        display: none !important;
    }

    #auth-user-badge,
    #session-countdown-badge {
        font-size: 9px !important;
        padding: 2px 6px !important;
    }
}
