/*
 * 配色トークン等はMyMoneyの public/style.css(自作アプリ共通のGUI規約の参照実装)からコピー。
 * このアプリは記録の操作(POST/PATCH/DELETE)が無いため、シート・チップ・トーストなど
 * 入力系の部品は持たない。持つのはログイン・帯・本文の描画・一覧・下部ナビだけ。
 *
 * 配色の方針(規約§2と同じ)
 *  - 既定をダークにする(常用がダークのため、環境の判定に依存させない)
 *  - 背景・面・境界はすべて無彩色。純黒(#000)は使わず #121212 を基準にし、
 *    面が上に重なるほど明度を上げて階層を出す
 *  - 色を持つのはアクセント(寒色)と警告(alert)のみ
 */

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-raised: #262626;
  --line: #333333;
  --text: #e8e8e8;
  --muted: #a0a0a0;
  --accent: #6ea8fe;
  --on-accent: #10151d;
  --alert: #ff8a80;

  --tap: 44px;
  --r-sm: 4px;
  --r-md: 6px;

  --nav-h: 56px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --line: #e0e0e0;
    --text: #1a1a1a;
    --muted: #5f5f5f;
    --accent: #1863dc;
    --on-accent: #ffffff;
    --alert: #c62828;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1,
h3,
.section-heading,
#header-date {
  font-feature-settings: "palt";
}

/* --- 共通の部品 ------------------------------------------------------------- */

input,
button {
  font: inherit;
  border-radius: var(--r-sm);
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

input::placeholder {
  color: var(--muted);
}

button {
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  background: none;
  color: inherit;
  font-weight: 400;
  cursor: pointer;
}

.btn-text {
  padding: 0 4px;
  min-height: var(--tap);
  color: var(--muted);
  font-weight: 400;
}

.btn-text.accent {
  color: var(--accent);
}

.link-btn-alert {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0 4px;
  min-height: var(--tap);
  color: var(--alert);
  font-weight: 600;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.error {
  margin: 6px 0 0;
  color: var(--alert);
  font-size: 0.85rem;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 8px;
}

/* --- ログイン ---------------------------------------------------------------- */

#login {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-inner {
  width: min(360px, 100%);
  display: grid;
  gap: 16px;
}

.login-inner h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.15;
  text-align: center;
}

#login-form {
  display: grid;
  gap: 10px;
}

#login-form button[type="submit"] {
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

/* --- 本体のレイアウト --------------------------------------------------------- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 640px;
  margin-inline: auto;
}

header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}

#header-date {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

#header-time {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.conn-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--alert);
  font-size: 0.85rem;
}

main {
  flex: 1;
  padding: 4px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

/* 「今日の分が届いていません」の帯。色だけでなく文言で示す(規約§2) */
.alert-banner {
  margin: 8px 0 16px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--alert) 14%, var(--surface));
  color: var(--alert);
  font-size: 0.85rem;
  font-weight: 600;
}

/* --- セクションの見出し(枠なし) ------------------------------------------------- */

.section-heading {
  margin: 0 0 6px;
  padding-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
}

/* --- 本文の描画(DESIGN.md §7・render.js) ------------------------------------- */

.brief-body {
  margin-top: 8px;
}

.brief-body h3 {
  margin: 24px 0 6px;
  padding-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
  font-feature-settings: "palt";
}

.brief-body h3:first-child {
  margin-top: 0;
}

.brief-body p {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

.brief-body ul,
.brief-body ol {
  margin: 0 0 12px;
  padding-left: 1.4em;
}

.brief-body ul ul {
  margin: 2px 0 0;
}

.brief-body li {
  margin: 2px 0;
  overflow-wrap: anywhere;
}

.brief-body strong {
  font-weight: 700;
}

/* --- 空状態 ----------------------------------------------------------------------- */

.empty-state {
  margin-top: 24px;
  display: grid;
  gap: 10px;
}

.empty-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.empty-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- 過去(一覧) ------------------------------------------------------------------ */

.history-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.history-row:last-child {
  border-bottom: none;
}

.history-row:active {
  background: var(--surface-raised);
}

.history-date {
  font-weight: 600;
}

.history-time {
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-header {
  margin: 12px 0 0;
}

#history-detail-date {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

#history-detail-time {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.logout-section {
  margin-top: 40px;
}

/* --- 下部固定ナビゲーション ------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  max-width: 640px;
  margin-inline: auto;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav-btn {
  flex: 1;
  min-height: var(--nav-h);
  border-top: 2px solid transparent;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.nav-btn[aria-selected="true"] {
  color: var(--text);
  font-weight: 700;
  border-top-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
