﻿/* ===========================================
   Stock Analyzer Web App - Mobile Responsive CSS
   Optimized for iPhone (375-430px width)
   =========================================== */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #4caf50;
  --danger: #f44336;
  --warning: #ff9800;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e8ecf0;
  --shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  --tab-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom));
}

/* ====================== TAB BAR ====================== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 20px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
  flex: 1;
}

.tab-item:active {
  opacity: 0.7;
}

.tab-icon {
  font-size: 22px;
  line-height: 1;
}

.tab-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.tab-item.active .tab-label {
  color: var(--primary);
  font-weight: 600;
}

.badge-count {
  position: absolute;
  top: 0;
  right: 16px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.badge-count.show {
  display: flex;
}

/* ====================== PAGE SYSTEM ====================== */
.page {
  display: none;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

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

/* ====================== BANNER ====================== */
.banner {
  background: linear-gradient(135deg, #1a73e8 0%, #6c5ce7 100%);
  padding: 48px 20px 40px;
  text-align: center;
}

.banner-inner {
  max-width: 420px;
  margin: 0 auto;
}

.banner-title {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.banner-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.8);
}

/* ====================== NAV CARDS ====================== */
.nav-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
  max-width: 430px;
  margin: 0 auto;
}

.nav-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px 14px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
}

.nav-card:active {
  transform: scale(0.95);
}

.card-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.card-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ====================== FEATURE LIST ====================== */
.feature-list {
  margin: 12px 16px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-width: 430px;
  margin-left: auto;
  margin-right: auto;
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 12px;
  line-height: 1.5;
}

.feature-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-right: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}

.feature-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ====================== DISCLAIMER ====================== */
.disclaimer-footer {
  margin: 16px;
  padding: 16px;
  background: #fff8e1;
  border-radius: 12px;
  border-left: 3px solid var(--warning);
  max-width: 430px;
  margin-left: auto;
  margin-right: auto;
}

.disclaimer-footer p {
  font-size: 12px;
  color: #888;
  line-height: 1.5;
}

