/* ============================================
   Daily Journal - Styles
   ============================================ */

/* CSS Custom Properties - Light Theme (default) */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Colors - Light */
  --bg-primary: #f8f9fc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f2f7;
  --bg-sidebar: #ffffff;
  --bg-hover: #eef0f5;
  --bg-active: #e3e8f0;

  --text-primary: #1a1d2e;
  --text-secondary: #5a5f7a;
  --text-tertiary: #9298b0;
  --text-inverse: #ffffff;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-glow: rgba(99, 102, 241, 0.15);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;

  --success: #22c55e;
  --success-light: #f0fdf4;

  --border: #e2e5ed;
  --border-light: #f0f2f7;
  --border-focus: #6366f1;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 4px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-width: 320px;
  --topbar-height: 64px;

  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #0f111a;
  --bg-secondary: #181b29;
  --bg-tertiary: #1e2235;
  --bg-sidebar: #131626;
  --bg-hover: #252a40;
  --bg-active: #2e3450;

  --text-primary: #e8eaf0;
  --text-secondary: #9ca3c1;
  --text-tertiary: #6b7294;
  --text-inverse: #0f111a;

  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: #1e2240;
  --accent-glow: rgba(129, 140, 248, 0.15);

  --danger: #f87171;
  --danger-hover: #ef4444;
  --danger-light: #2d1b1b;

  --success: #4ade80;
  --success-light: #1a2e1a;

  --border: #262b40;
  --border-light: #1e2235;
  --border-focus: #818cf8;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2), 0 1px 4px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  transition: background var(--transition-slow), color var(--transition-slow);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* App Container */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20;
  transition: transform var(--transition-slow), background var(--transition-slow);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  flex-shrink: 0;
}

.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.app-title i {
  font-size: 1.2rem;
  -webkit-text-fill-color: var(--accent);
}

.sidebar-search {
  padding: 0 16px 12px;
  flex-shrink: 0;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  pointer-events: none;
  transition: color var(--transition);
}

.search-box input {
  width: 100%;
  padding: 9px 36px 9px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-sans);
  outline: none;
  transition: all var(--transition);
}

.search-box input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-secondary);
}

.search-box input:focus ~ .search-icon,
.search-box input:focus + .search-icon {
  color: var(--accent);
}

.search-box input::placeholder {
  color: var(--text-tertiary);
}

.btn-clear-search {
  position: absolute;
  right: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.btn-clear-search.visible {
  opacity: 1;
  pointer-events: auto;
}

.btn-new-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 16px 12px;
  padding: 10px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-new-entry:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-new-entry:active {
  transform: translateY(0);
}

/* Entries List */
.entries-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.entries-list::-webkit-scrollbar {
  width: 3px;
}

.entry-group {
  margin-bottom: 4px;
}

.entry-group-header {
  padding: 8px 8px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.entry-group-header i {
  font-size: 0.65rem;
  transition: transform var(--transition);
}

.entry-group-header.collapsed i {
  transform: rotate(-90deg);
}

.entry-item {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  position: relative;
}

.entry-item:hover {
  background: var(--bg-hover);
}

.entry-item.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
}

.entry-item-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-item-date {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.entry-item-date i {
  font-size: 0.65rem;
}

.entry-item-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* No entries state in sidebar */
.no-entries {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}

.no-entries i {
  font-size: 2rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.no-entries p {
  font-size: 0.85rem;
}

/* Search results */
.search-highlight {
  background: var(--accent);
  color: white;
  border-radius: 2px;
  padding: 0 2px;
}

.no-search-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}

.no-search-results i {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.entry-count {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative;
  background: var(--bg-primary);
  transition: background var(--transition-slow);
}

/* Top Bar */
.top-bar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 16px;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.date-navigation {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-picker-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.date-picker-wrapper input[type="date"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  left: 0;
  top: 0;
}

.date-label {
  font-size: 1rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  min-width: 140px;
  text-align: center;
}

.date-label:hover {
  background: var(--bg-hover);
}

.btn-today {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-today:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-tertiary);
  transition: all var(--transition);
}

.save-indicator.saving {
  color: var(--accent);
}

.save-indicator.saved {
  color: var(--success);
}

.save-indicator i {
  font-size: 0.75rem;
}

/* ============================================
   Editor Area
   ============================================ */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
  pointer-events: none;
}

.editor-area.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  flex-wrap: wrap;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon.active {
  background: var(--accent-light);
  color: var(--accent);
}

.btn-delete:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.sidebar-toggle {
  display: none;
}

/* Editor Body */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 32px;
}

.entry-title-input {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  padding: 0 0 16px;
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
  width: 100%;
}

.entry-title-input::placeholder {
  color: var(--text-tertiary);
  opacity: 0.6;
}

.editor-content-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 200px;
}

