/* ============================================
   ALPHA DESK — Hedge Fund Trader Task Manager
   Dark Financial Theme with Premium Aesthetics
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── CSS Variables ─── */
:root {
  --bg-primary: #080c10;
  --bg-secondary: #0d1117;
  --bg-card: #111820;
  --bg-card-hover: #162030;
  --bg-modal: #0f1923;
  --bg-sidebar: #0a0f17;

  --border: rgba(32, 201, 151, 0.12);
  --border-strong: rgba(32, 201, 151, 0.25);

  --accent: #20c997;
  --accent-dim: rgba(32, 201, 151, 0.15);
  --accent-glow: rgba(32, 201, 151, 0.35);

  --gold: #ffc107;
  --gold-dim: rgba(255, 193, 7, 0.15);

  --red: #ff4d6d;
  --red-dim: rgba(255, 77, 109, 0.15);

  --yellow: #ffd60a;
  --yellow-dim: rgba(255, 214, 10, 0.12);

  --text-primary: #e8f0fe;
  --text-secondary: #8899aa;
  --text-muted: #4a5568;

  --sidebar-width: 260px;
  --topbar-height: 68px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-main: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(32, 201, 151, 0.06) inset;
  --shadow-modal: 0 24px 80px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(32, 201, 151, 0.1) inset;
  --shadow-glow: 0 0 24px rgba(32, 201, 151, 0.2);
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  background-color: var(--bg-sidebar);
  /* FIX PWA GAP: Make bottom native gap match the bottom nav bar */

  /* スマホでのダブルタップズームや不要なハイライトを防止 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none;
  /* iOS Safari プルトゥリフレッシュやPWAでのバウンス防止 */
  width: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* ─── Canvas Background ─── */
#bgCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
}

/* ─── App Shell ─── */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* FIX PWA GAP: 100dvh is buggy on iOS standalone mode. Use strict 100vh instead. */
@media (display-mode: standalone) {

  html,
  body,
  .app-shell {
    height: 100vh !important;
  }
}

html.pwa-standalone body,
html.pwa-standalone .app-shell {
  height: 100vh !important;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
  transition: var(--transition);
  overflow-y: auto;
  /* スクロールをここで制御 */
  overflow-x: hidden;
  scrollbar-gutter: stable;
  /* 全セクションで幅を統一 */
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  color: var(--accent);
  font-size: 22px;
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {

  0%,
  100% {
    text-shadow: 0 0 8px var(--accent-glow);
    opacity: 1;
  }

  50% {
    text-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-glow);
    opacity: 0.8;
  }
}

.logo-text {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
}

/* ─── Sidebar Nav ─── */
.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-right: 48px;
  /* バッジ用スペース */
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 13.5px;
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
  border-color: var(--border);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-strong);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 8px var(--accent-glow);
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
}

.nav-label {
  flex: 1;
}

.nav-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-secondary);
  font-weight: 600;
  position: absolute;
  /* 位置を固定 */
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.nav-badge.urgent {
  background: var(--red-dim);
  color: var(--red);
}

.nav-badge.medium {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.nav-badge.low {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-badge.done {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ─── Categories ─── */
.sidebar-categories {
  flex: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 0 12px 16px;
  border-bottom: 1px solid var(--border);
}

.section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 6px;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ＋ add button next to label */
.cat-add-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 1px 6px;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.cat-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* cat item — flex for delete button */
.cat-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 7px 12px;
  padding-right: 48px;
  /* ナビゲーションと合わせる */
  border-radius: var(--radius-sm);
  background: none;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 12.5px;
  text-align: left;
  transition: var(--transition);
  position: relative;
  /* iOS等での長押しテキスト選択防止 */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.cat-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}

@media (hover: hover) {
  .cat-item:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
  }
}

.cat-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--border);
}

