:root {
  --bg: #0f0f0f;
  --bg2: #1a1a1a;
  --bg3: #242424;
  --border: #333;
  --text: #e8e8e8;
  --text2: #999;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 12px;
  --tab-h: 58px;
  --header-h: 48px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; }
body { display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; }

/* ── Header ── */
#header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  position: sticky; top: 0; z-index: 10;
}
#header h1 { font-size: 16px; font-weight: 600; color: var(--accent2); }
#cost-badge {
  font-size: 11px; color: var(--text2);
  background: var(--bg3); border-radius: 8px; padding: 3px 8px;
}
#cost-badge span { color: var(--text); font-weight: 500; }

/* ── Content ── */
#content {
  flex: 1; overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(var(--tab-h) + 16px);
}

/* ── Tabs ── */
#tabs {
  height: var(--tab-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
}
.tab-btn {
  background: none; border: none; color: var(--text2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; font-size: 10px; transition: color .15s;
}
.tab-btn .icon { font-size: 19px; }
.tab-btn.active { color: var(--accent2); }

/* ── Section ── */
.section { display: none; }
.section.active { display: block; }

/* ── Capture tab ── */
.capture-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
  margin-bottom: 20px;
}
.capture-btn {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; padding: 20px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; transition: background .15s, border-color .15s;
}
.capture-btn:active { background: var(--bg2); border-color: var(--accent); }
.capture-btn .big { font-size: 32px; }

.text-area {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 15px; width: 100%; padding: 12px;
  resize: none; outline: none; min-height: 100px;
}
.text-area:focus { border-color: var(--accent); }
.send-btn {
  margin-top: 10px; width: 100%;
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius); padding: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.send-btn:active { background: #4f46e5; }
.send-btn:disabled { background: var(--bg3); color: var(--text2); cursor: not-allowed; }

/* ── Result card ── */
#result-card {
  margin-top: 16px; background: var(--bg3);
  border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px;
  display: none;
}
#result-card.show { display: block; }
#result-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; max-height: 45vh; overflow-y: auto; }
#result-label { font-size: 11px; color: var(--accent2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }

/* ── Camera preview ── */
#camera-wrap {
  display: none; margin-bottom: 16px;
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 4/3;
}
#camera-wrap.show { display: block; }
#camera-video { width: 100%; height: 100%; object-fit: cover; }
#shoot-btn {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: white; border: none; border-radius: 50%; width: 56px; height: 56px;
  font-size: 24px; cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,.5);
}
#cancel-cam-btn {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,.6); border: none; color: white;
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 13px;
}

/* ── Recording indicator ── */
#rec-indicator {
  display: none; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--red);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
  color: var(--red); font-size: 14px;
}
#rec-indicator.show { display: flex; }
.rec-dot { width: 10px; height: 10px; background: var(--red); border-radius: 50%; animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }
#stop-rec-btn {
  margin-left: auto; background: var(--red); border: none; color: white;
  border-radius: 8px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}

