/* ==========================================================================
   JrnlFish Styles
   ========================================================================== */

/* ==========================================================================
   0. CSS Custom Properties
   ========================================================================== */

:root {
  /* Colors */
  --color-bg: #fafafa;
  --color-text: #333;
  --color-text-muted: #666;
  --color-text-placeholder: #aaa;
  --color-card: #fff;
  --color-border: #e0e0e0;
  --color-primary: #0066cc;
  --color-primary-hover: #0056b3;
  --color-success: #22863a;
  --color-error: #dc3545;

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Shadows */
  --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-card-hover: 0 2px 8px rgba(0, 0, 0, 0.08);

  /* Container */
  --container-max-width: 600px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1a1a;
    --color-text: #e0e0e0;
    --color-text-muted: #999;
    --color-text-placeholder: #666;
    --color-card: #2a2a2a;
    --color-border: #404040;
    --color-primary: #4da3ff;
    --color-primary-hover: #79b8ff;
    --color-success: #4caf50;
    --color-error: #f44336;

    --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* ==========================================================================
   1. Base & Reset
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--spacing-md);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

@media (min-width: 768px) {
  body {
    padding: var(--spacing-xl);
  }
}

/* ==========================================================================
   2. Layout (header, nav, main, footer)
   ========================================================================== */

header {
  text-align: center;
  margin-bottom: 2rem;
}

nav {
  margin: 2rem 0;
}

nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

nav a {
  text-decoration: none;
  color: #0066cc;
  padding: 0.5rem 1rem;
  border: 1px solid #0066cc;
  border-radius: 4px;
  display: block;
  transition: all 0.2s ease;
}

nav a:hover {
  background: #0066cc;
  color: white;
}

nav button {
  text-decoration: none;
  color: #0066cc;
  padding: 0.5rem 1rem;
  border: 1px solid #0066cc;
  border-radius: 4px;
  display: block;
  transition: all 0.2s ease;
  background: none;
  font: inherit;
  cursor: pointer;
}

nav button:hover {
  background: #0066cc;
  color: white;
}

nav form {
  margin: 0;
  display: inline;
}

main {
  margin: 2rem 0;
}

footer {
  text-align: center;
  color: #666;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

/* ==========================================================================
   3. Cards
   ========================================================================== */

.card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--spacing-xl);
  margin: var(--spacing-xl) 0;
  background: var(--color-card);
  box-shadow: var(--shadow-card);
}

.card-muted {
  background: var(--color-bg);
}

/* Quick entry card variant */
.quick-entry {
  background: var(--color-card);
  border: 1px solid var(--color-primary);
}

.quick-entry textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
  background: var(--color-card);
  color: var(--color-text);
}

.quick-entry textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

/* ==========================================================================
   4. Forms (inputs, labels, groups, help text)
   ========================================================================== */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 16px;
  font-family: inherit;
  background: var(--color-card);
  color: var(--color-text);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.form-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
  background: var(--color-card);
  color: var(--color-text);
}

.form-textarea-large {
  min-height: 300px;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.form-checkbox {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.form-checkbox input {
  margin-right: 0.5rem;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.help-text {
  display: block;
  margin-top: 0.25rem;
  color: #666;
  font-size: 0.875rem;
}

.help-text-indent {
  margin-left: 1.6rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   5. Buttons
   ========================================================================== */

.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

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

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-card);
}

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #c82333;
}

.btn-block {
  width: 100%;
}

.button-group {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* ==========================================================================
   6. Status Messages
   ========================================================================== */

.status-message {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin: 1rem 0;
  font-weight: 500;
}

.status-message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.status-message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* ==========================================================================
   7. Entry List
   ========================================================================== */

.entry-list {
  list-style: none;
  padding: 0;
  margin: 2rem 0;
}

.entry-item {
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1rem 0;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.2s ease;
}

.entry-item:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.entry-date {
  font-weight: bold;
  color: var(--color-primary);
  margin-bottom: var(--spacing-sm);
}

.entry-preview {
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 0;
}

.entry-preview-date {
  font-weight: bold;
  color: var(--color-primary);
  font-size: 0.9em;
  margin-bottom: var(--spacing-xs);
}

.entry-preview-date a {
  color: var(--color-primary);
  text-decoration: none;
}

.entry-preview-content {
  color: var(--color-text-muted);
  font-size: 0.9em;
}

/* ==========================================================================
   8. Utilities
   ========================================================================== */

.text-muted {
  color: var(--color-text-muted);
}

.text-center {
  text-align: center;
}

.text-italic {
  font-style: italic;
}

.mb-0 {
  margin-bottom: 0;
}

.mb-1 {
  margin-bottom: 1rem;
}

.mb-2 {
  margin-bottom: 1.5rem;
}

.mt-1 {
  margin-top: 1rem;
}

.code-inline {
  background: var(--color-bg);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  font-family: monospace;
}

.list-plain {
  list-style: none;
  padding: 0;
}

.link-primary {
  color: var(--color-primary);
  text-decoration: none;
}

.link-primary:hover {
  text-decoration: underline;
}

/* ==========================================================================
   9. Responsive
   ========================================================================== */

@media (max-width: 767px) {
  nav ul {
    gap: 0.25rem;
    font-size: 14px;
  }

  nav a,
  nav button {
    padding: 0.375rem 0.75rem;
  }

  .card {
    padding: var(--spacing-md);
    margin: var(--spacing-md) 0;
  }

  .entry-item {
    padding: var(--spacing-md);
  }

  .btn {
    width: 100%;
    margin-bottom: var(--spacing-sm);
  }

  .button-group {
    flex-direction: column;
  }
}

/* ==========================================================================
   10. MVP Minimal Layout
   ========================================================================== */

/* Container for minimal layout */
.container {
  max-width: var(--container-max-width);
  margin: 0 auto;
}

/* Top bar for minimal pages */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-xl);
}

