@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500&family=DM+Mono:wght@400&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #378ADD;
  --blue-mid: #B5D4F4;
  --blue-dark: #185FA5;
  --blue-800: #0C447C;
  --border: #B5D4F4;
  --border-strong: #378ADD;
  --bg: #f4f6f8;
  --bg-panel: #ffffff;
  --bg-input: #EEF6FD;
  --text: #2C2C2A;
  --text-muted: #5F5E5A;
  --radius: 8px;
  --row-h: 38px;
  --ticker-w: 160px;
  --num-w: 80px;
  --remove-w: 36px;
  --col-gap: 8px;
  --group-gap: 24px;
}

html, body { height: 100%; width: 100%; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

#panel {
  background: var(--bg-panel);
  border: 1.5px solid var(--blue-mid);
  border-radius: 12px;
  padding: 28px 28px 0 28px;
  display: inline-flex;
  flex-direction: column;
  transition: opacity 0.3s ease, width 0.2s ease;
}

#scrollArea {
  overflow: visible;
  padding-bottom: 20px;
}

#outerWrap {
  display: flex;
  gap: var(--group-gap);
  align-items: flex-start;
}

.col-group {
  display: flex;
  flex-direction: column;
  width: calc(var(--ticker-w) + var(--num-w) + var(--remove-w) + var(--col-gap) * 2);
  flex-shrink: 0;
}

.col-header {
  display: grid;
  grid-template-columns: 26px calc(var(--ticker-w) - 26px) var(--num-w) var(--remove-w);
  gap: var(--col-gap);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue);
  margin-bottom: 6px;
}

.col-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue-800);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
}

.modeBtn {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: var(--blue);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 0 8px;
  cursor: pointer;
  height: 22px;
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  transition: background 0.12s;
  white-space: nowrap;
}

.modeBtn:hover { background: var(--blue-dark); }

.position {
  display: grid;
  grid-template-columns: 26px calc(var(--ticker-w) - 26px) var(--num-w) var(--remove-w);
  gap: var(--col-gap);
  align-items: center;
  margin-bottom: 6px;
  min-height: var(--row-h);
}

.position input {
  height: var(--row-h);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  padding: 0 10px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.position input:focus {
  border-color: var(--blue-dark);
  box-shadow: 0 0 0 3px rgba(55, 138, 221, 0.18);
  background: #fff;
}

.position input:hover:not(:focus) { border-color: var(--border-strong); }

.position input.ticker {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.position input::placeholder {
  color: #85B7EB;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
}

.autofill { color: #85B7EB !important; }

.removeBtn {
  height: var(--row-h);
  width: var(--remove-w);
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: #85B7EB;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.removeBtn:hover {
  background: #FCEBEB;
  border-color: #F09595;
  color: #A32D2D;
}

#footer {
  border-top: 2px solid var(--blue-mid);
  padding: 14px 0 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: var(--bg-panel);
}

#footerTop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

#addButton {
  height: 36px;
  padding: 0 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--blue-dark);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

#addButton:hover {
  background: var(--blue-mid);
  border-color: var(--blue-dark);
}

#posCount {
  font-size: 12px;
  color: var(--text-muted);
}

#submitButton {
  height: 40px;
  background: var(--blue);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  letter-spacing: 0.01em;
}

#submitButton:hover { background: var(--blue-dark); }

/* ── Results panel ────────────────────────────────────────── */

#resultsPanel {
  display: none;
  opacity: 0;
  width: 100%;
  min-height: 100vh;
  padding: 48px;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  background: var(--bg);
  transition: opacity 0.3s ease;
}

#resultsPanel.visible {
  display: flex;
  opacity: 1;
}

#metricGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 900px;
}

.metricSquare {
  height: 80px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  padding: 0 12px;
  text-align: center;
  letter-spacing: 0.01em;
}

.metricSquare:hover {
  border-color: var(--blue);
  background: var(--bg-input);
}

.metricSquare.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

#displayArea {
  width: 100%;
  max-width: 900px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  min-height: 160px;
}

#displayContent {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
}

#displayContent table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#displayContent th {
  text-align: left;
  font-weight: 500;
  color: var(--blue-800);
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue);
}

#displayContent td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
}

#displayContent td:first-child {
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  color: var(--text);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.stat-row:last-child { border-bottom: none; }

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

.stat-value {
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.stat-value.positive { color: #2E7D4F; }
.stat-value.negative { color: #A32D2D; }

#tabBar {
  display: flex;
  gap: 0;
  width: 100%;
  max-width: 900px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}

.tab {
  height: 38px;
  padding: 0 20px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--blue-dark);
  border-bottom-color: var(--blue);
}

#tabContent {
  width: 100%;
  max-width: 900px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 24px 28px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.75;
  min-height: 100px;
}

#tabContent .formula {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  line-height: 2;
}

#resultsFooter {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  padding: 8px 0 40px 0;
}

#newPortfolioBtn {
  height: 40px;
  padding: 0 28px;
  background: transparent;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--blue-dark);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

#newPortfolioBtn:hover {
  background: var(--blue-mid);
  border-color: var(--blue-dark);
}

.ticker[data-status="ok"]      { border-color: #3DA35D !important; box-shadow: 0 0 0 3px rgba(61,163,93,0.18) !important; }
.ticker[data-status="error"]   { border-color: #E24B4A !important; box-shadow: 0 0 0 3px rgba(226,75,74,0.18) !important; }
.ticker[data-status="warning"] { border-color: #EF9F27 !important; box-shadow: 0 0 0 3px rgba(239,159,39,0.18) !important; }
.ticker[data-status="loading"] { opacity: 0.6; }

.status-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    flex-shrink: 0;
    font-family: 'DM Sans', sans-serif;
    cursor: default;
    color: #fff;
}

.status-icon.ok      { background: #3DA35D; color: #fff; }
.status-icon.error   { background: #E24B4A; color: #fff; }
.status-icon.warning { background: #EF9F27; color: #fff; }
.status-icon.loading {
    background: none;
    border: 2px solid #ccc;
    border-top-color: #888;
    animation: spin 0.7s linear infinite;
}
.status-icon.hidden { visibility: hidden; }

@keyframes spin {
    to { transform: rotate(360deg); }
}