/* ==========================================================
   株価チェック - style.css
   Androidスマートフォンでの片手操作を重視したモバイルファーストUI
   ========================================================== */

:root {
  --color-bg: #f2f4f8;
  --color-header: #0a1b3a;
  --color-header-text: #ffffff;
  --color-card-bg: #ffffff;
  --color-border: #e2e6ee;
  --color-text: #1c2331;
  --color-text-sub: #6b7386;
  --color-accent: #ffb703;
  --color-accent-text: #1c2331;
  --color-primary: #1a3a6b;
  --color-primary-text: #ffffff;
  --color-up: #e6453c;      /* 日本の慣例：赤=上昇 */
  --color-down: #2f6fed;    /* 青=下降 */
  --color-flat: #6b7386;
  --color-positive: #d4483f;
  --color-negative: #2f6fed;
  --color-neutral: #8a90a2;
  --color-danger: #d4483f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  position: relative;
}

button, input {
  font-family: inherit;
}

/* ---------- 画面切り替え ---------- */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
}
.screen.active { display: flex; }

/* ---------- 共通ボタン ---------- */
.btn {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 16px;
  min-height: 48px;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); opacity: 0.9; }

.btn-primary { background: var(--color-primary); color: var(--color-primary-text); min-width: 92px; }
.btn-accent { background: var(--color-accent); color: var(--color-accent-text); }
.btn-secondary { background: #e9edf6; color: var(--color-primary); }
.btn-nav { background: #ffffff; color: var(--color-primary); border: 1px solid var(--color-border); flex: 1; }
.btn-link { background: transparent; color: var(--color-header-text); font-size: 15px; padding: 10px 6px; min-height: 40px; }
.btn-big { width: 100%; font-size: 18px; padding: 16px; margin: 4px 0 6px; box-shadow: 0 4px 14px rgba(255,183,3,0.35); }
.btn-danger { background: #fdecea; color: var(--color-danger); }

/* ---------- ヘッダー ---------- */
.app-header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding: calc(14px + var(--safe-top)) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.03em;
}
.notif-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
}
.notif-btn.enabled { background: var(--color-accent); }

.offline-banner {
  background: #3a2c0a;
  color: #ffe6a8;
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
}

/* ---------- 画面1 本文 ---------- */
.list-main {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px calc(24px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--color-card-bg);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(20,30,60,0.08);
}

.field-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.register-row { display: flex; gap: 8px; }
#stock-input {
  flex: 1;
  min-width: 0;
  padding: 12px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 16px;
  min-height: 48px;
}
#stock-input:focus { outline: 2px solid var(--color-primary); }
.input-hint { font-size: 12px; color: var(--color-text-sub); margin: 8px 0 0; }

