/**
 * Sketchdule - デザインシステム & コアスタイル
 * 白基調・シンプルカレンダー (Komorebi / Lifebear) スタイル
 * iOS セーフエリア（ノッチ・時計）完全対応
 */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* 白基調カラーパレット */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.92);
  
  --border-subtle: #f1f5f9;
  --border-medium: #e2e8f0;
  --border-active: #2563eb;

  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --accent-primary: #2563eb;
  --accent-secondary: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  /* 上品なシャドウ */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
  position: fixed; /* iOSの画面下部バウンスによるナビバーめり込みを防止 */
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

/* アプリコンテナ */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  position: relative;
  background-color: var(--bg-primary);
}

/* ヘッダー: iOSノッチ（時計・ステータスバー）と絶対に被らないようセーフエリアを設定 */
.app-header {
  display: flex;
  flex-direction: column;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-medium);
  z-index: 30;
  flex-shrink: 0;
  padding-top: max(8px, env(safe-area-inset-top, 0px)); /* iPhone11の時計・ノッチを完全回避 */
  transition: all 0.2s ease;
}

.header-main {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  width: 100%;
}

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

.logo-icon {
  width: 32px;
  height: 32px;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  flex-shrink: 0;
}

/* 前後ナビゲーション */
.nav-controls {
  display: flex;
  align-items: center;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  color: var(--text-primary);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.nav-btn:active {
  transform: scale(0.96);
}

.current-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* 同期ランプ（枠・テキストなし、小さな丸ランプのみ） */
.sync-lamp {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s ease;
}

.sync-lamp.saved .status-dot {
  background: #10b981; /* 🟢 正常保存 */
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.sync-lamp.syncing .status-dot, .sync-lamp.pending .status-dot {
  background: #f59e0b; /* 🟡 同期中 */
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
  animation: pulse 1.2s infinite ease-in-out;
}

.sync-lamp.error .status-dot {
  background: #ef4444; /* 🔴 エラー */
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.7);
}

.sync-lamp.local .status-dot {
  background: #94a3b8; /* グレー（ローカル保存・未ログイン） */
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* アカウントボタン（丸アイコンのみ、枠・テキストなし） */
.auth-icon-btn {
  background: transparent;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: opacity 0.15s ease;
}

.auth-icon-btn:hover {
  opacity: 0.8;
}

.user-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* 歯車ボタン（枠なしフラット） */
.icon-btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.icon-btn-ghost:hover {
  color: var(--text-primary);
  background: #f1f5f9;
}

/* メインステージ（上部ヘッダーと下部ボトムバーに挟まれた領域全体） */
.main-stage {
  flex: 1;
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  min-height: 0;
}

/* 最下部固定ナビゲーションバー（背景色付き、スリム化＆カレンダーと被らない設計） */
.app-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #f8fafc;
  border-top: 1px solid var(--border-medium);
  padding-top: 4px;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: max(6px, calc(env(safe-area-inset-bottom, 0px) + 5px)); /* ホームバーの上にスリムに配置 */
  z-index: 25;
  flex-shrink: 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

.bottom-tools-area {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.bottom-tools-area::-webkit-scrollbar { display: none; }

.app-bottom-bar.mode-navigation .bottom-tools-area {
  display: none; /* 操作モード時はツール群を隠してスッキリ */
}

.bottom-divider {
  width: 1px;
  height: 20px;
  background: var(--border-medium);
  flex-shrink: 0;
}

.tool-btn-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* 背面: カレンダーレイヤー */
.calendar-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
}

/* 前面: 手書きCanvasレイヤー */
.canvas-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  touch-action: none;
}

#sketch-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* モーダル */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: #ffffff;
  border: 1px solid var(--border-medium);
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body {
  padding: 22px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent-primary);
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.4;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.btn-primary {
  background: var(--accent-primary);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: #1d4ed8;
}

/* ロックアウト画面 */
.blocked-card {
  text-align: center;
  padding: 36px 24px;
}

.lock-icon-container {
  width: 56px;
  height: 56px;
  background: #fee2e2;
  border: 2px solid var(--danger);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--danger);
}

.blocked-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.blocked-email {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--danger);
  background: #fef2f2;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  margin-bottom: 14px;
}

.blocked-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* スマホ向けヘッダー最適化 */
@media (max-width: 640px) {
  .header-main {
    padding: 0 10px;
    height: 48px;
  }

  .current-title {
    font-size: 1.05rem;
  }

  .nav-btn {
    padding: 3px 6px;
    font-size: 0.78rem;
  }

  .status-badge {
    padding: 5px;
    border-radius: 50%;
  }

  .status-text {
    display: none;
  }

  .auth-btn {
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .auth-btn-label {
    display: none;
  }

  .settings-btn {
    width: 32px;
    height: 32px;
  }
}
