/* ============================================================
   Trinity Ichimoku Dashboard — Mobile-First Responsive CSS
   ============================================================ */

:root {
    --bg-main: #0b111e;
    --bg-sidebar: #0f182c;
    --bg-card: rgba(22, 34, 57, 0.45);
    --bg-card-hover: rgba(26, 40, 68, 0.6);
    --border-color: rgba(59, 130, 246, 0.12);
    --border-hover: rgba(59, 130, 246, 0.25);

    --color-primary: #3b82f6;
    --color-primary-glow: rgba(59, 130, 246, 0.35);
    --color-purple: #8b5cf6;
    --color-purple-glow: rgba(139, 92, 246, 0.3);

    --color-up: #ef4444;
    --color-up-glow: rgba(239, 68, 68, 0.25);
    --color-down: #3b82f6;
    --color-down-glow: rgba(59, 130, 246, 0.25);

    --grade-strong-buy: linear-gradient(135deg, #10b981, #059669);
    --grade-buy: linear-gradient(135deg, #34d399, #10b981);
    --grade-neutral: linear-gradient(135deg, #94a3b8, #64748b);
    --grade-sell: linear-gradient(135deg, #f87171, #ef4444);
    --grade-strong-sell: linear-gradient(135deg, #b91c1c, #7f1d1d);

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dark: #64748b;

    --font-heading: 'Outfit', 'Noto Sans KR', sans-serif;
    --font-body: 'Noto Sans KR', sans-serif;

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.5);

    /* Mobile bottom nav height */
    --mobile-nav-h: 64px;
    --mobile-header-h: 56px;
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    height: 100dvh;           /* dynamic viewport height — works in iOS Safari */
}

/* ── App Shell ── */
.app-container {
    display: flex;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* ================================================================
   DESKTOP SIDEBAR  (≥ 1025px)
   ================================================================ */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 100;
    flex-shrink: 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.logo-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-purple));
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: white;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
    flex-shrink: 0;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 20px; font-weight: 700; letter-spacing: 1px;
}
.logo-text span { color: var(--color-primary); }

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    font-size: 15px; font-weight: 500;
    transition: var(--transition-fast);
    white-space: nowrap;
}
.nav-item i { font-size: 18px; width: 20px; text-align: center; }
.nav-item:hover { color: var(--text-main); background-color: rgba(255,255,255,0.05); }
.nav-item.active {
    color: white;
    background: linear-gradient(90deg, rgba(59,130,246,0.15), rgba(59,130,246,0.02));
    border-left: 3px solid var(--color-primary);
    padding-left: 13px;
}

.sidebar-footer {
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}
.status-indicator-container {
    display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.pulse-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    position: relative;
}
.pulse-dot.green { background-color: #10b981; box-shadow: 0 0 8px #10b981; }
.pulse-dot.green::after {
    content: ''; position: absolute;
    width: 100%; height: 100%;
    border-radius: 50%; background-color: #10b981;
    animation: pulse 1.8s infinite;
}
@keyframes pulse {
    0%   { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(2.5); opacity: 0; }
}
.status-text { font-size: 12px; color: var(--text-muted); }
.copyright { font-size: 11px; color: var(--text-dark); }

/* ── Main workspace ── */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--bg-main);
}

