@import "tailwindcss";
@import "tw-animate-css";
@import "./themes/default.css";

@theme {
  --default-transition-duration: 150ms;
}

@layer base {
  * {
    @apply border-border outline-none ring-0;
  }

  body {
    @apply bg-background text-foreground;
  }

  /* ========================================
   * Task List Styles
   * Based on GitHub's implementation for proper nesting
   * ======================================== */

  /* Task list items - remove default list styling */
  .markdown-content .task-list-item,
  .prose .task-list-item {
    list-style-type: none;
  }

  /* Task list checkboxes - use negative margin for proper alignment */
  .markdown-content .task-list-item>input[type="checkbox"],
  .prose .task-list-item>input[type="checkbox"] {
    margin: 0 0.2em 0.25em -1.4em;
    vertical-align: middle;
  }

  /* Paragraphs inside task items should not have extra margins */
  .markdown-content .task-list-item>p,
  .prose .task-list-item>p {
    display: inline;
    margin: 0;
  }

  /* Task list containers maintain standard list spacing */
  .markdown-content .contains-task-list,
  .prose .contains-task-list {
    list-style: none;
    padding-left: 0;
  }

  /* Nested task lists get proper indentation (standard list padding) */
  .markdown-content .task-list-item .contains-task-list,
  .prose .task-list-item .contains-task-list {
    padding-left: 1.5em;
  }

  /* ========================================
   * Markdown Content Styles
   * Compact spacing optimized for memos/notes
   *
   * Key principles:
   * 1. Block elements use 8px (0.5rem) bottom margin (compact)
   * 2. First child has no top margin, last child has no bottom margin
   * 3. Nested elements have minimal spacing
   * 4. Inline elements have no vertical spacing
   * ======================================== */

  .markdown-content {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--foreground);
    word-wrap: break-word;
  }

  /* ========================================
   * First/Last Child Normalization
   * Remove boundary spacing to prevent double margins
   * ======================================== */

  .markdown-content> :first-child {
    margin-top: 0 !important;
  }

  .markdown-content> :last-child {
    margin-bottom: 0 !important;
  }

  /* ========================================
   * Block Elements
   * Compact 8px bottom margin
   * ======================================== */

  .markdown-content p,
  .markdown-content blockquote,
  .markdown-content ul,
  .markdown-content ol,
  .markdown-content dl,
  .markdown-content table,
  .markdown-content pre,
  .markdown-content hr {
    margin-top: 0;
    margin-bottom: 0.5rem;
  }

  /* ========================================
   * Headings
   * Compact spacing for visual separation
   * ======================================== */

  .markdown-content h1,
  .markdown-content h2,
  .markdown-content h3,
  .markdown-content h4,
  .markdown-content h5,
  .markdown-content h6 {
    margin-top: 0.75rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.25;
  }

  .markdown-content h1 {
    font-size: 2em;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.25rem;
  }

  .markdown-content h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.25rem;
  }

  .markdown-content h3 {
    font-size: 1.25em;
  }

  .markdown-content h4 {
    font-size: 1em;
  }

  .markdown-content h5 {
    font-size: 0.875em;
  }

  .markdown-content h6 {
    font-size: 0.85em;
    color: var(--muted-foreground);
  }

  /* ========================================
   * Paragraphs
   * ======================================== */

  .markdown-content p {
    line-height: 1.5;
  }

  /* ========================================
   * Links
   * ======================================== */

  .markdown-content a {
    color: var(--primary);
    text-decoration: underline;
    transition: opacity 150ms;
  }

  .markdown-content a:hover {
    opacity: 0.8;
  }

  /* ========================================
   * Lists
   * ======================================== */

  .markdown-content ul,
  .markdown-content ol {
    padding-left: 1.5em;
    list-style-position: outside;
  }

  .markdown-content ul {
    list-style-type: disc;
  }

  .markdown-content ol {
    list-style-type: decimal;
  }

  .markdown-content li {
    margin-top: 0.125rem;
    line-height: 1.5;
  }

  .markdown-content li>p {
    margin-bottom: 0.125rem;
  }

  /* Nested lists should have minimal spacing */
  .markdown-content li>ul,
  .markdown-content li>ol {
    margin-top: 0.125rem;
    margin-bottom: 0.125rem;
  }

  /* First and last items in lists */
  .markdown-content li:first-child {
    margin-top: 0;
  }

  .markdown-content li+li {
    margin-top: 0.125rem;
  }

  /* ========================================
   * Code (inline and blocks)
   * ======================================== */

  .markdown-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--muted);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
  }

  .markdown-content pre {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background: var(--muted);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .markdown-content pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    border-radius: 0;
  }

  /* ========================================
   * Blockquotes
   * ======================================== */

  .markdown-content blockquote {
    padding: 0 0.75rem;
    color: var(--muted-foreground);
    border-left: 0.25rem solid var(--border);
  }

  .markdown-content blockquote> :first-child {
    margin-top: 0;
  }

  .markdown-content blockquote> :last-child {
    margin-bottom: 0;
  }

  /* ========================================
   * Horizontal Rules
   * ======================================== */

  .markdown-content hr {
    height: 0.25em;
    padding: 0;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
  }

  /* ========================================
   * Tables
   * ======================================== */

  .markdown-content table {
    display: block;
    width: 100%;
    width: max-content;
    max-width: 100%;
    overflow: auto;
    border-spacing: 0;
    border-collapse: collapse;
  }

  .markdown-content table th,
  .markdown-content table td {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
  }

  .markdown-content table th {
    font-weight: 600;
    background: var(--muted);
  }

  .markdown-content table tr {
    background: transparent;
    border-top: 1px solid var(--border);
  }

  .markdown-content table tr:nth-child(2n) {
    background: var(--muted);
    opacity: 0.5;
  }

  /* ========================================
   * Images
   * ======================================== */

  .markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
  }

  /* ========================================
   * Embedded Content (iframes, videos)
   * ======================================== */

  .markdown-content iframe {
    max-width: 100%;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
  }

  /* ========================================
   * Inline Elements
   * No vertical spacing
   * ======================================== */

  .markdown-content strong {
    font-weight: 600;
  }

  .markdown-content em {
    font-style: italic;
  }

  .markdown-content code,
  .markdown-content strong,
  .markdown-content em,
  .markdown-content a {
    vertical-align: baseline;
  }

  /* Strikethrough (GFM) */
  .markdown-content del {
    text-decoration: line-through;
  }

  /* Leaflet Popup Overrides */
  .leaflet-popup-content-wrapper {
    border-radius: 0.5rem !important;
    border: 1px solid var(--border) !important;
    background-color: var(--background) !important;
    box-shadow: var(--shadow-lg) !important;
  }

  .leaflet-popup-content {
    margin: 4px !important;
    line-height: inherit !important;
    font-size: inherit !important;
  }

  .leaflet-popup-tip {
    background-color: var(--background) !important;
  }
}