/* ===================================
   Stock Portfolio Dashboard - Modern Design
   Design System & Component Library
   =================================== */

/* ===================================
   CSS Custom Properties (Design Tokens)
   =================================== */
:root {
    /* Color System - Dark Theme */
    --color-bg-base: #0A0E1A;
    --color-bg-surface: #141B2E;
    --color-bg-elevated: #1E2740;
    --color-bg-hover: #293548;

    --color-primary: #00C9A7;
    --color-primary-hover: #00B395;
    --color-primary-alpha: rgba(0, 201, 167, 0.1);

    --color-secondary: #845EF7;
    --color-secondary-hover: #7048E8;

    --color-warning: #FFB020;
    --color-danger: #FF6B6B;
    --color-danger-hover: #FA5252;
    --color-success: #00C9A7;
    --color-info: #3498db;

    --color-text-primary: #FFFFFF;
    --color-text-secondary: #94A3B8;
    --color-text-tertiary: #64748B;
    --color-text-muted: #475569;

    --color-border-subtle: #293548;
    --color-border-emphasis: #3A4A63;

    --color-gain: #00C9A7;
    --color-loss: #FF6B6B;

    /* Spacing Scale (8px base) */
    --space-xs: 0.25rem;    /* 4px */
    --space-sm: 0.5rem;     /* 8px */
    --space-md: 1rem;       /* 16px */
    --space-lg: 1.5rem;     /* 24px */
    --space-xl: 2rem;       /* 32px */
    --space-2xl: 3rem;      /* 48px */
    --space-3xl: 4rem;      /* 64px */

    /* Typography */
    --font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    --font-family-mono: 'SF Mono', 'Consolas', 'Monaco', monospace;

    --font-size-xs: 0.75rem;      /* 12px */
    --font-size-sm: 0.875rem;     /* 14px */
    --font-size-base: 1rem;       /* 16px */
    --font-size-lg: 1.125rem;     /* 18px */
    --font-size-xl: 1.5rem;       /* 24px */
    --font-size-2xl: 2rem;        /* 32px */
    --font-size-3xl: 2.5rem;      /* 40px */

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.25;
    --line-height-base: 1.5;
    --line-height-relaxed: 1.75;

    /* Border Radius */
    --radius-sm: 0.5rem;    /* 8px */
    --radius-md: 0.75rem;   /* 12px */
    --radius-lg: 1rem;      /* 16px */
    --radius-xl: 1.5rem;    /* 24px */
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index Scale */
    --z-base: 0;
    --z-dropdown: 1000;
    --z-sticky: 1100;
    --z-fixed: 1200;
    --z-modal: 1300;
    --z-tooltip: 1400;
}

/* Light Mode (Optional - can be implemented later) */
[data-theme="light"] {
    --color-bg-base: #F8FAFC;
    --color-bg-surface: #FFFFFF;
    --color-bg-elevated: #FFFFFF;
    --color-bg-hover: #F1F5F9;

    --color-text-primary: #0F172A;
    --color-text-secondary: #475569;
    --color-text-tertiary: #94A3B8;

    --color-border-subtle: #E2E8F0;
    --color-border-emphasis: #CBD5E1;

    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.1);
}

/* ===================================
   Base Styles & Reset
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family-base);
    background: var(--color-bg-base);
    color: var(--color-text-primary);
    line-height: var(--line-height-base);
    min-height: 100vh;
}

/* Ensure smooth scrolling */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   Accessibility - Skip to Main Content
   =================================== */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: var(--color-bg-base);
    padding: 8px 16px;
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 9999;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: 0;
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===================================
   Layout Components
   =================================== */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 3rem);
}

/* Navigation */
.app-nav {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
    padding: var(--space-sm);
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(10px);
    position: relative;
}

.app-nav a {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    transition: all var(--transition-base);
    /* Ensure touch targets are at least 44x44px for accessibility */
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-nav a:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-elevated);
}

