:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f8f9fa;
  --surface-blue: #f4f8ff;
  --border: #e4e7eb;
  --border-strong: #d6d9de;
  --text: #202124;
  --muted: #5f6368;
  --muted-light: #8a9098;
  --blue: #1a73e8;
  --blue-hover: #1765cc;
  --green: #137333;
  --red: #c5221f;
  --yellow: #f9ab00;
  --shadow: 0 10px 30px rgba(32, 33, 36, 0.12);
  --radius: 18px;
  --font: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

.auth-view {
  min-height: 100vh;
  padding: 32px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 15%, rgba(26, 115, 232, 0.09), transparent 32%),
    radial-gradient(circle at 82% 78%, rgba(19, 115, 51, 0.05), transparent 30%),
    #fff;
}

.login-card {
  width: min(440px, 100%);
  padding: 44px 42px 38px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 55px rgba(32, 33, 36, 0.12);
  text-align: center;
}

.login-brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 24px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--blue);
  background: var(--surface-blue);
}

.login-brand-mark svg {
  width: 32px;
  fill: currentColor;
}

.login-eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-card h1 {
  margin: 8px 0 10px;
  font-size: 36px;
  letter-spacing: -1px;
}

.login-card > p {
  max-width: 330px;
  margin: 0 auto 28px;
  color: var(--muted);
}

.google-login-button {
  width: 100%;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 11px;
  color: var(--text);
  background: #fff;
  font-weight: 700;
}

.google-login-button:hover {
  border-color: #b8c7df;
  background: var(--surface-blue);
}

.google-login-button svg {
  width: 20px;
}

.google-login-button svg path:nth-child(1) { fill: #4285f4; }
.google-login-button svg path:nth-child(2) { fill: #34a853; }
.google-login-button svg path:nth-child(3) { fill: #fbbc05; }
.google-login-button svg path:nth-child(4) { fill: #ea4335; }

.login-status {
  min-height: 20px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}

.login-status.is-error {
  color: var(--red);
}

.app-shell {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 0 0 56px;
}

.topbar {
  min-height: 112px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: end;
  gap: 24px;
  border-bottom: 1px solid var(--border);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--surface-blue);
  color: var(--blue);
}

.brand-mark svg {
  width: 24px;
  fill: currentColor;
}

.brand-block h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: -0.4px;
}

.brand-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-tabs {
  display: flex;
  align-items: flex-end;
  height: 100%;
  gap: 4px;
}

.tab {
  position: relative;
  height: 56px;
  padding: 0 22px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  font-weight: 600;
}

.tab.is-active {
  color: var(--text);
}

.tab.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--blue);
}

.tab span {
  margin-left: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-size: 11px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding-bottom: 18px;
}

.icon-button,
.close-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.icon-button:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.icon-button svg {
  width: 21px;
  fill: currentColor;
}

.icon-button.is-spinning svg {
  animation: spin 0.8s linear infinite;
}

.auth-button,
.primary-button,
.secondary-button,
.danger-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.auth-button,
.primary-button {
  color: #fff;
  background: var(--blue);
}

.auth-button:hover,
.primary-button:hover {
  background: var(--blue-hover);
}

.primary-button svg {
  width: 18px;
  fill: currentColor;
}

.secondary-button {
  color: var(--blue);
  background: #fff;
  border-color: var(--border-strong);
}

.secondary-button:hover {
  background: var(--surface-blue);
}

.danger-button {
  color: var(--red);
  background: #fff;
  border-color: #f1c7c6;
}

.danger-button:hover {
  background: #fce8e6;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 28px 0 18px;
}

.summary-card {
  min-height: 142px;
  padding: 22px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-primary {
  background: var(--surface-blue);
  border-color: #d8e7ff;
}

.summary-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.summary-value {
  margin-top: 12px;
  font-size: clamp(28px, 3vw, 40px);
  line-height: 1;
  font-weight: 500;
  letter-spacing: -1.2px;
}

.summary-secondary {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.summary-secondary .dot {
  padding: 0 7px;
}

.is-positive {
  color: var(--green) !important;
}

.is-negative {
  color: var(--red) !important;
}

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 64px;
  margin-bottom: 14px;
}

.market-loader {
  margin: 0 0 16px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #d8e7ff;
  border-radius: 12px;
  background: #f7faff;
  color: #174ea6;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}

.market-loader-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #bfd3ff;
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}

.market-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.market-status strong {
  color: var(--text);
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-light);
}

