/* === Base === */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Noto Sans CJK JP", sans-serif;
  background: #0e1116;
  color: #e6e8ec;
}
body.app-body { height: 100vh; height: 100dvh; overflow: hidden; }

a { color: #6cb6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Auth pages === */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #0e1116, #1a2030);
}
.auth-card {
  width: min(420px, 92vw);
  background: #161a22;
  border: 1px solid #232936;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.auth-card h1 { margin-top: 0; font-size: 22px; }
.auth-card form { display: grid; gap: 12px; margin-top: 16px; }
.auth-card label { display: grid; gap: 6px; font-size: 13px; color: #9aa3b2; }
.auth-card input[type=email],
.auth-card input[type=password],
.auth-card input[type=text] {
  background: #0e1116;
  border: 1px solid #2a3140;
  color: #e6e8ec;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: #6cb6ff; }
.auth-card button {
  background: #2964ff;
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
}
.auth-card button:hover { background: #3a76ff; }
.auth-card .auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 13px;
}
.msg { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.msg.err { background: #2a1218; color: #ffb4be; border: 1px solid #5a1f2a; }
.msg.ok  { background: #0f2a1c; color: #b4f1cf; border: 1px solid #1f5a3e; }

/* === App === */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #161a22;
  border-bottom: 1px solid #232936;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar nav { display: flex; gap: 12px; align-items: center; }
.filter-label {
  color: #c8cfdb;
  font-size: 14px;
  margin-right: 4px;
}
.filter-select {
  background: #2964ff;
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 8px 32px 8px 14px;
  cursor: pointer;
  font-size: 14px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='white' d='M2 4l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.filter-select:hover { background-color: #3a76ff; }
.filter-select:focus { outline: 2px solid #6cb6ff; outline-offset: 1px; }
.filter-select option { background: #161a22; color: #c8cfdb; }
.logout {
  font-size: 13px;
  color: #9aa3b2;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  padding: 16px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}
.panel {
  background: #161a22;
  border: 1px solid #232936;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel header h2 { margin: 0 0 8px; font-size: 15px; color: #c8cfdb; }
.panel header h2 span { color: #6b7384; font-weight: normal; font-size: 12px; margin-left: 6px; }

.results-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.results-header-row h2 { margin: 0; }

.csv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #d9730d 0%, #f59324 100%);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  box-shadow: 0 2px 8px rgba(217, 115, 13, .25);
}
.csv-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(217, 115, 13, .4);
}
.csv-btn:active { transform: translateY(0); filter: brightness(.95); }
.csv-btn:focus { outline: 2px solid #6cb6ff; outline-offset: 2px; }
.csv-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.csv-btn svg { flex: 0 0 auto; }

/* === Confirmation modal === */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 11, 16, .68);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: min(440px, 92vw);
  background: #161a22;
  border: 1px solid #2a3140;
  border-radius: 12px;
  padding: 22px 24px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  animation: modal-pop .14s ease-out;
}
@keyframes modal-pop {
  from { transform: translateY(6px) scale(.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #e6e8ec;
  letter-spacing: 0.02em;
}
.modal-body {
  margin: 0 0 10px;
  font-size: 13px;
  color: #c8cfdb;
}
.modal-filename {
  margin: 0 0 18px;
  padding: 10px 12px;
  background: #0e1116;
  border: 1px solid #232936;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #6cb6ff;
  word-break: break-all;
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.btn-ghost,
.btn-primary {
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: filter .12s ease, transform .12s ease;
}
.btn-ghost {
  background: transparent;
  color: #9aa3b2;
  border: 1px solid #2a3140;
}
.btn-ghost:hover { color: #c8cfdb; border-color: #3a4658; background: #1c2230; }
.btn-primary {
  background: linear-gradient(135deg, #1e8a4d 0%, #2dab66 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(30, 138, 77, .3);
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); filter: brightness(.95); }
.btn-ghost:focus,
.btn-primary:focus { outline: 2px solid #6cb6ff; outline-offset: 2px; }

/* 絞り込みバー: メジャーフィルター(トップバーのプルダウン)がデータセットを
   決め、ここは表示中リストを削るだけ。全グループ同じ見た目・同じ操作感。 */
.seg-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin: 2px 0 10px;
}
.seg-item { display: flex; align-items: center; gap: 6px; }
.seg-caption { font-size: 11px; color: #6b7384; }
.seg-group {
  display: inline-flex;
  border: 1px solid #2a3140;
  border-radius: 8px;
  overflow: hidden;
  background: #0e1116;
}
.seg-group .seg-btn {
  background: transparent;
  color: #9aa3b2;
  border: 0;
  padding: 6px 14px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  border-right: 1px solid #2a3140;
}
.seg-group .seg-btn:last-child { border-right: 0; }
.seg-group .seg-btn:hover { color: #c8cfdb; background: #1c2230; }
.seg-group .seg-btn.active { background: #2964ff; color: #fff; }
.seg-group .seg-btn:focus { outline: 2px solid #6cb6ff; outline-offset: -2px; }

/* 決算日セルの色分け: 10日以内=赤 / 11〜30日=橙 (バケット境界 10/30/90 に連動) */
td .earn-near { color: #fb7185; font-weight: 600; }
td .earn-mid { color: #f5b301; }
td .earn-none { color: #4a5262; }

.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid #232936; }
th { color: #9aa3b2; font-weight: 500; position: sticky; top: 0; background: #161a22; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: #c8cfdb; }
th[data-sort].active { color: #6cb6ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.row { cursor: pointer; }
tr.row:hover { background: #1c2230; }
tr.row.selected { background: #1f3052; }

/* chart panel */
.chart-panel { min-height: 0; }
.chart-panel header { flex: 0 0 auto; }
#chart-title { font-size: 16px; }
#chart-container {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 8px;
  background: #0e1116;
  border-radius: 8px;
  overflow: hidden;
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
}
.meta-grid .k { color: #9aa3b2; }
.meta-grid .v { color: #e6e8ec; font-weight: 500; }
.meta-grid .item {
  background: #1c2230;
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
}

/* TargetJP: market badge next to the title */
.jp-badge {
  display: inline-block;
  font-size: .62em;
  font-weight: 700;
  letter-spacing: .08em;
  vertical-align: middle;
  padding: .12em .5em;
  margin-left: .35em;
  border-radius: 5px;
  background: #b91c4a;
  color: #fff;
}