/* × delete button on each custom category */
.cat-del-btn {
  opacity: 0;
  visibility: hidden;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 3px;
  transition: var(--transition);
  flex-shrink: 0;
  position: absolute;
  right: 6px;
  /* バッジよりさらに右側に配置 */
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

/* デスクトップ用ホバー表示 */
@media (hover: hover) {
  .cat-item:hover .cat-del-btn {
    opacity: 1;
    visibility: visible;
  }
}

/* モバイル用：選択中（アクティブ時）に削除ボタンを表示 */
.cat-item.active .cat-del-btn {
  opacity: 1;
  visibility: visible;
}

.cat-del-btn:hover {
  color: var(--red);
  background: var(--red-dim);
}

/* inline add form */
.cat-add-form {
  padding: 6px 4px 4px;
}

.cat-add-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  margin-bottom: 6px;
  transition: var(--transition);
}

.cat-add-input::placeholder {
  color: var(--text-muted);
}

.cat-add-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.cat-add-actions {
  display: flex;
  gap: 6px;
}

.cat-add-ok {
  flex: 1;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--bg-primary);
  font-family: var(--font-main);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 0;
  cursor: pointer;
  transition: var(--transition);
}

.cat-add-ok:hover {
  filter: brightness(1.1);
}

.cat-add-cancel {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 11px;
  padding: 5px 10px;
  cursor: pointer;
  transition: var(--transition);
}

.cat-add-cancel:hover {
  border-color: var(--red);
  color: var(--red);
}

.cat-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--border);
}

.cat-item-label {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  /* テキスト選択を無効化 */
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  /* iOSの長押しメニューを無効化 */
  transition: transform 0.2s ease;
}

/* 長押し（アクティブ）中の視覚フィードバック */
.cat-item:active .cat-item-label {
  transform: scale(0.96);
  opacity: 0.8;
}

.cat-edit-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 16px;
  /* iOSの自動ズーム防止 */
  padding: 1px 6px;
  line-height: normal;
  outline: none;
  min-width: 0;
}

/* ─── Sidebar Stats ─── */
.sidebar-stats {
  margin-top: auto;
  padding: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 20px var(--accent-glow);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
  margin-bottom: 10px;
}

.progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #66d9b8);
  border-radius: 10px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ─── Forex Live Ticker ─── */
.forex-ticker-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.forex-ticker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.forex-ticker-title {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
}

.forex-ticker-source {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-muted);
}

.forex-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.forex-pair-select {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 6px;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.forex-pair-select:hover,
.forex-pair-select:focus {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: rgba(32, 201, 151, 0.06);
}

.forex-pair-select option {
  background: #0f1923;
  color: var(--text-primary);
}

.forex-bid {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  min-width: 62px;
  text-align: right;
  text-shadow: 0 0 8px var(--accent-glow);
  transition: color 0.3s;
}

.forex-bid.loading {
  color: var(--text-muted);
  text-shadow: none;
}

.forex-bid.error {
  color: var(--red);
  text-shadow: none;
  font-size: 10px;
}

.forex-bid.flash {
  color: #fff;
  text-shadow: 0 0 12px var(--accent);
}

.forex-ticker-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.forex-updated {
  font-size: 9px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.forex-refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 1px 5px;
  cursor: pointer;
  line-height: 1.4;
  transition: var(--transition);
}

.forex-refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.forex-refresh-btn.spinning {
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-secondary);
}

/* ─── Topbar ─── */
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
}

.sidebar-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.topbar-title h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
}

.topbar-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 9px 14px 9px 34px;
  width: 220px;
  outline: none;
  transition: var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ─── Priority Bar ─── */
.priority-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.priority-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.priority-pill:hover {
  filter: brightness(1.2);
}

.priority-pill strong {
  font-family: var(--font-mono);
  font-size: 13px;
}

.priority-pill.high {
  background: var(--red-dim);
  color: var(--red);
}

