:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-soft: #edf1ed;
  --ink: #17201b;
  --muted: #667269;
  --line: #dce3dd;
  --accent: #0f7b63;
  --accent-strong: #095943;
  --danger: #b44646;
  --shadow: 0 16px 36px rgba(23, 32, 27, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-inner {
  width: min(1180px, calc(100% - 32px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand-text strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.brand-text span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  font-weight: 700;
  white-space: nowrap;
}

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

.btn.danger {
  color: var(--danger);
  background: #fff2f2;
  border-color: #f0d4d4;
}

.btn:focus-visible,
input:focus-visible,
.tab:focus-visible {
  outline: 3px solid rgba(15, 123, 99, 0.22);
  outline-offset: 2px;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  margin-bottom: 18px;
}

.search-panel input,
.field input {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.search-panel input {
  min-height: 48px;
  padding: 0 14px;
  background: #fbfcfb;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) 340px;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  min-height: 58px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.panel-body {
  padding: 18px;
}

.stock-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.stock-title h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1;
}

.stock-title p {
  margin: 8px 0 0;
  color: var(--muted);
}

.price {
  text-align: right;
  min-width: 150px;
}

.price strong {
  display: block;
  font-size: 32px;
  line-height: 1;
}

.price span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-weight: 700;
}

.price small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
  min-height: 92px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

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

.result-list {
  display: grid;
  gap: 8px;
}

.result-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
}

.result-item strong,
.result-item span {
  display: block;
}

.result-item span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.status {
  margin-top: 12px;
  color: var(--muted);
  min-height: 22px;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

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

.favorite-table th,
.favorite-table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.favorite-table th {
  color: var(--muted);
  font-size: 13px;
  background: #fbfcfb;
}

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

.gain {
  color: var(--accent-strong);
  font-weight: 800;
}

.loss {
  color: var(--danger);
  font-weight: 800;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 17, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
}

.dialog-backdrop.open {
  display: flex;
}

dialog {
  width: min(460px, 100%);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(10, 15, 12, 0.28);
  color: var(--ink);
  background: var(--surface);
}

.dialog-form {
  padding: 20px;
}

.dialog-form h3 {
  margin: 0 0 16px;
  font-size: 21px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.field input {
  min-height: 44px;
  padding: 0 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.hidden-input {
  display: none;
}

@media (max-width: 860px) {
  .topbar-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 0;
  }

  .actions {
    justify-content: flex-start;
  }

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

  .stock-title {
    display: grid;
  }

  .price {
    text-align: left;
  }

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

@media (max-width: 620px) {
  .search-panel {
    grid-template-columns: 1fr;
  }

  .tabs,
  .actions {
    width: 100%;
  }

  .tab,
  .actions .btn {
    flex: 1;
  }

  .favorite-table,
  .favorite-table thead,
  .favorite-table tbody,
  .favorite-table tr,
  .favorite-table th,
  .favorite-table td {
    display: block;
  }

  .favorite-table thead {
    display: none;
  }

  .favorite-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .favorite-table td {
    border: 0;
    padding: 7px 16px;
  }

  .favorite-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 3px;
  }
}