/* ── Search tab ── */
.search-row {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.search-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 15px; padding: 10px 12px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-btn {
  background: var(--accent); border: none; color: white;
  border-radius: var(--radius); padding: 10px 16px; cursor: pointer; font-size: 14px;
}

.log-card {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.log-card-meta { font-size: 11px; color: var(--text2); margin-bottom: 5px; }
.log-card-meta .cat {
  background: var(--bg2); border-radius: 4px; padding: 1px 6px;
  display: inline-block; margin-right: 6px;
}
.log-card-content { font-size: 14px; line-height: 1.5; }

/* ── Today tab ── */
.insight-header {
  background: var(--bg3); border-radius: var(--radius); padding: 14px;
  margin-bottom: 16px;
}
.insight-header h2 { font-size: 16px; margin-bottom: 8px; }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-chip {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 10px; font-size: 12px;
}
.stat-chip b { color: var(--accent2); }

#today-logs-list .log-card { animation: fadeIn .2s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:none} }

/* ── Ask AI ── */
.ask-divider {
  font-size: 11px; color: var(--text2); text-transform: uppercase;
  letter-spacing: .5px; margin: 20px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.ask-divider::before, .ask-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.ask-btn { background: #7c3aed; }
.ask-btn:active { background: #6d28d9; }
#ask-result {
  background: var(--bg3); border: 1px solid #7c3aed33;
  border-radius: var(--radius); padding: 14px; margin-top: 10px;
  font-size: 14px; line-height: 1.7; white-space: pre-wrap;
  display: none;
}
#ask-result.show { display: block; }

/* ── Spinner ── */
.spinner {
  display: none; width: 24px; height: 24px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 20px auto;
}
.spinner.show { display: block; }
@keyframes spin { to{transform:rotate(360deg)} }

/* ── Toast ── */
#toast {
  position: fixed; bottom: calc(var(--tab-h) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 20px; font-size: 13px; opacity: 0; transition: opacity .2s;
  pointer-events: none; white-space: nowrap; z-index: 100;
}
#toast.show { opacity: 1; }

/* ── Notion button ── */
.notion-btn { background: #2d2d2d; border: 1px solid #555; color: var(--text); margin-top: 6px; }
.notion-btn:active { background: #3d3d3d; border-color: var(--accent2); }

/* ── Draft tab ── */
.draft-gen-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.draft-gen-btn {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; padding: 18px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; transition: border-color .15s;
}
.draft-gen-btn:active { border-color: var(--accent); }
.dg-icon { font-size: 28px; }

.platform-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.ptab {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); cursor: pointer; padding: 6px 14px; font-size: 13px;
  transition: all .15s;
}
.ptab.active { background: var(--accent); border-color: var(--accent); color: white; }

#draft-charcount { font-size: 11px; color: var(--text2); text-align: right; margin-bottom: 6px; }
#draft-charcount.warn { color: var(--yellow); }
#draft-charcount.over { color: var(--red); }

.draft-textarea {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; line-height: 1.65; width: 100%; padding: 12px;
  resize: vertical; outline: none; min-height: 260px; font-family: inherit;
}
.draft-textarea:focus { border-color: var(--accent); }

.draft-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.copy-btn { background: var(--green); }
.copy-btn:active { background: #16a34a; }

#topic-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.topic-chip {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 20px;
  color: var(--text2); cursor: pointer; padding: 5px 14px; font-size: 12px;
  transition: all .15s;
}
.topic-chip.active { background: var(--accent); border-color: var(--accent); color: white; }

.log-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.log-item:last-child { border-bottom: none; }
.log-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.log-cat { font-size: 11px; color: var(--text2); background: var(--bg3); padding: 2px 8px; border-radius: 10px; }
.log-del { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; padding: 2px 6px; }
.log-del:active { color: var(--red); }
.log-date { font-size: 11px; color: var(--text2); }
.log-content { font-size: 13px; line-height: 1.5; color: var(--text); }
.log-pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; }
.log-pagination button { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px 16px; cursor: pointer; }
.log-pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Log detail modal ── */
#log-modal { display: none; }
#log-modal.open {
  display: flex; position: fixed; inset: 0; z-index: 200;
  flex-direction: column; justify-content: flex-end;
}
#log-modal-sheet {
  position: relative; background: var(--bg2);
  border-radius: 20px 20px 0 0;
  max-height: 85vh; display: flex; flex-direction: column;
  animation: sheetUp .25s cubic-bezier(.32,0,.67,0);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
#log-modal-handle {
  width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 12px auto 0;
}
#log-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
#log-modal-close {
  background: var(--bg3); border: none; color: var(--text2);
  border-radius: 50%; width: 30px; height: 30px;
  cursor: pointer; font-size: 13px; flex-shrink: 0;
}
#log-modal-body {
  flex: 1; overflow-y: auto; padding: 16px;
}
#log-modal-content {
  font-size: 15px; line-height: 1.75; white-space: pre-wrap; color: var(--text);
}
#log-modal-footer {
  padding: 12px 16px; border-top: 1px solid var(--border);
}
#log-modal-delete {
  background: none; border: 1px solid var(--border); color: var(--text2);
  border-radius: var(--radius); padding: 8px 16px; cursor: pointer; font-size: 13px;
}
#log-modal-delete:active { color: var(--red); border-color: var(--red); }
