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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a1a;
    color: #fff;
    min-height: 100vh;
}

.container {
    max-width: 100%;
}

header {
    background: #1a1a1a;
    padding: 10px 20px;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.warning-banner {
    background: rgba(255, 159, 10, 0.15);
    border-left: 3px solid #ff9f0a;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ff9f0a;
    font-size: 13px;
    border-bottom: 1px solid rgba(255, 159, 10, 0.3);
}

.warning-banner svg {
    flex-shrink: 0;
    stroke: #ff9f0a;
}

.warning-banner span {
    flex: 1;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

h1 {
    font-size: 13px;
    color: #666;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 0;
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 4px;
    align-items: center;
}

.tab-btn {
    background: transparent;
    color: #666;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: transparent;
    color: #888;
}

.tab-btn.active {
    color: #fff;
    border-bottom-color: #667eea;
}

.tab-btn:active {
    transform: none;
}

.tab-content {
    display: block;
}

.tab-content.hidden {
    display: none;
}

.upload-controls-mobile {
    display: none;
    align-items: center;
    gap: 4px;
}

.upload-controls {
    display: none;
    align-items: center;
    gap: 8px;
    margin-left: 4px;
}

.upload-controls.visible {
    display: flex;
}


.upload-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.upload-icon-btn:hover {
    color: #aaa;
}

.toggle-values-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

.toggle-values-btn:hover {
    color: #aaa;
}

.toggle-values-btn.active {
    background: #2a2a2a;
    color: #48bb78;
    border-color: #48bb78;
}

.stock-action-btns {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Desktop: show header copy, hide controls copy */
.stock-action-mobile {
    display: none;
}

/* Tab-switch hide (applies to both copies) */
.stock-action-btns.hidden {
    display: none !important;
}

#collapseAllBtn,
#expandAllBtn,
#refreshBtn {
    background: transparent;
    color: #555;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    width: 26px;
    height: 22px;
    padding: 0;
    font-size: 11px;
    line-height: 1;
    letter-spacing: -1px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

#collapseAllBtn:hover,
#expandAllBtn:hover,
#refreshBtn:hover {
    background: #242424;
    color: #888;
    border-color: #333;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
}

.portfolio-controls.hidden {
    display: none;
}

.stock-controls.hidden {
    display: none;
}

.watchlist-controls.hidden {
    display: none;
}

.add-stock-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.add-graph-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.graph-selector-wrapper {
    position: relative;
}

#graphInput {
    padding: 6px 12px;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 12px;
    background: #242424;
    color: #fff;
    transition: all 0.2s;
    width: 180px;
}

#graphInput:focus {
    outline: none;
    border-color: #444;
    background: #2a2a2a;
}

#graphInput::placeholder {
    color: #555;
}

.graph-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 240px;
    max-height: 200px;
    overflow-y: auto;
    background: #242424;
    border: 1px solid #333;
    border-radius: 3px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.graph-dropdown.hidden {
    display: none;
}

.graph-list {
    display: flex;
    flex-direction: column;
}

.graph-option {
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.graph-option:last-child {
    border-bottom: none;
}

.graph-option:hover {
    background: #2a2a2a;
}

.graph-option.selected {
    background: #2a2a2a;
}

.graph-option-title {
    font-size: 12px;
    font-weight: 600;
    color: #aaa;
}

.graph-option-description {
    font-size: 10px;
    color: #666;
}

.graph-list-empty {
    padding: 12px;
    text-align: center;
    color: #666;
    font-size: 11px;
}

.graph-heading {
    padding: 6px 12px 4px 12px;
    font-size: 10px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
}

.graph-heading:not(:first-child) {
    margin-top: 4px;
}

/* Ticker Selector */
.ticker-selector-wrapper {
    position: relative;
    margin: 0 12px;
}

.ticker-selector-input {
    padding: 4px 10px;
    background: #1a1a1a;
    color: #fff;
    border: 1px solid #444;
    border-radius: 3px;
    font-size: 11px;
    width: 140px;
    transition: border-color 0.2s;
}

.ticker-selector-input:focus {
    outline: none;
    border-color: #667eea;
}

.ticker-selector-input::placeholder {
    color: #555;
}

.ticker-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 200px;
    max-height: 200px;
    overflow-y: auto;
    background: #242424;
    border: 1px solid #333;
    border-radius: 3px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ticker-dropdown.hidden {
    display: none;
}

.ticker-list {
    display: flex;
    flex-direction: column;
}

.ticker-list-item {
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #2a2a2a;
    font-size: 12px;
    color: #aaa;
}

.ticker-list-item:last-child {
    border-bottom: none;
}

.ticker-list-item:hover {
    background: #2a2a2a;
    color: #fff;
}

.ticker-list-empty {
    padding: 12px;
    text-align: center;
    color: #666;
    font-size: 11px;
}

/* Portfolio Filter Bar */
.ai-analysis-card {
    grid-column: 1 / -1;
    background: #1e2230;
    border: 1px solid #2a3a5c;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 4px;
}

.ai-analysis-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.ai-analysis-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b8ccc;
}

