/* base.css：BaseLog 共通スタイル - Dark theme inspired by H.T.CREATE */

:root {
  /* ダークカラーパレット（H.T.CREATE背景 × パープル＆イエローアクセント） */
  --color-bg:           #0D1117;   /* メイン背景（漆黒） */
  --color-bg-2:         #161B22;   /* セカンダリ背景 */
  --color-card:         #1C2128;   /* カード背景 */
  --color-card-hover:   #21262D;   /* カードホバー */

  /* アクセント */
  --color-primary:      #A855F7;   /* エレクトリックパープル（ワンポイント） */
  --color-primary-dark: #7C3AED;
  --gradient-primary: linear-gradient(135deg, #4C1D95, #7C3AED, #A855F7);
  --gradient-primary-btn: linear-gradient(135deg, #5B21B6 0%, #7C3AED 50%, #A855F7 100%);
  --color-accent:       #FFD454;   /* ウォームゴールド（ワンポイント） */
  --color-danger:       #FF4560;   /* ネオンレッド */
  --color-warning:      #EC4899;   /* ホットピンク */

  /* テキスト */
  --color-text:         #E6EDF3;   /* オフホワイト */
  --color-text-muted:   #7D8590;   /* ミュートグレー */

  /* ボーダー */
  --color-border:       #30363D;

  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
  --glow-primary: 0 0 24px rgba(168,85,247,0.4);
  --glow-accent:  0 0 24px rgba(255,212,84,0.4);

  --nav-height: 60px;
  --desktop-nav-width: 88px;
  --desktop-nav-gap: 20px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--color-bg);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(124,58,237,0.12) 0%, transparent 65%);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ヘッダー */
.header {
  background: linear-gradient(135deg, #1C0A3E 0%, #2D1B69 50%, #1C2128 100%);
  color: var(--color-text);
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--color-primary);
}

.header-nav a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  margin-left: 16px;
}

/* コンテナ */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* カード */
.card {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--color-border);
  margin-bottom: 14px;
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  min-height: 48px;
  background: var(--color-card);
  color: var(--color-text);
}

.btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-primary {
  background: var(--gradient-primary-btn);
  color: white;
  border-color: transparent;
  font-weight: 700;
}

.btn-primary:hover {
  box-shadow: var(--glow-primary);
  opacity: 0.9;
}

.btn-accent {
  background: var(--color-accent);
  color: #0D1117;
  border-color: var(--color-accent);
  font-weight: 700;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
}

.btn-full {
  width: 100%;
}

.btn-lg {
  padding: 20px 32px;
  font-size: 18px;
  border-radius: 14px;
  min-height: 60px;
}

/* テキストエリア・入力欄
   font-size: 16px 必須 → 16px未満だとiPhoneが自動ズームする */
textarea,
input[type="text"],
input[type="date"],
input[type="number"],
input[type="email"],
input[type="search"],
select {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
  background: var(--color-bg-2);
  color: var(--color-text);
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237D8590' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(168,85,247,0.2);
}

/* バッジ・タグ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-primary { background: rgba(168,85,247,0.15); color: var(--color-primary); }
.badge-accent  { background: rgba(255,212,84,0.15); color: var(--color-accent); }
.badge-warning { background: rgba(236,72,153,0.15); color: var(--color-warning); }
.badge-danger  { background: rgba(255,69,96,0.15);  color: var(--color-danger); }
.badge-gray    { background: var(--color-bg-2);     color: var(--color-text-muted); }

/* ローディング */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--color-text-muted);
  padding: 24px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/*
 * z-index 階層（被り防止のための統一ルール）
 * --------------------------------------------------
 * 100  : ヘッダー（sticky）
 * 200  : ボトムナビ
 * 1000 : モーダル・オーバーレイ
 * 1100 : モーダル内コンテンツ
 * 2000 : トースト通知
 * --------------------------------------------------
 * 新規でz-indexを追加する際はこの階層に従うこと
 */

/* トースト通知（最前面） */
#toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 70px);
  bottom: auto;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  opacity: 0;
  background: var(--color-card);
  color: var(--color-text);
  border: 1px solid var(--color-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 2000;
  transition: transform 0.25s ease, opacity 0.25s ease;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
  box-shadow: var(--glow-primary), var(--shadow-lg);
}

#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ナビゲーション（下タブ）z-index: 200 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* iOSスクロール時にコンテンツが透けないよう不透明背景 + ブラー */
  background: rgba(22, 27, 34, 0.96);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 200;
  /* iPhone X以降のホームインジケータ分を確保 */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px 8px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 10px;
  gap: 3px;
  transition: color 0.2s;
  min-height: var(--nav-height);
}

.bottom-nav a.active {
  color: var(--color-primary);
}

.bottom-nav a:hover {
  color: var(--color-primary);
}

.bottom-nav .nav-icon {
  font-size: 22px;
}

/* ページ下部のナビ分のパディング：余裕を大きく取る */
.page-with-nav {
  /* ナビ高さ + セーフエリア + 十分なバッファ（iOSキーボード・スクロールバグ対策） */
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 32px);
}