/* ── Header ── */
.main-header {
    padding: 30px 40px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(180deg, rgba(15,24,44,0.3) 0%, transparent 100%);
    flex-shrink: 0;
}
.header-title h1 {
    font-family: var(--font-heading);
    font-size: 24px; font-weight: 600;
    margin-bottom: 4px;
    background: linear-gradient(90deg, #ffffff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--text-muted); font-size: 13px; }

/* ── Search ── */
.search-container { position: relative; width: 320px; }
.search-box {
    display: flex; align-items: center;
    background-color: rgba(15,23,42,0.6);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 10px 16px;
    transition: var(--transition-normal);
}
.search-box:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 15px rgba(59,130,246,0.2);
    background-color: rgba(15,23,42,0.8);
}
.search-icon { color: var(--text-muted); margin-right: 12px; font-size: 15px; }
.search-box input {
    background: none; border: none;
    color: var(--text-main); font-size: 14px;
    width: 100%; outline: none;
    font-family: var(--font-body);
}
.search-box input::placeholder { color: var(--text-dark); }
.clear-search-btn {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    padding: 2px; font-size: 14px;
    display: flex; align-items: center;
    transition: var(--transition-fast);
}
.clear-search-btn:hover { color: var(--text-main); }

.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 8px); left: 0; right: 0;
    background-color: #0f172a;
    border: 1px solid var(--border-hover);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.6);
    z-index: 600;
    max-height: 280px;
    overflow-y: auto;
}
.search-result-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    transition: var(--transition-fast);
    border-bottom: 1px solid rgba(255,255,255,0.02);
    min-height: 48px;  /* touch target */
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background-color: rgba(59,130,246,0.12); }
.search-result-name { font-weight: 500; color: var(--text-main); }
.search-result-code {
    font-family: var(--font-heading); font-size: 12px; color: var(--text-muted);
    background-color: rgba(255,255,255,0.05);
    padding: 2px 6px; border-radius: 4px;
}

/* ── Content body ── */
.content-body {
    padding: 30px 40px;
    display: flex; flex-direction: column; gap: 30px;
}

/* ── Glass cards ── */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: var(--shadow-premium);
    padding: 24px;
    transition: var(--transition-normal);
}
.glass-card:hover { border-color: var(--border-hover); background: var(--bg-card-hover); }

/* ── Refresh Banner ── */
.refresh-banner {
    background: linear-gradient(90deg, rgba(139,92,246,0.15), rgba(59,130,246,0.15));
    border: 1px solid rgba(139,92,246,0.25);
    border-radius: 16px;
    padding: 16px 24px;
    display: flex; flex-direction: column; gap: 12px;
}
.banner-info { display: flex; align-items: center; gap: 16px; }
.spinner-container { font-size: 20px; color: var(--color-purple); }
.progress-details { display: flex; justify-content: space-between; flex-grow: 1; align-items: center; }
.progress-label { font-weight: 500; }
.progress-percentage { font-family: var(--font-heading); font-weight: 600; color: var(--color-purple); }
.progress-bar-container {
    background-color: rgba(255,255,255,0.05);
    border-radius: 6px; height: 8px; overflow: hidden; width: 100%;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-purple));
    border-radius: 6px; transition: width 0.4s ease;
}

