/* === Variables === */
:root {
  --color-bg: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #666666;
  --color-border: #e0e0e0;
  --color-accent: #2563eb;
  --color-accent-light: #dbeafe;
  --color-code-bg: #f8f8f8;
  --color-code-border: #e5e5e5;
  --color-danger: #dc2626;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.7;
}

/* === Header === */
.site-header {
  background: #fafafa;
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-title { font-size: 1.25rem; }
.site-title a { color: var(--color-text); text-decoration: none; }
.header-nav { display: flex; align-items: center; gap: 0.75rem; }
.user-info { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.avatar { border-radius: 50%; }

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: #f0f0f0; }
.btn-primary {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.8rem; }

/* === Inline actions (emoji) === */
.inline-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  margin-top: 0.25rem;
  opacity: 0.3;
  transition: opacity 0.2s;
}
.entry:hover .inline-actions,
.comment:hover .inline-actions { opacity: 1; }
.inline-actions a {
  font-size: 0.85rem;
  text-decoration: none;
  line-height: 1;
}
.inline-actions form {
  margin: 0;
  padding: 0;
  line-height: 0;
}
.inline-action-btn {
  font-size: 0.85rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0;
  line-height: 1;
}

/* === Archive === */
.archive { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--color-border); }
.archive h3 { font-size: 1rem; color: var(--color-text-muted); margin-bottom: 0.5rem; }
.archive-year { margin-bottom: 0.3rem; font-size: 0.9rem; }
.archive-year-label { color: var(--color-text-muted); margin-right: 0.3rem; }
.archive-year a { margin-right: 0.5rem; }

/* === Monthly nav === */
.monthly-nav { display: flex; justify-content: space-between; margin-bottom: 1.5rem; font-size: 0.9rem; }

/* === Container === */
.container { max-width: 960px; margin: 0 auto; padding: 2rem 1.5rem; }

