:root {
    --bg: #0a0f1e;
    --surface: #111827;
    --surface-2: #1a2332;
    --border: #1f2937;
    --text: #e5e7eb;
    --text-dim: #9ca3af;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --green: #10b981;
    --red: #ef4444;
    --yellow: #f59e0b;
    --radius: 12px;
}

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

body {
    font-family: 'Noto Sans SC', 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Header */
.header {
    padding: 40px 0 24px;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.logo-icon { font-size: 32px; }

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--accent);
    color: white;
    font-weight: 600;
}

.tagline {
    color: var(--text-dim);
    font-size: 15px;
}

/* Search */
.search-section {
    margin-bottom: 32px;
}

.search-box {
    display: flex;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
    transition: border-color 0.2s;
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 16px;
    padding: 12px 16px;
    outline: none;
}

.search-box input::placeholder { color: var(--text-dim); }

.search-box button {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.search-box button:hover { background: #2563eb; }
.search-box button:disabled { opacity: 0.6; cursor: not-allowed; }

.search-results {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 4px;
    display: none;
    max-height: 300px;
    overflow-y: auto;
}

.search-results.show { display: block; }

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.search-result-item:hover { background: var(--surface-2); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item .code { color: var(--accent); font-weight: 600; }
.search-result-item .name { color: var(--text-dim); }

.quick-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    justify-content: center;
}

.quick-tags span {
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
}

.quick-tags span:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Stock Header */
.stock-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

.stock-name { font-size: 24px; font-weight: 700; }
.stock-code { color: var(--text-dim); font-size: 14px; margin-left: 8px; }
.stock-price { font-size: 36px; font-weight: 700; margin: 8px 0; }
.stock-price.up { color: var(--red); }
.stock-price.down { color: var(--green); }
.stock-change { font-size: 14px; }

.stock-meta {
    display: flex;
    gap: 24px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.stock-meta-item {
    font-size: 13px;
    color: var(--text-dim);
}

.stock-meta-item span { color: var(--text); font-weight: 500; }

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.metric-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.metric-value {
    font-size: 20px;
    font-weight: 700;
}

.metric-change {
    font-size: 12px;
    margin-top: 2px;
}

.metric-change.up { color: var(--red); }
.metric-change.down { color: var(--green); }

/* Analysis Card */
.analysis-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 16px;
}

.analysis-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 500;
}

.analysis-content {
    padding: 20px;
    font-size: 14px;
    line-height: 1.8;
    white-space: pre-wrap;
}

.analysis-content h1,
.analysis-content h2,
.analysis-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}

/* Chat */
.chat-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 32px;
    overflow: hidden;
}

.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.chat-messages {
    max-height: 400px;
    overflow-y: auto;
    padding: 16px 20px;
}

.chat-msg {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
}

.chat-msg.user {
    background: var(--accent);
    color: white;
    margin-left: 40px;
    text-align: right;
}

.chat-msg.ai {
    background: var(--surface-2);
    margin-right: 40px;
}

.chat-input-box {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.chat-input-box input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    outline: none;
}

.chat-input-box input:focus { border-color: var(--accent); }

.chat-input-box button {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
}

.chat-suggestions {
    display: flex;
    gap: 8px;
    padding: 0 16px 12px;
    flex-wrap: wrap;
}

.chat-suggestions span {
    padding: 5px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
}

.chat-suggestions span:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0 40px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.8;
}

/* Loading */
.loading {
    text-align: center;
    padding: 60px 0;
    color: var(--text-dim);
}

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Responsive - Tablet */
@media (max-width: 768px) {
    .app { padding: 0 12px; }
    .header { padding: 28px 0 18px; }
    .logo h1 { font-size: 24px; }
    .tagline { font-size: 14px; }
    .stock-price { font-size: 30px; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .analysis-content { padding: 16px; font-size: 14px; }
    .chat-messages { max-height: 350px; }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    .app { padding: 0 10px; }

    /* Header */
    .header { padding: 20px 0 14px; }
    .logo { gap: 6px; }
    .logo-icon { font-size: 24px; }
    .logo h1 { font-size: 20px; }
    .badge { font-size: 10px; padding: 1px 6px; }
    .tagline { font-size: 13px; }

    /* Search */
    .search-section { margin-bottom: 20px; }
    .search-box { padding: 4px; }
    .search-box input { 
        font-size: 15px; 
        padding: 10px 10px; 
    }
    .search-box button { 
        padding: 10px 18px; 
        font-size: 14px; 
    }
    .quick-tags { gap: 6px; margin-top: 10px; }
    .quick-tags span { 
        padding: 5px 10px; 
        font-size: 12px; 
    }

    /* Stock Header */
    .stock-header { padding: 16px; }
    .stock-name { font-size: 20px; }
    .stock-code { font-size: 12px; }
    .stock-price { font-size: 28px; margin: 6px 0; }
    .stock-change { font-size: 13px; }
    .stock-meta { gap: 12px; margin-top: 10px; }
    .stock-meta-item { font-size: 12px; }

    /* Metrics */
    .metrics-grid { 
        grid-template-columns: repeat(2, 1fr); 
        gap: 6px; 
        margin-bottom: 12px; 
    }
    .metric-card { padding: 12px; }
    .metric-label { font-size: 11px; }
    .metric-value { font-size: 16px; }
    .metric-change { font-size: 11px; }

    /* Analysis */
    .analysis-header { 
        padding: 12px 14px; 
        font-size: 14px; 
        flex-wrap: wrap;
        gap: 6px;
    }
    .analysis-badge { font-size: 10px; }
    .analysis-content { 
        padding: 14px; 
        font-size: 13px; 
        line-height: 1.7; 
    }
    .analysis-content h1 { font-size: 16px; }
    .analysis-content h2 { font-size: 15px; }
    .analysis-content h3 { font-size: 14px; }

    /* Chat */
    .chat-header { padding: 12px 14px; font-size: 14px; }
    .chat-messages { 
        max-height: 300px; 
        padding: 12px 14px; 
    }
    .chat-msg { 
        padding: 10px 12px; 
        font-size: 13px; 
        line-height: 1.6; 
    }
    .chat-msg.user { margin-left: 16px; }
    .chat-msg.ai { margin-right: 16px; }
    .chat-input-box { 
        padding: 10px 12px; 
        gap: 6px; 
    }
    .chat-input-box input { 
        padding: 8px 10px; 
        font-size: 13px; 
    }
    .chat-input-box button { 
        padding: 8px 14px; 
        font-size: 13px; 
    }
    .chat-suggestions { 
        padding: 0 12px 10px; 
        gap: 6px; 
    }
    .chat-suggestions span { 
        padding: 4px 10px; 
        font-size: 11px; 
    }

    /* Footer */
    .footer { 
        padding: 16px 0 28px; 
        font-size: 11px; 
    }

    /* Loading */
    .loading { padding: 40px 0; }
    .loading p { font-size: 13px; }
}

/* Touch & input optimizations */
@media (hover: none) and (pointer: coarse) {
    .search-box button,
    .chat-input-box button,
    .quick-tags span,
    .chat-suggestions span,
    .search-result-item {
        -webkit-tap-highlight-color: transparent;
    }
    
    .search-box input,
    .chat-input-box input {
        font-size: 16px; /* prevent iOS zoom on focus */
    }
    
    .search-result-item {
        padding: 14px 16px;
    }
    
    .quick-tags span,
    .chat-suggestions span {
        min-height: 36px;
        display: inline-flex;
        align-items: center;
    }
}

/* Safe area for notch phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .footer {
        padding-bottom: calc(28px + env(safe-area-inset-bottom));
    }
    .app {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
}
