:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d5dce7;
  --text: #111827;
  --muted: #687385;
  --navy: #1b2740;
  --navy-2: #263b5d;
  --gold: #d6b66d;
  --green: #18794e;
  --red: #b42318;
  --amber: #b47a14;
  --button: #2a4f7a;
  --button-hover: #1d3c60;
  --shadow: 0 10px 24px rgba(20, 35, 60, 0.08);
  --shadow-soft: 0 1px 2px rgba(20, 35, 60, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: #07090d;
  border-bottom: 1px solid #191f2a;
  color: #d8dee9;
  display: flex;
  gap: 24px;
  min-height: 64px;
  padding: 0 32px;
}

.brand {
  align-items: baseline;
  color: #ffffff;
  display: inline-flex;
  flex: 0 0 auto;
  gap: 9px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand strong {
  color: var(--gold);
  font-weight: 900;
}

.nav {
  align-items: center;
  border-left: 1px solid #242a33;
  color: #b7bfcc;
  display: flex;
  flex: 0 0 auto;
  gap: 14px;
  font-size: 14px;
  padding-left: 18px;
}

.nav a {
  color: #d8dee9;
  font-weight: 700;
}

.nav a:hover {
  color: #ffffff;
}

.top-status {
  align-items: center;
  display: flex;
  gap: 22px;
  justify-content: flex-end;
  margin-left: auto;
  min-width: 0;
}

.status-item {
  align-items: center;
  color: #9ca6b6;
  display: inline-flex;
  gap: 7px;
  font-size: 13px;
  white-space: nowrap;
}

.status-item strong {
  color: #e7edf5;
  font-weight: 800;
}

.status-dot {
  border-radius: 50%;
  display: inline-block;
  height: 9px;
  width: 9px;
}

.status-dot.ready {
  background: #8bd6a8;
  box-shadow: 0 0 10px rgba(139, 214, 168, 0.85);
}

.status-dot.busy {
  background: #f5c16c;
  box-shadow: 0 0 10px rgba(245, 193, 108, 0.85);
}

.status-dot.danger {
  background: #ee9a94;
  box-shadow: 0 0 10px rgba(238, 154, 148, 0.8);
}

.state-ok {
  color: #9de4b8;
}

.state-warn {
  color: #f2cf83;
}

.state-bad {
  color: #f2aaa6;
}

.page {
  margin: 0 auto;
  max-width: 1680px;
  padding: 24px 28px 34px;
}

.summary-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric,
.action-panel,
.table-section,
.job-head,
.log-panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 96px;
  padding: 18px;
}

.label,
.subtext,
small,
.job-head p,
.empty {
  color: var(--muted);
}

.metric strong {
  font-size: 24px;
}

.ok {
  color: var(--green);
}

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

.warn {
  color: var(--amber);
}

.action-panel,
.table-section,
.job-head,
.log-panel {
  margin-bottom: 22px;
  padding: 22px 24px 24px;
}

h1,
h2 {
  color: var(--navy);
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 21px;
  font-weight: 850;
  margin-bottom: 18px;
}

h2 {
  font-size: 20px;
  font-weight: 850;
}

.action-panel h1 {
  text-align: center;
}

.run-layout {
  align-items: stretch;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(560px, 600px) minmax(960px, 1fr);
  margin: 0 auto;
  max-width: 1620px;
}

.profile-section,
.run-section {
  margin-bottom: 22px;
}

.panel-title-row {
  align-items: center;
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  margin-bottom: 18px;
}

.panel-title-row h1 {
  margin-bottom: 0;
}

.profile-panel {
  align-items: center;
  background: #f8fafc;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  min-height: 98px;
  padding: 18px;
}

.profile-fields {
  display: grid;
  gap: 8px;
  min-width: 0;
  width: 100%;
}

.workflow {
  align-items: center;
  background: #f8fafc;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: 230px 26px 250px 26px minmax(370px, 1fr);
  justify-content: center;
  padding: 18px;
}

.flow-step,
.inline-form {
  gap: 10px;
}