.priority-pill.medium {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.priority-pill.low {
  background: var(--accent-dim);
  color: var(--accent);
}

.priority-divider {
  flex: 1;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-label {
  font-size: 12px;
  color: var(--text-muted);
}

.sort-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 12px;
  padding: 5px 10px;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

.sort-select:focus {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ─── Task Container ─── */
.task-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  scrollbar-width: thin;
  scrollbar-color: rgba(32, 201, 151, 0.2) transparent;
}

.task-container::-webkit-scrollbar {
  width: 5px;
}

.task-container::-webkit-scrollbar-track {
  background: transparent;
}

.task-container::-webkit-scrollbar-thumb {
  background: rgba(32, 201, 151, 0.2);
  border-radius: 10px;
}

/* ─── Empty State ─── */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.empty-state.visible {
  display: flex;
}

.empty-icon {
  font-size: 48px;
  color: var(--text-muted);
  margin-bottom: 16px;
  opacity: 0.4;
  animation: floatPulse 3s ease-in-out infinite;
}

@keyframes floatPulse {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.empty-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ─── Task List ─── */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Task Card ─── */
.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  animation: cardIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.task-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.task-card.p-high::before {
  background: var(--red);
  box-shadow: 0 0 10px rgba(255, 77, 109, 0.5);
}

.task-card.p-medium::before {
  background: var(--yellow);
}

.task-card.p-low::before {
  background: var(--accent);
}

.task-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}

.task-card.done {
  opacity: 0.45;
  filter: grayscale(30%);
}

/* ─── Drag Handle ─── */
.drag-handle {
  color: var(--text-muted);
  font-size: 16px;
  cursor: grab;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 2px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  user-select: none;
}

.task-card:hover .drag-handle {
  opacity: 1;
}

.drag-handle:hover {
  color: var(--accent);
}

.drag-handle:active {
  cursor: grabbing;
}

/* ─── Drag & Drop States ─── */
.task-card.dragging {
  opacity: 0.35;
  transform: scale(0.98);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}

/* Drop indicator: glowing line above */
.task-card.drop-above {
  border-top: 2px solid var(--accent);
  box-shadow: 0 -3px 12px var(--accent-glow);
  transform: translateY(2px);
}

/* Drop indicator: glowing line below */
.task-card.drop-below {
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 3px 12px var(--accent-glow);
  transform: translateY(-2px);
}

/* ─── Checkbox ─── */
.task-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border-strong);
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  margin-top: 2px;
}

.task-checkbox:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.task-checkbox.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
  font-size: 11px;
  font-weight: 700;
}

/* ─── Task Body ─── */
.task-body {
  flex: 1;
  min-width: 0;
}

.task-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.task-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* max-width: 400px;  <- はみ出ない限り表示するため解除 */
}

.task-card.done .task-title {
  color: var(--text-muted);
}

.task-cat-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
}

.cat-market {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
}

.cat-risk {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.cat-client {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

.cat-research {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

.cat-compliance {
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
}

.cat-other {
  background: rgba(107, 114, 128, 0.15);
  color: #9ca3af;
}

.task-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.task-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.task-meta-item.overdue {
  color: var(--red);
}

.task-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.task-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-family: var(--font-mono);
}

/* ─── Task Actions ─── */
.task-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: var(--transition);
  flex-shrink: 0;
}

.task-card:hover .task-actions {
  opacity: 1;
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}

.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.action-btn.del:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-dim);
}

/* ─── Buttons ─── */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #17a589);
  border: none;
  border-radius: var(--radius-md);
  color: var(--bg-primary);
  font-family: var(--font-main);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 18px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger {
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius-md);
  color: var(--red);
  font-family: var(--font-main);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger:hover {
  background: var(--red);
  color: white;
}

.btn-danger-sm {
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger-sm:hover {
  background: var(--red);
  color: white;
}

/* ─── Modal ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  /* SidebarやDetail Panelよりも上で確実な最前面へ */
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* 背景のスクロール防止 (iOS15+ 向け) */
  overscroll-behavior: none;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.open {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 32px);
  /* 画面からはみ出さないように設定 */
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  animation: slideUp 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
  /* 角丸を保つため */
}

.modal-sm {
  max-width: 380px;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  border-color: var(--red);
  color: var(--red);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

/* ─── Form Elements ─── */
.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.required {
  color: var(--red);
}

.form-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13.5px;
  padding: 10px 14px;
  outline: none;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  max-height: 160px;
}

.form-select {
  cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.5) sepia(1) saturate(3) hue-rotate(120deg);
  cursor: pointer;
}

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 240px;
}

.toast.success {
  border-color: var(--accent);
}

.toast.error {
  border-color: var(--red);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(30px);
  }
}

