:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --sidebar: #1f2430;
  --sidebar-text: #c8cdd6;
  --sidebar-active: #2d3444;
  --accent: #e5658a;      /* やさしいピンク */
  --accent-dark: #d24d75;
  --text: #262a33;
  --muted: #8a909c;
  --border: #e6e8ec;
  --star: #f4b73f;
}

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

body {
  font-family: "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- サイドバー ---------- */
.sidebar {
  width: 270px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  overflow-y: auto;
  flex-shrink: 0;
}

.brand {
  font-size: 19px;
  color: #fff;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand i { color: var(--accent); }

.views { margin: 14px 0 6px; }

.view-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
  transition: background .15s;
}
.view-item:hover { background: var(--sidebar-active); }
.view-item.active { background: var(--accent); color: #fff; }
.view-item i { width: 18px; text-align: center; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin: 18px 6px 8px;
}

.feed-list { display: flex; flex-direction: column; gap: 2px; }

.cat-group { margin-bottom: 6px; }
.cat-label {
  font-size: 12px;
  color: #9aa1ad;
  padding: 6px 12px 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.feed-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background .15s;
}
.feed-item:hover { background: var(--sidebar-active); }
.feed-item.active { background: var(--accent); color: #fff; }
.feed-item .feed-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-item .badge {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
}
.feed-item .edit {
  opacity: 0;
  color: #c8cdd6;
  transition: opacity .15s;
}
.feed-item:hover .edit { opacity: .8; }
.feed-item.active .edit { color: #fff; }
.section-actions { display: flex; gap: 2px; }

.feed-item .drag-handle {
  opacity: 0;
  color: #6b7280;
  cursor: grab;
  font-size: 12px;
  transition: opacity .15s;
}
.feed-item:hover .drag-handle { opacity: .7; }
.feed-item.active .drag-handle { color: #fff; }
.feed-item.dragging {
  opacity: .5;
  background: var(--sidebar-active);
}
.cat-group.drop-target { outline: 2px dashed var(--accent); border-radius: 8px; }

/* ---------- ボタン ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #f0f1f4; color: var(--text); }
.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }

/* ---------- メイン ---------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0 12px;
  width: 320px;
}
.search-box i.fa-magnifying-glass { color: var(--muted); font-size: 13px; }
.search-box input {
  border: none;
  background: transparent;
  padding: 9px 8px;
  font-size: 14px;
  flex: 1;
  outline: none;
  font-family: inherit;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}
.current-title { font-weight: 600; font-size: 15px; }

/* ---------- 記事リスト ---------- */
.article-list { flex: 1; overflow-y: auto; padding: 8px 0; }

.article {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  gap: 14px;
  cursor: pointer;
  transition: background .12s;
}
.article:hover { background: #fafbfc; }
.article.read .article-title { color: var(--muted); font-weight: 400; }
.article.read .unread-dot { visibility: hidden; }

.unread-dot {
  color: var(--accent);
  font-size: 9px;
  margin-top: 6px;
  flex-shrink: 0;
}
.article-thumb {
  flex-shrink: 0;
  width: 120px;
  height: 78px;
  border-radius: 8px;
  overflow: hidden;
  background: #eef0f3;
}
.article-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.article-body { flex: 1; min-width: 0; }
.article-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.4;
}
.article-title a { color: inherit; text-decoration: none; }
.article-title a:hover { color: var(--accent-dark); }
.article-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.article-meta .feed-tag {
  background: #eef0f3;
  color: #5a616e;
  padding: 1px 8px;
  border-radius: 10px;
}
.article-summary {
  font-size: 13px;
  color: #5a616e;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.star-btn, .read-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
}
.star-btn:hover, .read-btn:hover { background: #f0f1f4; }
.star-btn.on { color: var(--star); }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 12px;
}
.empty i { font-size: 46px; opacity: .4; }

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal h2 { font-size: 18px; margin-bottom: 18px; display: flex; gap: 8px; align-items: center; }
.modal h2 i { color: var(--accent); }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.modal input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  cursor: pointer;
}
.modal select:focus { border-color: var(--accent); }
.cat-new-input { margin-top: 8px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.error { color: #d24d75; font-size: 13px; margin-top: 10px; }
.btn-danger { color: #d24d75; border-color: #f0c4d1; }
.btn-danger:hover { background: #fbeaf0; color: #d24d75; }
.modal-hint { font-size: 12px; color: var(--muted); margin: -6px 0 14px; line-height: 1.5; }

/* カテゴリ管理 */
.cat-add-row { display: flex; gap: 8px; margin-bottom: 6px; }
.cat-add-row input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.cat-add-row input:focus { border-color: var(--accent); }
.cat-add-row .btn { white-space: nowrap; }
.cat-manage-list { max-height: 300px; overflow-y: auto; margin-top: 8px; }
.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.cat-row .cat-name {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
.cat-row .cat-count { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; }
.cat-row .cat-save { color: var(--accent); }
.cat-row .cat-del { color: var(--muted); }
.cat-row .cat-del:hover { color: #d24d75; }
.cat-row .cat-del.disabled { opacity: .3; cursor: not-allowed; }
.modal .icon-btn:hover { background: #f0f1f4; }

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d3444;
  color: #fff;
  padding: 11px 20px;
  border-radius: 24px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 200;
}

/* ===================== ハンバーガー & レスポンシブ ===================== */

/* メニューボタンはPC表示では隠す */
.menu-btn {
  display: none;
  font-size: 18px;
  color: var(--text);
  margin-right: 2px;
}

/* サイドバー外側の暗幕（スマホでドロワーを開いたとき） */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 90;
}

@media (max-width: 768px) {
  .menu-btn { display: inline-flex; }

  /* サイドバーを横からスライドするドロワーに */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 82vw;
    max-width: 300px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 18px rgba(0, 0, 0, .3);
  }
  .sidebar.open { transform: translateX(0); }

  /* トップバーを詰める */
  .topbar { padding: 10px 14px; gap: 10px; }
  .search-box { width: auto; flex: 1; }
  .current-title { display: none; }
  .topbar-actions { margin-left: 0; }
  .mark-btn-label { }
  #mark-all-btn .btn-label { display: none; }   /* スマホではアイコンのみ */
  #mark-all-btn { padding: 9px 12px; }

  /* 記事カードを詰める */
  .article { padding: 12px 14px; gap: 10px; }
  .article-thumb { width: 92px; height: 62px; }
  .article-title { font-size: 14.5px; }
  .article-summary { -webkit-line-clamp: 2; }

  /* モーダルを画面幅に合わせる */
  .modal { width: 94vw; padding: 20px; }
}

/* さらに小さい端末 */
@media (max-width: 380px) {
  .article-thumb { display: none; }   /* 極小画面ではサムネ非表示で本文優先 */
}

/* ===================== ホーム画面アプリ（ノッチ / ホームバー）対応 ===================== */
/* iPhoneのノッチやホームバーに内容が被らないよう、セーフエリアぶん余白を足す */
.topbar  { padding-top: calc(12px + env(safe-area-inset-top)); }
.sidebar {
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

@media (max-width: 768px) {
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .article-list { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  /* 左右の切り欠き（横向き時）も避ける */
  .topbar { padding-left: calc(14px + env(safe-area-inset-left)); }
}

/* ===================== ログイン画面 ===================== */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1f2430 0%, #2d3444 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  width: 360px;
  max-width: 92vw;
  border-radius: 16px;
  padding: 34px 30px 30px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  text-align: center;
}
.login-brand {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 5px;
}
.login-field {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 12px;
}
.login-field:focus-within { border-color: var(--accent); }
.login-field i { color: var(--muted); font-size: 14px; }
.login-field input {
  flex: 1;
  border: none;
  outline: none;
  padding: 11px 4px;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
}
.login-btn {
  width: 100%;
  justify-content: center;
  margin-top: 22px;
  padding: 12px;
  font-size: 15px;
}
.login-error {
  background: #fbeaf0;
  color: #d24d75;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  text-align: left;
}

/* サイドバーのログアウト */
.logout-link {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: .8;
}
.logout-link:hover { background: var(--sidebar-active); opacity: 1; }
