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

:root {
  --bg: #f7f3ed;
  --surface: #fffdf8;
  --surface-alt: #f0ebe2;
  --primary: #6b5b4e;
  --primary-light: #8a7868;
  --primary-dark: #4a3f36;
  --accent: #c08552;
  --accent-light: #d49b6a;
  --accent-bg: #faf0e6;
  --text: #3d352e;
  --text-muted: #968b7e;
  --text-light: #b8aea1;
  --border: #e8e0d5;
  --border-light: #f0ebe2;
  --danger: #c45a5a;
  --danger-bg: #fce8e8;
  --success: #5a8a5a;
  --shadow: 0 2px 12px rgba(107, 91, 78, 0.08);
  --shadow-lg: 0 8px 32px rgba(107, 91, 78, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 320px;
  --font-serif: 'Noto Serif SC', Georgia, 'Times New Roman', serif;
  --font-sans: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Views ===== */
.view {
  display: none;
  width: 100%;
  height: 100%;
}
.view.active {
  display: flex;
}

/* ===== Auth & Lock Views ===== */
#authView, #lockView {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6b5b4e 0%, #4a3f36 50%, #3d352e 100%);
  position: relative;
  overflow: hidden;
}

#authView::before, #lockView::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(192, 133, 82, 0.15) 0%, transparent 70%);
  top: -200px;
  right: -200px;
}
#authView::after, #lockView::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(192, 133, 82, 0.1) 0%, transparent 70%);
  bottom: -150px;
  left: -100px;
}

.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 1;
  animation: cardIn 0.5s ease;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-icon {
  color: var(--accent);
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.auth-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(192, 133, 82, 0.15);
}

.input-group input::placeholder {
  color: var(--text-light);
}

.btn-primary {
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 1px;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-switch {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.auth-hint {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}

/* ===== Main App Layout ===== */
#appView {
  display: none;
}
#appView.active {
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
}

.btn-new {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
  margin-bottom: 14px;
}

.btn-new:hover {
  background: var(--primary-dark);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  flex: 1;
  color: var(--text);
  font-family: var(--font-sans);
}

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

/* Entry List */
.entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.entry-list::-webkit-scrollbar {
  width: 4px;
}
.entry-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.entry-item {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
  border: 2px solid transparent;
}

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

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

.entry-item-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.entry-item-mood {
  font-size: 14px;
}

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

.entry-item-preview {
  font-size: 13px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state p {
  font-size: 14px;
}

.empty-state .empty-sub {
  font-size: 12px;
  margin-top: 4px;
}

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

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
}

.btn-lock {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-lock:hover {
  background: var(--surface-alt);
  color: var(--primary);
}

/* Editor Panel */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  padding: 40px;
  text-align: center;
}

.editor-empty-icon {
  color: var(--border);
  margin-bottom: 20px;
}

.editor-empty h2 {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.editor-empty p {
  font-size: 14px;
  color: var(--text-light);
}

.editor-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface);
  flex-wrap: wrap;
}

.date-input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--surface);
  outline: none;
  cursor: pointer;
}

.date-input:focus {
  border-color: var(--accent);
}

.mood-selector {
  display: flex;
  gap: 4px;
}

.mood-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0.5;
  line-height: 1;
}

.mood-btn:hover {
  opacity: 1;
  background: var(--surface-alt);
}

.mood-btn.active {
  opacity: 1;
  background: var(--accent-bg);
  border-color: var(--accent-light);
}

.toolbar-spacer {
  flex: 1;
}

.save-status {
  font-size: 12px;
  color: var(--text-light);
  min-width: 60px;
  text-align: right;
}

.save-status.saving { color: var(--accent); }
.save-status.saved { color: var(--success); }

.btn-delete {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

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

.entry-title-input {
  border: none;
  outline: none;
  padding: 20px 28px 8px;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-serif);
  color: var(--primary-dark);
  background: transparent;
  width: 100%;
}

.entry-title-input::placeholder {
  color: var(--text-light);
  font-weight: 400;
}

.entry-content-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 28px 28px;
  font-size: 16px;
  font-family: var(--font-serif);
  line-height: 1.9;
  color: var(--text);
  background: transparent;
  resize: none;
  width: 100%;
  overflow-y: auto;
}

.entry-content-input::placeholder {
  color: var(--text-light);
}

.entry-content-input::-webkit-scrollbar {
  width: 6px;
}
.entry-content-input::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Sidebar Toggle (Mobile) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--primary-dark);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

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

.toast.success {
  background: var(--success);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 99;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }

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

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

  .entry-title-input {
    padding: 16px 16px 8px;
    font-size: 20px;
  }

  .entry-content-input {
    padding: 8px 16px 16px;
    font-size: 15px;
  }

  .auth-card {
    margin: 20px;
    padding: 36px 24px;
  }

  .mood-selector {
    flex-wrap: wrap;
  }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Overlay for mobile sidebar */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 98;
}

.overlay.show {
  display: block;
}