.ai-analysis-refresh-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #4a6a9c;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    margin-left: auto;
}

.ai-analysis-refresh-btn:hover {
    color: #6b8ccc;
    background: rgba(107, 140, 204, 0.1);
}

.ai-analysis-body {
    font-size: 0.85rem;
    color: #c0cce8;
    line-height: 1.55;
}

.ai-analysis-body.ai-analysis-collapsed {
    max-height: calc(1.55em * 3);
    overflow: hidden;
    mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
    cursor: pointer;
}

.ai-analysis-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: #4a6a9c;
    font-size: 0.78rem;
    padding: 4px 0 0;
    display: block;
    margin-top: 2px;
    text-align: center;
    width: 100%;
}

.ai-analysis-toggle:hover {
    color: #6b8ccc;
}

.ai-analysis-body p {
    margin: 0 0 10px;
}

.ai-analysis-body p:last-child {
    margin-bottom: 0;
}

.ai-section-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b8ccc;
    margin-bottom: 4px;
}

.ai-analysis-loading {
    color: #4a6a9c;
    font-style: italic;
    font-size: 0.82rem;
}

/* Buy recommendations box */
.buy-reco-box {
    margin-bottom: 12px;
}

.buy-reco-box.hidden {
    display: none;
}

#buy-reco-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.buy-pick {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.buy-pick-badge {
    font-size: 0.65rem;
    padding: 2px 7px;
    flex-shrink: 0;
}

.buy-pick-symbol {
    font-size: 0.88rem;
    font-weight: 600;
    color: #e0e0e0;
    flex-shrink: 0;
}

.buy-pick-rationale {
    font-size: 0.82rem;
    color: #c0cce8;
    line-height: 1.4;
}

.portfolio-filter-bar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    margin-bottom: -4px;
}

.portfolio-filter-wrapper {
    position: relative;
}

.portfolio-filter-btn {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #666;
    cursor: pointer;
    font-size: 0.78rem;
    padding: 4px 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: border-color 0.15s, color 0.15s;
}

.portfolio-filter-btn:hover {
    border-color: #555;
    color: #aaa;
}

.portfolio-filter-btn.has-exclusions {
    border-color: #d97706;
    color: #d97706;
}

.portfolio-filter-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: #1a1a1a;
    border: 1px solid #2e2e2e;
    border-radius: 6px;
    z-index: 200;
    min-width: 150px;
    max-height: 480px;
    overflow-y: auto;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
}

.portfolio-filter-dropdown.hidden {
    display: none;
}

.portfolio-filter-select-all-row {
    border-bottom: 1px solid #272727;
}

.portfolio-filter-item {
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    user-select: none;
    transition: background 0.1s;
}

.portfolio-filter-item:hover {
    background: #232323;
}

.pf-check {
    font-size: 10px;
    color: #48bb78;
    width: 12px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.pf-label {
    font-size: 0.78rem;
    color: #999;
    letter-spacing: 0.3px;
}

.portfolio-filter-select-all-row .pf-label {
    font-weight: 600;
    color: #777;
    font-size: 0.75rem;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.portfolio-filter-item:hover .pf-label {
    color: #ccc;
}

/* Portfolio View Grid */
#portfolioView {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 20px;
    padding: 20px;
}

#portfolioView.hidden {
    display: none !important;
}

#portfolioView .empty-state {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Portfolio Graph Cards */
.portfolio-graph-card {
    background: #242424;
    border: 1px solid #333;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    transition: background 0.3s, opacity 0.3s;
}