.status-dot.is-live {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(19, 115, 51, 0.1);
}

.separator {
  color: #bdc1c6;
}


.position-editor {
  margin: -2px 0 18px;
  padding: 14px;
  border: 1px solid #d8e7ff;
  border-radius: 14px;
  background: var(--surface-blue);
  overflow-x: auto;
}

.position-inline-form {
  min-width: 1220px;
  display: grid;
  grid-template-columns:
    minmax(160px, 1.35fr)
    76px
    88px
    104px
    82px
    104px
    58px
    104px
    minmax(112px, 1.1fr)
    76px
    auto;
  gap: 8px;
  align-items: end;
}

.inline-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.inline-field > span {
  padding-left: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.inline-field input,
.inline-field select {
  width: 100%;
  height: 38px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
  font-size: 13px;
}

.inline-field input:focus,
.inline-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.13);
}

.inline-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.compact-primary-button,
.compact-secondary-button,
.compact-danger-button {
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.compact-primary-button {
  min-width: 58px;
  border: 1px solid var(--blue);
  color: #fff;
  background: var(--blue);
}

.compact-primary-button:hover { background: var(--blue-hover); }

.compact-secondary-button {
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: #fff;
}

.compact-danger-button {
  border: 1px solid #f1c7c6;
  color: var(--red);
  background: #fff;
}

#addPositionButton.is-active {
  background: var(--blue-hover);
}

.notice {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 10px;
  color: #174ea6;
  background: #e8f0fe;
  font-size: 13px;
}

.notice.is-error {
  color: #8c1d18;
  background: #fce8e6;
}

.is-hidden {
  display: none !important;
}

.portfolio-sections {
  display: grid;
  gap: 26px;
}

.currency-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.currency-heading {
  min-height: 74px;
  padding: 17px 20px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.currency-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.currency-badge {
  min-width: 49px;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  background: var(--surface-blue);
  font-size: 13px;
  font-weight: 800;
}

.currency-title h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.2px;
}

.currency-title p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.currency-total {
  text-align: right;
}

.currency-total strong {
  display: block;
  font-size: 19px;
  font-weight: 500;
}

.currency-total span {
  color: var(--muted);
  font-size: 12px;
}

.table-scroll {
  overflow-x: auto;
}

.portfolio-table {
  width: 100%;
  min-width: 1030px;
  border-collapse: collapse;
}