.top-bar h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.top-bar button {
  background: none;
  border: none;
  color: var(--color-primary);
  font: inherit;
  cursor: pointer;
  padding: var(--spacing-sm);
}

.top-bar button:hover {
  text-decoration: underline;
}

/* Back button - hidden until hover */
.back-btn {
  font-size: 0.9375rem;
  padding: var(--spacing-xs) var(--spacing-sm);
  opacity: 0;
  transition: opacity 0.15s ease;
  color: var(--color-primary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.back-btn:hover,
.back-btn:focus,
.back-btn:active {
  opacity: 1;
  text-decoration: none;
}

/* Show back button on container hover or when focused */
.top-bar:hover .back-btn,
.back-btn:focus {
  opacity: 1;
}

/* ==========================================================================
   11. MVP Entry Card & Contenteditable
   ========================================================================== */

.entry-card {
  position: relative;
}

.entry-heading {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0 0 var(--spacing-md);
}

/* Saved indicator */
.saved-indicator {
  position: absolute;
  top: var(--spacing-lg);
  right: var(--spacing-xl);
  color: var(--color-success);
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.saved-indicator.visible {
  opacity: 1;
}

.saved-indicator.error {
  color: var(--color-danger);
}

/* Contenteditable entry area */
.entry-content {
  width: 80ch;
  max-width: 100%;
  min-height: 300px;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 18px;
  line-height: 1.7;
  background: transparent;
  color: var(--color-text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.entry-content:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-placeholder);
  pointer-events: none;
}

/* Images in contenteditable */
.entry-content img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: var(--spacing-lg) 0;
  border-radius: 4px;
}

/* Drag-over state for images */
.entry-content.drag-over {
  background: rgba(0, 102, 204, 0.05);
  outline: 2px dashed var(--color-primary);
  outline-offset: -2px;
}

@media (prefers-color-scheme: dark) {
  .entry-content.drag-over {
    background: rgba(77, 163, 255, 0.1);
  }
}

/* ==========================================================================
   12. MVP Entries List
   ========================================================================== */

.entries-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
}

.entries-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.entries-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Card-based entry list item */
.entry-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: box-shadow 0.15s ease;
  text-decoration: none;
  color: inherit;
}

.entry-list-item:hover,
.entry-list-item:focus {
  box-shadow: var(--shadow-card-hover);
  outline: none;
}

.entry-list-item:focus {
  border-color: var(--color-primary);
}

.entry-list-item-content {
  flex: 1;
  min-width: 0;
}

.entry-list-item-date {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--spacing-xs);
}

.entry-list-item-preview {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-list-item-chevron {
  color: var(--color-text-placeholder);
  margin-left: var(--spacing-md);
  font-size: 1.25rem;
}

/* ==========================================================================
   13. MVP Login Screen
   ========================================================================== */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 2rem;
  margin: 0 0 var(--spacing-sm);
  color: var(--color-text);
}

.login-card .tagline {
  color: var(--color-text-muted);
  margin: 0 0 var(--spacing-xl);
}

.login-card .form-group {
  text-align: left;
}

.login-card .form-group label {
  color: var(--color-text-muted);
}

/* ==========================================================================
   14. Accessibility - Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
