/* === カラートークン === */
:root {
  --bg: #0f0f0f;
  --bg-raised: #1a1a1a;
  --surface: #1e1e1e;
  --surface-2: #2a2a2a;
  --border: #333;
  --border-2: #444;
  --text: #e5e5e5;
  --text-sub: #888;
  --accent: #60a5fa;
  --success: #4ade80;
  --danger: #f87171;
  --info: #60a5fa;

  --xs: 4px;
  --sm: 8px;
  --md: 16px;
  --lg: 24px;
  --xl: 32px;
  --2xl: 48px;
}

/* === リセット + ベース === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', 'Noto Sans JP', sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.8;
  letter-spacing: 0.04em;
  color: var(--text);
  background: var(--bg);
  overflow-wrap: anywhere;
  line-break: strict;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  padding-top: env(safe-area-inset-top);
}

h2, h3 {
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.02em;
  font-feature-settings: "palt";
}

h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--text-sub); }

/* === タブナビゲーション === */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--xs);
  padding: var(--sm) 0;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 12px;
  cursor: pointer;
  transition: color 150ms;
}

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

.tab-content { display: none; padding: var(--md); max-width: 560px; margin: 0 auto; }
.tab-content.active { display: block; }

/* === クリップボード保存ボタン === */
.btn-clipboard-save {
  width: 100%;
  min-height: 48px;
  padding: var(--md);
  margin-bottom: var(--md);
  background: var(--accent);
  color: #0f0f0f;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms;
}

.btn-clipboard-save:active { background: #4a90e0; }

.manual-input {
  margin-bottom: var(--md);
}

.manual-input summary {
  font-size: 12px;
  color: var(--text-sub);
  cursor: pointer;
  padding: var(--xs) 0;
}

.manual-input .input-section {
  margin-top: var(--sm);
}

/* === 入力セクション === */
.input-section {
  display: flex;
  gap: var(--sm);
  margin-bottom: var(--md);
}

.input-section textarea {
  flex: 1;
  min-height: 44px;
  padding: var(--sm) var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  resize: none;
}

.input-section textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.input-section textarea::placeholder { color: var(--text-sub); }

/* === 検索 === */
.search-section { margin-bottom: var(--md); }

.search-section input {
  width: 100%;
  height: 36px;
  padding: var(--sm) var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}

.search-section input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-section input::placeholder { color: var(--text-sub); }

/* === ボタン === */
.btn-primary {
  min-width: 44px;
  min-height: 44px;
  padding: var(--sm) var(--md);
  background: var(--accent);
  color: #0f0f0f;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms;
  white-space: nowrap;
}

.btn-primary:active { background: #4a90e0; }

.btn-outline {
  min-height: 44px;
  padding: var(--sm) var(--md);
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 150ms;
}

.btn-outline:active { background: var(--surface-2); }

.btn-danger {
  min-height: 44px;
  padding: var(--sm) var(--md);
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #0f0f0f;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
}

.btn-file-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* === アイテムリスト === */
.item-list { list-style: none; }

.item-card {
  position: relative;
  padding: var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: var(--sm);
  cursor: pointer;
  transition: background 150ms;
  overflow: hidden;
}

.item-card:active { background: var(--surface-2); }

.item-card.pinned { border-left: 3px solid var(--accent); }

.item-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.6;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-top: var(--xs);
  font-size: 12px;
  color: var(--text-sub);
  font-variant-numeric: tabular-nums;
}

.category-badge {
  display: inline-block;
  padding: 2px var(--sm);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* === タブヘッダー === */
.tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--md);
}

/* === カテゴリグループ === */
.category-group { margin-bottom: var(--lg); }
.category-group-title {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: var(--sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* === 設定 === */
.settings-group {
  margin-bottom: var(--xl);
}

.settings-group h3 { margin-bottom: var(--md); }

.settings-group select {
  width: 100%;
  height: 36px;
  padding: var(--sm) var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.settings-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-group button,
.settings-group .btn-file-label {
  display: block;
  width: 100%;
  margin-bottom: var(--sm);
  text-align: center;
}

.add-category-row {
  display: flex;
  gap: var(--sm);
  align-items: center;
}

.add-category-row input[type="text"] {
  flex: 1;
  height: 36px;
  padding: var(--sm) var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.add-category-row input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sm) var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: var(--sm);
}

.category-item-name {
  display: flex;
  align-items: center;
  gap: var(--sm);
}

.category-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* === モーダル === */
dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - var(--xl));
  max-width: 400px;
  padding: var(--lg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

dialog::backdrop { background: rgba(0,0,0,0.6); }

dialog h3 {
  color: var(--text);
  margin-bottom: var(--md);
}

dialog input,
dialog textarea,
dialog select {
  width: 100%;
  padding: var(--sm) var(--md);
  margin-bottom: var(--md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

dialog input:focus,
dialog textarea:focus,
dialog select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: var(--sm);
  justify-content: flex-end;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-bottom: var(--md);
  min-height: 44px;
  cursor: pointer;
}

/* === トースト === */
.toast {
  position: fixed;
  top: calc(var(--lg) + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--sm) var(--lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;
  z-index: 200;
}

.toast.show { opacity: 1; }

/* === スワイプ削除 === */
.item-card.swiping { transition: transform 150ms; }
.item-card .delete-bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border-radius: 0 8px 8px 0;
  opacity: 0;
}

.item-card.swiped .delete-bg { opacity: 1; }

/* === 空状態 === */
.empty-state {
  text-align: center;
  padding: var(--2xl) var(--md);
  color: var(--text-sub);
  font-size: 14px;
}

/* === テンプレートのタイトル === */
.item-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--xs);
  color: var(--text);
}

/* === レスポンシブ === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

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