/* ═══════════════════════════════════════════════════════════════════
   TradeMate VN — App Shell (Header + Sidebar + Main)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Header ──────────────────────────────────────────────────── */
.tm-header {
    position: sticky;
    top: 0;
    z-index: var(--z-dropdown);
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--space-lg);
    height: 56px;
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.tm-logo {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
    white-space: nowrap;
}
.tm-logo span { color: var(--color-text); font-weight: 400; }

.tm-hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
}
.tm-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text);
    border-radius: 1px;
    transition: var(--transition-fast);
}

.tm-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-left: auto;
}

/* ── Search ──────────────────────────────────────────────────── */
.tm-search-box { position: relative; }
.tm-search-toggle { display: none; }  /* Hidden on desktop */

.tm-search-input {
    width: 220px;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    outline: none;
    transition: width var(--transition-fast), border-color var(--transition-fast);
}
.tm-search-input::placeholder { color: var(--color-text-muted); }
.tm-search-input:focus { border-color: var(--color-primary); width: 280px; }

.tm-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
}
.tm-search-results.open { display: block; }

.tm-search-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    text-decoration: none;
    color: var(--color-text);
    transition: background var(--transition-fast);
}
.tm-search-item:hover { background: var(--color-bg-hover); }

.tm-search-symbol {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 56px;
}
.tm-search-name {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tm-search-empty {
    padding: var(--space-md);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    text-align: center;
}

/* ── Theme Button ────────────────────────────────────────────── */
.tm-theme-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: var(--color-bg-hover);
    border: none;
    cursor: pointer;
    color: var(--color-text);
    transition: background var(--transition-fast);
}
.tm-theme-btn:hover { background: var(--color-primary-muted); }

/* ── User Menu ───────────────────────────────────────────────── */
.tm-user-menu { position: relative; }

.tm-user-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    background: var(--color-bg-hover);
    border: none;
    cursor: pointer;
    color: var(--color-text);
    transition: background var(--transition-fast);
}
.tm-user-btn:hover { background: var(--color-primary-muted); }

.tm-user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: 600;
}
.tm-user-name {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.tm-user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    overflow: hidden;
}
.tm-user-dropdown.open { display: block; }

.tm-user-dropdown a {
    display: block;
    padding: var(--space-sm) var(--space-lg);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-sm);
    transition: background var(--transition-fast);
}
.tm-user-dropdown a:hover { background: var(--color-bg-hover); }
.tm-user-dropdown hr { border: none; border-top: 1px solid var(--color-border); margin: 0; }

/* ── Body Layout ─────────────────────────────────────────────── */
.tm-body {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 56px);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.tm-sidebar {
    width: 220px;
    min-width: 220px;
    background: var(--color-bg-secondary);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.tm-nav {
    padding: var(--space-md) var(--space-sm);
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tm-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all var(--transition-fast);
}
.tm-nav-item:hover { background: var(--color-bg-hover); color: var(--color-text); }
.tm-nav-item.active { background: var(--color-primary-muted); color: var(--color-primary); }

.tm-nav-icon { font-size: 18px; width: 24px; text-align: center; }

.tm-sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--color-border);
}

.tm-style-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}
.tm-style-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* ── Sidebar Overlay (mobile) ────────────────────────────────── */
.tm-sidebar-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-overlay);
    z-index: calc(var(--z-dropdown) - 1);
}

/* ── Main Content ────────────────────────────────────────────── */
.tm-main {
    flex: 1;
    padding: var(--space-xl);
    overflow-y: auto;
    min-width: 0;
}

/* ── Shared Content Cards ────────────────────────────────────── */
.tm-content-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
}

.tm-content-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.tm-content-card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.tm-page-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: var(--space-xl);
}

.tm-page-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-top: calc(var(--space-xs) * -1);
    margin-bottom: var(--space-lg);
}

/* ── Stat Grid ───────────────────────────────────────────────── */
.tm-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.tm-stat-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}
.tm-stat-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}
.tm-stat-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
}
.tm-stat-sub {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    margin-top: 2px;
}

/* ── Table ───────────────────────────────────────────────────── */
.tm-table-wrap { overflow-x: auto; }