.inline-form {
  display: flex;
}

.flow-step {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  min-width: 0;
}

.step-badge {
  align-items: center;
  background: #f3f7fb;
  border: 1px solid #c5d3e3;
  border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  color: #263b5d;
  display: inline-flex;
  flex: 0 0 30px;
  font-size: 14px;
  font-weight: 800;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.flow-arrow {
  align-self: center;
  color: #8a95a7;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  padding-bottom: 2px;
}

.cash-step {
  min-width: 250px;
}

.final-step {
  align-items: center;
  justify-content: stretch;
}

.final-buttons {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  width: 100%;
}

.final-buttons button {
  flex: 1 1 0;
  min-width: 0;
}

button,
.button-link {
  align-items: center;
  background: linear-gradient(180deg, #315c8d 0%, var(--button) 100%);
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.14);
}

button:hover,
.button-link:hover {
  background: linear-gradient(180deg, #274e7d 0%, var(--button-hover) 100%);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  background: #ffffff;
  border: 1px solid #cfd8e5;
  border-radius: 6px;
  font: inherit;
  min-height: 42px;
  padding: 0 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
  border-color: #6f95bd;
  box-shadow: 0 0 0 3px rgba(111, 149, 189, 0.18);
  outline: none;
}

.input-stack {
  display: grid;
  gap: 8px;
  width: 100%;
}

.cash-input,
.profile-select,
.profile-custom {
  font-weight: 750;
  width: 100%;
}

.profile-select {
  color: var(--text);
  padding: 0 12px;
}

.profile-custom {
  display: none;
}

.profile-custom.is-visible {
  display: block;
}

.table-wrap {
  border: 1px solid #cfd8e5;
  border-radius: 8px;
  overflow-x: auto;
}

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

.portfolio-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1540px;
  table-layout: fixed;
}

.portfolio-table .col-asset {
  width: 260px;
}

.portfolio-table .col-ticker {
  width: 150px;
}

.portfolio-table .col-qty {
  width: 170px;
}

.portfolio-table .col-avg,
.portfolio-table .col-price {
  width: 165px;
}

.portfolio-table .col-invest,
.portfolio-table .col-eval {
  width: 185px;
}

.portfolio-table .col-ratio,
.portfolio-table .col-return {
  width: 130px;
}

th,
td {
  border-bottom: 1px solid #d9e0ea;
  border-right: 1px solid #d9e0ea;
  overflow: hidden;
  padding: 13px 16px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th:last-child,
td:last-child {
  border-right: 0;
}

th {
  background: #1d2942;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.portfolio-table th {
  border-color: #2f3b53;
  text-align: center;
}

.portfolio-table td {
  font-variant-numeric: tabular-nums;
  height: 56px;
}

.portfolio-table .num {
  text-align: right;
}

.portfolio-table .manual-cell {
  background: #e8f3fa;
}

.portfolio-table .price-cell {
  background: #fff8e6;
}

.portfolio-table .readonly-cell {
  background: #ffffff;
}

.portfolio-table .child-asset {
  color: #0f5d88;
  font-style: italic;
  padding-left: 32px;
}

.portfolio-table tfoot td {
  background: #d6dcde;
  border-bottom: 0;
  border-color: #c4ccd3;
  font-weight: 800;
  height: 50px;
}

.portfolio-table tbody tr:nth-child(even) td:not(.manual-cell):not(.price-cell) {
  background: #f8fafc;
}

.portfolio-table tbody tr:hover td {
  background-color: #f5f9fd;
}

.portfolio-table tbody tr:hover td.manual-cell {
  background-color: #dff0fa;
}

.portfolio-table tbody tr:hover td.price-cell {
  background-color: #fff4d6;
}

.asset-cell {
  padding-left: 46px;
  position: relative;
}

.row-delete {
  background: transparent;
  border: 0;
  color: #9aa1ad;
  cursor: pointer;
  font-size: 22px;
  font-weight: 500;
  left: 12px;
  min-height: 24px;
  padding: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
}

.row-delete:hover {
  background: #fef3f2;
  color: var(--red);
}

.cell-input {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: inherit;
  font: inherit;
  min-height: 34px;
  min-width: 0;
  padding: 0 6px;
  width: 100%;
}

.cell-input:focus {
  background: #ffffff;
  border-color: #93b4d8;
  box-shadow: 0 0 0 2px rgba(74, 128, 183, 0.13);
  outline: none;
}

.manual-cell .cell-input {
  color: #174ea6;
  font-weight: 650;
}

.num-input {
  color: #004eea;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.ticker-input {
  font-style: italic;
}

.readonly-cell {
  color: var(--text);
}

tbody tr:nth-child(even) {
  background: #f9fafb;
}

.section-head,
.job-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.portfolio-head {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr auto 1fr;
  margin-bottom: 16px;
}

.section-title-with-note {
  align-items: center;
  display: flex;
  gap: 10px;
  grid-column: 2;
  justify-self: center;
  min-width: 0;
}

.title-step {
  flex: 0 0 30px;
}

.title-note {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
}

.toolbar {
  align-items: center;
  background: #f5f7fa;
  border: 1px solid #dce3ed;
  border-radius: 8px;
  display: flex;
  gap: 4px;
  grid-column: 3;
  justify-self: end;
  padding: 3px;
}

.icon-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #8a8f98;
  cursor: pointer;
  display: inline-flex;
  height: 32px;
  justify-content: center;
  min-height: 32px;
  padding: 0;
  width: 32px;
}

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

.icon-button:hover {
  background: #e9eef5;
}

.save-icon {
  color: #9f2eb7;
}

.muted-icon {
  color: #8d939c;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.dirty-save {
  transition: background-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.dirty-save.is-dirty:not(:disabled) {
  background: #9f2eb7;
  box-shadow: 0 0 0 3px rgba(159, 46, 183, 0.14), 0 8px 18px rgba(105, 24, 125, 0.22);
  color: #ffffff;
}

.dirty-save.is-dirty:not(:disabled):hover {
  background: #84249a;
}

.text-link {
  color: var(--button);
  font-weight: 700;
}

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

.list {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
}

.list-row {
  align-items: center;
  border: 1px solid transparent;
  border-top: 1px solid #e2e8f0;
  border-radius: 6px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 10px;
}

.list-row:hover {
  background: #f8fafc;
  border-color: #dce4ee;
}

.list-row span {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.list-row strong,
.list-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 9px;
  text-transform: uppercase;
  white-space: nowrap;
}

.status.running {
  background: #fff7ed;
  color: var(--amber);
}

.status.finished {
  background: #ecfdf3;
  color: var(--green);
}

.status.failed {
  background: #fef3f2;
  color: var(--red);
}

.log-panel pre {
  background: #101828;
  border-radius: 6px;
  color: #f2f4f7;
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
  max-height: 68vh;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
}

.login-panel {
  margin: 56px auto;
  max-width: 420px;
  padding: 24px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-stack label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-weight: 700;
}

.notice,
.flash {
  border-radius: 6px;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.notice {
  background: #fff7ed;
  color: var(--amber);
}

.flash.error {
  background: #fef3f2;
}

.footer-actions {
  margin-top: 12px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px 18px;
  }

  .top-status {
    justify-content: flex-start;
    margin-left: 0;
    width: 100%;
  }

  .nav {
    border-left: 0;
    padding-left: 0;
  }

  .page {
    padding: 18px;
  }

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

  .run-layout,
  .workflow,
  .inline-form {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .profile-panel {
    width: 100%;
  }

  .portfolio-head {
    display: flex;
    flex-direction: column;
  }

  .section-title-with-note {
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }

  .title-note {
    white-space: normal;
  }

  .flow-step,
  .final-buttons {
    width: 100%;
  }

  .flow-arrow {
    align-self: flex-start;
    margin-left: 13px;
    transform: rotate(90deg);
  }

  button,
  .button-link,
  input {
    justify-content: center;
    width: 100%;
  }

  .icon-button,
  .row-delete {
    width: 32px;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}