.app-nav a.active {
    color: var(--color-primary);
    background: var(--color-primary-alpha);
}

/* Mobile Navigation Toggle */
.nav-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    z-index: calc(var(--z-fixed) + 1);
}

.nav-toggle:hover {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-emphasis);
}

.nav-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

/* Hamburger icon using CSS only */
.nav-toggle-icon {
    position: relative;
    width: 24px;
    height: 2px;
    background: var(--color-text-primary);
    display: block;
    transition: all var(--transition-base);
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: var(--color-text-primary);
    transition: all var(--transition-base);
}

.nav-toggle-icon::before {
    top: -8px;
}

.nav-toggle-icon::after {
    bottom: -8px;
}

/* Hamburger animation when active */
.nav-toggle.active .nav-toggle-icon {
    background: transparent;
}

.nav-toggle.active .nav-toggle-icon::before {
    transform: rotate(45deg);
    top: 0;
}

.nav-toggle.active .nav-toggle-icon::after {
    transform: rotate(-45deg);
    bottom: 0;
}

.nav-links {
    display: flex;
    gap: var(--space-md);
    flex: 1;
}

/* ===================================
   Header Components
   =================================== */
.header {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-md);
}

.header-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-lg);
}

.header h1 {
    color: var(--color-text-primary);
    font-size: clamp(2rem, 3vw, 2.5rem);
    font-weight: var(--font-weight-bold);
    margin: 0;
    letter-spacing: -0.02em;
}

/* Sync Status Indicator */
.sync-status {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    transition: all var(--transition-base);
}

.sync-status.syncing {
    border-color: var(--color-info);
    background: rgba(52, 152, 219, 0.1);
    color: var(--color-info);
}

.sync-status.syncing #sync-icon {
    animation: spin 1s linear infinite;
}

.sync-status.success {
    border-color: var(--color-success);
    background: rgba(0, 201, 167, 0.1);
    color: var(--color-success);
}

.sync-status.error {
    border-color: var(--color-danger);
    background: rgba(255, 107, 107, 0.1);
    color: var(--color-danger);
}

#sync-icon {
    font-size: var(--font-size-base);
    line-height: 1;
}

#sync-text {
    white-space: nowrap;
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-lg);
}

.card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--color-border-emphasis);
}

.card:hover::before {
    opacity: 1;
}

.card h3 {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-sm);
}

.card p {
    font-size: clamp(1.75rem, 3vw, 2.5rem);
    font-weight: var(--font-weight-bold);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-primary);
    line-height: var(--line-height-tight);
}

/* ===================================
   Main Content
   =================================== */
.main-content {
    display: grid;
    gap: var(--space-xl);
}

.add-stock-section,
.portfolio-section,
.sold-stocks-section,
.charts-section {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    box-shadow: var(--shadow-md);
    /* Prevent horizontal overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    width: 100%;
}

.add-stock-section h2,
.portfolio-section h2,
.sold-stocks-section h2,
.charts-section h2 {
    color: var(--color-text-primary);
    margin-bottom: var(--space-lg);
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.01em;
}

/* ===================================
   Forms
   =================================== */
.add-stock-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
    /* Mobile-first: single column by default */
}

.form-submit {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    margin-top: var(--space-md);
}

.form-submit .btn-primary {
    min-width: 200px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-sm);
    display: block;
    /* Allow labels to wrap properly on small screens */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.form-group input,
.form-group select {
    background: var(--color-bg-base);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-family: var(--font-family-base);
    transition: all var(--transition-base);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    /* Ensure form controls are at least 44px tall for accessibility */
    min-height: 44px;
    width: 100%;
    /* Prevent horizontal overflow on small screens */
    box-sizing: border-box;
}

.form-group input {
    font-variant-numeric: tabular-nums;
}

.form-group input::placeholder {
    color: var(--color-text-muted);
}

.form-group input:hover,
.form-group select:hover {
    border-color: var(--color-border-emphasis);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
    background: var(--color-bg-elevated);
}