.portfolio-graph-card:hover {
    background: #282828;
}

.portfolio-graph-card.resizing {
    transition: none;
    background: #2a2a2a;
}

.portfolio-graph-card.dragging {
    opacity: 0.4;
}

.portfolio-graph-card.drag-over {
    border-left: 3px solid #667eea;
    background: #2a2a2a;
}

.portfolio-divider {
    grid-column: 1 / -1;
    height: 40px;
    background: transparent;
    position: relative;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    transition: background 0.2s;
}

.portfolio-divider.has-title {
    height: 50px;
}

.portfolio-divider:hover {
    background: rgba(255, 255, 255, 0.02);
}

.portfolio-divider.dragging {
    opacity: 0.4;
}

.portfolio-divider.drag-over {
    border-top: 3px solid #667eea;
    border-bottom: 3px solid #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.portfolio-divider .divider-line {
    width: 100%;
    height: 2px;
    background: #333;
    transition: all 0.2s;
}

.portfolio-divider:hover .divider-line {
    background: #444;
}

.portfolio-divider.has-title .divider-line {
    background: #333;
}

.portfolio-divider .divider-remove-btn {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: transparent;
    color: #666;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
}

.portfolio-divider:hover .divider-remove-btn {
    opacity: 1;
}

.portfolio-divider .divider-remove-btn:hover {
    color: #fc8181;
    background: rgba(255, 255, 255, 0.05);
}

.graph-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #333;
    cursor: move;
}

.graph-drag-handle {
    color: #555;
    font-size: 12px;
    cursor: grab;
    user-select: none;
    margin-right: 8px;
}

.graph-drag-handle:active {
    cursor: grabbing;
}

.graph-card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: #aaa;
    margin: 0;
    flex: 1;
}

.timeframe-selector {
    display: flex;
    gap: 4px;
    margin: 0 12px;
}

.timeframe-btn {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timeframe-btn:hover {
    background: #2a2a2a;
    color: #aaa;
    border-color: #555;
}

.timeframe-btn.active {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
}

.allocation-time-btn {
    background: transparent;
    border: none;
    color: #48bb78;
    width: 24px;
    height: 24px;
    padding: 0;
    margin-right: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s;
    flex-shrink: 0;
}

.allocation-time-btn:hover {
    color: #68d391;
}

.allocation-time-btn.inactive {
    color: #444;
}

.allocation-time-btn.inactive:hover {
    color: #666;
}

.portfolio-refresh-btn.loading svg {
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.remove-graph-btn {
    background: transparent;
    color: #666;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.3s;
}

.remove-graph-btn:hover {
    color: #fc8181;
    background: transparent;
}

.graph-card-body {
    padding: 20px;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.graph-card-body canvas {
    max-height: 400px;
}

.graph-placeholder {
    color: #666;
    font-size: 13px;
    text-align: center;
}

#stockInput,
#watchlistInput {
    padding: 6px 12px;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 12px;
    background: #242424;
    color: #fff;
    transition: all 0.2s;
    width: 180px;
}

#stockInput:focus,
#watchlistInput:focus {
    outline: none;
    border-color: #444;
    background: #2a2a2a;
}

#stockInput::placeholder,
#watchlistInput::placeholder {
    color: #555;
}

button {
    padding: 6px 12px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

button:hover {
    background: #242424;
    color: #aaa;
    border-color: #333;
}

button:active {
    transform: scale(0.98);
}


#settingsBtn {
    display: none;
}

/* Stock Grid - Horizontal Ticker Style */
.stock-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
    overflow-x: auto;
}