.tm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}
.tm-table th {
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.tm-table td {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}
.tm-table tbody tr:hover { background: var(--color-bg-hover); }

.tm-table .text-right { text-align: right; }
.tm-table .text-center { text-align: center; }
.tm-table .positive { color: var(--color-positive); }
.tm-table .negative { color: var(--color-negative); }
.tm-table .symbol-link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}
.tm-table .symbol-link:hover { text-decoration: underline; }

/* ── Badge ───────────────────────────────────────────────────── */
.tm-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-sm);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1.4;
}
.tm-badge-buy { background: rgba(34,197,94,0.15); color: var(--color-positive); }
.tm-badge-sell { background: rgba(239,68,68,0.15); color: var(--color-negative); }
.tm-badge-watch { background: rgba(245,158,11,0.15); color: var(--color-neutral); }
.tm-badge-open { background: rgba(99,102,241,0.15); color: var(--color-primary); }
.tm-badge-closed { background: rgba(100,116,139,0.15); color: var(--color-text-muted); }

/* ── Empty State ─────────────────────────────────────────────── */
.tm-empty {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
    color: var(--color-text-muted);
}
.tm-empty-icon { font-size: 48px; margin-bottom: var(--space-md); }
.tm-empty-title { font-size: var(--font-size-lg); font-weight: 600; color: var(--color-text-secondary); margin-bottom: var(--space-sm); }

/* ── Modal ───────────────────────────────────────────────────── */
.tm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-overlay);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}
.tm-modal {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}
.tm-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--color-border);
}
.tm-modal-title { font-size: var(--font-size-lg); font-weight: 600; }
.tm-modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--space-xs);
}
.tm-modal-close:hover { color: var(--color-text); }
.tm-modal-body { padding: var(--space-xl); }
.tm-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--color-border);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .tm-hamburger { display: flex; }

    .tm-sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        z-index: var(--z-dropdown);
    }
    .tm-sidebar.open { transform: translateX(0); }
    .tm-sidebar-overlay.open { display: block; }

    .tm-search-input { width: 140px; }
    .tm-search-input:focus { width: 180px; }
    .tm-user-name { display: none; }
    .tm-main { padding: var(--space-md); }

    .tm-modal { max-width: calc(100vw - var(--space-lg) * 2); }

    /* Touch targets ≥44px on mobile */
    .tm-theme-btn { width: 44px; height: 44px; }
    .tm-modal-close { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
}

@media (max-width: 480px) {
    .tm-stat-grid { grid-template-columns: repeat(2, 1fr); }

    /* Sidebar width 80vw on small screens */
    .tm-sidebar { width: 80vw; min-width: auto; }

    /* Search icon toggle replaces full search bar */
    .tm-search-box .tm-search-input { display: none; }
    .tm-search-toggle {
        display: flex;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        font-size: 18px;
        color: var(--color-text);
        -webkit-tap-highlight-color: transparent;
    }
    /* Expanded search: fullscreen bar */
    .tm-search-box.expanded {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: var(--color-bg-secondary);
        z-index: calc(var(--z-dropdown) + 1);
        display: flex;
        align-items: center;
        padding: 0 var(--space-md);
        gap: var(--space-sm);
    }
    .tm-search-box.expanded .tm-search-input {
        display: block;
        flex: 1;
        width: auto;
    }
    .tm-search-box.expanded .tm-search-toggle {
        font-size: 16px;
        width: 40px;
        flex-shrink: 0;
    }
    .tm-search-box.expanded .tm-search-results {
        top: 56px;
        left: 0;
        right: 0;
        border-radius: 0;
    }

    /* Modal near-fullscreen */
    .tm-modal-overlay { padding: var(--space-xs); }
    .tm-modal {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: var(--radius-md);
    }
    .tm-modal-header,
    .tm-modal-body,
    .tm-modal-footer {
        padding-left: var(--space-md);
        padding-right: var(--space-md);
    }

    /* Table scroll hint */
    .tm-table-wrap {
        position: relative;
    }
    .tm-table-wrap.has-scroll::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 24px;
        background: linear-gradient(to left, var(--color-bg-card), transparent);
        pointer-events: none;
        z-index: 1;
    }
}