/* ===================================
   Buttons
   =================================== */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-info {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    font-family: var(--font-family-base);
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-bg-base);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(0, 201, 167, 0.3);
}

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

.btn-secondary {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border-subtle);
}

.btn-secondary:hover {
    background: var(--color-bg-elevated);
    border-color: var(--color-border-emphasis);
    color: var(--color-text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    padding: 0.5rem 1rem;
    font-size: var(--font-size-xs);
}

.btn-danger:hover {
    background: var(--color-danger);
    color: white;
}

.btn-info {
    background: var(--color-info);
    color: white;
    border: none;
}

.btn-info:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

/* Button focus states */
.btn-primary:focus,
.btn-secondary:focus,
.btn-danger:focus,
.btn-info:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

/* ===================================
   Section Headers
   =================================== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.portfolio-filter {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.portfolio-filter label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
}

.portfolio-filter select {
    padding: 0.625rem 1rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-base);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family-base);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-base);
    min-width: 150px;
}

.portfolio-filter select:hover {
    border-color: var(--color-border-emphasis);
    background: var(--color-bg-elevated);
}

.portfolio-filter select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
    background: var(--color-bg-elevated);
}

.portfolio-actions {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

/* ===================================
   Tables
   =================================== */
.portfolio-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.portfolio-table th {
    background: transparent;
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border-subtle);
}

.portfolio-table td {
    padding: var(--space-md);
    border-bottom: 1px solid rgba(41, 53, 72, 0.3);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

.portfolio-table tbody tr {
    transition: background-color var(--transition-fast);
}

.portfolio-table tbody tr:hover {
    background: rgba(30, 39, 64, 0.5);
}

.portfolio-table tbody tr:last-child td {
    border-bottom: none;
}

/* Right-align numeric columns */
.portfolio-table td:nth-child(n+3),
.portfolio-table th:nth-child(n+3) {
    text-align: right;
}

/* Symbol column */
.portfolio-table .symbol {
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    font-size: var(--font-size-base);
}

/* Gain/Loss styling */
.portfolio-table .gain,
.gain {
    color: var(--color-gain);
    font-weight: var(--font-weight-semibold);
}

.portfolio-table .loss,
.loss {
    color: var(--color-loss);
    font-weight: var(--font-weight-semibold);
}

/* Strategy Badge styling */
.strategy-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    background: var(--color-primary-alpha);
    color: var(--color-primary);
    border: 1px solid rgba(0, 201, 167, 0.2);
    white-space: nowrap;
    transition: all var(--transition-base);
}

.strategy-badge:hover {
    background: rgba(0, 201, 167, 0.15);
    border-color: rgba(0, 201, 167, 0.3);
}

.strategy-none {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

/* ===================================
   Empty States
   =================================== */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-lg);
    color: var(--color-text-tertiary);
}

.empty-state h3 {
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-xl);
    color: var(--color-text-secondary);
}

.empty-state p {
    font-size: var(--font-size-base);
    color: var(--color-text-tertiary);
}

/* ===================================
   Charts
   =================================== */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-xl);
}

.chart-card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
}