/* ─── Detail Panel ─── */
.panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1500;
  /* HeaderやSidebar(60), Bottom Nav(200)よりも手前に表示 */
  background: rgba(0, 0, 0, 0.4);
}

.panel-overlay.open {
  display: block;
  animation: fadeIn 0.2s ease;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--bg-modal);
  border-left: 1px solid var(--border-strong);
  z-index: 1501;
  /* Overlay(1500)よりも手前に表示 */
  display: flex;
  flex-direction: column;
  transition: right 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.4);
  /* モバイル・Safariでのスクロールを滑らかにし、オーバースクロールを防止 */
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

.detail-panel.open {
  right: 0;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.detail-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  /* スクロール領域内でのタッチスクロールを優先 */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.detail-field {
  margin-bottom: 20px;
}

.detail-field-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.detail-field-value {
  font-size: 13.5px;
  color: var(--text-primary);
  line-height: 1.6;
}

.detail-footer {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ─── Delete Confirm ─── */
.delete-confirm-text {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    height: auto;
    z-index: 60;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .task-actions {
    opacity: 1;
  }

  .topbar {
    padding: 0 16px;
  }

  .priority-bar {
    padding: 10px 16px;
    overflow-x: auto;
  }

  .task-container {
    padding: 16px;
    /* タスクの最後がBottom Navに隠れないようにする */
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  /* 画面幅が狭い場合はエクスポートボタンを非表示 */
  #exportBtn {
    display: none;
  }

  /* iOS Safari 入力ズーム防止: 16px未満はズームされるため強制的に16pxに設定 */
  .form-input,
  .cat-add-input,
  .search-input {
    font-size: 16px !important;
  }

  /* モバイル端末でのDetail Panel全画面化 */
  .detail-panel {
    width: 100%;
    right: -100%;
  }
}

/* ─── Login Overlay ─── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 360px;
  text-align: center;
  box-shadow: var(--shadow-modal);
  animation: cardIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 32px;
}

.login-sub {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 28px;
}

.btn-google-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  background: #fff;
  border: none;
  border-radius: var(--radius-md);
  color: #333;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 16px;
}

.btn-google-login:hover {
  background: #f1f3f4;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  transform: translateY(-1px);
}

.login-note {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ─── User Widget (Topbar) ─── */
.user-widget {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 30px;
  background: var(--bg-card);
  transition: var(--transition);
}

.user-widget:hover {
  border-color: var(--border-strong);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.btn-logout:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-dim);
}

/* ============================================================
   MOBILE / TOUCH DEVICE OPTIMIZATION (HOVER DISABLE)
   ============================================================ */
@media (hover: none) {

  .drag-handle,
  .task-actions {
    opacity: 1 !important;
  }
}

/* ============================================================
   MOBILE / iPHONE RESPONSIVE  (max-width: 768px)
   ============================================================ */

/* Bottom Nav: hidden on desktop */
.bottom-nav {
  display: none;
}

.mobile-sidebar-overlay {
  display: none;
}

@media (max-width: 768px) {

  /* Bottom Nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    /* Extend background below safe-area via ::after */
    overflow: visible;
  }

  /* Visual extension: fill the safe-area gap with nav background color.
     We use a background pseudo-element that stretches 100px below. */
  .bottom-nav::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: -100px;
    background: var(--bg-sidebar);
    z-index: -1;
    /* Put behind the flex items */
    pointer-events: none;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-main);
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item.active {
    color: var(--accent);
  }

  .bottom-nav-item.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--accent);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 0 8px var(--accent-glow);
  }

  .bottom-nav-icon {
    font-size: 16px;
    line-height: 1;
  }

  .bottom-nav-label {
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.02em;
  }

  .bottom-nav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 16px);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
    padding: 1px 5px;
    border-radius: 20px;
    min-width: 16px;
    text-align: center;
  }

  .bottom-nav-badge.urgent {
    background: var(--red-dim);
    color: var(--red);
  }

  .bottom-nav-badge.done {
    background: var(--accent-dim);
    color: var(--accent);
  }

  /* Sidebar: slide-in overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
    width: 280px;
    padding-top: env(safe-area-inset-top);
    padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
    overflow-y: auto;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.6);
  }

  .mobile-sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 299;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .mobile-sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Topbar */
  .topbar {
    height: 56px;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
  }

  .topbar-title h1 {
    font-size: 16px;
  }

  .topbar-time {
    display: none;
  }

  .search-wrapper {
    display: none;
  }

  /* Priority Bar */
  .priority-bar {
    padding: 8px 14px;
    gap: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .priority-bar::-webkit-scrollbar {
    display: none;
  }

  .priority-pill {
    padding: 4px 10px;
    font-size: 11px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .sort-controls {
    flex-shrink: 0;
  }

  /* Task Container */
  .task-container {
    padding: 12px 12px calc(80px + env(safe-area-inset-bottom));
  }

  /* Task Card */
  .task-card {
    padding: 14px 14px 14px 12px;
    margin-bottom: 10px;
  }

  .drag-handle {
    display: none;
  }

  .task-title {
    font-size: 14px;
  }

  .task-desc {
    font-size: 12px;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .task-actions {
    opacity: 1;
  }

  .action-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .task-checkbox {
    width: 24px;
    height: 24px;
    font-size: 13px;
    flex-shrink: 0;
  }

  /* Modal: bottom sheet */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    overflow-y: auto;
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    animation: none;
  }

  .modal-overlay.open .modal {
    transform: translateY(0);
    animation: none;
  }

  .modal::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 12px auto -4px;
  }

  .modal-sm {
    max-height: 60vh;
  }

  .modal-body {
    padding: 16px 20px;
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  /* Detail Panel: bottom sheet */
  .detail-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    width: 100%;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
  }

  .detail-panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 12px auto 0;
  }

  .detail-panel.open {
    transform: translateY(0);
  }

  /* Login */
  .login-card {
    width: calc(100vw - 40px);
    max-width: 380px;
    padding: 36px 28px;
  }

  .login-title {
    font-size: 18px;
  }

  /* User Widget */
  .user-name {
    display: none;
  }

  .user-widget {
    padding: 4px;
  }

  /* Toast */
  .toast-container {
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }

  .btn-primary {
    padding: 9px 14px;
    font-size: 13px;
  }
}

