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

@theme {
  --default-transition-duration: 150ms;
  --animate-shimmer: shimmer 1.5s infinite;
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

@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;
  }

  /* ========================================
   * Deadlines Page
   * ======================================== */

  .deadlines-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 16px 48px;
  }

  .deadlines-header {
    margin-bottom: 28px;
  }

  .deadlines-header__title {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--foreground);
  }

  .deadlines-header__title h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
  }

  .deadlines-header__sub {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    margin: 4px 0 0 34px;
  }

  .deadlines-sections {
    display: flex;
    flex-direction: column;
    gap: 28px;
  }

  /* Section */
  .deadline-section {}

  .deadline-section__header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .deadline-section__count {
    background: currentColor;
    color: white;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 7px;
    opacity: 0.85;
  }

  .deadline-section__empty {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    padding: 8px 0;
  }

  .deadline-section__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  /* Card */
  .memo-deadline-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--background);
    transition: box-shadow 0.15s, border-color 0.15s;
  }

  .memo-deadline-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
    border-color: var(--primary);
  }

  .memo-deadline-card--overdue {
    border-color: #fca5a5;
    background: #fff5f5;
  }

  .memo-deadline-card--done {
    opacity: 0.6;
  }

  .memo-deadline-card__check {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-top: 2px;
    flex-shrink: 0;
    transition: transform 0.15s;
  }

  .memo-deadline-card__check:hover {
    transform: scale(1.15);
  }

  .memo-deadline-card__body {
    flex: 1;
    min-width: 0;
  }

  .memo-deadline-card__title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--foreground);
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: text-decoration 0.15s;
  }

  .memo-deadline-card__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
  }

  .memo-deadline-card__tag {
    font-size: 11px;
    color: var(--muted-foreground);
    background: var(--muted);
    padding: 1px 6px;
    border-radius: 4px;
  }

  /* Loading / Error */
  .deadlines-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 200px;
    color: var(--muted-foreground);
  }

  .deadlines-error {
    color: #dc2626;
    padding: 16px;
    text-align: center;
  }

  .animate-spin {
    animation: spin 1s linear infinite;
  }

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