/* ===== Global Reset & Theme ===== */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d2e;
  --bg-tertiary: #232740;
  --bg-card: #1e2235;
  --bg-hover: #2a2f4a;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0b8;
  --text-muted: #6b7194;
  --accent-blue: #4a9eff;
  --accent-green: #00d68f;
  --accent-red: #ff4d6a;
  --accent-orange: #ffa84a;
  --accent-purple: #8b5cf6;
  --border-color: #2a2f4a;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.2s ease;
}

* {
  margin: 0; padding: 0; box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Left Panel ===== */
.left-panel {
  width: 340px;
  min-width: 340px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.panel-header h1 {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.panel-header h1 i {
  color: var(--accent-blue);
}

.panel-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Auth Area ===== */
.auth-area {
  position: relative;
}

.auth-loading {
  color: var(--text-muted);
  font-size: 14px;
}

/* Google Login Button */
.google-login-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  white-space: nowrap;
}

.google-login-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-blue);
}

.google-login-btn svg {
  flex-shrink: 0;
}

/* User Profile */
.user-profile {
  cursor: pointer;
  position: relative;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  transition: var(--transition);
  object-fit: cover;
}

.user-avatar:hover {
  border-color: var(--accent-blue);
}

.user-avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* User Dropdown */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  display: none;
  overflow: hidden;
}

.user-dropdown.show {
  display: block;
  animation: dropdownIn 0.15s ease-out;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.dropdown-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.dropdown-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropdown-email {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
}

.dropdown-info {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.dropdown-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.logout-btn:hover {
  color: var(--accent-red);
}

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-error { border-color: var(--accent-red); }
.toast-error i { color: var(--accent-red); }
.toast-success { border-color: var(--accent-green); }
.toast-success i { color: var(--accent-green); }
.toast-info i { color: var(--accent-blue); }

/* Empty hint */
.empty-hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Login prompt in empty state */
.login-prompt {
  margin-top: 24px;
  padding: 16px 24px;
  background: rgba(74,158,255,0.06);
  border: 1px solid rgba(74,158,255,0.15);
  border-radius: var(--radius-sm);
  text-align: center;
}

.login-prompt p {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ===== Search Box ===== */
.search-container {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(74,158,255,0.15);
}

.search-box i {
  color: var(--text-muted);
  font-size: 14px;
}

.search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  padding: 10px 8px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* ===== Search Results Dropdown ===== */
.search-results {
  position: absolute;
  top: calc(100% - 4px);
  left: 20px;
  right: 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow);
  display: none;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(42,47,74,0.5);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item .name {
  font-size: 14px;
  font-weight: 500;
}

.search-result-item .code {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
}

/* ===== Stock List ===== */
.stock-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.stock-list-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.stock-list-empty i {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
  opacity: 0.3;
}

.stock-list-empty p {
  font-size: 14px;
  line-height: 1.6;
}

.stock-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  gap: 12px;
}

.stock-item:hover {
  background: var(--bg-hover);
}

.stock-item.active {
  background: rgba(74,158,255,0.08);
  border-left-color: var(--accent-blue);
}

.stock-item .stock-info {
  flex: 1;
  min-width: 0;
}

.stock-item .stock-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-item .stock-code {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
  margin-top: 2px;
}

.stock-item .stock-price-area {
  text-align: right;
  min-width: 90px;
}

.stock-item .stock-price {
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', monospace;
}

.stock-item .stock-change {
  font-size: 11px;
  font-family: 'SF Mono', monospace;
  margin-top: 2px;
}

.stock-item .delete-btn {
  opacity: 0;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
}

.stock-item:hover .delete-btn {
  opacity: 1;
}

.stock-item .delete-btn:hover {
  color: var(--accent-red);
  background: rgba(255,77,106,0.1);
}

.price-up { color: var(--accent-red) !important; }
.price-down { color: var(--accent-blue) !important; }
.price-even { color: var(--text-secondary) !important; }

/* ===== Update Timer ===== */
.update-bar {
  padding: 10px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.update-bar .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  display: inline-block;
  margin-right: 6px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: var(--transition);
  font-size: 12px;
}

.refresh-btn:hover {
  color: var(--accent-blue);
  background: rgba(74,158,255,0.1);
}

/* ===== Right Panel ===== */
.right-panel {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-primary);
  padding: 0;
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  padding: 40px;
}

.empty-state i {
  font-size: 80px;
  margin-bottom: 24px;
  opacity: 0.15;
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  max-width: 360px;
}

/* ===== Stock Detail Header ===== */
.detail-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.detail-header .top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.detail-header .title-area {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stock-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  object-fit: contain;
}

.detail-header .stock-title {
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.market-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
}

.market-status.closed {
  background: rgba(107,113,148,0.15);
  color: var(--text-muted);
}

.market-status.open {
  background: rgba(0,214,143,0.15);
  color: var(--accent-green);
}

.detail-header .stock-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-family: 'SF Mono', monospace;
  margin-top: 4px;
}

.detail-header .price-display {
  text-align: right;
}

.detail-header .current-price {
  font-size: 32px;
  font-weight: 700;
  font-family: 'SF Mono', monospace;
}

.detail-header .current-price .currency-unit {
  font-size: 16px;
  color: var(--text-muted);
  margin-left: 4px;
  font-weight: 400;
}

.detail-header .price-change-info {
  font-size: 14px;
  font-family: 'SF Mono', monospace;
  margin-top: 4px;
}

/* ===== Chart Area ===== */
.chart-area {
  margin: 12px 0 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 8px;
  text-align: center;
  overflow: hidden;
}

.day-chart {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  filter: brightness(1.1);
}

/* ===== Key Metrics Grid ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.metric-item {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.metric-item .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-item .value {
  font-size: 14px;
  font-weight: 600;
  font-family: 'SF Mono', monospace;
}

/* ===== Tab Navigation ===== */
.tab-nav {
  display: flex;
  padding: 0 32px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  gap: 4px;
}

.tab-btn {
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  color: var(--accent-blue);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-blue);
  border-radius: 1px 1px 0 0;
}

.tab-btn .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(74,158,255,0.15);
  color: var(--accent-blue);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

/* ===== Tab Content ===== */
.tab-content {
  padding: 24px 32px;
}

/* ===== News List ===== */
.news-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.news-item {
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.news-item:hover {
  border-color: var(--border-color);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.news-item .news-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.news-item .news-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.news-item .news-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.news-item .news-meta .source {
  color: var(--accent-blue);
  font-weight: 500;
}

/* ===== Disclosure List ===== */
.disclosure-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.disclosure-item {
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 14px;
}

.disclosure-item:hover {
  border-color: var(--border-color);
  background: var(--bg-hover);
}

.disclosure-item .disc-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(139,92,246,0.12);
  color: var(--accent-purple);
  font-size: 14px;
  flex-shrink: 0;
}

.disclosure-item .disc-content {
  flex: 1;
  min-width: 0;
}

.disclosure-item .disc-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.disclosure-item .disc-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.disclosure-item .disc-date {
  color: var(--text-muted);
}

/* ===== Loading ===== */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  gap: 12px;
}

.loading-spinner i {
  font-size: 24px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.loading-placeholder {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  height: 16px;
  margin-bottom: 8px;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ===== No Data ===== */
.no-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.no-data i {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.3;
  display: block;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .left-panel {
    width: 100%;
    min-width: unset;
  }

  .right-panel {
    display: none;
  }

  .right-panel.mobile-show {
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