.chart-card h3 {
    margin-bottom: var(--space-lg);
    color: var(--color-text-primary);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

.chart-card canvas {
    max-height: 300px;
    width: 100%;
}

/* ===================================
   Notifications
   =================================== */
.portfolio-notification {
    background: var(--color-bg-surface);
    border-left: 3px solid var(--color-primary);
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideInDown 0.3s ease-out;
}

.portfolio-notification.info {
    border-left-color: var(--color-info);
    background: rgba(52, 152, 219, 0.05);
}

.portfolio-notification.success {
    border-left-color: var(--color-success);
    background: rgba(0, 201, 167, 0.05);
}

.portfolio-notification.warning {
    border-left-color: var(--color-warning);
    background: rgba(255, 176, 32, 0.05);
}

.portfolio-notification.error {
    border-left-color: var(--color-danger);
    background: rgba(255, 107, 107, 0.05);
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===================================
   Backup Status
   =================================== */
.backup-status-info {
    background: rgba(52, 152, 219, 0.05);
    border: 1px solid rgba(52, 152, 219, 0.2);
    padding: var(--space-md);
    margin-top: var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    animation: slideInDown 0.3s ease-out;
}

/* ===================================
   Loading States
   =================================== */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--color-border-subtle);
    border-top: 2px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===================================
   Responsive Design - Mobile First Approach
   =================================== */

/* ===================================
   Mobile Navigation (< 768px)
   =================================== */
@media (max-width: 767px) {
    /* Transform the desktop nav container for mobile bottom nav */
    .app-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin-bottom: 0;
        padding: 0;
        background: transparent;
        border: none;
        backdrop-filter: none;
        border-radius: 0;
        z-index: var(--z-fixed);
    }

    /* Hide hamburger menu on mobile */
    .nav-toggle {
        display: none !important;
    }

    /* Bottom Navigation Bar - Mobile Only */
    .nav-links {
        display: flex !important;
        position: relative;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-top: 1px solid var(--color-border-subtle);
        padding: var(--space-sm) env(safe-area-inset-right)
                 calc(var(--space-sm) + env(safe-area-inset-bottom))
                 env(safe-area-inset-left);
        transform: none;
        transition: none;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        gap: 0;
        overflow: visible;
        border-right: none;
        visibility: visible;
        pointer-events: auto;
        margin: 0;
    }

    /* Dark mode support for bottom nav */
    @media (prefers-color-scheme: dark) {
        .nav-links {
            background: rgba(30, 30, 30, 0.95);
            border-top-color: rgba(255, 255, 255, 0.1);
        }
    }

    /* Bottom navigation items */
    .nav-links .nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 8px 12px;
        text-decoration: none;
        color: #6B7280;
        font-size: 12px;
        font-weight: 500;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 16px;
        min-height: 60px;
        /* Ensure touch targets are at least 44x44px */
        min-width: 44px;
        position: relative;
    }

    /* SVG icon styling */
    .nav-links .nav-icon {
        width: 24px;
        height: 24px;
        stroke-width: 2;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Text label */
    .nav-links .nav-text {
        font-size: 11px;
        line-height: 1.2;
        text-align: center;
        white-space: nowrap;
        font-weight: 500;
    }

    /* Active state - Pill-shaped background like examples */
    .nav-links .nav-item.active {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: #FFFFFF;
        font-weight: 600;
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    }

    .nav-links .nav-item.active .nav-icon {
        stroke-width: 2.5;
        transform: scale(1.1);
    }

    .nav-links .nav-item.active .nav-text {
        font-weight: 600;
    }

    /* Hover/touch feedback for non-active items */
    .nav-links .nav-item:not(.active):hover,
    .nav-links .nav-item:not(.active):active {
        color: #667eea;
        background: rgba(102, 126, 234, 0.1);
    }

    @media (prefers-color-scheme: dark) {
        .nav-links .nav-item {
            color: #9CA3AF;
        }

        .nav-links .nav-item:not(.active):hover,
        .nav-links .nav-item:not(.active):active {
            background: rgba(102, 126, 234, 0.15);
            color: #a78bfa;
        }

        .nav-links .nav-item.active {
            background: linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%);
            box-shadow: 0 4px 12px rgba(124, 58, 237, 0.5);
        }
    }

    /* Add bottom padding to main content to prevent overlap with bottom nav */
    .container {
        padding-bottom: calc(80px + var(--space-md));
    }

    /* Ensure modals appear above bottom nav */
    .modal {
        z-index: calc(var(--z-fixed) + 10);
    }

    /* Remove backdrop styles (no longer needed) */
    .nav-links::before,
    .nav-links.active::before {
        display: none;
    }
}

