/* xDrive — 墨のサイドバー × 明るいギャラリー */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --ink: #141414;
  --ink-soft: #2a2a2a;
  --paper: #f7f6f3;
  --card: #ffffff;
  --text: #1c1c1c;
  --text-dim: #8a8781;
  --line: #e6e3dd;
  --accent: #d95d39;
  --radius: 12px;
  --sidebar-w: 232px;
}
html, body { height: 100%; }
body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; }

/* ---------- login ---------- */
.login {
  height: 100vh; display: grid; place-items: center;
  background: var(--ink); color: #f2efe9;
}
.login-card { text-align: center; padding: 32px; }
.login-logo { font-size: 40px; font-weight: 700; letter-spacing: .02em; margin-bottom: 16px; }
.login-lead { color: #b8b3aa; line-height: 1.9; margin-bottom: 36px; }
.btn-google {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #1c1c1c; text-decoration: none;
  padding: 13px 28px; border-radius: 999px; font-weight: 600;
  transition: transform .15s ease;
}
.btn-google:hover { transform: translateY(-1px); }
.login-note { margin-top: 36px; font-size: 12px; color: #7d7970; line-height: 1.9; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--ink); color: #d9d5cd;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-size: 20px; font-weight: 700; color: #f2efe9; padding: 22px 20px 14px; }
.nav { padding: 0 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 8px; font-size: 13.5px; text-align: left;
}
.nav-item:hover { background: var(--ink-soft); }
.nav-item.active { background: var(--ink-soft); color: #fff; }
.nav-icon { opacity: .7; width: 16px; text-align: center; }
.nav-count { margin-left: auto; font-size: 11px; color: #6f6b64; }
.side-section { padding: 18px 10px 10px; flex: 1; display: flex; flex-direction: column; }
.side-add { margin-top: 14px; border-top: 1px solid #26241f; padding-top: 8px; }
.side-add button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 8px; font-size: 12px; color: #8a8680;
}
.side-add button:hover { color: #fff; background: var(--ink-soft); }
.cat-name {
  padding: 10px 10px 4px; font-size: 11px; color: #8a8680;
  display: flex; justify-content: space-between; align-items: center;
}
.cat-name .cat-label { cursor: pointer; }
.cat-name .cat-label:hover, .cat-name.active .cat-label { color: #fff; }
.folder-item.in-cat { padding-left: 22px; }
.cat-name .cat-edit { visibility: hidden; font-size: 10px; color: #6f6b64; }
.cat-name:hover .cat-edit { visibility: visible; }
.cat-name.drop-target { outline: 1.5px dashed var(--accent); border-radius: 6px; }
.folder-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border-radius: 8px; font-size: 13px; text-align: left; color: #c9c4bb;
}
.folder-item:hover { background: var(--ink-soft); }
.folder-item.active { background: var(--ink-soft); color: #fff; }
.folder-item.drop-target { outline: 1.5px dashed var(--accent); }
.folder-dot { width: 6px; height: 6px; border-radius: 50%; background: #5f5b54; flex-shrink: 0; }
.folder-item.active .folder-dot { background: var(--accent); }
.side-footer {
  padding: 14px 20px; font-size: 11.5px; color: #6f6b64;
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid #26241f;
}
.side-footer-actions { display: flex; gap: 12px; align-items: center; }
.side-footer a, .side-footer button { color: #6f6b64; text-decoration: none; font-size: 15px; }
.side-footer a:hover, .side-footer button:hover { color: #fff; }

/* ---------- main ---------- */
.main { flex: 1; padding: 0 28px 60px; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 0 14px; position: sticky; top: 0; background: var(--paper); z-index: 5;
}
.topbar h1 { font-size: 19px; font-weight: 700; margin-right: auto; }
.btn-menu { display: none; font-size: 20px; padding: 4px 8px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
#search {
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px;
  width: 220px; background: var(--card); outline: none; font-size: 13px;
}
#search:focus { border-color: #bbb; }
.btn {
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  transition: transform .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.ghost { border: 1px solid var(--line); background: var(--card); }
.btn.danger-ghost { border: 1px solid #eecfc5; background: #fff; color: #c0392b; }
.view-tools { display: flex; gap: 8px; padding-bottom: 10px; }
.tool { font-size: 12px; color: var(--text-dim); padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.tool:hover { color: var(--text); }
.tool.danger:hover { color: #c0392b; border-color: #eecfc5; }

/* ---------- grid (masonry) ----------
   Pinterest基準：カラム幅を~240pxに固定し、画面幅に応じて本数が増える */
.grid { column-width: 240px; column-gap: 14px; }
@media (max-width: 640px)  { .grid { column-width: auto; column-count: 2; column-gap: 10px; } }
.card {
  break-inside: avoid; margin-bottom: 16px;
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(20,20,20,.06);
  cursor: pointer; position: relative;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(20,20,20,.12); }
.card img { width: 100%; display: block; background: #eceae5; }
.card .ph { width: 100%; background: #eceae5; }
.card-badge {
  position: absolute; top: 8px; right: 8px; font-size: 10px;
  background: rgba(20,20,20,.72); color: #fff; padding: 3px 8px; border-radius: 999px;
}
.card-caption { padding: 9px 12px 10px; font-size: 12px; color: var(--text-dim); }
.card-caption .t { color: var(--text); font-weight: 600; display: block; margin-bottom: 2px; }
/* link card（Notion Webクリップ風）
   横長OGP→上にバナー（全体表示）／正方形・縦長→テキスト左・サムネ右 */
.card.link .link-thumb {
  width: 100%; height: auto; max-height: 170px; object-fit: contain;
  display: block; background: #eceae5;
}
.card.link .link-row { display: flex; align-items: stretch; }
.card.link .link-main { flex: 1; min-width: 0; }
.card.link .link-thumb-side {
  display: none; /* sideレイアウト時のみ表示 */
  width: 84px; height: 84px; object-fit: contain; flex-shrink: 0;
  background: #eceae5; border-radius: 8px; margin: 12px 12px 12px 0;
}
.card.link.side .link-thumb { display: none; }
.card.link.side .link-thumb-side { display: block; }
.card.link .link-body { padding: 14px 14px 4px; }
.card.link .link-title { font-size: 13.5px; font-weight: 700; line-height: 1.5; word-break: break-all; }
.card.link .link-memo {
  font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card.link .link-domain {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px 12px; font-size: 11px; color: var(--text-dim);
}
.card.link .link-domain img { width: 14px; height: 14px; border-radius: 3px; }

.empty { text-align: center; color: var(--text-dim); padding: 100px 0; line-height: 2; }
.empty-mark { font-size: 40px; opacity: .3; margin-bottom: 8px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,14,12,.75); }
.modal-body {
  position: relative; background: var(--card); border-radius: 16px;
  width: min(1060px, 94vw); max-height: 90vh; display: flex; overflow: hidden;
}
.modal-media {
  /* flex-basis 0 = 中身の画像サイズに左右されず幅が安定する */
  flex: 1.6 1 0; background: #0f0e0c; display: grid; place-items: center; min-width: 0;
}
.modal-media img, .modal-media video { max-width: 100%; max-height: 90vh; object-fit: contain; }
.modal-media .link-hero { color: #d9d5cd; padding: 40px; text-align: center; word-break: break-all; font-size: 14px; }
.modal-panel { flex: 1 1 0; padding: 26px 24px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-width: 280px; }
.modal-panel input, .modal-panel textarea, .modal-panel select {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; outline: none; background: #fff;
}
.modal-panel input:focus, .modal-panel textarea:focus { border-color: #bbb; }
/* タイトル欄：透明な複製(::after)が同じ書式で高さを確保する＝JS計測不要で常に全文表示 */
.grow-wrap { display: grid; }
.grow-wrap::after {
  content: attr(data-rep) " ";
  white-space: pre-wrap; word-break: break-word; visibility: hidden;
}
.grow-wrap::after, #modal-title {
  grid-area: 1 / 1 / 2 / 2;
  font-weight: 700; font-size: 15px; line-height: 1.6;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
}
.grow-wrap::after { border-color: transparent; }
#modal-title { resize: none; overflow: hidden; min-height: 0; width: 100%; }

/* select：iOSネイティブ描画の縦切れ対策＝自前描画＋高さ明示 */
.modal-panel select {
  -webkit-appearance: none; appearance: none;
  height: 44px; line-height: 1.3; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8781' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
#modal-memo { min-height: 110px; resize: vertical; line-height: 1.7; font-size: 13px; }
.modal-label { font-size: 11px; color: var(--text-dim); margin-bottom: -6px; }
/* URLは控えめな編集可能フィールド＋隣に開くボタン */
.modal-url-row { display: flex; gap: 6px; align-items: center; margin-top: -4px; }
input.modal-url {
  flex: 1; min-width: 0;
  font-size: 12px !important; color: var(--text-dim) !important;
  background: #f4f2ee !important; border-color: transparent !important;
  padding: 6px 10px !important;
}
input.modal-url:focus { border-color: #bbb !important; color: var(--text) !important; }
#modal-url-open {
  flex-shrink: 0; width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 8px; background: #f4f2ee; color: var(--text-dim);
  text-decoration: none; font-size: 14px;
}
#modal-url-open:hover { background: var(--ink); color: #fff; }
.modal-meta { font-size: 11.5px; color: var(--text-dim); line-height: 1.8; }
.modal-share-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.modal-share-row .btn { font-size: 12px; padding: 7px 14px; }
.modal-share-row .share-hint { font-size: 11px; color: var(--text-dim); }

/* タグチップエディタ */
.tag-editor {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff;
}
.tag-editor:focus-within { border-color: #bbb; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #efece6; border-radius: 999px; padding: 4px 6px 4px 12px;
  font-size: 12px; font-weight: 600;
}
.tag-chip button { color: var(--text-dim); font-size: 13px; line-height: 1; padding: 0 4px; }
.tag-chip button:hover { color: #c0392b; }
.tag-editor input {
  border: none !important; outline: none; flex: 1; min-width: 90px;
  padding: 4px !important; font-size: 13px; background: transparent !important;
}
.modal-actions { margin-top: auto; display: flex; gap: 10px; justify-content: space-between; }
.modal-actions .btn { text-decoration: none; }
.modal-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  font-size: 22px; color: #fff; mix-blend-mode: difference;
}

/* ---------- overlays ---------- */
.drop-overlay {
  /* サイドバーは覆わない＝フォルダへの直接ドロップを生かす */
  position: fixed; top: 0; right: 0; bottom: 0; left: var(--sidebar-w);
  z-index: 60; background: rgba(20,20,20,.82); pointer-events: none;
  display: grid; place-items: center; color: #fff; font-size: 20px; font-weight: 700;
  border: 3px dashed rgba(255,255,255,.5); border-radius: 4px;
}
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 22px; border-radius: 999px;
  font-size: 13px; z-index: 70; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.loading {
  position: fixed; inset: 0; z-index: 80; background: var(--ink);
  display: grid; place-items: center;
}
.loading-mark { color: #f2efe9; font-size: 26px; font-weight: 700; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- triage（インボックス整理モード） ---------- */
.triage {
  position: fixed; inset: 0; z-index: 55; background: var(--ink); color: #f2efe9;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
.triage-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; font-size: 13px; color: #b8b3aa;
}
.triage-head button { font-size: 22px; color: #f2efe9; padding: 2px 8px; }
.triage-media {
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 0 18px;
}
.triage-media img {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; border-radius: 8px;
}
.triage-media .link-hero { text-align: center; word-break: break-all; font-size: 14px; padding: 20px; }
.triage-info { padding: 10px 20px 0; font-size: 13px; color: #b8b3aa; text-align: center; min-height: 20px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.triage-label { padding: 14px 20px 8px; font-size: 11px; color: #6f6b64; letter-spacing: .08em; }
.triage-folders {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 20px 4px;
  -webkit-overflow-scrolling: touch; flex-wrap: wrap; max-height: 30dvh; overflow-y: auto;
}
.triage-folders button {
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  background: var(--ink-soft); color: #e6e2da; white-space: nowrap;
}
.triage-folders button:active { background: var(--accent); color: #fff; }
.triage-folders .t-cat { width: 100%; font-size: 10.5px; color: #6f6b64; padding: 6px 2px 0; }
.triage-actions {
  display: flex; justify-content: space-between; gap: 10px; padding: 14px 20px 20px;
}
.triage-done { text-align: center; padding: 60px 20px; color: #b8b3aa; line-height: 2; }

/* ---------- settings ---------- */
.settings-body {
  position: relative; background: var(--card); border-radius: 16px;
  width: min(460px, 92vw); padding: 30px 28px;
}
.settings-body h2 { font-size: 17px; margin-bottom: 12px; }
.settings-body p { font-size: 13px; color: var(--text-dim); line-height: 1.8; margin-bottom: 18px; }
.key-row { display: flex; gap: 10px; align-items: center; }
.key-row code {
  flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
  background: #f4f2ee; padding: 10px 12px; border-radius: 8px; font-size: 12px;
}
#settings .modal-close { color: var(--text-dim); mix-blend-mode: normal; }

/* ---------- mobile ---------- */
.nav-scrim { position: fixed; inset: 0; z-index: 39; background: rgba(15,14,12,.5); }
body.nav-open, body.modal-open { overflow: hidden; } /* 背面スクロールを奪わせない */

@media (max-width: 640px) {
  .sidebar {
    position: fixed; top: 0; left: -280px; width: 280px; z-index: 40;
    height: 100vh; height: 100dvh; /* Safari下部バーを考慮した実表示高 */
    transition: left .22s ease;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }
  body.nav-open .sidebar { left: 0; box-shadow: 12px 0 40px rgba(0,0,0,.35); }
  .side-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .cat-name .cat-edit { visibility: visible; } /* タッチにhoverは無い */
  .btn-menu { display: inline-block; }
  .main { padding: 0 12px 40px; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-actions { width: 100%; }
  #search { flex: 1; width: auto; min-width: 0; }
  .drop-overlay { left: 0; }

  /* モーダル＝全画面シート */
  .modal { place-items: stretch; }
  .modal-body {
    flex-direction: column; width: 100%; max-height: none; border-radius: 0;
    height: 100vh; height: 100dvh;
  }
  .modal-media {
    flex: 0 0 auto; max-height: 42dvh; min-height: 160px;
  }
  .modal-media img, .modal-media video { max-height: 42dvh; }
  .modal-panel {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  /* iOSは16px未満の入力欄でフォーカス時に強制ズームされ、レイアウトが崩れる */
  .modal-panel input, .modal-panel textarea, .modal-panel select, .tag-editor input,
  .grow-wrap::after {
    font-size: 16px !important;
  }
  .modal-close {
    position: absolute; top: 10px; right: 10px;
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(20,20,20,.65); color: #fff; mix-blend-mode: normal;
    display: grid; place-items: center; font-size: 19px;
  }
}
@media (min-width: 641px) {
  .nav-scrim { display: none !important; }
}