.portfolio-table th {
  height: 48px;
  padding: 0 16px;
  color: var(--muted);
  background: #fff;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.portfolio-table th:first-child,
.portfolio-table td:first-child {
  padding-left: 20px;
  text-align: left;
}

.portfolio-table th:last-child,
.portfolio-table td:last-child {
  padding-right: 14px;
}

.portfolio-table td {
  height: 62px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

.portfolio-table tbody tr:last-child td {
  border-bottom: 0;
}

.portfolio-table tbody tr {
  transition: background 0.15s ease;
}

.portfolio-table tbody tr:hover {
  background: #fafafa;
}

.symbol-cell {
  min-width: 260px;
}

.symbol-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.symbol-main {
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.15px;
}

.symbol-subtitle {
  max-width: 260px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.position-chip {
  padding: 2px 7px;
  border-radius: 999px;
  color: #3c4043;
  background: #f1f3f4;
  font-size: 10px;
  font-weight: 800;
}

.position-chip.short {
  color: #8c1d18;
  background: #fce8e6;
}

.number-primary {
  color: var(--text);
  font-size: 15px;
}

.number-secondary {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.price-auto {
  color: var(--blue);
  font-weight: 700;
}

.price-error {
  color: var(--red);
}

.allocation-cell {
  min-width: 134px;
}

.allocation-value {
  font-size: 15px;
}

.allocation-track {
  width: 88px;
  height: 4px;
  margin: 7px 0 0 auto;
  border-radius: 99px;
  background: #e8eaed;
  overflow: hidden;
}

.allocation-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.row-action {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.row-action:hover {
  color: var(--text);
  background: #eef0f2;
}

.section-footer {
  min-height: 58px;
  padding: 11px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 28px;
  color: var(--muted);
  background: #fbfbfb;
  font-size: 12px;
}

.section-footer strong {
  margin-left: 7px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.empty-state {
  padding: 78px 20px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.empty-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: var(--blue);
  background: var(--surface-blue);
}

.empty-icon svg {
  width: 30px;
  fill: currentColor;
}

.empty-state h3 {
  margin: 18px 0 6px;
  font-size: 20px;
}

.empty-state p {
  max-width: 470px;
  margin: 0;
  color: var(--muted);
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.dialog {
  width: min(760px, calc(100% - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dialog::backdrop {
  background: rgba(32, 33, 36, 0.46);
  backdrop-filter: blur(2px);
}

.dialog-card {
  max-height: calc(100vh - 40px);
  padding: 24px;
  overflow-y: auto;
  background: #fff;
}

.dialog-card-small {
  max-width: 520px;
  margin: 0 auto;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 22px;
}

.dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.close-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
}

.close-button:hover {
  background: var(--surface-subtle);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid.one-column {
  grid-template-columns: 1fr;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.form-grid label > span {
  color: #3c4043;
  font-size: 12px;
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.form-grid input:focus,
.form-grid select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.15);
}

.form-grid small {
  color: var(--muted);
  font-size: 11px;
}

.calculation-preview {
  margin-top: 18px;
  padding: 13px 14px;
  border-radius: 10px;
  color: #3c4043;
  background: var(--surface-subtle);
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.dialog-spacer {
  flex: 1;
}

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

.skeleton-bar {
  display: inline-block;
  height: 0.9em;
  min-width: 32px;
  border-radius: 4px;
  vertical-align: middle;
  background: linear-gradient(90deg, var(--surface-subtle) 25%, rgba(0, 0, 0, 0.06) 50%, var(--surface-subtle) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100% - 28px, 1480px);
  }

  .topbar {
    grid-template-columns: 1fr auto;
    align-items: center;
    min-height: 82px;
  }

  .brand-block,
  .top-actions {
    padding-bottom: 0;
  }

  .top-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    order: 3;
    height: 52px;
  }

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

  .summary-card {
    min-height: 118px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: calc(100% - 20px);
  }

  .brand-mark {
    display: none;
  }

  .brand-block h1 {
    font-size: 21px;
  }

  .top-actions .icon-button {
    display: none;
  }

  .auth-button {
    padding: 0 13px;
  }

  .tab {
    padding: 0 14px;
    font-size: 15px;
  }

  .summary-grid {
    padding-top: 18px;
  }

  .control-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .primary-button {
    min-height: 42px;
  }

  .control-row > .primary-button {
    width: 100%;
  }

  .currency-heading {
    align-items: flex-start;
  }

  .currency-total strong {
    font-size: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .dialog-card {
    padding: 20px;
  }

  .empty-actions {
    width: 100%;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .auth-view { padding: 18px; }
  .login-card { padding: 36px 24px 30px; }
}

/* Compact spreadsheet alignment shared with the Dashboard tab. */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-subtle: #f7f9fc;
  --surface-blue: #f2f6fd;
  --border: #d7deea;
  --border-strong: #c8d2e1;
  --text: #1a2230;
  --muted: #5e6878;
  --muted-light: #7b8596;
  --blue: #2a61d8;
  --blue-hover: #1f52bd;
  --green: #0b7f2a;
  --red: #d62d2d;
  --radius: 10px;
  --font: "DM Sans", "Segoe UI", Arial, Helvetica, sans-serif;
}

html,
body {
  background: var(--bg);
}

body {
  font-size: 12px;
  line-height: 1.25;
}

.app-shell {
  width: min(100%, 1540px);
  padding: 0 18px 40px;
}

.topbar {
  min-height: 66px;
  grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
  align-items: center;
  gap: 16px;
  background: rgba(246, 248, 251, 0.96);
}

.brand-block,
.top-actions {
  padding-bottom: 0;
}

.brand-block {
  gap: 9px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
}

.brand-mark svg { width: 19px; }
.brand-block h1 { font-size: 17px; letter-spacing: -0.15px; }
.brand-block p { margin-top: 2px; font-size: 10px; }

.top-tabs {
  align-items: center;
}

.tab {
  height: 36px;
  padding: 0 13px;
  font-size: 12px;
}

.tab.is-active::after { height: 2px; }
.tab span { font-size: 8px; padding: 1px 5px; }

.top-actions { gap: 4px; }
.icon-button { width: 31px; height: 31px; }
.icon-button svg { width: 17px; }

.summary-grid {
  gap: 9px;
  padding: 13px 0 9px;
}

.summary-card {
  min-height: 82px;
  padding: 11px 14px;
  border-radius: 9px;
}

.summary-label { font-size: 10px; }
.summary-value {
  margin-top: 7px;
  font-size: clamp(20px, 2vw, 27px);
  letter-spacing: -0.45px;
}
.summary-secondary { margin-top: 6px; font-size: 10px; }

.control-row {
  min-height: 43px;
  margin-bottom: 8px;
  gap: 12px;
}

.market-status { gap: 5px; font-size: 10px; }
.status-dot { width: 7px; height: 7px; }

.portfolio-add-actions,
.currency-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.compact-add-button,
.section-add-button {
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #214f9f;
  background: #fff;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.compact-add-button:hover,
.compact-add-button.is-active,
.section-add-button:hover,
.section-add-button.is-active {
  border-color: rgba(42, 97, 216, 0.55);
  background: rgba(42, 97, 216, 0.09);
}

.market-loader {
  min-height: 32px;
  margin-bottom: 8px;
  padding: 6px 9px;
  border-radius: 7px;
  font-size: 10px;
}
.market-loader-spinner { width: 13px; height: 13px; }

.position-editor {
  margin: 0 0 9px;
  padding: 8px;
  border-radius: 8px;
}

.position-inline-form {
  min-width: 1110px;
  grid-template-columns:
    minmax(140px, 1.2fr)
    62px
    70px
    88px
    70px
    88px
    48px
    82px
    minmax(105px, 1fr)
    64px
    auto;
  gap: 5px;
}

.inline-field { gap: 3px; }
.inline-field > span { font-size: 8px; }
.inline-field input,
.inline-field select,
.locked-field strong {
  height: 29px;
  border-radius: 5px;
  font-size: 10px;
}

.inline-field input,
.inline-field select { padding: 0 7px; }

.locked-field strong {
  display: flex;
  align-items: center;
  padding: 0 7px;
  border: 1px solid var(--border-strong);
  color: #315aa8;
  background: #f7f9fc;
  font-weight: 800;
}

.compact-primary-button,
.compact-secondary-button,
.compact-danger-button {
  height: 29px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 9px;
}

.notice {
  margin-bottom: 8px;
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 10px;
}

.portfolio-sections { gap: 12px; }
.currency-section {
  border-radius: 9px;
  box-shadow: 0 5px 18px rgba(22, 38, 62, 0.045);
}

.currency-heading {
  min-height: 48px;
  padding: 7px 9px;
  gap: 10px;
  background: #f3f6fb;
}

.currency-title { gap: 8px; }
.currency-badge {
  min-width: 39px;
  height: 24px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 9px;
}
.currency-title h2 { font-size: 13px; letter-spacing: 0; }
.currency-title p { margin-top: 1px; font-size: 9px; }
.currency-total { min-width: 165px; }
.currency-total strong { font-size: 13px; font-weight: 650; }
.currency-total span { font-size: 9px; }

.table-scroll {
  overflow-x: auto;
  scrollbar-width: thin;
}

.portfolio-table {
  min-width: 1440px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.portfolio-table th {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 30px;
  padding: 4px 7px;
  color: #2b3340;
  background: #fbfcff;
  border-bottom: 1px solid var(--border);
  font-size: 9px;
  font-weight: 700;
}

.portfolio-table td {
  height: 30px;
  padding: 4px 7px;
  border-bottom: 1px solid #e7ebf2;
  color: var(--text);
  font-size: 10px;
  line-height: 1.05;
}

.portfolio-table th:first-child,
.portfolio-table td:first-child { padding-left: 8px; }
.portfolio-table th:last-child,
.portfolio-table td:last-child { padding-right: 5px; }
.portfolio-table tbody tr:hover td { background: #f5f8fd; }

.text-left { text-align: left !important; }
.ticker-cell {
  width: 92px;
  color: #1e4ea6 !important;
  font-weight: 800;
}
.position-name-cell {
  width: 180px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 650;
}

.sticky-ticker,
.sticky-name {
  position: sticky !important;
  z-index: 6 !important;
  background: #fff;
}
.portfolio-table thead .sticky-ticker,
.portfolio-table thead .sticky-name {
  z-index: 8 !important;
  background: #fbfcff;
}
.sticky-ticker { left: 0; width: 92px; }
.sticky-name {
  left: 92px;
  width: 180px;
  box-shadow: 1px 0 0 var(--border);
}
.portfolio-table tbody tr:hover .sticky-ticker,
.portfolio-table tbody tr:hover .sticky-name { background: #f5f8fd; }

.position-chip {
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 7px;
}

.price-auto { font-weight: 750; }

.row-actions-cell {
  width: 55px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
}

.row-action {
  width: 23px;
  height: 23px;
  border-radius: 4px;
  font-size: 14px;
}
.delete-action { color: var(--red); }
.delete-action:hover { background: #fce8e6; }

.section-footer {
  min-height: 36px;
  padding: 6px 9px;
  gap: 18px;
  font-size: 9px;
  background: #fbfcff;
}
.section-footer strong {
  margin-left: 4px;
  font-size: 10px;
}

.empty-state {
  padding: 46px 16px;
  border-radius: 9px;
}
.empty-icon { width: 42px; height: 42px; border-radius: 10px; }
.empty-icon svg { width: 23px; }
.empty-state h3 { margin: 12px 0 4px; font-size: 16px; }
.empty-state p { font-size: 11px; }
.empty-actions { margin-top: 14px; gap: 6px; }

@media (max-width: 920px) {
  .app-shell { width: 100%; padding-inline: 10px; }
  .topbar { min-height: 58px; grid-template-columns: 1fr auto; }
  .top-tabs { display: none; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary-card { min-height: 76px; }
}

@media (max-width: 680px) {
  .summary-grid { grid-template-columns: 1fr; }
  .control-row { align-items: stretch; }
  .portfolio-add-actions { width: 100%; }
  .compact-add-button { flex: 1; }
  .currency-heading { align-items: center; }
  .currency-heading-actions { gap: 4px; }
  .currency-total { min-width: 0; }
  .section-footer { justify-content: flex-start; overflow-x: auto; }
}


/* v7: canonical ticker + independent editable label */
.position-inline-form {
  min-width: 1220px;
  grid-template-columns:
    minmax(105px, .7fr)
    minmax(150px, 1.1fr)
    62px
    70px
    88px
    70px
    88px
    48px
    82px
    88px
    64px
    auto;
}

.inline-label-input {
  width: 100%;
  height: 22px;
  padding: 0 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-weight: 650;
  outline: none;
}
.inline-label-input::placeholder { color: var(--muted-light); font-weight: 500; }
.inline-label-input:hover { border-color: var(--border); background: #fff; }
.inline-label-input:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(26, 115, 232, .12);
}
.inline-label-input:disabled { opacity: .65; }
.position-name-cell { padding-top: 3px !important; padding-bottom: 3px !important; }

/* v8: remove redundant internal Portfolio / Insights navigation */
.topbar {
  grid-template-columns: minmax(210px, 1fr) auto;
}

.top-actions {
  grid-column: 2;
  justify-self: end;
}


/* v9: calculated invested capital and closed-position workflow */
.position-inline-form {
  min-width: 1440px;
  grid-template-columns:
    minmax(105px, .75fr)
    minmax(145px, 1fr)
    62px
    72px
    88px
    68px
    48px
    92px
    86px
    96px
    64px
    72px
    108px
    auto;
  grid-template-areas: "ticker label currency direction entry qty multiplier invested source market quote sold realized actions";
  align-items: end;
}
.field-ticker { grid-area: ticker; }
.field-label { grid-area: label; }
.field-currency { grid-area: currency; }
.field-direction { grid-area: direction; }
.field-entry { grid-area: entry; }
.field-qty { grid-area: qty; }
.field-multiplier { grid-area: multiplier; }
.field-invested { grid-area: invested; }
.field-source { grid-area: source; }
.field-market { grid-area: market; }
.field-quote { grid-area: quote; }
.field-sold { grid-area: sold; }
.field-realized-pnl { grid-area: realized; }
.inline-form-actions { grid-area: actions; }

.field-invested input[readonly] {
  color: #315aa8;
  background: #f3f6fb;
  border-color: #d7deea;
  font-weight: 750;
  cursor: default;
}

.sold-toggle-field { min-width: 0; }
.checkbox-control {
  height: 29px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}
.checkbox-control input {
  width: 14px !important;
  height: 14px !important;
  margin: 0;
  padding: 0 !important;
  accent-color: var(--blue);
}

.position-chip.sold {
  color: #6f7784;
  background: #eceff3;
  border-color: #d7dce3;
}

.portfolio-table tbody tr.sold-row td,
.portfolio-table tbody tr.sold-row td.is-positive,
.portfolio-table tbody tr.sold-row td.is-negative,
.portfolio-table tbody tr.sold-row .ticker-cell,
.portfolio-table tbody tr.sold-row .inline-label-input {
  color: var(--muted-light) !important;
}
.portfolio-table tbody tr.sold-row td,
.portfolio-table tbody tr.sold-row .sticky-ticker,
.portfolio-table tbody tr.sold-row .sticky-name {
  background: #fafbfc;
}
.portfolio-table tbody tr.sold-row:hover td,
.portfolio-table tbody tr.sold-row:hover .sticky-ticker,
.portfolio-table tbody tr.sold-row:hover .sticky-name {
  background: #f5f6f8;
}
.portfolio-table tbody tr.sold-row .inline-label-input { font-weight: 550; }
.portfolio-table tbody tr.sold-row .row-action { opacity: .72; }

/* v10: no internal header, compact actions, finance links, and 12px portfolio grid */
.topbar,
.brand-block {
  display: none !important;
}

.app-shell {
  padding-top: 0;
}

.top-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  margin: 0 1px;
  padding: 0;
}

.top-actions .icon-button {
  width: 26px;
  height: 26px;
  border-radius: 5px;
}

.top-actions .icon-button svg {
  width: 15px;
}

.control-row {
  min-height: 38px;
  padding-top: 4px;
}

.market-status {
  gap: 5px;
}

.position-inline-form {
  min-width: 1640px;
  grid-template-columns:
    minmax(105px, .72fr)
    minmax(145px, .95fr)
    62px
    62px
    88px
    68px
    48px
    92px
    86px
    96px
    minmax(170px, 1.25fr)
    72px
    108px
    auto;
  grid-template-areas: "ticker label currency direction entry qty multiplier invested source quote finance sold realized actions";
}

.field-finance-link { grid-area: finance; }
.field-direction { min-width: 0; }

.portfolio-table {
  min-width: 1510px;
}

.portfolio-table th,
.portfolio-table td,
.inline-label-input,
.investment-finance-link {
  font-size: 12px;
}

.portfolio-table th {
  height: 32px;
  padding: 4px 7px;
}

.portfolio-table td {
  height: 32px;
  padding: 4px 7px;
}

.direction-col {
  width: 62px !important;
  min-width: 62px !important;
  max-width: 62px !important;
  padding-inline: 3px !important;
  text-align: center !important;
}

.position-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 10px;
  line-height: 16px;
  font-weight: 800;
}

.position-chip.long {
  color: #0b6b2a;
  background: #e9f5ec;
  border-color: #c8e6d0;
}

.position-chip.short {
  color: #a12620;
  background: #fcebea;
  border-color: #f1c8c5;
}

.position-chip.sold {
  color: #6f7784;
  background: #eceff3;
  border-color: #d7dce3;
}

.investment-finance-link {
  color: #1e4ea6;
  text-decoration: none;
  font-weight: 800;
}

.investment-finance-link:hover {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 920px) {
  .control-row {
    padding-top: 4px;
  }
}

/* Preserve the manual-price field in the editor's ordered grid. */
.position-inline-form {
  min-width: 1740px;
  grid-template-columns:
    minmax(105px, .72fr)
    minmax(145px, .95fr)
    62px
    62px
    88px
    68px
    48px
    92px
    86px
    96px
    64px
    minmax(170px, 1.25fr)
    72px
    108px
    auto;
  grid-template-areas: "ticker label currency direction entry qty multiplier invested source market quote finance sold realized actions";
}

.position-chip {
  font-size: 12px;
  line-height: 17px;
}


/* v12: stable scrolling, IBKR FX display, and reduced mobile portfolio tables */
.mobile-only-col {
  display: none;
}

.table-scroll {
  overflow-anchor: none;
  overscroll-behavior-inline: contain;
  scroll-behavior: auto;
}

#eurUsdRate {
  cursor: help;
}

.fx-source {
  display: inline-flex;
  align-items: center;
  min-height: 16px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  background: #fff;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  vertical-align: 1px;
}

.fx-source.is-ibkr {
  color: var(--green);
  border-color: #c8e6d0;
  background: #e9f5ec;
}

@media (max-width: 680px) {
  /* Keep the complete three-card summary visible; only the grid arrangement changes. */
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .portfolio-table {
    width: 100%;
    min-width: 520px;
    table-layout: fixed;
  }

  .portfolio-table .mobile-hide-col {
    display: none !important;
  }

  .portfolio-table .mobile-only-col,
  .portfolio-table .mobile-keep-col {
    display: table-cell;
  }

  .portfolio-table th,
  .portfolio-table td {
    padding-inline: 6px;
    font-size: 11px;
  }

  .portfolio-table .ticker-col {
    width: 86px !important;
    min-width: 86px !important;
    max-width: 86px !important;
    left: 0 !important;
    text-align: left !important;
  }

  .portfolio-table .mobile-invested-col {
    width: 112px !important;
  }

  .portfolio-table .mobile-pnl-eur-col {
    width: 108px !important;
  }

  .portfolio-table .mobile-pnl-pct-col {
    width: 92px !important;
  }

  .portfolio-table .mobile-allocation-col {
    width: 110px !important;
  }

  .sticky-name {
    position: static !important;
    box-shadow: none !important;
  }

  .currency-heading {
    flex-wrap: wrap;
  }

  .currency-heading-actions {
    width: 100%;
    justify-content: space-between;
  }
}

/* v12: exact market state, persistent closed-position visibility, newest-first rows */
.closed-positions-toggle {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
  font-size: 10px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.closed-positions-toggle:hover {
  border-color: #b6c5de;
  background: #f5f8fd;
}

.closed-positions-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--blue);
}

.closed-positions-toggle:has(input:checked) {
  color: #214f9f;
  border-color: rgba(42, 97, 216, 0.48);
  background: rgba(42, 97, 216, 0.08);
}

.closed-hidden-row td {
  height: 38px;
  color: var(--muted);
  background: var(--surface-subtle);
  text-align: center;
  font-size: 11px;
}

@media (max-width: 680px) {
  .closed-positions-toggle,
  .section-add-button {
    flex: 0 0 auto;
  }

  .currency-heading-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .currency-total {
    margin-left: auto;
  }
}

/* v17 price-route indicators */
.market-price-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 4px;
  border: 1px solid #d4dae4;
  border-radius: 4px;
  color: #667085;
  background: #f8fafc;
  font-size: 8px;
  font-weight: 700;
  line-height: 1.2;
  vertical-align: 1px;
}
.market-price-badge.overnight {
  color: #315aa8;
  background: #eef4ff;
  border-color: #c9d8f5;
}
.market-price-badge.fallback {
  color: #8a5a00;
  background: #fff8e6;
  border-color: #ecd8a6;
}


/* v18 connection/data status + per-ticker delayed indicator */
.market-status .status-dot { flex: 0 0 auto; }
.ticker-cell-content { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.ticker-market-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; display: inline-block; background: var(--muted-light); }
.ticker-market-dot.is-live { background: var(--green); box-shadow: 0 0 0 2px rgba(11, 127, 42, 0.10); }
.ticker-market-dot.is-delayed { background: var(--yellow); box-shadow: 0 0 0 2px rgba(249, 171, 0, 0.12); }
.market-price-badge { display: none !important; }


/* v19: truthful delayed marker + denser Side / X / Qty columns */
.portfolio-table .direction-col {
  width: 34px !important;
  min-width: 34px !important;
  max-width: 34px !important;
  padding-inline: 2px !important;
  text-align: center !important;
}

.portfolio-table .multiplier-col {
  width: 34px !important;
  min-width: 34px !important;
  max-width: 34px !important;
  padding-inline: 2px !important;
  text-align: center !important;
}

.portfolio-table .qty-col {
  width: 48px !important;
  min-width: 48px !important;
  max-width: 48px !important;
  padding-inline: 4px !important;
  text-align: right !important;
}

.direction-letter {
  display: inline-block;
  min-width: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
  text-align: center;
}

.direction-letter.long { color: var(--green); }
.direction-letter.short { color: var(--red); }
.sold-row .direction-letter { opacity: .55; }
