:root {
  --bg: #f9fafb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --danger: #dc2626;
  --warning: #f59e0b;
  --success: #16a34a;
  --sat: #2563eb;
  --sun: #dc2626;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif; font-size: 14px; line-height: 1.5; }

.app-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; }
.header-left { display: flex; align-items: center; gap: 16px; }
.app-header h1 { margin: 0; font-size: 1.2rem; }
.header-right { display: flex; align-items: center; gap: 12px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.user-badge { color: var(--muted); font-size: 0.9rem; }
.link { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.link:hover { text-decoration: underline; }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px 8px; font-size: 0.9rem; }
.btn-link:hover { color: var(--text); }

.container { max-width: 1100px; margin: 0 auto; padding: 20px 24px 80px; }

.error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h2 { margin: 0; font-size: 1.1rem; min-width: 130px; text-align: center; }

button { font-family: inherit; font-size: 14px; }
.btn-primary { padding: 8px 16px; background: var(--accent); color: white; border: none; border-radius: 6px; cursor: pointer; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { padding: 7px 14px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.btn-secondary:hover { background: #f3f4f6; }
.btn-danger { padding: 7px 14px; background: var(--panel); color: var(--danger); border: 1px solid var(--danger); border-radius: 6px; cursor: pointer; }
.btn-danger:hover { background: #fef2f2; }
.btn-icon { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 18px; line-height: 1; }
.btn-icon:hover { background: #f3f4f6; }

/* Calendar */
.calendar-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); background: #f3f4f6; border-bottom: 1px solid var(--border); }
.weekday-row span { padding: 8px 12px; font-size: 0.85rem; color: var(--muted); text-align: center; font-weight: 600; }
.weekday-row .sat { color: var(--sat); }
.weekday-row .sun { color: var(--sun); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.day-cell { min-height: 96px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px 8px; background: var(--panel); cursor: pointer; display: flex; flex-direction: column; gap: 4px; position: relative; }
.day-cell:nth-child(7n) { border-right: none; }
.day-cell.other-month { background: #fafafa; color: #cbd5e1; cursor: default; }
.day-cell.other-month .day-number { color: #cbd5e1; }
.day-cell.today { background: #eef2ff; }
.day-cell.today .day-number { color: var(--accent); font-weight: 700; }
.day-cell:hover:not(.other-month) { background: var(--accent-soft); }
.day-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.day-number { font-size: 0.95rem; font-weight: 600; }
.day-cell.sat .day-number { color: var(--sat); }
.day-cell.sun .day-number { color: var(--sun); }
.note-badge { font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-badge.unread { background: #fee2e2; color: var(--danger); font-weight: 600; }
.note-badge.mention { background: #fef3c7; color: #92400e; font-weight: 600; }
.note-badge.read { background: #ecfdf5; color: var(--success); }

/* Day panel (right side) */
.day-panel { margin-top: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; }
.day-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.day-panel-header h3 { margin: 0; font-size: 1.05rem; }
.note-item { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; background: #fafafa; }
.note-item.mention-me { border-left: 4px solid var(--warning); background: #fffbeb; }
.note-item.unread { border-left: 4px solid var(--danger); }
.note-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 8px; }
.note-item-header h4 { margin: 0; font-size: 1rem; }
.note-actions { display: flex; gap: 6px; }
.note-body { white-space: pre-wrap; word-break: break-word; margin-bottom: 10px; }
.note-body.md-body { white-space: normal; line-height: 1.7; }
.note-body.md-body .md-h2 { font-size: 1.05rem; margin: 16px 0 8px; padding: 6px 10px; background: #eef2ff; color: var(--accent); border-radius: 6px; border-left: 4px solid var(--accent); scroll-margin-top: 20px; }
.note-body.md-body strong { font-weight: 700; }
.note-body.md-body ul.md-list { padding-left: 22px; margin: 8px 0; }
.note-body.md-body ul.md-list li { margin: 2px 0; }
.note-body.md-body a { color: var(--accent); text-decoration: underline; }
/* 色 */
.color-red { color: #dc2626; }
.color-orange { color: #f59e0b; }
.color-green { color: #16a34a; }
.color-blue { color: #2563eb; }
.color-purple { color: #9333ea; }

.mention-chip { display: inline-block; background: #fef3c7; color: #92400e; padding: 1px 6px; border-radius: 4px; font-weight: 600; font-size: 0.9em; scroll-margin-top: 80px; }
.mention-chip.mention-self { background: #fde68a; box-shadow: 0 0 0 2px #f59e0b; color: #78350f; }
@keyframes mention-flash { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); box-shadow: 0 0 0 4px #fbbf24; } }
.mention-chip.flash { animation: mention-flash 1s ease-in-out 2; }

.jump-self-btn { background: #fef3c7 !important; color: #92400e !important; border-color: #f59e0b !important; font-weight: 600; }
.jump-self-btn:hover { background: #fde68a !important; }
.note-mentions-summary { margin-top: 8px; padding: 6px 10px; background: #fafafa; border-radius: 6px; }
.note-meta { display: flex; gap: 12px; align-items: center; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; margin-top: 8px; }
.read-btn { padding: 4px 10px; border: 1px solid var(--success); background: var(--panel); color: var(--success); border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.read-btn.is-read { background: var(--success); color: white; cursor: default; }
.read-btn:hover:not(.is-read) { background: #ecfdf5; }
.readers-link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal[hidden] { display: none; }
.modal-content { background: var(--panel); border-radius: 12px; max-width: 600px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal-content.modal-sm { max-width: 400px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 28px 28px 24px; overflow-y: auto; }

.form-field { margin-bottom: 24px; }
.form-field:last-child { margin-bottom: 16px; }
.form-field label { display: block; margin-bottom: 10px; font-weight: 600; font-size: 0.95rem; color: var(--text); }
.required { color: var(--danger); margin-left: 2px; }
.form-field input, .form-field textarea { width: 100%; padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; box-sizing: border-box; line-height: 1.5; }
.form-field input:focus, .form-field textarea:focus { outline: none; border-color: var(--accent); }
.form-field textarea { resize: vertical; font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", monospace; }

.editor-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: #f9fafb; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; }
.editor-toolbar .tb { padding: 6px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 0.85rem; transition: all 0.1s; }
.editor-toolbar .tb:hover { background: #eef2ff; border-color: var(--accent); color: var(--accent); }
.editor-toolbar .tb-divider { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.editor-toolbar .tb-label { font-size: 0.85rem; color: var(--muted); margin-right: 2px; }
.editor-toolbar .tb-color { width: 24px; height: 24px; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; transition: transform 0.1s; }
.editor-toolbar .tb-color:hover { transform: scale(1.2); box-shadow: 0 0 0 2px var(--accent); }
.editor-wrap textarea, .editor-toolbar + textarea { border-top-left-radius: 0; border-top-right-radius: 0; border-top: none; }

.editor-wrap { position: relative; }
.mention-picker { position: absolute; left: 0; right: 0; top: 100%; margin-top: 6px; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); z-index: 100; max-height: 360px; overflow-y: auto; padding: 6px; }
.mention-option { padding: 12px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-radius: 8px; margin-bottom: 2px; transition: background 0.1s; }
.mention-option:last-child { margin-bottom: 0; }
.mention-option.selected, .mention-option:hover { background: var(--accent-soft); }
.mention-option .opt-name { font-weight: 600; color: var(--text); font-size: 0.95rem; }
.mention-option .opt-alias { font-size: 0.85rem; color: var(--muted); background: #f3f4f6; padding: 3px 10px; border-radius: 12px; }
.mention-option.selected .opt-alias, .mention-option:hover .opt-alias { background: var(--panel); color: var(--accent); }

.body-preview { border: 1px solid var(--border); border-top: none; border-radius: 0 0 6px 6px; padding: 12px 14px; min-height: 200px; background: var(--panel); }
.body-preview .md-h2 { font-size: 1.05rem; margin: 12px 0 8px; padding: 6px 10px; background: #eef2ff; color: var(--accent); border-radius: 6px; border-left: 4px solid var(--accent); }
.body-preview ul.md-list { padding-left: 22px; }
.body-preview a { color: var(--accent); }
.body-preview .color-red { color: #dc2626; }
.body-preview .color-orange { color: #f59e0b; }
.body-preview .color-green { color: #16a34a; }
.body-preview .color-blue { color: #2563eb; }
.body-preview .color-purple { color: #9333ea; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }
.hint code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }
.spacer { flex: 1; }

/* Readers list */
.reader-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.reader-row:last-child { border-bottom: none; }
.reader-row.unread { color: var(--danger); font-weight: 600; }
.reader-row .read-time { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 600px) {
  .day-cell { min-height: 64px; padding: 4px; }
  .note-badge { font-size: 0.65rem; padding: 1px 4px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .month-nav { justify-content: center; }
}
