/* ==============================
   Base / Reset
============================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f9fafb;
  --bg-alt: #ffffff;
  --fg: #111827;
  --fg-muted: #6b7280;
  --primary: #2563eb;
  --danger: #dc2626;
  --border: #e5e7eb;
  --sidebar-width: 280px;
  --header-height: 60px; /* ヘッダー高さ */
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --fg: #f1f5f9;
  --fg-muted: #94a3b8;
  --border: #334155;
}

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
}

/* ==============================
   Layout
============================== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  height: var(--header-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fg);
}

.header-left .subtitle {
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-sidebar {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--fg);
}

.ad-slot {
  background: var(--border);
  color: var(--fg-muted);
  font-size: 0.75rem;
  padding: 6px 12px;
  border-radius: 4px;
  min-width: 100px;
  text-align: center;
}

/* PCヘッダー広告の余白をゼロに */
#header-ad-pc {
  margin: 0;
  padding: 0;
}

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ------------------------------
   Sidebar
------------------------------ */
.sidebar {
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-alt);
  padding: 12px;
  transition: transform 0.3s ease;
}

.sidebar-top,
.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-bottom {
  margin-top: auto;
  gap: 8px;
}

/* ------------------------------
   Notes List
------------------------------ */
.notes-list {
  list-style: none;
  margin-top: 10px;
  flex: 1;
  overflow-y: auto;
}

.note-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.note-item:hover {
  background: var(--border);
}

.note-item.active {
  background: var(--primary);
  color: #fff;
}

.note-item.active .meta {
  color: #e0e0e0; /* 選択時の更新日時を見やすく */
}

.note-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.note-info .title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.note-info .meta {
  font-size: 0.75rem;
  color: var(--fg-muted);
}

.note-actions {
  margin-left: 6px;
  flex-shrink: 0;
}

.note-actions .trash {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
}

/* ------------------------------
   Editor Area
------------------------------ */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  min-height: 0;
}

.editor {
  flex: 1;
  padding: 16px;
  font-size: 1rem;
  border: none;
  outline: none;
  resize: none;
  background: var(--bg);
  color: var(--fg);
  height: 100%;
}

.last-update {
  font-size: 0.8rem;
  color: var(--fg-muted);
  padding: 4px 16px;
  text-align: right;
}

.footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  text-align: center;
  font-size: 0.8rem;
  color: var(--fg-muted);
}

/* ------------------------------
   Buttons
------------------------------ */
.btn {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
  color: var(--fg);
}

.btn:hover {
  background: var(--border);
}

.btn.full {
  width: 100%;
  text-align: center;
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn.danger:hover {
  background: var(--danger);
  color: #fff;
}

.search {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  width: 100%;
}

.import-label {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  text-align: center;
}

.import-label input {
  position: absolute;
  left: -9999px;
}

/* ==============================
   Responsive
============================== */
@media (max-width: 768px) {
  .sidebar {
    width: 200px;
  }
}

@media (max-width: 600px) {
  .main {
    flex-direction: column;
    height: calc(100vh - var(--header-height)); /* ヘッダー下から開始 */
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    transform: translateX(-100%);
    position: absolute;          
    top: var(--header-height);           /* ヘッダー直下 */
    left: 0;
    height: calc(100% - var(--header-height)); /* ヘッダー分を差し引く */
    z-index: 10;
    background: var(--bg-alt);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .editor-area {
    flex: 1 1 auto;
    min-height: 0;
  }

  .editor {
    flex: 1 1 auto;
    height: 100%;
  }

  .header-right .ad-slot {
    display: none;
  }

  /* モバイルフッター広告を固定し画面内に収める */
  #footer-ad-mobile {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    background: var(--bg-alt);
    padding: 8px 0;
    text-align: center;
    padding-bottom: env(safe-area-inset-bottom); /* iOSセーフエリア対応 */
    box-shadow: 0 -1px 4px rgba(0,0,0,0.1);
  }

  #footer-ad-pc {
    display: none;
  }
}

/* PC時：メニュー呼び出しボタン非表示 */
@media (min-width: 601px) {
  .toggle-sidebar {
    display: none;
  }

  #footer-ad-pc {
    display: block;
  }

  #footer-ad-mobile {
    display: none;
  }
}
