:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e3e8;
  --text: #1f1f1f;
  --text-dim: #5f6368;
  --accent: #2f6df6;
  --accent-soft: #e8f0fe;
  --danger: #d93025;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --font: "Google Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { background: #245ad0; }
.btn.block { width: 100%; justify-content: center; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.icon-btn {
  border: none; background: transparent; width: 36px; height: 36px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-dim);
}
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* ---------- Top page (notebook list) ---------- */
.home { max-width: 1080px; margin: 0 auto; padding: 28px 24px 80px; }
.home-header { display: flex; align-items: center; gap: 12px; margin: 12px 0 28px; }
.home-header .logo { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.home-header .spacer { flex: 1; }

.home-title { font-size: 34px; font-weight: 500; margin: 24px 0 20px; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button { border: none; background: transparent; padding: 7px 14px; font-size: 13px; color: var(--text-dim); }
.seg button.active { background: var(--surface-2); color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }

.nb-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; min-height: 168px;
  display: flex; flex-direction: column; position: relative;
  transition: box-shadow .15s, transform .05s;
}
.nb-card:hover { box-shadow: var(--shadow); }
.nb-card .emoji { font-size: 30px; }
.nb-card .card-title { font-size: 16px; font-weight: 500; margin-top: 14px; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.nb-card .card-meta { font-size: 12px; color: var(--text-dim); margin-top: 12px; }
.nb-card .card-menu { position: absolute; top: 10px; right: 8px; opacity: 0; transition: opacity .1s; }
.nb-card:hover .card-menu { opacity: 1; }
.nb-card.create {
  align-items: center; justify-content: center; color: var(--accent);
  border-style: dashed; background: var(--surface-2); font-weight: 500;
}
.nb-card.create .plus { font-size: 34px; line-height: 1; }
.nb-card.create span { margin-top: 8px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 60px 0; }

/* ---------- Notebook (3-pane) ---------- */
.nb-topbar {
  height: 56px; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.nb-topbar .nb-emoji { font-size: 22px; }
.nb-topbar .nb-name { font-size: 17px; font-weight: 500; border: none; background: transparent;
  padding: 6px 8px; border-radius: 8px; min-width: 120px; }
.nb-topbar .nb-name:hover { background: var(--surface-2); }
.nb-topbar .spacer { flex: 1; }

.panes { display: grid; grid-template-columns: 300px 1fr 340px; gap: 12px;
  padding: 12px; height: calc(100vh - 56px); }
.pane { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.pane-head h2 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; }
.pane-body { flex: 1; overflow-y: auto; padding: 12px 14px; }

/* Sources list */
.src-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; }
.src-item:hover { background: var(--surface-2); }
.src-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.src-item .src-ico { font-size: 16px; }
.src-item .src-title { font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-item .src-del { opacity: 0; }
.src-item:hover .src-del { opacity: 1; }
.pane-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 30px 10px; }

/* Chat */
.chat { }
.chat-summary { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 16px; }
.chat-summary h3 { margin: 0 0 8px; font-size: 15px; }
.chat-summary p { margin: 0; font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.msg { display: flex; gap: 10px; margin: 14px 0; font-size: 14px; line-height: 1.6; }
.msg .avatar { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px;
  display: flex; align-items: center; justify-content: center; font-size: 15px; }
.msg.user .avatar { background: var(--accent-soft); }
.msg.ai .avatar { background: #ececf3; }
.msg .bubble { flex: 1; }
.msg.user .bubble { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 12px; font-size: 12.5px; color: var(--text-dim); }
.chip:hover { background: var(--surface-2); color: var(--text); }

.chat-input-wrap { padding: 12px 14px; border-top: 1px solid var(--border); }
.chat-input { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border);
  border-radius: 14px; padding: 8px 8px 8px 14px; background: var(--surface); }
.chat-input textarea { flex: 1; border: none; outline: none; resize: none; font-family: inherit;
  font-size: 14px; max-height: 140px; background: transparent; line-height: 1.5; padding: 4px 0; }
.chat-input .count { font-size: 12px; color: var(--text-dim); align-self: center; }

/* Studio */
.studio-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.studio-card h3 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.studio-card p.desc { margin: 0 0 12px; font-size: 12px; color: var(--text-dim); }
.gen-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gen-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 10px; font-size: 12.5px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.gen-btn:hover { background: var(--surface-2); }
.gen-btn .gi { font-size: 16px; }
.note-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.note-item .note-title { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.note-item .note-body { font-size: 12px; color: var(--text-dim); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px;
  max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-family: inherit; font-size: 14px; outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { min-height: 160px; resize: vertical; }
.src-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.src-tabs button { flex: 1; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 14px; font-size: 13px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; color: var(--text-dim); }
.src-tabs button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.src-tabs button .ti { font-size: 22px; }

/* menu popover */
.popover { position: absolute; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 40; min-width: 160px; }
.popover button { display: flex; align-items: center; gap: 10px; width: 100%; border: none;
  background: transparent; padding: 9px 12px; border-radius: 8px; font-size: 13px; text-align: left; }
.popover button:hover { background: var(--surface-2); }
.popover button.danger { color: var(--danger); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #202124; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 13px; z-index: 60; }

/* Dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 34px 20px;
  text-align: center; color: var(--text-dim); font-size: 14px; cursor: pointer; transition: .15s; background: var(--surface-2); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone .dz-ico { font-size: 34px; margin-bottom: 8px; }
.dropzone .dz-sub { font-size: 12px; margin-top: 6px; }

/* Preset bar (tabs) */
.preset-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 18px;
  background: var(--accent-soft); border-radius: 10px; padding: 8px; }
.preset-bar::before { content: 'プリセット:'; font-size: 12px; color: var(--text-dim); margin-right: 2px; }
.preset-tab { border: 1px solid transparent; background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 12.5px; color: var(--text-dim); }
.preset-tab:hover { background: rgba(255,255,255,.6); }
.preset-tab.active { background: var(--accent); color: #fff; }
.preset-tab.add, .preset-tab.save { color: var(--accent); }

/* Customize dialog */
.cust-label { font-size: 13px; font-weight: 500; margin: 16px 0 8px; }
.format-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.format-card { text-align: left; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 12px; font-size: 13px; position: relative; }
.format-card:hover { background: var(--surface-2); }
.format-card.active { border-color: var(--accent); background: var(--accent-soft); }
.format-card .chk { position: absolute; top: 8px; right: 10px; color: var(--accent); opacity: 0; }
.format-card.active .chk { opacity: 1; }
.cust-select { width: 200px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit; }
.cust-prompt { width: 100%; min-height: 150px; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 13px; font-family: inherit; line-height: 1.6; resize: vertical; outline: none; }
.cust-prompt:focus { border-color: var(--accent); }

/* thinking / loading dots */
.thinking span { animation: blink 1.2s infinite both; }
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }
.note-img { max-width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }

@media (max-width: 900px) {
  .panes { grid-template-columns: 1fr; height: auto; }
}
