/* ===== 変数・リセット ===== */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273549;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99,102,241,0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239,68,68,0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --sidebar-w: 220px;
  --detail-w: 380px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

input, textarea, select, button { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); }

.hidden { display: none !important; }

/* ===== セットアップ画面 ===== */
#setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 540px;
  width: 100%;
  box-shadow: var(--shadow);
}

.setup-card h1 { font-size: 24px; margin-bottom: 8px; }
.setup-card > p { color: var(--text-muted); margin-bottom: 32px; }
.setup-card section { margin-bottom: 28px; }
.setup-card h2 { font-size: 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}

.hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ===== アプリレイアウト ===== */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== サイドバー ===== */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition);
  overflow-y: auto;
}

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

.logo { font-size: 17px; font-weight: 700; letter-spacing: -0.5px; }

nav { padding: 10px 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; }

.sidebar-section {
  padding: 14px 8px 4px;
  border-top: 1px solid var(--border);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.add-small-btn {
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 2px;
  transition: color var(--transition);
}
.add-small-btn:hover { color: var(--text); }

.category-item, .tag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.category-item:hover, .tag-item:hover { background: var(--surface2); color: var(--text); }
.category-item.active, .tag-item.active { color: var(--text); font-weight: 500; }

.color-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.icon-text-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  width: 100%;
}
.icon-text-btn:hover { background: var(--surface2); color: var(--text); }

/* ===== メインエリア ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 18px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 10px; }

#mobile-menu-btn { display: none; }

#search-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  width: 200px;
  outline: none;
  transition: border-color var(--transition);
}
#search-input:focus { border-color: var(--accent); }

#task-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ===== タスクカード ===== */
#task-list { display: flex; flex-direction: column; gap: 10px; }

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.task-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.task-card.active { border-color: var(--accent); background: var(--surface2); }
.task-card.done .task-card-title { text-decoration: line-through; opacity: 0.5; }

.task-card-check {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  transition: border-color var(--transition), background var(--transition);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}

.task-card.done .task-card-check {
  background: var(--success);
  border-color: var(--success);
}
.task-card.in-progress .task-card-check {
  border-color: var(--accent);
}

.task-card-body { flex: 1; min-width: 0; }
.task-card-title { font-weight: 500; font-size: 14px; margin-bottom: 4px; }

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}

.deadline-chip {
  font-size: 11px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 3px;
}

.deadline-chip.overdue { color: var(--danger); }
.deadline-chip.today { color: var(--warning); }

.task-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.todo { background: var(--text-muted); }
.status-dot.in-progress { background: var(--accent); }
.status-dot.done { background: var(--success); }

/* ===== 空状態 ===== */
#empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}
#empty-state p { margin-bottom: 20px; font-size: 16px; }

/* ===== 詳細パネル ===== */
#detail-panel {
  width: var(--detail-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-actions { display: flex; gap: 8px; }

.detail-body { padding: 20px; }

#detail-status-row { margin-bottom: 16px; }
#detail-status {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  outline: none;
}

#detail-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.4;
}

#detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

#detail-description {
  color: var(--text-muted);
  margin-bottom: 24px;
  white-space: pre-wrap;
  line-height: 1.7;
}

#detail-subtasks-section { margin-bottom: 24px; }
#detail-subtasks-section h3 { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; }

#detail-subtasks { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.subtask-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}

.subtask-item input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; flex-shrink: 0; cursor: pointer; }
.subtask-item label { cursor: pointer; font-size: 13px; }
.subtask-item.done label { text-decoration: line-through; opacity: 0.5; }

/* ===== AIパネル ===== */
#ai-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
}

#ai-panel h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 12px;
}

#ai-buttons { display: flex; flex-direction: column; gap: 8px; }

.ai-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color var(--transition), background var(--transition);
  text-align: left;
}

.ai-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

#ai-output {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

#ai-result {
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--text);
  max-height: 300px;
  overflow-y: auto;
}

#ai-result h4 { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
#ai-result ul { padding-left: 18px; }
#ai-result li { margin-bottom: 4px; }

#ai-apply-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

#ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

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

/* ===== モーダル ===== */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-small { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 { font-size: 17px; font-weight: 700; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ===== フォーム ===== */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 500; color: var(--text-muted); }
.required { color: var(--danger); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

input[type="text"], input[type="password"], input[type="date"],
input[type="search"], textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--transition);
  color: var(--text);
}

input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }

.tag-selector { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-option {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-muted);
}

.tag-option.selected { font-weight: 600; }

/* ===== カラーピッカー ===== */
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }

.color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition);
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: white; }

/* ===== ボタン ===== */
.btn-primary {
  background: var(--accent);
  color: white;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: border-color var(--transition), color var(--transition);
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: background var(--transition);
}
.btn-danger:hover { background: var(--danger); color: white; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 15px;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ===== Google 連携パネル ===== */
#google-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
  margin-top: 16px;
}
#google-panel h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 12px;
}
#google-buttons { display: flex; flex-direction: column; gap: 8px; }
#google-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--success);
}

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== モバイル対応 ===== */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  #mobile-menu-btn { display: flex; }
  #sidebar-toggle { display: none; }
  #detail-panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    z-index: 50;
    width: min(var(--detail-w), 100vw);
  }
  .header-right { gap: 8px; }
  #search-input { width: 140px; }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  #main-header { padding: 12px 16px; }
  #task-container { padding: 14px 16px; }
  .modal-card { padding: 20px; }
  #search-input { display: none; }
}