/* === Flash messages === */
.flash { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1.5rem; }
.flash-notice { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.flash-alert { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }

/* === Entry === */
.entry { margin-bottom: 3rem; border-bottom: 1px solid var(--color-border); padding-bottom: 2rem; }
.entry:last-child { border-bottom: none; }
.entry-header { margin-bottom: 1rem; }
.entry-title { font-size: 1.75rem; margin-bottom: 0.25rem; }
.entry-title a { color: var(--color-text); text-decoration: none; }
.entry-title a:hover { color: var(--color-accent); }
.entry-meta { font-size: 0.85rem; color: var(--color-text-muted); display: flex; align-items: center; gap: 0.5rem; }
.entry-actions { margin-top: 1rem; display: flex; gap: 0.5rem; }

/* === Markdown content === */
.markdown-body h1 { font-size: 1.6rem; margin: 1.5rem 0 0.75rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3rem; }
.markdown-body h2 { font-size: 1.35rem; margin: 1.3rem 0 0.6rem; }
.markdown-body h3 { font-size: 1.15rem; margin: 1rem 0 0.5rem; }
.markdown-body p { margin-bottom: 0.75rem; }
.markdown-body ul, .markdown-body ol { margin: 0.5rem 0 0.75rem 1.5rem; }
.markdown-body li { margin-bottom: 0.25rem; }
.markdown-body a { color: var(--color-accent); }
.markdown-body blockquote {
  border-left: 4px solid var(--color-border);
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  color: var(--color-text-muted);
}
.markdown-body pre {
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.markdown-body :not(pre) > code {
  background: var(--color-code-bg);
  padding: 0.15em 0.3em;
  border-radius: 3px;
}
.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--color-border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.markdown-body th { background: #fafafa; font-weight: 600; }

/* === Admonitions === */
.admonition {
  border-radius: 6px;
  padding: 1rem;
  margin: 0.75rem 0;
  border-left: 4px solid;
}
.admonition-title { font-weight: 700; margin-bottom: 0.3rem; }
.admonition-note { background: #eff6ff; border-color: #3b82f6; }
.admonition-tip { background: #f0fdf4; border-color: #22c55e; }
.admonition-warning { background: #fffbeb; border-color: #f59e0b; }
.admonition-caution { background: #fef2f2; border-color: #ef4444; }
.admonition-important { background: #faf5ff; border-color: #a855f7; }

/* === Mermaid === */
.mermaid { margin: 0.75rem 0; text-align: center; }
.mermaid-source { margin: 0.3rem 0; font-size: 0.85rem; }

/* === Math === */
.math-block { margin: 0.75rem 0; text-align: center; overflow-x: auto; }

/* === Comments === */
.comments-section { margin-top: 2rem; }
.comments-section h3 { font-size: 1.2rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; }
.comment {
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: #fafafa;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}
.comment-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.comment-actions { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.comment-form { margin-top: 1rem; }
.comment-form textarea {
  width: 100%;
  min-height: 100px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  resize: vertical;
}

/* === Editor === */
.editor-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0;
}
.editor-tab {
  padding: 0.5rem 1.25rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.editor-tab:hover { color: var(--color-text); }
.editor-tab.active {
  color: var(--color-text);
  border-color: var(--color-border);
  background: var(--color-bg);
  margin-bottom: -1px;
  padding-bottom: calc(0.5rem + 1px);
}
.editor-container {
  min-height: 500px;
}
.editor-pane textarea {
  width: 100%;
  height: 100%;
  min-height: 500px;
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  resize: vertical;
}
.preview-pane {
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 1rem;
  overflow-y: auto;
  min-height: 500px;
  max-height: 80vh;
}
.editor-toolbar {
  margin-bottom: 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.editor-toolbar input[type="text"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1.1rem;
}
.editor-toolbar input[type="date"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.editor-status {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-left: auto;
}
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.1);
  border: 2px dashed var(--color-accent);
  border-radius: 6px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--color-accent);
  pointer-events: none;
}
.editor-pane { position: relative; }
.editor-pane.dragging .drop-overlay { display: flex; }

/* === Search === */
.header-search-link {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.header-search-link:hover { color: var(--color-link); }
.search-form { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-input {
  flex: 1; padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border); border-radius: 6px; font-size: 1rem;
}
.search-result-count { color: var(--color-text-muted); margin-bottom: 1rem; }
.search-result { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--color-border); }
.search-result h3 { margin: 0 0 0.25rem; }
.search-excerpt { color: var(--color-text-muted); margin: 0.5rem 0 0; }

/* === Uploads Table === */
.uploads-table { width: 100%; border-collapse: collapse; }
.uploads-table th, .uploads-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}
.uploads-table th { font-weight: 600; font-size: 0.85rem; color: var(--color-text-muted); }
.upload-preview { width: 60px; }
.upload-preview img { max-width: 60px; max-height: 40px; border-radius: 4px; }
.upload-ext {
  display: inline-block; padding: 0.2rem 0.4rem; background: var(--color-border);
  border-radius: 4px; font-size: 0.75rem; font-family: var(--font-mono);
}
.badge { font-size: 0.75rem; padding: 0.15rem 0.5rem; border-radius: 10px; }
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* === Tags === */
.entry-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
a.tag {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  background: var(--color-accent-light);
  color: var(--color-accent);
  border-radius: 12px;
  font-size: 0.8rem;
  text-decoration: none;
  line-height: 1.4;
}
a.tag:hover { background: var(--color-accent); color: #fff; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.editor-tags-input {
  flex: 1 1 120px;
  min-width: 120px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
}

/* === Admin === */
.admin-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.admin-card {
  display: block;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--color-text);
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.admin-card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.admin-card-count {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-accent);
}
.admin-card-label {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}
.admin-table th { font-weight: 600; font-size: 0.85rem; color: var(--color-text-muted); }
