/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0d1117;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --border: #30363d;
  --border-light: #484f58;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-green: #3fb950;
  --accent-red: #f85149;
  --accent-blue: #58a6ff;
  --accent-orange: #d29922;
  --accent-purple: #bc8cff;
  --accent-cyan: #39d2c0;
  --accent-yellow: #e3b341;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ========== HEADER ========== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
}

.nav-tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s;
  font-family: inherit;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

.nav-tab.active {
  color: var(--text-primary);
  background: rgba(88,166,255,0.15);
  font-weight: 600;
}

/* ========== MAIN CONTENT ========== */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab-section {
  display: none;
}

.tab-section.active {
  display: block;
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

/* ========== AUTH SCREEN ========== */
.auth-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

body.logged-in .auth-screen {
  display: none;
}

body:not(.logged-in) .header,
body:not(.logged-in) .main-content,
body:not(.logged-in) .footer {
  display: none;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  margin: 0 1rem;
}

.auth-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.auth-field {
  margin-bottom: 1rem;
}

.auth-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.auth-field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.auth-field input:focus {
  border-color: var(--accent-blue);
}

.auth-field input::placeholder {
  color: var(--text-muted);
}

.auth-btn {
  width: 100%;
  padding: 0.7rem;
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.auth-error {
  color: var(--accent-red);
  font-size: 0.8rem;
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.auth-switch a {
  color: var(--accent-blue);
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* ========== USER AREA ========== */
.user-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.user-greeting {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.btn-logout {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-logout:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: rgba(255,255,255,0.05);
}

.form-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-row input {
  flex: 1;
  min-width: 140px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-row input:focus {
  border-color: var(--accent-blue);
}

.form-row input::placeholder {
  color: var(--text-muted);
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}

.btn-primary:hover {
  background: #4090e0;
}

.btn-danger {
  background: transparent;
  color: var(--accent-red);
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: rgba(248,81,73,0.15);
}

.api-note {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

.api-status {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.api-status.success {
  color: var(--accent-green);
}

.api-status.error {
  color: var(--accent-red);
}

/* ========== PORTFOLIO SUMMARY ========== */
.portfolio-summary {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.chart-container-small {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-container-small canvas {
  max-width: 240px;
  max-height: 240px;
}

/* ========== TABLES ========== */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: right;
  white-space: nowrap;
  font-size: 0.85rem;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

td {
  border-bottom: 1px solid rgba(48,54,61,0.5);
}

th:first-child, td:first-child {
  text-align: left;
}

tr:hover td {
  background: rgba(255,255,255,0.02);
}

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.positive {
  color: var(--accent-green);
}

.negative {
  color: var(--accent-red);
}

.sparkline-cell {
  width: 80px;
}

.sparkline-cell canvas {
  width: 80px;
  height: 30px;
}

/* ========== MACRO SECTION ========== */
.section-title {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.indicator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.indicator-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.2s;
}

.indicator-card:hover {
  border-color: var(--border-light);
}

.indicator-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.indicator-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.indicator-trend {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.indicator-trend.up {
  color: var(--accent-green);
  background: rgba(63,185,80,0.1);
}

.indicator-trend.down {
  color: var(--accent-red);
  background: rgba(248,81,73,0.1);
}

.indicator-trend.flat {
  color: var(--accent-orange);
  background: rgba(210,153,34,0.1);
}

.indicator-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.indicator-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.indicator-chart {
  height: 50px;
  margin-top: 0.25rem;
}

.indicator-chart canvas {
  width: 100% !important;
  height: 50px !important;
}

/* ========== ATMOSPHERE GAUGE ========== */
.atmosphere-card {
  text-align: center;
}

.atmosphere-card h2 {
  margin-bottom: 0.75rem;
}

.atmosphere-gauge {
  position: relative;
  display: inline-block;
  width: 220px;
  height: 130px;
  margin: 0 auto;
}

.atmosphere-gauge canvas {
  width: 220px !important;
  height: 130px !important;
}

.atmosphere-label {
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.25rem;
  font-weight: 700;
}

.atmosphere-desc {
  margin-top: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* ========== HEATMAP ========== */
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.heatmap-cell {
  border-radius: 6px;
  padding: 0.75rem 0.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 70px;
  transition: transform 0.15s;
  cursor: default;
}

.heatmap-cell:hover {
  transform: scale(1.04);
}

.heatmap-ticker {
  font-weight: 700;
  font-size: 0.85rem;
}

.heatmap-change {
  font-size: 0.75rem;
  font-weight: 600;
}

.heatmap-price {
  font-size: 0.65rem;
  opacity: 0.8;
}

/* ========== SETTINGS ========== */
.settings-card {
  max-width: 640px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.settings-field label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.settings-field input {
  padding: 0.55rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.settings-field input:focus {
  border-color: var(--accent-blue);
}

.settings-field input::placeholder {
  color: var(--text-muted);
}

.settings-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.settings-info-box {
  background: rgba(88,166,255,0.08);
  border: 1px solid rgba(88,166,255,0.2);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.settings-info-box strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--accent-blue);
}

.settings-info-box small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.settings-info-box code {
  background: var(--bg-primary);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.settings-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.save-status {
  font-size: 0.8rem;
  margin-left: 0.5rem;
}

.save-status.success { color: var(--accent-green); }
.save-status.error { color: var(--accent-red); }

/* Toggle switch */
.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-toggle-row:last-child {
  border-bottom: none;
}

.settings-toggle-row > label:first-child {
  flex: 1;
  font-size: 0.9rem;
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-blue);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.4;
  cursor: not-allowed;
}

.coming-soon-badge {
  font-size: 0.7rem;
  background: rgba(210,153,34,0.15);
  color: var(--accent-orange);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

/* ========== FOOTER ========== */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .header-inner {
    flex-direction: column;
    height: auto;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .portfolio-summary {
    grid-template-columns: 1fr;
  }

  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .heatmap-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .indicator-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .user-area {
    order: -1;
    align-self: flex-end;
  }
}

@media (max-width: 600px) {
  .nav-tabs {
    flex-wrap: wrap;
    justify-content: center;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row input {
    min-width: auto;
  }

  .summary-cards {
    grid-template-columns: 1fr 1fr;
  }

  .heatmap-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  th, td {
    padding: 0.4rem 0.5rem;
    font-size: 0.78rem;
  }

  .settings-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-toggle-row {
    flex-wrap: wrap;
  }
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ========== LOADING SPINNER ========== */
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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