/* ── Sections ── */
.dashboard-section { display: flex; flex-direction: column; gap: 18px; }
.section-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.section-title-wrapper { display: flex; align-items: center; gap: 12px; }
.header-icon { font-size: 22px; }
.text-yellow { color: #f59e0b; }
.text-blue   { color: #3b82f6; }
.text-purple { color: #a78bfa; }
.section-header h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.2px; }
.section-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.last-updated { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
    border: none; border-radius: 12px;
    font-weight: 500; cursor: pointer;
    font-family: var(--font-body);
    transition: var(--transition-fast);
    display: flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px;   /* touch target */
    white-space: nowrap;
}
.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #1d4ed8);
    color: white; padding: 10px 20px;
    box-shadow: 0 4px 15px rgba(59,130,246,0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(59,130,246,0.45); }
.btn-secondary {
    background-color: rgba(255,255,255,0.08);
    color: var(--text-main); padding: 10px 20px;
    border: 1px solid rgba(255,255,255,0.05);
}
.btn-secondary:hover { background-color: rgba(255,255,255,0.12); }
.btn-purple {
    background: linear-gradient(135deg, var(--color-purple), #6d28d9);
    color: white; padding: 10px 20px;
    box-shadow: 0 4px 15px rgba(139,92,246,0.35);
}
.btn-purple:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(139,92,246,0.45); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 8px; min-height: 38px; }

/* ── Watchlist Table ── */
.table-card { padding: 0; overflow: hidden; }
.table-responsive { overflow-x: auto; width: 100%; -webkit-overflow-scrolling: touch; }
.watchlist-table { width: 100%; border-collapse: collapse; text-align: left; }
.watchlist-table th,
.watchlist-table td { padding: 18px 24px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.watchlist-table th {
    font-family: var(--font-heading); font-weight: 500;
    color: var(--text-muted); font-size: 13px;
    background-color: rgba(15,23,42,0.2); letter-spacing: 0.5px;
    white-space: nowrap;
}
.watchlist-table tbody tr { cursor: pointer; transition: var(--transition-fast); }
.watchlist-table tbody tr:hover { background-color: rgba(255,255,255,0.02); }
.watchlist-table tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* Stock table badges */
.stock-code { font-family: var(--font-heading); color: var(--text-muted); font-size: 13px; }
.stock-name { font-weight: 600; color: var(--text-main); }
.price-value { font-family: var(--font-heading); font-weight: 600; }
.price-up   { color: var(--color-up); }
.price-down { color: var(--color-down); }
.price-flat { color: var(--text-muted); }
.badge-change {
    font-family: var(--font-heading); font-size: 12px; font-weight: 600;
    padding: 4px 8px; border-radius: 6px;
}
.badge-change.up   { background-color: var(--color-up-glow);   color: var(--color-up); }
.badge-change.down { background-color: var(--color-down-glow); color: var(--color-down); }
.badge-change.flat { background-color: rgba(255,255,255,0.05); color: var(--text-muted); }

.zscore-badge {
    font-family: var(--font-heading); font-size: 13px; font-weight: 600;
    padding: 3px 10px; border-radius: 20px;
    display: inline-block; min-width: 60px;
}
.zscore-badge.high   { background-color: rgba(239,68,68,0.15);  color: #ef4444; border: 1px solid rgba(239,68,68,0.25); box-shadow: 0 0 10px rgba(239,68,68,0.15); }
.zscore-badge.normal { background-color: rgba(255,255,255,0.05); color: var(--text-main); }
.zscore-badge.low    { background-color: rgba(59,130,246,0.15);  color: #3b82f6; border: 1px solid rgba(59,130,246,0.2); }

.grade-badge {
    font-size: 12px; font-weight: 700; color: white;
    padding: 4px 12px; border-radius: 8px;
    text-transform: uppercase; display: inline-block;
    letter-spacing: 0.5px; text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.grade-strong-buy  { background: var(--grade-strong-buy);  box-shadow: 0 0 12px rgba(16,185,129,0.3); }
.grade-buy         { background: var(--grade-buy); }
.grade-neutral     { background: var(--grade-neutral); }
.grade-sell        { background: var(--grade-sell); }
.grade-strong-sell { background: var(--grade-strong-sell); box-shadow: 0 0 12px rgba(239,68,68,0.3); }

.action-text { font-weight: 500; font-size: 13px; }
.action-text.strong-buy  { color: #10b981; }
.action-text.buy         { color: #34d399; }
.action-text.neutral     { color: var(--text-muted); }
.action-text.sell        { color: #f87171; }
.action-text.strong-sell { color: #ef4444; }

.btn-view-detail {
    background: none; border: none;
    color: var(--color-primary); cursor: pointer;
    font-size: 18px; transition: var(--transition-fast);
    padding: 8px; min-width: 40px; min-height: 40px;
}
.btn-view-detail:hover { color: white; transform: scale(1.15); }

.btn-delete-row {
    background: none; border: none;
    color: var(--text-dark); cursor: pointer;
    font-size: 18px; transition: var(--transition-fast);
    padding: 8px; min-width: 40px; min-height: 40px;
}
.btn-delete-row:hover { color: #ef4444; transform: scale(1.2); }

.table-placeholder { padding: 60px 0 !important; color: var(--text-muted); }
.placeholder-icon  { font-size: 32px; color: var(--text-dark); margin-bottom: 12px; }

/* ── Detail Analysis ── */
.detail-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 30px;
}
.chart-card { display: flex; flex-direction: column; }
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 12px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.chart-legend-custom { display: flex; gap: 16px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.color-dot { width: 8px; height: 8px; border-radius: 50%; }
.color-dot.price  { background-color: var(--color-primary); }
.color-dot.volume { background-color: var(--color-purple); }
.chart-wrapper { position: relative; height: 350px; width: 100%; }

.summary-result-card {
    background: linear-gradient(135deg, rgba(22,34,57,0.6) 0%, rgba(15,23,42,0.8) 100%);
    display: flex; flex-direction: column; gap: 20px;
    margin-bottom: 24px;
}
.verdict-header {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 14px;
}
.verdict-title  { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.verdict-grade  {
    font-family: var(--font-heading); font-size: 32px; font-weight: 700;
    background: linear-gradient(135deg, #10b981, #3b82f6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.score-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.02);
}
.score-row:last-child { border-bottom: none; }
.score-row .label { color: var(--text-muted); }
.score-row .value { font-weight: 600; }
.action-badge {
    font-size: 13px; padding: 4px 10px;
    border-radius: 6px; background-color: rgba(255,255,255,0.05);
}

.metrics-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 18px; }
.metrics-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
}
.metric-item {
    display: flex; flex-direction: column; gap: 6px;
    background-color: rgba(15,23,42,0.3);
    padding: 14px; border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.02);
}
.metric-item .label { font-size: 12px; color: var(--text-muted); }
.metric-item .value { font-family: var(--font-heading); font-size: 16px; font-weight: 600; }

.detail-bottom-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 30px; margin-top: 30px;
}

.factors-card h3, .targets-card h3 {
    font-size: 14px; font-weight: 600;
    display: flex; align-items: center; gap: 8px;
}
.font-green h3 { color: #34d399; }
.font-red h3   { color: #f87171; }
.font-blue h3  { color: #60a5fa; }

.factor-list { list-style: none; display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.factor-list li {
    display: flex; align-items: flex-start; gap: 8px;
    color: var(--text-muted); font-size: 13px; line-height: 1.4;
}
.factor-list li::before { content: '•'; color: var(--text-dark); font-weight: bold; display: inline-block; width: 6px; }
.font-green .factor-list li::before { color: #10b981; }
.font-red   .factor-list li::before { color: #ef4444; }

.targets-container { display: flex; flex-direction: column; gap: 20px; margin-top: 16px; }
.targets-sub-grid  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.target-box {
    display: flex; flex-direction: column; align-items: center;
    background-color: rgba(15,23,42,0.4);
    padding: 10px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.02);
}
.target-title { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.target-value { font-family: var(--font-heading); font-weight: 700; font-size: 13px; }
.target-box:nth-child(1) .target-value { color: #34d399; }
.target-box:nth-child(2) .target-value { color: #60a5fa; }
.target-box:nth-child(3) .target-value { color: #f87171; }

.confluence-section h4 {
    font-size: 12px; color: var(--text-muted);
    margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.confluence-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.confluence-list li {
    font-size: 12px; color: var(--text-muted);
    background-color: rgba(59,130,246,0.06);
    padding: 6px 12px; border-radius: 6px;
    border-left: 3px solid var(--color-primary);
}

/* ── Watchlist Manager ── */
.manager-layout { display: grid; grid-template-columns: 2fr 3fr; gap: 30px; }
.add-stock-card { height: fit-content; }
.add-stock-card h3, .watchlist-list-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.description { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.form-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.form-group label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.input-with-button { display: flex; gap: 12px; }
.input-with-button input {
    flex-grow: 1;
    background-color: rgba(15,23,42,0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px; padding: 12px 16px;
    color: white; font-family: var(--font-heading);
    font-size: 15px; outline: none;
    letter-spacing: 2px; text-align: center;
    transition: var(--transition-fast);
    min-height: 48px;
}
.input-with-button input:focus {
    border-color: var(--color-purple);
    box-shadow: 0 0 10px rgba(139,92,246,0.2);
}
.help-text { font-size: 12px; margin-top: 4px; transition: var(--transition-fast); }
.help-text.success { color: #10b981; }
.help-text.error   { color: #ef4444; }

.search-tip {
    background-color: rgba(245,158,11,0.05);
    border-left: 3px solid #f59e0b;
    padding: 14px; border-radius: 0 10px 10px 0;
}
.search-tip h4 { font-size: 13px; color: #f59e0b; margin-bottom: 4px; }
.search-tip p  { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ── Watchlist Manager Items — table layout ── */
.watchlist-items-list {
    width: 100%;
    overflow-y: auto;
    max-height: 500px;
}
/* Manager table */
.watchlist-mgr-table {
    width: 100%;
    border-collapse: collapse;
}
.watchlist-mgr-table th {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-align: left;
    padding: 8px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: rgba(15,23,42,0.3);
    white-space: nowrap;
}
.watchlist-mgr-table th:last-child { text-align: center; }
.watchlist-mgr-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 13px;
    vertical-align: middle;
}
.watchlist-mgr-table tr:last-child td { border-bottom: none; }
.watchlist-mgr-table tbody tr {
    transition: var(--transition-fast);
}
.watchlist-mgr-table tbody tr:hover {
    background-color: rgba(59,130,246,0.05);
}
.mgr-stock-name { font-weight: 600; color: var(--text-main); }
.mgr-stock-code {
    font-family: var(--font-heading);
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    padding: 2px 7px;
    border-radius: 4px;
    display: inline-block;
}
.mgr-seq { color: var(--text-dark); font-size: 12px; font-family: var(--font-heading); }
.mgr-delete-btn {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: #f87171;
    border-radius: 6px;
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition-fast);
    margin: 0 auto;
}
.mgr-delete-btn:hover {
    background: rgba(239,68,68,0.25);
    color: white;
    transform: scale(1.05);
}
.no-items {
    padding: 40px; text-align: center; color: var(--text-muted);
    border: 1px dashed rgba(255,255,255,0.1); border-radius: 12px;
    width: 100%;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }


/* ================================================================
   MOBILE BOTTOM NAVIGATION  (hidden on desktop)
   ================================================================ */
.mobile-bottom-nav {
    display: none;  /* shown via media query */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mobile-nav-h);
    background: rgba(15, 24, 44, 0.95);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    z-index: 1000;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom);
}
.mobile-nav-inner {
    display: flex;
    height: 100%;
    align-items: stretch;
}
.mobile-nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px; font-weight: 500;
    padding: 6px 4px;
    border-radius: 12px;
    transition: var(--transition-fast);
    cursor: pointer;
    border: none; background: none;
    -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item i { font-size: 20px; }
.mobile-nav-item.active {
    color: var(--color-primary);
}
.mobile-nav-item.active i {
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.7));
}

/* mobile rotate button */
.mobile-nav-item.rotate-btn { position: relative; }

/* ── Mobile Top Header ── */
.mobile-top-bar {
    /* NOTE: display starts as none; media query sets it to flex */
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--mobile-header-h);
    background: rgba(11, 17, 30, 0.97);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    z-index: 900;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.mobile-logo {
    display: flex; align-items: center; gap: 8px;
    flex-shrink: 0;
}
.mobile-logo-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-purple));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: white;
}
.mobile-logo-text {
    font-family: var(--font-heading);
    font-size: 15px; font-weight: 700;
    white-space: nowrap;
}
.mobile-logo-text span { color: var(--color-primary); }

/* Mobile inline search — full flexible width with add button */
.mobile-search-bar {
    flex: 1;
    display: flex; align-items: center;
    background-color: rgba(15,23,42,0.8);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0 0 0 10px;
    gap: 6px;
    min-width: 0;          /* allow flex shrink */
    overflow: hidden;
}
.mobile-search-bar > i { color: var(--text-muted); font-size: 13px; flex-shrink: 0; }
.mobile-search-bar input {
    background: none; border: none;
    color: var(--text-main); font-size: 13px;
    flex: 1; min-width: 0;
    outline: none;
    font-family: var(--font-body);
    padding: 10px 0;
}
/* Add button inside mobile search bar */
#btn-mobile-search-add {
    height: 100%;
    padding: 0 14px;
    background: linear-gradient(135deg, var(--color-primary), #1d4ed8);
    border: none;
    border-radius: 0 10px 10px 0;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; gap: 5px;
    white-space: nowrap;
    transition: var(--transition-fast);
    flex-shrink: 0;
}
#btn-mobile-search-add:hover { background: linear-gradient(135deg, #2563eb, #1e40af); }
#btn-clear-mobile-search {
    background: none; border: none;
    color: var(--text-muted); font-size: 14px;
    cursor: pointer; flex-shrink: 0;
    padding: 0 4px;
    display: flex; align-items: center;
}

/* ================================================================
   TABLET  (≤ 1024px)
   ================================================================ */
@media (max-width: 1024px) {
    .sidebar { display: none; }

    .main-content { padding-top: 0; }

    .main-header {
        padding: 20px 20px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .header-title h1 { font-size: 20px; }
    .search-container { width: 100%; }

    .content-body { padding: 16px 20px 100px; }

    .detail-grid { grid-template-columns: 1fr; }
    .detail-bottom-grid { grid-template-columns: 1fr; }
    .manager-layout { grid-template-columns: 1fr; }

    .watchlist-table th,
    .watchlist-table td { padding: 14px 16px; }
}

/* ================================================================
   MOBILE PORTRAIT  (≤ 768px)
   ================================================================ */
@media (max-width: 768px) {
    body { font-size: 13px; }

    /* Show mobile chrome */
    .mobile-top-bar   { display: flex !important; }
    .mobile-bottom-nav { display: block !important; }

    /* Hide desktop header elements, show mobile bar */
    .main-header { display: none; }

    .main-content {
        padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top));
        padding-bottom: 0;
    }

    .content-body {
        padding: 14px 12px calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + 12px);
        gap: 16px;
    }

    /* Section headers wrap nicely */
    .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .section-actions { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
    .btn-primary, .btn-secondary, .btn-purple { width: 100%; justify-content: center; }
    .last-updated { font-size: 11px; }

    /* ── Mobile Table: hide less-important columns ── */
    .watchlist-table th:nth-child(1),   /* 코드 */
    .watchlist-table td:nth-child(1)   { display: none; }

    .watchlist-table th:nth-child(5),  /* 거래량 Z-Score */
    .watchlist-table td:nth-child(5),
    .watchlist-table th:nth-child(6),  /* 종가 Z-Score */
    .watchlist-table td:nth-child(6),
    .watchlist-table th:nth-child(8),  /* 액션 가이드 */
    .watchlist-table td:nth-child(8)   { display: none; }

    .watchlist-table th,
    .watchlist-table td { padding: 12px 10px; font-size: 12px; }

    .stock-name { font-size: 13px; }
    .price-value { font-size: 13px; }
    .grade-badge { font-size: 11px; padding: 3px 8px; }

    /* Glass cards */
    .glass-card { padding: 16px; border-radius: 16px; }

    /* Chart */
    .chart-wrapper { height: 220px; }

    .card-header h3 i { margin-right: 6px; }
    
    .raw-report-card {
        margin-top: 15px;
        padding: 15px;
    }
    
    .raw-text-report {
        background: #0f172a;
        color: #e2e8f0;
        padding: 15px;
        border-radius: 8px;
        font-family: 'Consolas', 'Courier New', monospace;
        font-size: 13px;
        line-height: 1.5;
        white-space: pre-wrap;
        overflow-x: auto;
        max-height: 400px;
        overflow-y: auto;
        border: 1px solid rgba(255, 255, 255, 0.1);
        margin-top: 10px;
    }

    /* Verdict card smaller */
    .verdict-grade { font-size: 24px; }
    .metrics-grid { grid-template-columns: 1fr; gap: 10px; }
    .metric-item { padding: 10px; }
    .metric-item .value { font-size: 14px; }

    /* Detail bottom */
    .detail-bottom-grid { gap: 14px; }

    /* Manager */
    .manager-layout { gap: 14px; }
    .watchlist-items-list { max-height: 60vh; }

    /* Mobile autocomplete: anchored below mobile top bar */
    .mobile-dropdown {
        position: fixed !important;
        top: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        left: 0 !important; right: 0 !important;
        max-height: 55vh;
        border-radius: 0 0 20px 20px;
        border-left: none; border-right: none; border-top: none;
        box-shadow: 0 20px 40px rgba(0,0,0,0.85);
        z-index: 950;
    }
    /* Desktop autocomplete: keep normal absolute positioning on mobile too */
    .search-container .autocomplete-dropdown {
        position: absolute;
        top: calc(100% + 8px);
        left: 0; right: 0;
        max-height: 280px;
    }
    .search-result-item { padding: 15px 18px; min-height: 54px; }

    /* Refresh banner */
    .refresh-banner { padding: 12px 16px; }
    .progress-label { font-size: 12px; }

    /* Mobile autocomplete: anchored below mobile top bar */
    .mobile-dropdown {
        position: fixed !important;
        top: calc(var(--mobile-header-h) + env(safe-area-inset-top)) !important;
        left: 0 !important; right: 0 !important;
        max-height: 55vh;
        border-radius: 0 0 20px 20px;
        border-left: none; border-right: none; border-top: none;
        box-shadow: 0 20px 40px rgba(0,0,0,0.85);
        z-index: 950;
    }
    .search-result-item { padding: 15px 18px; min-height: 54px; }

    /* Watchlist table responsive: hide rank col on very small */
    .watchlist-mgr-table th:first-child,
    .watchlist-mgr-table td:first-child { display: none; }

    /* Watchlist manager items mobile override */
    .watchlist-items-list { max-height: none; }
    .watchlist-mgr-table td { padding: 9px 10px; font-size: 12px; }
    .watchlist-mgr-table th { padding: 7px 10px; }
}

/* ================================================================
   LANDSCAPE PHONE  (max-width 950px & landscape)
   ================================================================ */
@media (max-width: 950px) and (orientation: landscape) {
    :root {
        --mobile-nav-h: 52px;
        --mobile-header-h: 46px;
    }

    .mobile-top-bar   { display: flex !important; height: var(--mobile-header-h); }
    .mobile-bottom-nav { display: block !important; }
    .main-header { display: none; }

    .main-content {
        padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top));
    }

    .content-body {
        padding: 10px 16px calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + 8px);
        gap: 12px;
    }

    /* In landscape: two-column layout for table + detail */
    .app-landscape-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    /* Smaller chart in landscape */
    .chart-wrapper { height: 200px; }

    /* Side-by-side detail grid */
    .detail-grid { grid-template-columns: 3fr 2fr; gap: 12px; }

    /* Bottom grid two columns */
    .detail-bottom-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

    /* Table condensed */
    .watchlist-table th,
    .watchlist-table td { padding: 10px 12px; font-size: 12px; }

    /* Glass card smaller */
    .glass-card { padding: 12px; border-radius: 12px; }
    .verdict-grade { font-size: 22px; }
}

/* ================================================================
   VERY SMALL (≤ 360px)
   ================================================================ */
@media (max-width: 360px) {
    .content-body { padding-left: 8px; padding-right: 8px; }
    .watchlist-table th:nth-child(4),
    .watchlist-table td:nth-child(4) { display: none; } /* 대비 숨김 */
    .section-header h2 { font-size: 15px; }
}

/* ================================================================
   ORIENTATION TOAST  (화면 회전 안내 오버레이)
   ================================================================ */
#orientation-toast {
    display: none;
    position: fixed;
    bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom) + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15,23,42,0.95);
    border: 1px solid var(--border-hover);
    border-radius: 14px;
    padding: 14px 20px;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    z-index: 1100;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    backdrop-filter: blur(12px);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastSlideUp 0.3s ease;
    pointer-events: none;
}
@keyframes toastSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
#orientation-toast.hidden { display: none !important; }