@media (min-width: 720px) {
  body.page-with-desktop-right-nav.page-with-nav {
    padding-bottom: 24px;
    overflow-x: hidden;
  }

  body.page-with-desktop-right-nav .bl-screen {
    width: min(
      var(--bl-screen-width),
      calc(100vw - var(--desktop-nav-width) - var(--desktop-nav-gap) - 24px)
    );
    margin: 0;
    padding: 28px 24px 44px;
  }

  body.page-with-desktop-right-nav .bottom-nav {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: calc(var(--desktop-nav-width) + env(safe-area-inset-right, 0px));
    min-height: 100vh;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 8px;
    padding:
      max(18px, env(safe-area-inset-top, 0px))
      calc(12px + env(safe-area-inset-right, 0px))
      max(18px, env(safe-area-inset-bottom, 0px))
      12px;
    border-top: none;
    border-left: 1px solid var(--color-border);
    background: rgba(22, 27, 34, 0.94);
  }

  body.page-with-desktop-right-nav .bottom-nav .nav-handle {
    display: none;
  }

  body.page-with-desktop-right-nav .bottom-nav a {
    position: relative;
    flex: 0 0 auto;
    min-height: 72px;
    padding: 12px 8px;
    gap: 6px;
    font-size: 11px;
    border-radius: 18px;
  }

  body.page-with-desktop-right-nav .bottom-nav a.active,
  body.page-with-desktop-right-nav .bottom-nav a:hover {
    background: rgba(168, 85, 247, 0.08);
  }

  body.page-with-desktop-right-nav .bottom-nav a.active::before {
    content: "";
    position: absolute;
    top: 12px;
    right: 4px;
    bottom: 12px;
    width: 3px;
    border-radius: 999px;
    background: var(--color-primary);
    box-shadow: var(--glow-primary);
  }

  body.page-with-desktop-right-nav .bottom-nav .nav-icon {
    font-size: 20px;
  }
}

body.page-with-nav.page-calendar-wide {
  padding-bottom: 24px;
  overflow-x: hidden;
}

body.page-with-nav.page-calendar-wide .bl-screen {
  width: min(
    var(--bl-screen-width),
    calc(100vw - var(--desktop-nav-width) - var(--desktop-nav-gap) - 24px)
  );
  margin: 0;
  padding: 28px 24px 44px;
}

body.page-with-nav.page-calendar-wide .bottom-nav {
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  width: calc(var(--desktop-nav-width) + env(safe-area-inset-right, 0px));
  min-height: 100vh;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  padding:
    max(18px, env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    max(18px, env(safe-area-inset-bottom, 0px))
    12px;
  border-top: none;
  border-left: 1px solid var(--color-border);
  background: rgba(22, 27, 34, 0.94);
}

body.page-with-nav.page-calendar-wide .bottom-nav .nav-handle {
  display: none;
}

body.page-with-nav.page-calendar-wide .bottom-nav a {
  position: relative;
  flex: 0 0 auto;
  min-height: 72px;
  padding: 12px 8px;
  gap: 6px;
  font-size: 11px;
  border-radius: 18px;
}

body.page-with-nav.page-calendar-wide .bottom-nav a.active,
body.page-with-nav.page-calendar-wide .bottom-nav a:hover {
  background: rgba(168, 85, 247, 0.08);
}

body.page-with-nav.page-calendar-wide .bottom-nav a.active::before {
  content: "";
  position: absolute;
  top: 12px;
  right: 4px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: var(--color-primary);
  box-shadow: var(--glow-primary);
}

body.page-with-nav.page-calendar-wide .bottom-nav .nav-icon {
  font-size: 20px;
}

/* 共通ボトムシート z-index: 1100 */
.modal-sheet {
  background: var(--color-bg);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  position: fixed; bottom: 0; left: 0; right: 0;
  max-height: 80vh; overflow-y: auto;
  z-index: 1100;
}

/* フルスクリーンオーバーレイ z-index: 1000 */
.modal-overlay,
[class*="-overlay"],
[id*="-overlay"] {
  z-index: 1000;
}

/* テキスト */
.text-muted  { color: var(--color-text-muted); }
.text-sm     { font-size: 14px; }
.text-xs     { font-size: 12px; }
.text-center { text-align: center; }

/* セクションタイトル */
.section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--color-text);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* セパレーター */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: 16px 0;
}

/* ── スワイプ削除 ── */
.swipe-row {
  position: relative;
  overflow: hidden;
  width: 100%;
  transform: translateZ(0); /* GPU同一レイヤーにしてoverflow:hiddenを確実にクリップ */
}
.swipe-row-bg {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 80px;
  background: var(--color-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  cursor: pointer;
  user-select: none;
  z-index: 0;
}
.swipe-row-inner {
  position: relative;
  z-index: 1;
  transform: translateX(0);
  /* 背後の削除ボタン（swipe-row-bg）が透けないよう背景を塗りつぶす */
  /* ページごとに --swipe-row-bg で上書き可能 */
  background: var(--swipe-row-bg, var(--color-card));
  width: 100%;
  box-sizing: border-box;
  user-select: none; /* ドラッグ中のテキスト選択を防止 */
}
.swipe-row-inner.sw-snap {
  transition: transform 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
/* PCでマウスドラッグ中のカーソル（enableSwipeDelete と enableMouseSwipe の両方に対応） */
@media (hover: hover) {
  .swipe-row-inner,
  .diary-item,
  .receipt-item,
  .event-item {
    cursor: grab;
  }
  .swipe-row-inner:active,
  .diary-item:active,
  .receipt-item:active,
  .event-item:active {
    cursor: grabbing;
  }
}