/* iPhone SE / small screens */
@media (max-width: 375px) {
  .bottom-nav-label {
    font-size: 8px;
  }

  .task-card {
    padding: 12px;
  }
}


/* ============================================================
   FIX: Desktop sidebar closed state
   ============================================================ */
@media (min-width: 769px) {
  .sidebar.closed {
    width: 0;
    padding: 0;
    border-right: none;
    overflow: hidden;
    min-width: 0;
  }
}

/* ============================================================
   FIX: Mobile sidebar overlay — no dimming (transparent)
   ============================================================ */
@media (max-width: 768px) {
  .mobile-sidebar-overlay {
    background: transparent;
  }

  .mobile-sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* FIX: Scroll — allow sidebar content to scroll on mobile */
  .sidebar {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ============================================================
   FIX: Vertical scroll on small desktop windows
   ============================================================ */
@media (max-height: 600px) and (min-width: 769px) {
  .task-container {
    overflow-y: auto;
  }

  .sidebar {
    overflow-y: auto;
  }
}


/* ============================================================
   FIX: Sidebar scrollable on ALL screen sizes
   ============================================================ */
.sidebar {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* Ensure flex children can shrink to allow inner scroll */
.main-content {
  min-height: 0;
}





/* ============================================================
   FIX: Scrollbar styling (desktop) - thin + accent color
   ============================================================ */

/* Sidebar, Task container, and Modal body scrollbar */
.sidebar,
.task-container,
.modal-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(32, 201, 151, 0.2) transparent;
}

.sidebar::-webkit-scrollbar,
.task-container::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 3px !important;
}

.sidebar::-webkit-scrollbar-track,
.task-container::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: transparent !important;
}

.sidebar::-webkit-scrollbar-thumb,
.task-container::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(32, 201, 151, 0.2) !important;
  border-radius: 10px !important;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.task-container::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(32, 201, 151, 0.45) !important;
}

