:root {
  --sidebar-width: 220px;
  --color-bg: #fafafa;
  --color-surface: #fff;
  --color-border: #e0e0e0;
  --color-accent: #0075ca;
  --color-text: #222;
  --color-muted: #666;
  --color-danger: #c0392b;
  --header-height: 48px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--color-text); background: var(--color-bg); }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-height);
  background: var(--color-accent); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 0 16px; z-index: 100;
}
.app-logo { color: #fff; font-weight: bold; font-size: 18px; }
.search-form { flex: 1; max-width: 400px; }
.search-form input { width: 100%; padding: 6px 10px; border-radius: 4px; border: none; font-size: 14px; }
.header-nav a { color: #fff; margin-left: 12px; font-size: 13px; }

.app-body { display: flex; margin-top: var(--header-height); height: calc(100vh - var(--header-height)); }

.sidebar { width: var(--sidebar-width); flex-shrink: 0; border-right: 1px solid var(--color-border); overflow-y: auto; background: var(--color-surface); padding: 12px 0; }
.sidebar-section { margin-bottom: 8px; }
.sidebar-section h3 { padding: 6px 16px; font-size: 11px; text-transform: uppercase; color: var(--color-muted); letter-spacing: 0.05em; }
.sidebar-section ul { list-style: none; }
.sidebar-section li a { display: block; padding: 5px 16px; color: var(--color-text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-section li a:hover, .sidebar-section li a.active { background: #e8f0fe; color: var(--color-accent); text-decoration: none; }
.sidebar-section .count { font-size: 11px; color: var(--color-muted); float: right; }

.main-content { flex: 1; overflow-y: auto; padding: 24px; }

.note-list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.note-list { list-style: none; }
.note-item { border-bottom: 1px solid var(--color-border); }
.note-item-link { display: block; padding: 12px 8px; color: var(--color-text); }
.note-item-link:hover { background: #f5f5f5; text-decoration: none; }
.note-item-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.note-item-excerpt { font-size: 12px; color: var(--color-muted); margin: 2px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-meta { font-size: 12px; color: var(--color-muted); }
.note-item-meta .tag { background: #e8f0fe; color: var(--color-accent); border-radius: 3px; padding: 1px 5px; margin-right: 4px; }
.note-item-meta .notebook { margin-right: 8px; }
.note-item-meta .date { float: right; }

.note-detail-header { margin-bottom: 24px; }
.note-detail-header h1 { font-size: 24px; margin-bottom: 8px; }
.note-detail-meta { font-size: 13px; color: var(--color-muted); margin-bottom: 12px; }
.note-detail-meta .tag { background: #e8f0fe; color: var(--color-accent); border-radius: 3px; padding: 1px 6px; margin-right: 4px; }
.note-detail-actions { display: flex; gap: 8px; }
.note-body { line-height: 1.7; max-width: 800px; cursor: text; }
.note-body h1, .note-body h2, .note-body h3 { margin: 1em 0 0.5em; }
.note-body p { margin-bottom: 0.8em; }
.note-body code { background: #f4f4f4; padding: 1px 4px; border-radius: 3px; font-family: monospace; }
.note-body pre { background: #f4f4f4; padding: 12px; border-radius: 4px; overflow-x: auto; margin-bottom: 1em; }
.note-body blockquote { border-left: 3px solid var(--color-border); padding-left: 12px; color: var(--color-muted); margin-bottom: 1em; }
.note-attachments { margin-top: 24px; border-top: 1px solid var(--color-border); padding-top: 16px; }
.attachment-image { max-width: 100%; max-height: 400px; }

/* 添付パネル（編集画面） */
.attach-panel {
  border: 1px solid var(--color-border);
  border-radius: 4px;
  margin-top: 12px;
  background: var(--color-surface);
}
.attach-panel-header {
  font-size: 12px;
  color: var(--color-muted);
  padding: 6px 12px;
  border-bottom: 1px solid var(--color-border);
}
.attach-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  min-height: 36px;
}
.attach-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  background: #fafafa;
  max-width: 180px;
}
.attach-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
}
.attach-icon { font-size: 20px; }
.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
}
.attach-delete {
  border: none;
  background: none;
  color: var(--color-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.attach-delete:hover { color: var(--color-danger); }
.attach-drop-hint {
  font-size: 11px;
  color: var(--color-muted);
  padding: 4px 12px 8px;
  text-align: center;
}

/* ドラッグオーバー */
.drag-over { outline: 2px dashed var(--color-accent); outline-offset: -2px; }

/* トースト通知 */
.attach-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 200;
}
.attach-toast--success { background: #1a7f37; color: #fff; }
.attach-toast--error   { background: var(--color-danger); color: #fff; }

.btn { display: inline-block; padding: 6px 14px; border: 1px solid var(--color-border); border-radius: 4px; font-size: 13px; cursor: pointer; background: #fff; color: var(--color-text); }
.btn:hover { background: #f0f0f0; text-decoration: none; }
.btn-primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-primary:hover { background: #005fa3; }
.btn-danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover { background: #fdf0f0; }

.empty { color: var(--color-muted); padding: 32px 0; text-align: center; }
.pagination { margin-top: 16px; display: flex; gap: 8px; align-items: center; }
.tag-cloud { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.tag-cloud li a { background: #e8f0fe; color: var(--color-accent); border-radius: 4px; padding: 4px 10px; font-size: 13px; }
.notebook-list { list-style: none; }
.notebook-list li { padding: 8px 0; border-bottom: 1px solid var(--color-border); }

/* Note editor */
.note-editor { display: flex; flex-direction: column; height: 100%; }
.editor-toolbar { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--color-border); margin-bottom: 12px; }
.editor-title { font-size: 20px; font-weight: 600; border: none; outline: none; padding: 4px 0; width: 100%; }
.editor-meta { display: flex; gap: 8px; }
.editor-meta select, .editor-meta input { padding: 4px 8px; border: 1px solid var(--color-border); border-radius: 4px; font-size: 13px; }
.editor-meta input { flex: 1; }
.editor-actions { display: flex; gap: 8px; }
.editor-cm { flex: 1; border: 1px solid var(--color-border); border-radius: 4px; overflow: auto; min-height: 400px; }
.editor-cm .cm-editor { height: 100%; }

/* Import / Export pages */
.import-page, .export-page { max-width: 640px; }
.import-page h1, .export-page h1 { font-size: 22px; margin-bottom: 6px; }
.page-desc { color: var(--color-muted); margin-bottom: 24px; }
.alert { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fdf0f0; border: 1px solid var(--color-danger); color: var(--color-danger); }
.alert-info  { background: #e8f0fe; border: 1px solid var(--color-accent); color: var(--color-accent); }
.import-results { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 6px; padding: 20px; margin-bottom: 24px; }
.import-results h2 { font-size: 16px; margin-bottom: 12px; }
.results-table { border-collapse: collapse; width: 100%; }
.results-table th, .results-table td { padding: 6px 12px; border: 1px solid var(--color-border); font-size: 14px; }
.results-table th { background: #f5f5f5; text-align: left; width: 120px; }
.import-warnings { margin-top: 12px; }
.import-warnings h3 { font-size: 13px; color: var(--color-muted); margin-bottom: 6px; }
.import-warnings ul { font-size: 13px; color: var(--color-danger); padding-left: 18px; }
.section-divider { border: none; border-top: 1px solid var(--color-border); margin: 24px 0; }
.import-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; font-weight: 500; }
.form-group .required { color: var(--color-danger); }
.form-control { padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 4px; font-size: 14px; }
.form-check label { font-size: 13px; display: flex; align-items: center; gap: 6px; font-weight: normal; }
.form-actions { margin-top: 8px; }
.export-section { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 6px; padding: 20px; margin-bottom: 20px; }
.export-section h2 { font-size: 16px; margin-bottom: 8px; }
.export-section p { font-size: 13px; color: var(--color-muted); margin-bottom: 12px; line-height: 1.6; }
.export-actions { margin-bottom: 12px; }
.export-notebook-filter { margin-top: 12px; }
.export-notebook-filter summary { font-size: 13px; color: var(--color-accent); cursor: pointer; }
.notebook-export-list { list-style: none; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.save-status { font-size: 12px; color: var(--color-text); height: 18px; transition: opacity 0.5s; }
.save-status.hidden { opacity: 0; }
.save-status.error { color: var(--color-danger); }
.save-status.muted { color: var(--color-muted); }

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg); }
.login-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 40px 32px; width: 100%; max-width: 360px; }
.login-title { font-size: 24px; text-align: center; margin-bottom: 24px; color: var(--color-accent); }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.btn-block { width: 100%; text-align: center; padding: 10px; font-size: 15px; }

/* =============================================
   Responsive / Mobile  (max-width: 767px)
   ============================================= */

/* ハンバーガーボタン: PCでは非表示 */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* オーバーレイ: 常時非表示、JS で .is-visible を付与 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
}
.sidebar-overlay.is-visible {
  display: block;
}

@media (max-width: 767px) {

  /* ハンバーガーを表示 */
  .sidebar-toggle {
    display: block;
  }

  /* ヘッダーの検索フォームを縮小 */
  .search-form {
    max-width: 160px;
  }

  /* ヘッダーナビ（インポート/エクスポート）を非表示（画面幅が足りない） */
  .header-nav {
    display: none;
  }

  /* サイドバー: オフキャンバスに格納 */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 95;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

  /* JS で .is-open を付与するとスライドイン */
  .sidebar.is-open {
    transform: translateX(0);
  }

  /* メインコンテンツを全幅に */
  .main-content {
    width: 100%;
    padding: 16px;
  }

  /* ノート本文の max-width を解除 */
  .note-body {
    max-width: 100%;
  }

  /* ノート詳細ヘッダーのタイトルフォントを縮小 */
  .note-detail-header h1 {
    font-size: 18px;
  }

  /* エディタのメタ行を縦並びに */
  .editor-meta {
    flex-direction: column;
  }

  /* インポート/エクスポートページの幅を解除 */
  .import-page, .export-page {
    max-width: 100%;
  }
}
