/**
 * Trapper Keeper Web - Styles
 * Modern, clean design for a markdown notes web application
 */

/* CSS Variables */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-editor: #1e1e2e;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --accent: #e94560;
  --accent-hover: #ff6b6b;
  --success: #4ecca3;
  --warning: #ffc107;
  --error: #ff4757;
  --border: #2a2a4a;
  --shadow: rgba(0, 0, 0, 0.3);
  
  --sidebar-width: 280px;
  --header-height: 50px;
  --find-bar-height: 40px;
  
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  height: 100%;
  display: flex;
}

.hidden {
  display: none !important;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

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

/* ==================== LOGIN SCREEN ==================== */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.login-container {
  text-align: center;
  padding: 40px;
  background: var(--bg-secondary);
  border-radius: 16px;
  box-shadow: 0 20px 60px var(--shadow);
  max-width: 400px;
  width: 90%;
}

.logo h1 {
  font-size: 2.5rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.logo p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.login-btn .icon {
  font-size: 1.2rem;
}

.login-btn.cognito {
  background: var(--accent);
  color: white;
}

.login-btn.cognito:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.login-btn.google {
  background: #4285f4;
  color: white;
}

.login-btn.google:hover {
  background: #5a95f5;
  transform: translateY(-2px);
}

.login-btn.apple {
  background: #000;
  color: white;
}

.login-btn.apple:hover {
  background: #333;
  transform: translateY(-2px);
}

.login-btn.microsoft {
  background: #00a4ef;
  color: white;
}

.login-btn.microsoft:hover {
  background: #1cb0f6;
  transform: translateY(-2px);
}

.security-note {
  margin-top: 24px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.desktop-note {
  margin-top: 16px;
  font-size: 0.85rem;
}

.desktop-note a {
  color: var(--accent);
  text-decoration: none;
}

.desktop-note a:hover {
  text-decoration: underline;
}

/* ==================== MAIN SCREEN ==================== */
#main-screen {
  display: flex;
  height: 100%;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.search-box {
  padding: 0 12px 12px;
}

.search-box input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.documents-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.document-item {
  padding: 12px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background var(--transition-fast);
}

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

.document-item.active {
  background: var(--accent);
}

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

.document-item .doc-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-item .doc-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-email {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Buttons */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
}

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

.text-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}

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

/* Spinning animation for sync button */
.icon-btn.spinning {
  animation: spin 1s linear infinite;
}

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

/* ==================== EDITOR PANEL ==================== */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-editor);
  overflow: hidden;
}

/* Find/Replace Bar */
.find-replace-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
}

.find-row, .replace-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.replace-row {
  margin-top: 8px;
}

.find-replace-bar input {
  flex: 1;
  max-width: 300px;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.find-replace-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

.find-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 60px;
}

/* Editor Header */
#editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.doc-title-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
}

.doc-title-input:focus {
  outline: none;
}

.doc-title-input::placeholder {
  color: var(--text-muted);
}

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

.save-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.save-status.saving {
  color: var(--warning);
}

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

.save-status.error {
  color: var(--error);
}

/* Editor Container */
#editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.pane {
  flex: 1;
  overflow: auto;
}

#markdown-editor {
  width: 100%;
  height: 100%;
  padding: 20px;
  background: var(--bg-editor);
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: none;
}

#markdown-editor:focus {
  outline: none;
}

#markdown-editor::placeholder {
  color: var(--text-muted);
}

/* Preview Pane */
#preview-pane {
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
}

#markdown-preview {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

/* Markdown Preview Styles */
.markdown-body {
  color: var(--text-primary);
  line-height: 1.7;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin-top: 24px;
  margin-bottom: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.markdown-body h1 { font-size: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.markdown-body h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-body h3 { font-size: 1.25rem; }
.markdown-body h4 { font-size: 1rem; }

.markdown-body p {
  margin-bottom: 16px;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.markdown-body pre {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
}

.markdown-body pre code {
  background: none;
  padding: 0;
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 16px;
  margin: 16px 0;
  color: var(--text-secondary);
}

.markdown-body ul, .markdown-body ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.markdown-body li {
  margin-bottom: 8px;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* Search Highlight */
.search-highlight {
  background-color: var(--warning);
  color: var(--bg-primary);
  border-radius: 2px;
}

.search-highlight.current {
  background-color: var(--accent);
}

/* ==================== LOADING OVERLAY ==================== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-overlay p {
  margin-top: 16px;
  color: var(--text-secondary);
}

/* ==================== TOAST NOTIFICATIONS ==================== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px var(--shadow);
  animation: slideIn 0.3s ease;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warning { background: var(--warning); color: var(--bg-primary); }
.toast.info { background: var(--accent); }

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ==================== EMPTY STATES ==================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.empty-state .icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 1.1rem;
}

/* ==================== MOBILE MENU ==================== */
#mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 101;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
  #sidebar {
    width: 240px;
  }
}

@media (max-width: 700px) {
  #mobile-menu-btn {
    display: block;
  }
  
  #sidebar {
    position: fixed;
    left: -280px;
    height: 100%;
    z-index: 100;
    transition: left var(--transition-normal);
    width: var(--sidebar-width);
    box-shadow: 4px 0 20px var(--shadow);
  }
  
  #sidebar.open {
    left: 0;
  }
  
  #editor-header {
    padding-left: 60px;
  }
  
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
  }
  
  .sidebar-overlay.visible {
    display: block;
  }
}