/* Stock Divider */
.stock-divider {
    flex: 0 0 auto;
    height: 40px;
    background: #242424;
    border-bottom: 1px solid #333;
    position: relative;
    cursor: move;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.stock-divider.has-title {
    height: 50px;
}

.stock-divider:hover {
    background: #2a2a2a;
}

.stock-divider.dragging {
    opacity: 0.4;
}

.stock-divider.drag-over {
    border-top: 3px solid #667eea;
    border-bottom: 3px solid #667eea;
    background: #2a2a2a;
}

.divider-line {
    width: 100%;
    height: 2px;
    background: #444;
    transition: all 0.2s;
}

.stock-divider:hover .divider-line {
    background: #555;
    height: 3px;
}

.stock-divider.has-title .divider-line {
    height: 3px;
    background: #555;
}

.stock-divider.has-title:hover .divider-line {
    background: #666;
    height: 4px;
}

.divider-content {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
}

.divider-title {
    color: #888;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.stock-divider:hover .divider-title {
    color: #aaa;
}

.divider-remove-btn {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: transparent;
    color: #666;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s;
}

.stock-divider:hover .divider-remove-btn {
    opacity: 1;
}

.divider-remove-btn:hover {
    color: #fc8181;
    background: rgba(255, 255, 255, 0.05);
}

/* Stock Card - Horizontal Ticker Style */
.stock-card {
    background: #242424;
    border-right: 1px solid #333;
    padding: 20px 30px;
    transition: background 0.3s, opacity 0.3s;
    position: relative;
    width: 280px;
    flex-shrink: 0;
    cursor: move;
    box-sizing: border-box;
}

.stock-card.resizing {
    transition: none;
    background: #2a2a2a;
}

.stock-card:hover {
    background: #2a2a2a;
}

.stock-card.loading {
    opacity: 0.5;
}

.stock-card.dragging {
    opacity: 0.4;
}

.stock-card.drag-over {
    border-left: 3px solid #667eea;
    background: #2a2a2a;
}

.stock-card.collapsed .chart-container {
    display: none;
}

.stock-card.collapsed .ma-info {
    display: none;
}

.stock-card.collapsed .watchlist-card-body {
    display: none;
}

.stock-card.collapsed .ai-description {
    display: none !important;
}

.stock-card.collapsed {
    cursor: pointer;
}

/* Collapsed summary: shown only when card is collapsed */
.collapsed-summary {
    display: none;
    padding: 4px 0 8px;
    gap: 6px;
    flex-direction: column;
}

.stock-card.collapsed .collapsed-summary {
    display: flex;
}

.cs-metrics {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    flex-wrap: wrap;
}

.cs-price {
    color: #ccc;
    font-weight: 600;
}

.cs-change.positive, .cs-7d.positive { color: #48bb78; }
.cs-change.negative, .cs-7d.negative { color: #f56565; }

.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.stock-symbol {
    font-size: 14px;
    font-weight: 600;
    color: #aaa;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.drag-handle {
    color: #555;
    font-size: 12px;
    cursor: grab;
    user-select: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.remove-btn {
    background: transparent;
    color: #666;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.3s;
}

.remove-btn:hover {
    color: #fc8181;
    background: transparent;
}

.watchlist-add-btn {
    background: transparent;
    color: #555;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.2s;
    flex-shrink: 0;
}

.watchlist-add-btn:hover {
    color: #90cdf4;
    background: transparent;
}

.watchlist-add-btn.in-watchlist {
    color: #667eea;
}

.watchlist-add-btn.in-watchlist:hover {
    color: #5a67d8;
}

.stock-metrics {
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
    padding: 8px;
    margin: -8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.stock-metrics:hover {
    background: rgba(255, 255, 255, 0.03);
}

.primary-metric {
    font-size: 28px;
    font-weight: 600;
    line-height: 1;
    position: relative;
    white-space: nowrap;
}

.primary-metric::after {
    content: '▼';
    font-size: 10px;
    opacity: 0.3;
    margin-left: 8px;
    transition: transform 0.2s;
}

.stock-card.collapsed .primary-metric::after {
    transform: rotate(-90deg);
}

.primary-metric.positive {
    color: #48bb78;
}

.primary-metric.negative {
    color: #f56565;
}

.secondary-metrics {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.price-value {
    color: #aaa;
    font-weight: 500;
    white-space: nowrap;
}

.weekly-change {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.weekly-change.positive {
    color: #48bb78;
}

.weekly-change.negative {
    color: #f56565;
}

.chart-container {
    height: 100px;
    margin: 15px 0 10px 0;
    position: relative;
}

.ma-info {
    display: flex;
    gap: 15px;
    align-items: center;
    padding-top: 8px;
    border-top: 1px solid #333;
    font-size: 12px;
    flex-wrap: nowrap;
}

.ma-comparison {
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}

.ma-comparison.ma-50.above {
    color: #f59e0b;
}

.ma-comparison.ma-50.below {
    color: #f59e0b;
}

.ma-comparison.ma-200.above {
    color: #fbbf24;
}

.ma-comparison.ma-200.below {
    color: #fbbf24;
}

.ma-period {
    font-size: 10px;
    opacity: 0.7;
    font-weight: 500;
}

/* AI Analysis Section */
/* ai-description: below card body on both desktop and mobile in watchlistGrid */
.ai-description {
    display: none;
}

#watchlistGrid .ai-description {
    display: block;
    border-top: 1px solid #333;
    padding-top: 10px;
    margin-top: 8px;
}

#watchlistGrid .ai-description.hidden {
    display: none;
}

/* On desktop: ratings are shown in ai-section, hide duplicate in ai-description */
@media (min-width: 769px) {
    #watchlistGrid .ai-description .ai-ratings {
        display: none;
    }
}

.ai-desc-collapsed {
    display: none;
}

.ai-desc-toggle {
    background: none;
    border: none;
    color: #888;
    font-size: 0.72rem;
    cursor: pointer;
    padding: 0;
    text-align: left;
    width: 100%;
}

.ai-desc-toggle:hover {
    color: #aaa;
}

/* Mobile verdict badge slot — hidden on desktop */
.watchlist-verdict-mobile {
    display: none;
}

/* Watchlist card layout */
#watchlistGrid .stock-card {
    width: 560px;
}

.watchlist-card-body {
    display: flex;
    gap: 0;
    align-items: flex-start;
    margin-top: 8px;
}

.watchlist-card-left {
    flex: 0 0 220px;
}

.watchlist-card-left .chart-container {
    margin-top: 0;
}

.watchlist-card-body .ai-section {
    flex: 1;
    border-top: none;
    border-left: 1px solid #333;
    padding-top: 0;
    padding-left: 16px;
    margin-top: 0;
    min-width: 0;
}

.ai-section {
    border-top: 1px solid #333;
    padding-top: 12px;
    margin-top: 12px;
}

.ai-section.hidden {
    display: none;
}

.stock-card.collapsed .ai-section {
    display: none;
}

/* AI bar */
#ai-bar {
    display: flex;
    align-items: center;
    gap: 6px;
}

#ai-bar-status {
    font-size: 0.72rem;
    color: #555;
    letter-spacing: 0.3px;
}

#aiRefreshBtn {
    background: none;
    border: 1px solid #333;
    border-radius: 4px;
    color: #666;
    cursor: pointer;
    padding: 3px 6px;
    display: flex;
    align-items: center;
    transition: border-color 0.15s, color 0.15s;
}