/* ===================================
   Tablet & Mobile Styles (< 1024px)
   =================================== */
@media (max-width: 1023px) {
    /* Container adjustments */
    .container {
        padding: var(--space-md);
    }

    /* Header adjustments */
    .header {
        padding: var(--space-lg);
    }

    .header-title-row {
        flex-direction: column;
        text-align: center;
        gap: var(--space-md);
    }

    /* Stack summary cards on smaller screens */
    .summary-cards {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    /* Section headers */
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-md);
    }

    /* Portfolio filters */
    .portfolio-filters {
        display: flex;
        flex-direction: column;
        gap: var(--space-md);
        width: 100%;
    }

    .portfolio-filter {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-sm);
    }

    .portfolio-filter label {
        font-size: var(--font-size-sm);
    }

    .portfolio-filter select {
        width: 100%;
    }

    /* Portfolio actions */
    .portfolio-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }

    .portfolio-actions button {
        width: 100%;
        font-size: var(--font-size-xs);
        padding: var(--space-sm) var(--space-md);
    }

    /* Charts */
    .charts-container {
        grid-template-columns: 1fr;
    }

    .chart-card {
        padding: var(--space-lg);
    }
}

/* Hide mobile footer and spacer on desktop by default */
.mobile-footer,
.mobile-spacer {
    display: none;
}

/* ===================================
   Mobile Styles (< 768px)
   =================================== */
@media (max-width: 767px) {
    /* Reduce container padding on mobile */
    .container {
        padding: var(--space-md);
        padding-bottom: 240px; /* Generous space for footer + bottom nav */
        max-width: 100%;
    }

    /* Ensure main content has extra bottom padding */
    .main-content {
        padding-bottom: var(--space-3xl);
    }

    /* Hide Add New Stock section on mobile */
    .add-stock-section {
        display: none;
    }

    /* Ensure all cards are consistent width */
    .header,
    .portfolio-section,
    .sold-stocks-section,
    .charts-section {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Header adjustments */
    .header {
        padding: var(--space-lg);
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-lg);
        background: linear-gradient(135deg, var(--color-bg-surface), rgba(132, 94, 247, 0.05));
    }

    .header h1 {
        font-size: 1.75rem;
    }

    /* Stack summary cards vertically */
    .summary-cards {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }

    .card {
        padding: var(--space-lg);
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-lg);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .card p {
        font-size: 2rem;
    }

    /* Enhanced first summary card (Total Value) */
    .summary-cards .card:first-child {
        background: linear-gradient(135deg, rgba(0, 201, 167, 0.15), rgba(132, 94, 247, 0.15));
        border: 2px solid var(--color-primary);
    }

    .summary-cards .card:first-child p {
        color: var(--color-primary);
        font-size: 2.25rem;
    }

    /* Portfolio and Sold Stocks sections */
    .portfolio-section,
    .sold-stocks-section {
        padding: var(--space-lg);
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-lg);
        margin-bottom: var(--space-md);
    }

    /* Extra bottom padding for sold stocks section to clear footer */
    .sold-stocks-section {
        padding-bottom: var(--space-lg);
        margin-bottom: var(--space-xl);
    }

    /* Mobile spacer to push content above footer */
    .mobile-spacer {
        display: block;
        height: 120px; /* Generous space to clear footer */
        width: 100%;
    }

    /* Form adjustments */
    .add-stock-form {
        gap: var(--space-md);
        /* Already single column from base styles */
    }

    .form-submit .btn-primary {
        width: 100%;
        min-width: auto;
    }

    /* All buttons full width on mobile */
    .portfolio-actions {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }

    /* Hide export, import, and clear buttons on mobile */
    #export-portfolio,
    #import-portfolio,
    #import-commsec,
    #clear-portfolio,
    #clear-sold-history {
        display: none;
    }

    /* Keep only Refresh & Sync button on mobile */
    #refresh-prices {
        width: 100%;
    }

    /* Hide desktop sync status on mobile */
    .sync-status {
        display: none;
    }

    /* Mobile Footer */
    .mobile-footer {
        display: block;
        position: fixed;
        bottom: 60px; /* Just above bottom nav */
        left: 0;
        right: 0;
        background: var(--color-bg-elevated);
        border-top: 1px solid var(--color-border-subtle);
        padding: var(--space-md) var(--space-md) var(--space-lg); /* Extra bottom padding */
        z-index: 99;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    }

    .mobile-footer-content {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .mobile-sync-status {
        display: flex;
        align-items: center;
        gap: var(--space-xs);
        font-size: 0.75rem;
        padding: var(--space-xs) var(--space-sm);
        border-radius: var(--radius-md);
        background: var(--color-bg-surface);
        border: 1px solid var(--color-border-subtle);
        color: var(--color-text-secondary);
    }

    .mobile-sync-status.syncing {
        border-color: var(--color-info);
        background: rgba(52, 152, 219, 0.1);
    }

    .mobile-sync-status.syncing .mobile-sync-icon {
        animation: spin 1s linear infinite;
    }

    .mobile-sync-status.success {
        border-color: var(--color-success);
        background: rgba(0, 201, 167, 0.1);
        color: var(--color-success);
    }

    .mobile-sync-status.error {
        border-color: var(--color-danger);
        background: rgba(255, 107, 107, 0.1);
        color: var(--color-danger);
    }

    .mobile-sync-icon {
        font-size: 0.9rem;
    }

    .mobile-sync-text {
        font-size: 0.75rem;
        font-weight: var(--font-weight-medium);
    }

    /* Chart adjustments */
    .chart-card {
        padding: var(--space-md);
    }

    .chart-card h3 {
        font-size: var(--font-size-base);
    }
}

