/* ---------------------------------------------------------------------------
   Cloud Reader – Global Styles
   Minimal, clean design system for the bookmark & notes management UI.
   --------------------------------------------------------------------------- */

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

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-secondary: #6b7280;
  --color-secondary-hover: #4b5563;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-quote-bg: #f3f4f6;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

/* App container */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.app-nav {
  display: flex;
  gap: 1rem;
}

.nav-link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

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

/* Main content */
.app-main {
  min-height: 70vh;
  padding-bottom: 3rem;
}

.page {
  padding: 1rem 0;
}

.page h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* Quick links */
.quick-links {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.card-link {
  display: block;
  padding: 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.card-link:hover {
  box-shadow: var(--shadow-lg);
}

.card-link h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.card-link p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-secondary);
  border-color: var(--color-border);
}

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

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

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

.btn-block {
  width: 100%;
  display: block;
}

/* Annotation list */
.annotations-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.annotation-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.annotation-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.annotation-kind-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bookmark-badge {
  background: #dbeafe;
  color: #1d4ed8;
}

.note-badge {
  background: #fef3c7;
  color: #b45309;
}

.annotation-book-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.annotation-page {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.annotation-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-left: auto;
}

.annotation-quote {
  margin: 0.5rem 0;
  padding: 0.5rem 0.75rem;
  background: var(--color-quote-bg);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
  font-style: italic;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.note-content-text {
  font-size: 0.9375rem;
  line-height: 1.6;
  margin: 0.5rem 0;
  white-space: pre-wrap;
}

.annotation-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* Loading & empty states */
.annotations-loading,
.annotations-empty {
  padding: 2rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* Dashboard summary */
.annotations-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.summary-separator {
  color: var(--color-border);
}

/* Add annotation modal */
.add-annotation-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.add-annotation-modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
}

.modal-close:hover {
  color: var(--color-text);
}

.add-annotation-modal h3 {
  font-size: 1.125rem;
  margin-bottom: 0.75rem;
}

/* Annotation form */
.mode-selector {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.annotation-form {
  margin-top: 1rem;
}

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

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

.form-textarea {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  resize: vertical;
}

.form-textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

.form-error {
  color: var(--color-danger);
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
}

/* Note edit inline */
.note-edit-form {
  margin: 0.5rem 0;
}

.note-edit-textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  resize: vertical;
}

.note-edit-textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary);
}

.note-edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Marker threads (bookmarks-notes page) */
.marker-books-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.marker-book-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--color-surface);
}

.marker-book-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border: none;
  background: #f8fafc;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.marker-book-title {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}

.marker-book-count {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

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

.marker-thread-list {
  list-style: none;
  margin: 0;
  padding: 0.75rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.marker-thread {
  padding-left: 0.75rem;
  border-left: 2px solid #e5e7eb;
}

.marker-thread-chapter {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #4f46e5;
  display: block;
  margin-bottom: 0.35rem;
}

.marker-thread-passage {
  margin: 0.25rem 0 0.5rem;
}

.marker-passage-text {
  display: block;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.marker-passage-text--clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  white-space: normal;
}

.marker-thought-wrap {
  margin: 0.5rem 0 0.25rem 1rem;
}

.marker-thought-text {
  margin: 0;
}

.marker-thought-text--clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.marker-text-toggle {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0;
  border: none;
  background: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: #4f46e5;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.marker-text-toggle:hover {
  color: #3730a3;
}

.marker-thread-thought {
  padding: 0.65rem 0.85rem;
  background: #f9fafb;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.marker-thread-reply {
  border-left: 2px solid #d1d5db;
}

/* Responsive */
@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }

  .annotation-card-header {
    flex-wrap: wrap;
  }

  .annotation-date {
    margin-left: 0;
  }
}