/* ====================== ADD SECTION ====================== */
.add-section {
  margin: 16px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.stock-input {
  flex: 1;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 15px;
  background: #f7f9fc;
  outline: none;
  transition: border-color 0.2s;
}

.stock-input:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn-search {
  height: 44px;
  padding: 0 24px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-search:active {
  opacity: 0.85;
}

.found-info {
  padding: 8px 0;
  font-size: 14px;
}

.found-info.error {
  color: var(--danger);
}

.search-tips {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ====================== HELD STOCKS ====================== */
.held-section {
  margin: 0 16px;
}

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

.btn-analyze-all {
  height: 36px;
  padding: 0 18px;
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-analyze-all:active {
  opacity: 0.85;
}

.stock-card {
  background: var(--card-bg);
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
}

.stock-card:active {
  transform: scale(0.98);
}

.card-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.stock-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.stock-code {
  font-size: 12px;
  color: var(--text-muted);
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.score-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid;
}

.score-circle.green {
  border-color: var(--success);
  background: #e8f5e9;
}

.score-circle.red {
  border-color: var(--danger);
  background: #ffebee;
}

.score-num {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

.score-label {
  font-size: 9px;
  margin-left: 1px;
}

.score-circle.green .score-num { color: var(--success); }
.score-circle.green .score-label { color: var(--success); }
.score-circle.red .score-num { color: var(--danger); }
.score-circle.red .score-label { color: var(--danger); }

.decision-text {
  font-size: 13px;
  font-weight: 600;
}

.decision-text.green { color: var(--success); }
.decision-text.red { color: var(--danger); }

.status-pending {
  margin-top: 4px;
}

.card-right {
  flex-shrink: 0;
}

.card-right .arrow {
  font-size: 24px;
  color: #ddd;
}

.delete-stock-btn {
  display: inline-block;
  padding: 4px 16px;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  border: 1px solid var(--danger);
  border-radius: 6px;
  margin-top: 4px;
  cursor: pointer;
}

.empty-state {
  margin-top: 160px;
  text-align: center;
}

.empty-icon {
  font-size: 72px;
  margin-bottom: 16px;
}

.empty-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* ====================== LOADING OVERLAY ====================== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.loading-box {
  background: #fff;
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
  width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.loading-spinner {
  font-size: 40px;
  margin-bottom: 12px;
  animation: spin 1.5s linear infinite;
  display: inline-block;
}

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.loading-progress {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.progress-bar-bg {
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transition: width 0.3s ease;
  border-radius: 4px;
}

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

/* ====================== DETAIL PAGE ====================== */
.detail-header {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

.btn-back {
  width: 40px;
  height: 40px;
  background: transparent;
  color: var(--text-primary);
  font-size: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-back:active {
  background: #f0f0f0;
}

.stock-title {
  flex: 1;
}

.title-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.title-code {
  font-size: 13px;
  color: var(--text-muted);
}

/* Score card */
.score-card {
  margin: 0 16px 16px;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.score-main {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-bottom: 20px;
}

.score-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 5px solid;
}

.score-ring.green {
  border-color: var(--success);
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
}

.score-ring.red {
  border-color: var(--danger);
  background: linear-gradient(135deg, #ffebee, #ffcdd2);
}

.score-ring.orange {
  border-color: var(--warning);
  background: linear-gradient(135deg, #fff3e0, #ffe0b2);
}

.ring-score {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
}

.score-ring.green .ring-score { color: #2e7d32; }
.score-ring.red .ring-score { color: #c62828; }
.score-ring.orange .ring-score { color: #e65100; }

.ring-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.decision-badge {
  font-size: 17px;
  font-weight: 700;
  padding: 8px 24px;
  border-radius: 20px;
}

.badge-green { background: #e8f5e9; color: #2e7d32; }
.badge-red { background: #ffebee; color: #c62828; }
.badge-orange { background: #fff3e0; color: #e65100; }

.score-summary {
  border-top: 1px solid #f0f0f0;
  padding-top: 16px;
}

.summary-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.summary-icon {
  flex-shrink: 0;
}

.summary-text {
  color: var(--text-secondary);
}

.sell-reasons .summary-text {
  color: var(--danger);
}

/* Signals section */
.signals-section {
  margin: 0 16px 16px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.signal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.signal-item {
  padding: 16px 12px;
  border-radius: 10px;
  text-align: center;
  background: #f7f9fc;
}

.signal-item.hold { background: #e8f5e9; }
.signal-item.sell { background: #ffebee; }

.signal-icon {
  font-size: 28px;
  display: block;
  margin-bottom: 6px;
}

.signal-name {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.signal-value {
  font-size: 15px;
  font-weight: 700;
}

.signal-item.hold .signal-value { color: #2e7d32; }
.signal-item.sell .signal-value { color: #c62828; }
.signal-item.neutral .signal-value { color: var(--warning); }

/* Details section */
.details-section {
  margin: 0 16px;
}

.detail-block {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.block-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.block-content {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: block;
  margin-bottom: 10px;
}

.score-tag {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
}

.tag-green { background: #e8f5e9; color: #2e7d32; }
.tag-red { background: #ffebee; color: #c62828; }
.tag-orange { background: #fff3e0; color: #e65100; }

.bad-news-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.bad-news-tag {
  padding: 3px 12px;
  background: #ffebee;
  color: #c62828;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

/* Disclaimer detail */
.disclaimer {
  margin: 16px;
  padding: 16px;
  background: #fff8e1;
  border-radius: 12px;
  border-left: 3px solid var(--warning);
}

.disclaimer p {
  font-size: 12px;
  color: #888;
  line-height: 1.5;
}

/* Loading/Error states in detail */
.loading-page,
.error-page {
  margin-top: 120px;
  text-align: center;
}

.loading-page .loading-spinner {
  font-size: 60px;
  display: inline-block;
}

.loading-page p {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 16px;
}

.error-icon {
  font-size: 60px;
  display: block;
  margin-bottom: 16px;
}

.error-text {
  font-size: 14px;
  color: var(--danger);
  display: block;
  margin-bottom: 32px;
  white-space: pre-line;
  line-height: 1.5;
}

.btn-retry {
  height: 44px;
  padding: 0 40px;
  background: var(--primary);
  color: #fff;
  border-radius: 22px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.btn-retry:active {
  opacity: 0.85;
}

/* ====================== ANIMATIONS ====================== */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ====================== MAX-WIDTH CONSTRAINT ====================== */
@media (min-width: 500px) {
  .page > * {
    max-width: 430px;
    margin-left: auto;
    margin-right: auto;
  }
  .banner {
    max-width: 430px;
    margin: 0 auto;
    border-radius: 0;
  }
}

/* ====================== LANDSCAPE MODE ====================== */
@media (max-height: 500px) and (orientation: landscape) {
  .banner {
    padding: 20px 16px;
  }
  .banner-title {
    font-size: 20px;
  }
  .tab-bar {
    height: 50px;
  }
}