/* ===================================
   Responsive Tables
   =================================== */
@media (max-width: 1023px) {
    /* Make tables scrollable horizontally on tablet and mobile */
    #portfolio-table-container,
    #sold-stocks-table-container,
    #cgt-events-container,
    #dividends-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    /* Add subtle shadow to indicate scroll */
    #portfolio-table-container::after,
    #sold-stocks-table-container::after,
    #cgt-events-container::after,
    #dividends-table-container::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to left, var(--color-bg-surface), transparent);
        pointer-events: none;
        opacity: 0.8;
    }

    /* Reduce table font size */
    .portfolio-table {
        font-size: var(--font-size-xs);
        min-width: 900px; /* Ensure table doesn't collapse */
    }

    .portfolio-table th,
    .portfolio-table td {
        padding: var(--space-sm);
        white-space: nowrap;
    }

    /* Make first column (symbol) sticky on scroll */
    .portfolio-table th:first-child,
    .portfolio-table td:first-child {
        position: sticky;
        left: 0;
        background: var(--color-bg-surface);
        z-index: 10;
        box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    }

    .portfolio-table th:first-child {
        z-index: 11;
    }
}

/* ===================================
   Small Mobile Styles (< 480px)
   =================================== */
@media (max-width: 479px) {
    /* Further reduce spacing */
    .container {
        padding: var(--space-xs);
    }

    .header,
    .add-stock-section,
    .portfolio-section,
    .sold-stocks-section {
        padding: var(--space-md);
        border-radius: var(--radius-md);
    }

    /* Additional spacing adjustments for form section */
    .add-stock-section {
        padding: var(--space-md) var(--space-sm);
    }

    /* Smaller title */
    .header h1 {
        font-size: 1.5rem;
    }

    /* Compact cards */
    .card {
        padding: var(--space-md);
    }

    .card h3 {
        font-size: 0.65rem;
    }

    .card p {
        font-size: 1.5rem;
    }

    /* Smaller table text */
    .portfolio-table {
        font-size: 0.7rem;
        min-width: 700px; /* Reduced from 800px for better iPhone SE experience */
    }

    .portfolio-table th,
    .portfolio-table td {
        padding: var(--space-xs) var(--space-sm);
    }

    /* Compact buttons */
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-info {
        padding: 0.625rem 1rem;
        font-size: 0.8125rem;
    }

    /* Form inputs - 16px minimum to prevent iOS auto-zoom */
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 0.75rem 0.875rem;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    /* Charts - single column for small screens */
    .charts-container {
        grid-template-columns: 1fr !important;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .modal-header,
    .modal-form,
    .modal-body {
        padding: var(--space-md);
    }

    .modal-header h2 {
        font-size: var(--font-size-lg);
    }
}

/* ===================================
   Responsive Modals
   =================================== */
@media (max-width: 767px) {
    /* Full-screen modals on mobile */
    .modal-content {
        max-width: 100%;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-actions {
        flex-direction: column-reverse;
        gap: var(--space-sm);
    }

    .modal-actions button {
        width: 100%;
    }

    /* Dividend summary on mobile */
    .dividend-summary {
        grid-template-columns: 1fr;
        gap: var(--space-md);
        padding: var(--space-md);
    }

    .summary-value {
        font-size: var(--font-size-lg);
    }
}

/* ===================================
   Tablet Landscape & Desktop Breakpoint (768px+)
   =================================== */
@media (min-width: 768px) {
    /* Form in two columns for larger screens */
    .add-stock-form {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===================================
   Desktop Breakpoint (1024px+)
   =================================== */
@media (min-width: 1024px) {
    /* Optimize layout for desktop */
    .container {
        padding: var(--space-xl);
    }

    /* Show more cards per row */
    .summary-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Portfolio actions in a row */
    .portfolio-actions {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

/* ===================================
   Large Desktop Breakpoint (1440px+)
   =================================== */
@media (min-width: 1440px) {
    .container {
        padding: clamp(2rem, 4vw, 4rem);
    }

    /* Add more sophisticated layouts for large screens */
    .summary-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===================================
   Print Optimization
   =================================== */
@media print {
    /* Hide navigation and actions when printing */
    .app-nav,
    .nav-toggle,
    .portfolio-actions,
    .add-stock-section,
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-info,
    .modal {
        display: none !important;
    }

    /* Optimize tables for printing */
    .portfolio-table {
        border: 1px solid #000;
        font-size: 10pt;
    }

    body {
        background: white;
        color: black;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }
}

/* ===================================
   Utility Classes
   =================================== */
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }

.bg-surface { background: var(--color-bg-surface); }
.bg-elevated { background: var(--color-bg-elevated); }

.font-mono { font-family: var(--font-family-mono); }
.font-bold { font-weight: var(--font-weight-bold); }
.font-semibold { font-weight: var(--font-weight-semibold); }

.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }

/* ===================================
   Modal Components
   =================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
    animation: fadeIn var(--transition-base);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-emphasis);
    border-radius: var(--radius-xl);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideInUp var(--transition-slow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-xl);
    border-bottom: 1px solid var(--color-border-subtle);
}

.modal-header h2 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
}

.modal-close:hover {
    background: var(--color-bg-hover);
    color: var(--color-text-primary);
}

.modal-form {
    padding: var(--space-xl);
    display: grid;
    gap: var(--space-lg);
}

.modal-form .form-group {
    display: flex;
    flex-direction: column;
}

.modal-form .form-group input[disabled] {
    background: var(--color-bg-elevated);
    color: var(--color-text-tertiary);
    cursor: not-allowed;
    opacity: 0.7;
}

.modal-actions {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
    margin-top: var(--space-md);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--color-border-subtle);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Make table rows clickable */
.portfolio-table tbody tr {
    cursor: pointer;
}

/* ===================================
   Print Styles
   =================================== */
@media print {
    body {
        background: white;
        color: black;
    }

    .portfolio-actions,
    .add-stock-section,
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-info,
    .modal {
        display: none;
    }

    .portfolio-table {
        border: 1px solid #000;
    }
}

/* ===================================
   Commsec Import Styles
   =================================== */
.modal-body {
    padding: var(--space-xl);
}

.modal-description {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-lg);
    line-height: var(--line-height-relaxed);
}

.file-input {
    padding: var(--space-md);
    border: 2px dashed var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-bg-base);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family-base);
    cursor: pointer;
    transition: all var(--transition-base);
}

.file-input:hover {
    border-color: var(--color-primary);
    background: var(--color-bg-elevated);
}

.file-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

.form-group small {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    font-style: italic;
}

.import-preview {
    margin-top: var(--space-lg);
    padding: var(--space-lg);
    background: var(--color-bg-base);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
}

.import-preview h3 {
    margin-bottom: var(--space-md);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.import-preview p {
    margin-bottom: var(--space-md);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

#commsec-preview-table {
    max-height: 400px;
    overflow-y: auto;
    margin-top: var(--space-md);
}

#commsec-preview-table table {
    font-size: var(--font-size-xs);
}

#commsec-preview-table td,
#commsec-preview-table th {
    padding: var(--space-sm);
}

/* ===================================
   Form Validation Styles
   =================================== */

/* Required field indicator */
.required {
    color: var(--color-danger);
    font-weight: var(--font-weight-bold);
    margin-left: var(--space-xs);
}

/* Field hints */
.field-hint {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    font-style: normal;
    /* Allow hints to wrap properly on small screens */
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: var(--line-height-relaxed);
}

/* Invalid input styling */
.form-group input:invalid:not(:placeholder-shown):not(:focus),
.form-group select:invalid:not(:focus) {
    border-color: var(--color-danger);
    background: rgba(255, 107, 107, 0.05);
}

/* Invalid input focus state */
.form-group input:invalid:focus,
.form-group select:invalid:focus {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}

/* Valid input styling (optional, subtle feedback) */
.form-group input:valid:not(:placeholder-shown):not([type="text"]):not([type="date"]),
.form-group select:valid:not([value=""]) {
    border-color: var(--color-border-subtle);
}

/* Browser's native validation messages */
.form-group input:user-invalid,
.form-group select:user-invalid {
    border-color: var(--color-danger);
}

/* Ensure validation messages have proper styling */
input::-webkit-validation-bubble-message,
select::-webkit-validation-bubble-message {
    background: var(--color-bg-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    font-size: var(--font-size-sm);
}

/* Disabled field styling (for consistency) */
.form-group input:disabled,
.form-group select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--color-bg-elevated);
    color: var(--color-text-muted);
}