.entry-content {
  width: 100%;
  height: 100%;
  min-height: 300px;
  padding: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.8;
  font-family: var(--font-sans);
}

.entry-content::placeholder {
  color: var(--text-tertiary);
  opacity: 0.5;
}

.entry-preview {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 300px;
  padding: 0;
  line-height: 1.8;
  color: var(--text-primary);
  overflow-y: auto;
}

.entry-preview.visible {
  display: block;
}

.entry-content.preview-hidden {
  display: none;
}

.entry-preview h1,
.entry-preview h2,
.entry-preview h3,
.entry-preview h4 {
  margin: 1.5em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.entry-preview h1 { font-size: 1.75rem; }
.entry-preview h2 { font-size: 1.4rem; }
.entry-preview h3 { font-size: 1.2rem; }

.entry-preview p {
  margin-bottom: 1em;
}

.entry-preview strong {
  font-weight: 600;
}

.entry-preview em {
  font-style: italic;
}

.entry-preview blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 1em 0;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.entry-preview ul,
.entry-preview ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.entry-preview li {
  margin-bottom: 0.25em;
}

.entry-preview code {
  font-family: var(--font-mono);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875em;
}

.entry-preview pre {
  background: var(--bg-tertiary);
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 1em 0;
}

.entry-preview pre code {
  background: none;
  padding: 0;
}

/* Editor Footer */
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.stats {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.entry-date-display {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}

.empty-state.visible {
  opacity: 1;
  pointer-events: auto;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.empty-state h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 360px;
  line-height: 1.6;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 8px;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-tertiary);
}

.btn-danger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--danger);
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 90%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  transform: scale(0.95);
  transition: transform var(--transition);
  overflow: hidden;
}

.modal-overlay.visible .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close {
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
}

.modal-body {
  padding: 16px 24px 24px;
}

.modal-body p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 24px 20px;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 300ms ease-out;
  pointer-events: auto;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast i {
  font-size: 1rem;
}

.toast.success i {
  color: var(--success);
}

.toast.error i {
  color: var(--danger);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.removing {
  animation: toastOut 200ms ease-in forwards;
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
    --topbar-height: 56px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex !important;
  }

  .top-bar {
    padding: 0 16px;
  }

  .editor-toolbar {
    padding: 8px 12px;
  }

  .editor-body {
    padding: 16px;
  }

  .entry-title-input {
    font-size: 1.35rem;
  }

  .date-label {
    min-width: 100px;
    font-size: 0.9rem;
  }

  .btn-today {
    display: none;
  }

  .editor-footer {
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
    padding: 10px 16px;
  }
}

@media (max-width: 480px) {
  .editor-body {
    padding: 12px;
  }

  .entry-title-input {
    font-size: 1.2rem;
  }

  .editor-toolbar {
    padding: 4px 8px;
    gap: 1px;
  }

  .date-label {
    min-width: 80px;
    font-size: 0.85rem;
  }

  .toolbar-separator {
    display: none;
  }
}