.message { min-height: 20px; font-size: 14px; margin: 10px 0 0; font-weight: 600; }
.message.success { color: #1a7d3c; }
.message.error { color: var(--color-danger); }
.message.info { color: var(--color-primary); }

.section-title { font-size: 16px; margin: 0 0 10px; }
.empty-message { color: var(--color-text-sub); font-size: 14px; margin: 6px 0 0; display: none; }
.stock-list.is-empty + .empty-message { display: block; }

.stock-list { list-style: none; margin: 0; padding: 0; }
.stock-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-card-bg);
}
.stock-item:last-child { border-bottom: none; }
.stock-item.dragging { opacity: 0.55; background: #eef2fb; }

.drag-handle {
  cursor: grab;
  color: #b6bccb;
  font-size: 20px;
  padding: 8px 6px;
  touch-action: none;
  user-select: none;
}

.stock-checkbox {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  accent-color: var(--color-primary);
}

.stock-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stock-info .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stock-info .code { font-size: 12px; color: var(--color-text-sub); }

.delete-btn {
  background: none;
  border: none;
  color: #b6bccb;
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  min-width: 40px;
  min-height: 40px;
}
.delete-btn:active { color: var(--color-danger); }

/* ---------- 画面2 ヘッダー・フッター ---------- */
.detail-header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding: calc(10px + var(--safe-top)) 10px 10px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.page-indicator { font-size: 14px; font-weight: 700; padding: 6px 12px; background: rgba(255,255,255,0.12); border-radius: 20px; }

.detail-footer {
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: var(--color-card-bg);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ---------- 画面2 スワイプ領域 ---------- */
.swipe-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.swipe-track {
  display: flex;
  height: 100%;
  transition: transform 0.28s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}
.swipe-track.no-transition { transition: none; }

.stock-page {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px calc(28px + var(--safe-bottom));
  flex-shrink: 0;
}

.market-status-banner {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  background: #eef1f8;
  color: var(--color-text-sub);
  padding: 4px 10px;
  border-radius: 20px;
  margin: 0 0 8px;
}
.market-status-banner.open { background: #e6f7ea; color: #1a7d3c; }

.stock-name { margin: 0 0 2px; font-size: 22px; }
.stock-code { margin: 0 0 12px; color: var(--color-text-sub); font-size: 14px; }

.price-block { margin-bottom: 6px; }
.current-price { font-size: 34px; font-weight: 800; margin: 0; line-height: 1.2; }
.price-change { font-size: 17px; font-weight: 700; margin: 2px 0 0; }
.price-change.up { color: var(--color-up); }
.price-change.down { color: var(--color-down); }
.price-change.flat { color: var(--color-flat); }

.alert-banner {
  margin-top: 10px;
  background: #fff4e0;
  color: #8a5a00;
  border: 1px solid #ffdb99;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 14px;
}

.update-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 16px;
}
.update-row .refresh-btn { flex-shrink: 0; }
.last-updated { font-size: 12px; color: var(--color-text-sub); margin: 0; text-align: right; }

.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.vwap-toggle { font-size: 12px; color: var(--color-text-sub); display: flex; align-items: center; gap: 4px; }

.price-chart { width: 100%; height: auto; display: block; background: #fbfcfe; border-radius: 8px; }
.chart-note { font-size: 12px; color: var(--color-text-sub); margin: 8px 0 12px; }

.ohlc-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.ohlc-item { background: #f7f9fc; border-radius: 8px; padding: 8px 6px; text-align: center; }
.ohlc-label { display: block; font-size: 11px; color: var(--color-text-sub); }
.ohlc-value { display: block; font-size: 14px; font-weight: 700; margin-top: 2px; }

.settings-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}
.settings-item { background: #fff8ea; border-radius: 8px; padding: 8px 6px; text-align: center; }
.settings-label { display: block; font-size: 11px; color: var(--color-text-sub); }
.settings-value { display: block; font-size: 14px; font-weight: 700; margin-top: 2px; color: var(--color-primary); }
.settings-value.unset { color: var(--color-text-sub); font-weight: 400; }

.trend-direction { font-size: 17px; font-weight: 800; color: var(--color-primary); margin: 0 0 6px; }
.trend-comment { margin: 0 0 6px; }
.trend-basis { font-size: 12px; color: var(--color-text-sub); margin: 0; }

.supply-demand-list { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.supply-demand-list div.sd-row { background: #f7f9fc; border-radius: 8px; padding: 8px 10px; }
.sd-row dt { font-size: 11px; color: var(--color-text-sub); margin: 0; }
.sd-row dd { font-size: 14px; font-weight: 700; margin: 2px 0 0; }

.news-list { list-style: none; margin: 0; padding: 0; }
.news-item { padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.news-item:last-child { border-bottom: none; }
.news-item a { color: var(--color-primary); font-weight: 700; text-decoration: none; font-size: 14.5px; }
.news-item a:active { text-decoration: underline; }
.news-meta { font-size: 12px; color: var(--color-text-sub); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.news-tag { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 8px; }
.news-tag.positive { background: #fdecea; color: var(--color-positive); }
.news-tag.negative { background: #e7effe; color: var(--color-negative); }
.news-tag.neutral { background: #eef0f4; color: var(--color-neutral); }

.web-links { display: flex; flex-wrap: wrap; gap: 8px; }
.web-links a {
  display: inline-block;
  background: #eef1f8;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 20px;
}
.web-links a:active { background: #dde3f2; }

.setting-row { display: flex; align-items: center; gap: 8px; }
.setting-row input[type="number"] {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-size: 16px;
  min-height: 48px;
}
.setting-unit { font-size: 14px; color: var(--color-text-sub); }
.setting-status { min-height: 20px; font-size: 13px; font-weight: 700; margin: 8px 0 0; }
.setting-status.reached { color: #a5670b; }
.setting-status.error { color: var(--color-danger); }

.disclaimer {
  font-size: 12px;
  color: var(--color-text-sub);
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
  margin-top: 6px;
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1c2331;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
  z-index: 999;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* ---------- 大きめ画面(PC等)でも見やすいように ---------- */
@media (min-width: 560px) {
  body { background: #dde3ee; }
  #app { box-shadow: 0 0 24px rgba(0,0,0,0.12); min-height: 100vh; }
  .ohlc-grid { grid-template-columns: repeat(6, 1fr); }
  .supply-demand-list { grid-template-columns: 1fr 1fr 1fr; }
}