/* ===================================
   Dividend Components
   =================================== */

/* Dividend summary in view modal */
.dividend-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    padding: var(--space-lg);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.summary-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
}

.summary-value {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
}

/* Dividend display in portfolio table */
.dividend-total {
    color: var(--color-success);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.dividend-total:hover {
    color: var(--color-primary-hover);
    text-decoration-style: solid;
}

.dividend-none {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.clickable {
    cursor: pointer;
}

/* Smaller buttons for table actions */
.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: var(--font-size-xs);
}

/* Dividend table styling */
#dividends-table-container {
    margin-top: var(--space-lg);
    max-height: 500px;
    overflow-y: auto;
}

#dividends-table {
    width: 100%;
}

#dividends-table th {
    position: sticky;
    top: 0;
    background: var(--color-bg-surface);
    z-index: 10;
}

/* Modal body styling */
.modal-body {
    padding: var(--space-xl);
    max-height: calc(90vh - 200px);
    overflow-y: auto;
}

/* Responsive adjustments for dividend modals */
@media (max-width: 767px) {
    .dividend-summary {
        grid-template-columns: 1fr;
    }

    .summary-value {
        font-size: var(--font-size-lg);
    }

    .btn-small {
        padding: 0.4rem 0.6rem;
        font-size: 0.7rem;
    }

    #dividends-table-container {
        max-height: 300px;
    }
}