#aiRefreshBtn:hover { border-color: #555; color: #aaa; }
#aiRefreshBtn:disabled { opacity: 0.3; cursor: default; }

.ai-verdict-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.ai-collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #555;
    font-size: 0.7rem;
    padding: 0 2px;
    line-height: 1;
    margin-left: auto;
    flex-shrink: 0;
}

.ai-collapse-btn:hover {
    color: #999;
}

.stock-card.ai-collapsed .ai-body {
    display: none;
}

.stock-card.ai-collapsed .ai-description {
    display: none !important;
}

.ai-rationale {
    font-size: 0.75rem;
    color: #888;
    line-height: 1.4;
    flex-basis: 100%;
}

.ai-verdict {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 3px;
    flex-shrink: 0;
}

.ai-verdict.buy {
    background: rgba(72, 187, 120, 0.15);
    color: #48bb78;
    border: 1px solid rgba(72, 187, 120, 0.3);
}

.ai-verdict.hold {
    background: rgba(160, 160, 160, 0.12);
    color: #aaa;
    border: 1px solid rgba(160, 160, 160, 0.25);
}

.ai-verdict.avoid {
    background: rgba(245, 101, 101, 0.15);
    color: #f56565;
    border: 1px solid rgba(245, 101, 101, 0.3);
}

.ai-summary {
    font-size: 12px;
    color: #888;
    line-height: 1.5;
    margin-bottom: 8px;
}


.ai-detail {
    font-size: 11px;
    color: #666;
    line-height: 1.7;
    margin-top: 6px;
}

.ai-detail p {
    margin: 3px 0;
}