/* ============================================================
   FIX: iPhone sidebar scroll
   -webkit-overflow-scrolling: touch + overflow-y: scroll
   (iOS Safari requires 'scroll' not 'auto' for reliable touch scroll)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
}

/* ============================================================
   FIX #5: PWA Standalone - safe-area gap fix (definitive)
   Two-layer approach:
     1. padding-bottom: env(safe-area-inset-bottom)  → positions items above home bar
     2. .bottom-nav::after (in mobile media query)   → fills any remaining visual gap
   ============================================================ */
html.pwa-standalone .bottom-nav {
  padding-bottom: env(safe-area-inset-bottom) !important;
}

html.pwa-standalone .task-container {
  padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
}

html.pwa-standalone .topbar {
  height: calc(56px + env(safe-area-inset-top)) !important;
  padding-top: calc(env(safe-area-inset-top) + 8px) !important;
  padding-bottom: 8px;
  align-items: flex-end;
}

html.pwa-standalone .sidebar {
  padding-top: calc(env(safe-area-inset-top) + 20px) !important;
}

html.pwa-standalone .login-overlay {
  padding-top: env(safe-area-inset-top);
}

/* Mirror with @media display-mode for Safari compatibility */
@media (display-mode: standalone) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom) !important;
  }

  .task-container {
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }

  .topbar {
    height: calc(56px + env(safe-area-inset-top)) !important;
    padding-top: calc(env(safe-area-inset-top) + 8px) !important;
    padding-bottom: 8px;
    align-items: flex-end;
  }

  .sidebar {
    padding-top: calc(env(safe-area-inset-top) + 20px) !important;
  }

  .login-overlay {
    padding-top: env(safe-area-inset-top);
  }
}

/* ============================================================
   FIX #6 + #3: Overlay must NOT cover the sidebar
   Without this fix, the overlay steals all touch events
   on the sidebar (scroll + item taps don't work on iPhone)
   ============================================================ */
@media (max-width: 768px) {
  .mobile-sidebar-overlay.active {
    /* Only cover the area to the RIGHT of the sidebar */
    left: 280px;
  }
}

/* ─── Recurring Tasks UI ─── */
.repeat-days-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.repeat-day-lbl {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.repeat-day-cb {
  display: none;
}

.repeat-day-lbl span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-main);
  transition: var(--transition);
}

.repeat-day-cb:checked+span {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(32, 201, 151, 0.15);
}

.repeat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--accent);
  background: rgba(32, 201, 151, 0.1);
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 6px;
  border: 1px solid rgba(32, 201, 151, 0.2);
  vertical-align: middle;
}

.repeat-badge svg {
  width: 10px;
  height: 10px;
  margin-right: 3px;
  fill: currentColor;
}

/* ─── Quick Memo Feature ─── */
.sidebar-memo-section {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
}

.memo-toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 12.5px;
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: var(--transition);
}

.memo-toggle-btn:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.memo-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: -420px;
  width: 400px;
  background: var(--bg-modal);
  border-left: 1px solid var(--border-strong);
  z-index: 1600;
  display: flex;
  flex-direction: column;
  transition: right 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.memo-panel.open {
  right: 0;
}

.memo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.memo-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.memo-header-icon {
  font-size: 18px;
}

.memo-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.memo-body {
  flex: 1;
  min-height: 0;
  padding: 0;
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

#memoTextarea {
  flex: 1;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 16px; /* Prevent iOS auto-zoom */
  line-height: 1.6;
  padding: 24px;
  resize: none;
  scrollbar-width: thin;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none; /* Block propagation to body */
}

.memo-footer {
  padding: 12px 24px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.memo-status {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.memo-panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1599;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.memo-panel-overlay.open {
  display: block;
  animation: fadeIn 0.3s ease;
}

@media (max-width: 768px) {
  .memo-panel {
    width: 100%;
    right: -100%;
  }
  #memoTextarea {
    font-size: 16px; /* Prevent iOS auto-zoom */
  }
}

/* Body lock for memo open - Strict multi-lock for iOS */
html.memo-open,
body.memo-open {
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
  overscroll-behavior: none;
}