* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: #f7f8fa;
  color: #1a1d23;
  font-size: 14px;
  overflow: hidden;
}

/* ===== App Layout ===== */
.cal-app {
  display: flex;
  height: 100vh;
  background: #fff;
}

/* ===== Sidebar ===== */
.cal-sidebar {
  width: 260px;
  background: #fafbfc;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.cal-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}
.app-title {
  font-size: 18px;
  font-weight: 700;
  color: #2563eb;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.app-logo {
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-radius: 5px;
  display: inline-block;
}

/* Search */
.search-box {
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}
.search-box input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-box::before {
  content: '⌕';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 14px;
}

.search-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-top: none;
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
  display: none;
  margin-top: 2px;
  border-radius: 0 0 8px 8px;
}
.search-panel.show { display: block; }
.search-header-info {
  padding: 8px 16px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  font-size: 11px;
  color: #6b7280;
  font-weight: 600;
}
.search-result-item {
  padding: 10px 16px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
}
.search-result-item:hover { background: #f9fafb; }
.search-result-item:last-child { border-bottom: none; }
.search-result-title {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  margin-bottom: 2px;
}
.search-result-title mark {
  background: #fef3c7;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
.search-result-meta {
  font-size: 11px;
  color: #9ca3af;
  display: flex;
  gap: 10px;
}
.search-result-snippet {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  line-height: 1.5;
}
.search-result-snippet mark {
  background: #fef3c7;
  padding: 0 2px;
  border-radius: 2px;
}
.search-no-result {
  padding: 24px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}

/* Mini Calendar */
.mini-cal {
  padding: 16px;
}
.mini-cal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.mini-cal-header .month-label {
  font-weight: 700;
  font-size: 13px;
}
.mini-cal-nav { display: flex; gap: 4px; }
.mini-cal-nav button {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-cal-nav button:hover { background: #e5e7eb; }

.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.mini-cal-grid .dow {
  font-size: 10px;
  color: #9ca3af;
  text-align: center;
  padding: 4px 0;
  font-weight: 600;
}
.mini-cal-grid .day {
  font-size: 11px;
  text-align: center;
  padding: 5px 0;
  border-radius: 4px;
  cursor: pointer;
  color: #374151;
}
.mini-cal-grid .day:hover { background: #e5e7eb; }
.mini-cal-grid .day.other-month { color: #d1d5db; }
.mini-cal-grid .day.today {
  background: #2563eb;
  color: white;
  font-weight: 700;
}
.mini-cal-grid .day.selected {
  background: #dbeafe;
  color: #2563eb;
  font-weight: 700;
}
.mini-cal-grid .day.has-entry::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #10b981;
  margin: 1px auto 0;
}
.mini-cal-grid .day.today.has-entry::after { background: white; }

/* Categories */
.cal-categories {
  padding: 16px;
  border-top: 1px solid #e5e7eb;
}
.cal-categories h4 {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.category-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
}
.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.category-item:hover { color: #2563eb; }

/* ===== Main Calendar ===== */
.cal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cal-main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid #e5e7eb;
}
.cal-main-header .current-month {
  font-size: 20px;
  font-weight: 700;
}
.cal-view-switch {
  display: flex;
  gap: 4px;
  background: #f3f4f6;
  padding: 3px;
  border-radius: 6px;
}
.cal-view-switch button {
  padding: 5px 12px;
  border: none;
  background: transparent;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: #6b7280;
  font-weight: 500;
}
.cal-view-switch button.active {
  background: white;
  color: #2563eb;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  font-weight: 600;
}
.btn-today {
  padding: 6px 14px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
  color: #374151;
}
.btn-today:hover { background: #f9fafb; }
.btn-nav {
  width: 30px;
  height: 30px;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #6b7280;
}
.btn-nav:hover { background: #f9fafb; }

.cal-grid {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
.cal-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid #e5e7eb;
}
.cal-grid-header .dow-cell {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-right: 1px solid #e5e7eb;
}
.cal-grid-header .dow-cell:last-child { border-right: none; }
.cal-grid-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  overflow: hidden;
}
.cal-day-cell {
  border-right: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 8px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.15s;
}
.cal-day-cell:nth-child(7n) { border-right: none; }
.cal-day-cell:hover { background: #f9fafb; }
.cal-day-cell.other-month { background: #fafbfc; }
.cal-day-cell.other-month .day-number { color: #d1d5db; }
.cal-day-cell.today .day-number {
  background: #2563eb;
  color: white;
}
.cal-day-cell.selected { background: #eff6ff; }

.day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 50%;
}
.day-entries {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.day-entry {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.day-entry.life { background: #d1fae5; color: #065f46; }
.day-entry.stock { background: #fef3c7; color: #92400e; }
.day-entry.note { background: #ede9fe; color: #5b21b6; }
.day-entry.more {
  background: transparent;
  color: #6b7280;
  font-style: italic;
}

/* ===== Editor Panel ===== */
.cal-editor {
  width: 360px;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: #fff;
}
.editor-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}
.editor-date {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.editor-weekday { font-size: 12px; color: #6b7280; }
.btn-new-entry {
  padding: 5px 12px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-new-entry:hover { background: #1d4ed8; }

.editor-tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  border-bottom: 1px solid #e5e7eb;
  overflow-x: auto;
}
.editor-tab {
  padding: 10px 10px;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.editor-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}

/* Entry list */
.entry-list {
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
  max-height: 200px;
  overflow-y: auto;
  flex-shrink: 0;
}
.entry-card {
  display: flex;
  gap: 0;
  background: #fafbfc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.15s;
}
.entry-card:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}
.entry-card.active {
  border-color: #2563eb;
  background: #eff6ff;
}
.entry-card-left {
  width: 4px;
  flex-shrink: 0;
}
.entry-cat-bar { width: 100%; height: 100%; }
.entry-cat-bar.life { background: #10b981; }
.entry-cat-bar.stock { background: #f59e0b; }
.entry-cat-bar.note { background: #8b5cf6; }

.entry-card-body {
  flex: 1;
  padding: 8px 10px;
  min-width: 0;
}
.entry-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}
.entry-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-open-btn {
  font-size: 12px;
  color: #9ca3af;
  padding: 2px 4px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-left: 6px;
}
.entry-open-btn:hover {
  background: #dbeafe;
  color: #2563eb;
}
.entry-card-snippet {
  font-size: 11px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.entry-card-time { font-size: 10px; color: #9ca3af; }

/* Editor body */
.editor-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.editor-category-select {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.cat-chip {
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #d1d5db;
  background: white;
  user-select: none;
}
.cat-chip.active.life {
  background: #d1fae5;
  border-color: #10b981;
  color: #065f46;
}
.cat-chip.active.stock {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}
.cat-chip.active.note {
  background: #ede9fe;
  border-color: #8b5cf6;
  color: #5b21b6;
}

.editor-title-input {
  width: 100%;
  padding: 8px 0;
  border: none;
  border-bottom: 1px solid #e5e7eb;
  font-size: 16px;
  font-weight: 600;
  outline: none;
  margin-bottom: 12px;
  background: transparent;
}

.editor-toolbar {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  padding: 4px;
  background: #f9fafb;
  border-radius: 6px;
  flex-wrap: wrap;
}
.toolbar-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar-btn:hover {
  background: #e5e7eb;
  color: #374151;
}
.toolbar-divider {
  width: 1px;
  background: #e5e7eb;
  margin: 4px 2px;
}

.editor-content {
  flex: 1;
  min-height: 120px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  overflow-y: auto;
}
.editor-content:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Tables in editor */
.entry-table-wrapper {
  margin-top: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.entry-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}
.entry-table-actions { display: flex; gap: 4px; }
.entry-table-actions button {
  padding: 3px 8px;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  color: #6b7280;
}
.entry-table-actions button:hover { background: #f3f4f6; }

.entry-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.entry-table th,
.entry-table td {
  border: 1px solid #e5e7eb;
  padding: 6px 8px;
  text-align: center;
  min-width: 60px;
}
.entry-table th {
  background: #f3f4f6;
  font-weight: 600;
  font-size: 11px;
  color: #6b7280;
}
.entry-table td[contenteditable] { outline: none; }
.entry-table td[contenteditable]:focus {
  background: #eff6ff;
  box-shadow: inset 0 0 0 2px #2563eb;
}
.entry-table .up { color: #dc2626; font-weight: 600; }
.entry-table .down { color: #10b981; font-weight: 600; }
.entry-table tr.summary-row {
  background: #f9fafb;
  font-weight: 700;
}

.editor-footer {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.btn-save {
  padding: 8px 18px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-save:hover { background: #1d4ed8; }
.editor-status { font-size: 11px; color: #6b7280; }
.editor-status.saved { color: #10b981; }
.editor-status.saving { color: #f59e0b; }
.editor-status.error { color: #ef4444; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .cal-sidebar { width: 220px; }
  .cal-editor { width: 300px; }
}

@media (max-width: 768px) {
  .cal-app { flex-direction: column; height: auto; min-height: 100vh; }
  .cal-sidebar { width: 100%; }
  .cal-editor { width: 100%; border-left: none; border-top: 1px solid #e5e7eb; }
  body { overflow: auto; }
}