/* Rating bullet pills shown before expanding */
.ai-ratings {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.ai-rating-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 10px;
    background: rgba(255,255,255,0.05);
    color: #999;
    text-transform: capitalize;
    white-space: nowrap;
    flex: 1;
    justify-content: center;
}

.ai-rating-label {
    color: #555;
    font-size: 8px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Valuation: cheap=green, expensive=red, mid=neutral */
.ai-rating-item.valuation-cheap { color: #48bb78; background: rgba(72,187,120,0.1); }
.ai-rating-item.valuation-expensive { color: #f56565; background: rgba(245,101,101,0.1); }

/* Fundamentals: strong=green, weak=red */
.ai-rating-item.fundamentals-strong { color: #48bb78; background: rgba(72,187,120,0.1); }
.ai-rating-item.fundamentals-weak { color: #f56565; background: rgba(245,101,101,0.1); }

/* Portfolio fit: high=green, low=red */
.ai-rating-item.fit-high { color: #48bb78; background: rgba(72,187,120,0.1); }
.ai-rating-item.fit-low { color: #f56565; background: rgba(245,101,101,0.1); }

/* Long term: bullish=green, bearish=red */
.ai-rating-item.longterm-bullish { color: #48bb78; background: rgba(72,187,120,0.1); }
.ai-rating-item.longterm-bearish { color: #f56565; background: rgba(245,101,101,0.1); }

.ai-label {
    color: #888;
    font-weight: 600;
}

.ai-loading {
    font-size: 12px;
    color: #555;
    padding: 4px 0;
}

.ai-error {
    font-size: 12px;
    color: #f56565;
    padding: 4px 0;
}

.ai-analyze-btn {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #888 !important;
}

.ai-analyze-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 100%;
    cursor: ew-resize;
    opacity: 0;
    transition: opacity 0.2s;
    background: linear-gradient(to right, transparent 55%, #667eea);
    z-index: 10;
}

.stock-card:hover .resize-handle {
    opacity: 0.3;
}

.resize-handle:hover {
    opacity: 0.6 !important;
}

.stock-card.resizing .resize-handle {
    opacity: 0.8 !important;
}

/* Graph Resize Handle */
.graph-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 100%;
    cursor: ew-resize;
    opacity: 0;
    transition: opacity 0.2s;
    background: linear-gradient(to right, transparent 55%, #667eea);
    z-index: 10;
}

.portfolio-graph-card:hover .graph-resize-handle {
    opacity: 0.3;
}

.graph-resize-handle:hover {
    opacity: 0.6 !important;
}

.portfolio-graph-card.resizing .graph-resize-handle {
    opacity: 0.8 !important;
}

/* Responsive portfolio grid */
@media (max-width: 1200px) {
    #portfolioView {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Cap graph cards to 2 columns — prevents implicit grid tracks
       from breaking the AI card's grid-column: 1 / -1 span */
    .portfolio-graph-card,
    .portfolio-divider {
        grid-column: 1 / -1 !important;
    }
}

@media (max-width: 768px) {
    #portfolioView {
        grid-template-columns: repeat(1, 1fr);
    }
}

/* Chart clickable indicator */
.chart-container {
    cursor: pointer;
}

.chart-container canvas {
    cursor: pointer;
}

/* Loading and Error States */
.loading-spinner {
    text-align: center;
    padding: 30px;
    color: #666;
}

.error-message {
    color: #f56565;
    font-size: 13px;
    text-align: center;
    padding: 15px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    font-size: 16px;
}

.empty-state.hidden {
    display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Header: 2-row layout */
    header {
        flex-wrap: wrap;
        padding: 8px 12px;
        gap: 6px;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .header-center {
        flex: 0 0 auto;
    }

    .controls {
        flex: 0 0 100%;
        order: 3;
        justify-content: flex-start;
    }

    /* Mobile: hide header copies, show controls copies */
    .stock-action-desktop {
        display: none;
    }

    .stock-action-mobile {
        display: flex;
        order: -1;
    }

    .upload-controls-desktop.visible {
        display: none;
    }

    .upload-controls-mobile {
        display: flex;
    }

    .add-stock-form {
        flex: 1;
        max-width: unset;
    }

    #stockInput,
    #watchlistInput {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .add-graph-form {
        flex: 1;
    }

    .graph-selector-wrapper {
        display: flex;
        flex: 1;
        min-width: 0;
    }

    #graphInput {
        flex: 1;
        width: auto;
        min-width: 0;
    }

/* Abbreviate sign-out: hide email, keep button */
    .user-email {
        display: none;
    }

    /* Stock grid: 2 per row */
    .stock-grid {
        flex-direction: row;
        flex-wrap: wrap;
        overflow: hidden;
    }

    .stock-card {
        width: 50%;
        flex-shrink: 0;
        border-right: 1px solid #333;
        border-bottom: 1px solid #333;
        padding: 14px 16px;
        min-width: 0;
    }

    /* Dividers span full width */
    #stockGrid .divider {
        width: 100% !important;
    }

    /* :2+ cards should match 2 :1 cards (2 × 50% = 100%) */
    .stock-card[data-width="2"],
    .stock-card[data-width="3"],
    .stock-card[data-width="4"],
    .stock-card[data-width="5"],
    .stock-card[data-width="6"] {
        width: 100% !important;
    }

    .primary-metric {
        font-size: 22px;
    }

    .chart-container {
        height: 75px;
        margin: 10px 0 8px;
    }

    /* Hide resize handle — desktop-only */
    .resize-handle {
        display: none;
    }

    /* Portfolio graphs */
    .graph-card-body {
        min-height: 280px;
        padding: 12px;
    }

    .graph-card-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .graph-resize-handle {
        display: none;
    }

    #portfolioView {
        gap: 12px;
        padding: 12px;
    }

    /* Force each portfolio graph card and divider to full width on mobile,
       overriding any saved span-N inline styles */
    .portfolio-graph-card,
    .portfolio-divider {
        grid-column: 1 / -1 !important;
    }
}

/* Compact mode for many stocks */
@media (min-width: 769px) {
    .stock-grid.many-stocks .stock-card {
        width: 240px;
    }

    .stock-grid.many-stocks .primary-metric {
        font-size: 24px;
    }

    .stock-grid.many-stocks .chart-container {
        height: 80px;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    max-width: 1200px;
    width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.modal-header {
    display: none;
}

#modalStockSymbol {
    position: absolute;
    top: 29px;
    left: 40px;
    z-index: 10;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin: 0;
    letter-spacing: 0.5px;
    pointer-events: none;
}

.modal-close-btn {
    display: none;
}

.modal-body {
    padding: 20px 24px 24px 24px;
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#candlestickChartContainer {
    flex: 1;
    min-height: 550px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#candlestickChart {
    width: 100% !important;
    height: 550px !important;
}

#candlestickChartContainer.loading::after {
    content: 'Loading data...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 16px;
}

#candlestickChartContainer.no-data::after {
    content: 'Select a time period below';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 16px;
}

.controls-container {
    border-top: 1px solid #333;
    padding: 20px 0 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.period-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.interval-selector {
    display: flex;
    gap: 6px;
}

.period-btn {
    padding: 6px 14px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.period-btn:hover {
    background: #242424;
    color: #aaa;
    border-color: #333;
}

.period-btn.active {
    background: #2a2a2a;
    color: #fff;
    border-color: #444;
}

.period-btn:active {
    transform: scale(0.98);
}

.interval-btn {
    padding: 6px 12px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 36px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.interval-btn:hover {
    background: #242424;
    color: #aaa;
    border-color: #333;
}

.interval-btn.active {
    background: #2a2a2a;
    color: #fff;
    border-color: #444;
}

.interval-btn:active {
    transform: scale(0.98);
}

.interval-btn.disabled,
.interval-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.interval-btn.disabled:hover,
.interval-btn:disabled:hover {
    background: transparent;
    color: #888;
    border-color: #2a2a2a;
}

/* Modal controls responsive */
@media (max-width: 768px) {
    .controls-container {
        flex-direction: column;
        align-items: stretch;
    }

    .period-selector,
    .interval-selector {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    #watchlistGrid .stock-card {
        width: 100%;
    }

    .watchlist-card-body {
        flex-direction: row;
    }

    /* On mobile: card-left becomes flex-row — info on left, chart on right */
    .watchlist-card-left {
        flex: 1;
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 8px;
    }

    .watchlist-card-info {
        flex: 1;
        min-width: 0;
    }

    .watchlist-card-left .chart-container {
        flex: 0 0 33.33%;
        height: 80px;
        padding-right: 8px;
    }

    /* Hide full ai-section on mobile — verdict shown via watchlist-verdict-mobile */
    #watchlistGrid .ai-section {
        display: none;
    }

    .watchlist-verdict-mobile {
        display: block;
        margin-top: 6px;
    }
}

/* Upload Modal Styles */
.upload-modal-content {
    max-width: 440px;
    padding: 20px;
    background: #242424;
}

.modal-close-btn-visible {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    color: #555;
    border: none;
    font-size: 20px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s;
    padding: 0;
}

.modal-close-btn-visible:hover {
    background: #2a2a2a;
    color: #888;
}

.upload-step.hidden {
    display: none;
}

.upload-step-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.upload-step-header .upload-modal-title {
    margin-bottom: 0;
}

.upload-back-btn {
    background: transparent;
    border: none;
    color: #555;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    transition: all 0.2s;
}

.upload-back-btn:hover {
    color: #aaa;
    background: #2a2a2a;
}

.upload-source-options {
    display: flex;
    gap: 8px;
}

.upload-source-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 12px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    color: #888;
}

.upload-source-option:hover:not(:disabled) {
    background: #2a2a2a;
    border-color: #444;
    color: #aaa;
}

.upload-source-option:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.upload-source-icon {
    color: #555;
    display: flex;
}

.upload-source-option:hover:not(:disabled) .upload-source-icon {
    color: #888;
}

.upload-source-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.upload-source-label strong {
    font-size: 11px;
    font-weight: 600;
    color: inherit;
    letter-spacing: 0.3px;
}

.upload-source-label small {
    font-size: 10px;
    color: #444;
}

.upload-source-option:hover:not(:disabled) .upload-source-label small {
    color: #666;
}

.upload-modal-title {
    font-size: 13px;
    font-weight: 500;
    color: #888;
    margin: 0 0 16px 0;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.upload-modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.upload-type-selector {
    display: flex;
    gap: 8px;
}

.upload-type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    position: relative;
}

.upload-type-option:hover {
    background: #2a2a2a;
    border-color: #444;
}

.upload-type-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.upload-type-option:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: #1e1e2e;
}

.upload-type-option.has-data {
    border-color: #2d5a3d;
}

.upload-type-option.has-data .upload-type-label strong {
    color: #48bb78;
}

.upload-type-option.has-data:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: #1e1e2e;
}

.upload-type-check {
    font-size: 11px;
    color: #48bb78;
    display: none;
    line-height: 1;
    font-weight: 600;
}

.upload-type-option.has-data .upload-type-check {
    display: block;
}

.upload-type-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: center;
    color: #888;
}

.upload-type-label strong {
    font-size: 12px;
    font-weight: 600;
    color: #aaa;
}

.upload-type-label small {
    font-size: 10px;
    color: #666;
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    border: 1px dashed #333;
    border-radius: 3px;
    background: #1a1a1a;
    transition: border-color 0.15s, background 0.15s;
}

.upload-area.drag-active {
    border-color: #667eea;
    background: #1e1e2e;
}

.select-file-btn {
    padding: 8px 16px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.select-file-btn:hover {
    background: #2a2a2a;
    color: #aaa;
    border-color: #333;
}

.file-info {
    font-size: 11px;
    color: #888;
    text-align: center;
}

.file-info.hidden {
    display: none;
}

.upload-error {
    padding: 10px;
    background: rgba(245, 101, 101, 0.05);
    border: 1px solid rgba(245, 101, 101, 0.2);
    border-radius: 3px;
    color: #f56565;
    font-size: 11px;
}

.upload-error.hidden {
    display: none;
}

.upload-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}

.cancel-btn {
    padding: 8px 16px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cancel-btn:hover {
    background: #2a2a2a;
    border-color: #333;
    color: #aaa;
}

.confirm-btn {
    padding: 8px 16px;
    background: transparent;
    color: #888;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.confirm-btn:hover {
    background: #2a2a2a;
    border-color: #333;
    color: #aaa;
}

.confirm-btn:disabled {
    background: transparent;
    color: #555;
    border-color: #2a2a2a;
    cursor: not-allowed;
}

.confirm-btn:disabled:hover {
    background: transparent;
    color: #555;
    border-color: #2a2a2a;
}

