/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: #f0f2f5; color: #333; line-height: 1.5; font-size: 14px;
  background-image: radial-gradient(circle at 25% 0%, rgba(67,97,238,0.03) 0%, transparent 50%),
                    radial-gradient(circle at 75% 100%, rgba(124,58,237,0.03) 0%, transparent 50%);
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  color: #fff; padding: 14px 32px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.header-left { display: flex; align-items: center; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo svg { flex-shrink: 0; filter: drop-shadow(0 2px 4px rgba(67,97,238,0.3)); }
.logo-text { display: flex; flex-direction: column; }
.header h1 { font-size: 20px; font-weight: 800; letter-spacing: 1px; line-height: 1.2; }
.header-sub { font-size: 11px; color: #64748b; font-weight: 400; letter-spacing: 0.5px; }
.header-actions { display: flex; gap: 8px; }

/* ===== Buttons ===== */
.btn {
  padding: 7px 16px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 500; transition: all 0.15s; display: inline-flex; align-items: center; gap: 4px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #4361ee; color: #fff; }
.btn-primary:hover { background: #3b54d4; box-shadow: 0 2px 8px rgba(67,97,238,0.3); }
.btn-success { background: #10b981; color: #fff; }
.btn-success:hover { background: #059669; box-shadow: 0 2px 8px rgba(16,185,129,0.3); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-ghost { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.2); }
.btn-ghost:hover { background: rgba(255,255,255,0.2); }
.btn-outline { background: transparent; border: 1px solid #4361ee; color: #4361ee; }
.btn-outline:hover { background: #4361ee; color: #fff; }
.btn-warn { background: #f59e0b; color: #fff; }
.btn-warn:hover { background: #d97706; }

/* ===== Layout ===== */
.container { max-width: 1500px; margin: 0 auto; padding: 20px 24px; }

/* ===== Tabs ===== */
.tabs {
  display: flex; gap: 0; margin-bottom: 20px;
  border-bottom: 2px solid #e2e8f0;
  background: #fff; border-radius: 12px 12px 0 0;
  padding: 0 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.tab {
  padding: 12px 20px; cursor: pointer; font-size: 14px; font-weight: 500;
  color: #64748b; border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.15s; user-select: none;
  display: flex; align-items: center;
}
.tab.active { color: #4361ee; border-bottom-color: #4361ee; background: rgba(67,97,238,0.04); }
.tab:hover { color: #4361ee; background: rgba(67,97,238,0.02); }
.panel { display: none; }
.panel.active { display: block; }

/* ===== Summary Cards ===== */
.summary-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.summary-card {
  background: #fff; border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
  border-left: 3px solid #e2e8f0;
  transition: all 0.15s;
}
.summary-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); border-left-color: #4361ee; }
.summary-card .label { font-size: 11px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.summary-card .value { font-size: 22px; font-weight: 800; margin-top: 2px; letter-spacing: -0.5px; }

/* ===== Sector Group ===== */
.sector-group { margin-bottom: 24px; }
.sector-header {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(135deg, #f8fafc, #eef2ff);
  border-left: 4px solid #4361ee; padding: 10px 18px; border-radius: 0 10px 10px 0;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(67,97,238,0.06);
}
.sector-header h2 { font-size: 15px; font-weight: 700; color: #1e293b; }
.sector-header .weight-badge {
  background: linear-gradient(135deg, #4361ee, #7c3aed); color: #fff;
  padding: 3px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  box-shadow: 0 2px 6px rgba(67,97,238,0.25);
}

/* ===== Table ===== */
.table-wrap { overflow-x: auto; border-radius: 10px; }
.stock-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
}
.stock-table th {
  background: #f8fafc; padding: 8px 12px; text-align: left;
  font-size: 11px; color: #94a3b8; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
  border-bottom: 2px solid #e2e8f0; position: sticky; top: 0;
}
.stock-table td {
  padding: 10px 12px; font-size: 13px; border-top: 1px solid #f1f5f9;
  white-space: nowrap; vertical-align: middle;
}
.stock-table tbody tr { transition: background 0.1s; }
.stock-table tbody tr:hover td { background: #f8fafc; }
.stock-table tbody tr:last-child td:first-child { border-bottom-left-radius: 10px; }
.stock-table tbody tr:last-child td:last-child { border-bottom-right-radius: 10px; }

/* ===== Price Colors ===== */
.price-up { color: #ef4444; font-weight: 600; }
.price-down { color: #10b981; font-weight: 600; }
.price-neutral { color: #94a3b8; }
.gain-positive { color: #ef4444; font-weight: 700; font-size: 14px; }
.gain-negative { color: #10b981; font-weight: 700; font-size: 14px; }

/* ===== Tags ===== */
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  font-size: 11px; margin: 1px 2px; font-weight: 500;
  background: #eff1ff; color: #4361ee;
}
.tag-risk { background: #fef2f2; color: #ef4444; }
.tag-logic { background: #ecfdf5; color: #059669; }

/* ===== Valuation ===== */
.valuation-label { font-size: 11px; color: #94a3b8; display: block; }
.valuation-value { font-weight: 600; font-size: 13px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15,23,42,0.5); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; justify-content: center; align-items: center;
}
.modal {
  background: #fff; border-radius: 16px; width: 620px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px; border-bottom: 1px solid #f1f5f9;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; cursor: pointer; color: #94a3b8; font-size: 20px;
  transition: all 0.15s;
}
.modal-close:hover { background: #f1f5f9; color: #333; }
.modal-body { padding: 24px; }

/* ===== Form ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; color: #64748b; margin-bottom: 4px; font-weight: 600; }
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px; border: 1.5px solid #e2e8f0; border-radius: 8px; font-size: 14px;
  transition: all 0.15s; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: #4361ee; box-shadow: 0 0 0 3px rgba(67,97,238,0.1);
}
.form-group input:disabled {
  background: #f8fafc; color: #94a3b8; cursor: not-allowed; border-color: #e2e8f0;
}
.form-group textarea { resize: vertical; min-height: 56px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ===== Calculator Result ===== */
.calc-result {
  margin-top: 16px; padding: 16px; background: #f8fafc; border-radius: 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  border: 1px solid #e2e8f0;
}
.calc-result-item { text-align: center; }
.calc-result-item .label { font-size: 12px; color: #94a3b8; font-weight: 500; }
.calc-result-item .value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.calc-result-item .value.target { color: #4361ee; }
.calc-result-item .value.bubble { color: #ef4444; }

/* ===== Sector Management ===== */
.sector-card {
  background: #fff; border-radius: 12px; padding: 16px 20px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04); border: 1px solid #f1f5f9;
  display: flex; justify-content: space-between; align-items: center;
  transition: box-shadow 0.15s;
}
.sector-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.sector-card .info { display: flex; align-items: center; gap: 16px; }
.sector-card .name { font-size: 15px; font-weight: 700; }
.sector-card .weight { color: #4361ee; font-weight: 600; font-size: 14px; }
.sector-card .actions { display: flex; gap: 6px; }

/* ===== PS fields toggle ===== */
.ps-fields { display: none; }
.ps-fields.show { display: contents; }
.pe-fields { display: contents; }
.pe-fields.hide { display: none; }

/* ===== Live Price ===== */
.live-price-cell { min-width: 80px; text-align: center; }
.live-flash { animation: flash 0.5s ease; }
@keyframes flash {
  0% { background: #fef9c3; }
  100% { background: transparent; }
}

/* ===== Warning Row ===== */
.stock-table tr.row-warning td { background: #fffbeb; }
.stock-table tr.row-warning:hover td { background: #fef3c7; }

/* ===== Stock Link ===== */
.stock-link {
  font-weight: 700; color: #1e293b; text-decoration: none;
  border-bottom: 1px dashed #4361ee; transition: color 0.15s;
}
.stock-link:hover { color: #4361ee; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header { padding: 12px 16px; flex-direction: column; gap: 10px; align-items: flex-start; }
  .logo { gap: 8px; }
  .header h1 { font-size: 18px; }
  .container { padding: 12px; }
  .summary-row { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { width: 98vw; }
  .tabs { padding: 0 4px; overflow-x: auto; }
  .tab { padding: 10px 14px; font-size: 13px; white-space: nowrap; }
}


/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== IV Analysis ===== */
#iv-analysis .iv-mode-tabs { display: flex; justify-content: center; gap: 0; margin-bottom: 24px; }
#iv-analysis .iv-mode-tab {
  padding: 10px 28px; border: 2px solid #4361ee; background: white; color: #4361ee;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
#iv-analysis .iv-mode-tab:first-child { border-radius: 8px 0 0 8px; }
#iv-analysis .iv-mode-tab:last-child { border-radius: 0 8px 8px 0; border-left: none; }
#iv-analysis .iv-mode-tab.active { background: linear-gradient(135deg, #4361ee, #7c3aed); color: white; border-color: #4361ee; }
#iv-analysis .iv-mode-tab:hover:not(.active) { background: rgba(67,97,238,0.06); }

#iv-analysis .iv-upload-section { display: flex; justify-content: center; margin-bottom: 24px; }
#iv-analysis .iv-upload-form {
  display: none; background: #fff; padding: 28px 32px; border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
  flex-direction: column; align-items: center; gap: 20px; width: 100%; max-width: 700px;
}
#iv-analysis .iv-upload-form.active { display: flex; }

#iv-analysis .iv-drop-zones-row { display: flex; gap: 16px; width: 100%; }
#iv-analysis .iv-drop-zones-row .iv-drop-zone { flex: 1; }

#iv-analysis .iv-drop-zone {
  position: relative; width: 100%; min-height: 160px;
  border: 2px dashed #cbd5e1; border-radius: 14px; cursor: pointer;
  transition: all 0.2s; background: #f8fafc; overflow: hidden;
}
#iv-analysis .iv-drop-zone:hover { border-color: #4361ee; background: #eef2ff; }
#iv-analysis .iv-drop-zone.drag-over { border-color: #4361ee; background: #e0e7ff; box-shadow: 0 0 0 4px rgba(67,97,238,0.12); }
#iv-analysis .iv-drop-zone.has-file { border-style: solid; border-color: #4361ee; background: #eef2ff; cursor: default; }

#iv-analysis .iv-drop-zone-prompt {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 16px; gap: 8px; height: 100%; min-height: 160px; text-align: center;
}
#iv-analysis .iv-drop-icon { width: 40px; height: 40px; color: #94a3b8; margin-bottom: 4px; transition: all 0.2s; }
#iv-analysis .iv-drop-zone:hover .iv-drop-icon { color: #4361ee; transform: translateY(-2px); }
#iv-analysis .iv-drop-label { font-size: 15px; font-weight: 700; color: #1e293b; }
#iv-analysis .iv-drop-hint { font-size: 13px; color: #64748b; }
#iv-analysis .iv-drop-hint em { color: #4361ee; font-style: normal; text-decoration: underline; text-underline-offset: 2px; }
#iv-analysis .iv-drop-accept { font-size: 11px; color: #94a3b8; margin-top: 2px; }

#iv-analysis .iv-drop-zone-file { display: flex; align-items: center; gap: 14px; padding: 20px; min-height: 160px; }
#iv-analysis .iv-drop-zone-file.hidden { display: none !important; }
#iv-analysis .iv-file-icon { width: 36px; height: 36px; color: #4361ee; flex-shrink: 0; }
#iv-analysis .iv-file-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
#iv-analysis .iv-file-name { font-size: 14px; font-weight: 700; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#iv-analysis .iv-file-size { font-size: 12px; color: #64748b; }
#iv-analysis .iv-file-remove {
  width: 30px; height: 30px; border: none; background: rgba(0,0,0,0.05); border-radius: 8px;
  font-size: 18px; color: #64748b; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
#iv-analysis .iv-file-remove:hover { background: #ef4444; color: white; }

#iv-analysis .iv-loading { text-align: center; padding: 48px; font-size: 15px; color: #64748b; }
#iv-analysis .iv-spinner {
  display: inline-block; width: 36px; height: 36px;
  border: 3px solid #e2e8f0; border-top-color: #4361ee;
  border-radius: 50%; animation: ivSpin 0.7s linear infinite; margin-bottom: 14px;
}
@keyframes ivSpin { to { transform: rotate(360deg); } }

#iv-analysis .iv-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #dc2626;
  padding: 16px 20px; border-radius: 10px; text-align: center; margin-bottom: 20px; font-weight: 500;
}

#iv-analysis .iv-summary-card {
  background: #fff; border-radius: 14px; padding: 22px 28px; margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
}
#iv-analysis .iv-summary-card h2 { font-size: 18px; font-weight: 800; margin-bottom: 14px; color: #1e293b; }
#iv-analysis .iv-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
#iv-analysis .iv-summary-item {
  padding: 12px 16px; background: #f8fafc; border-radius: 10px;
  border-left: 3px solid #e2e8f0; transition: border-color 0.15s;
}
#iv-analysis .iv-summary-item:hover { border-left-color: #4361ee; }
#iv-analysis .iv-summary-item .label { font-size: 11px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
#iv-analysis .iv-summary-item .value { font-size: 18px; font-weight: 800; color: #1e293b; }

#iv-analysis .iv-charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#iv-analysis .iv-chart-box {
  background: #fff; border-radius: 14px; padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
}
#iv-analysis .iv-chart { width: 100%; height: 420px; }

@media (max-width: 900px) {
  #iv-analysis .iv-charts-grid { grid-template-columns: 1fr; }
  #iv-analysis .iv-upload-form { padding: 20px 16px; }
  #iv-analysis .iv-drop-zones-row { flex-direction: column; }
}
