/* CSS Reset Layer */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
  }
}

/* Design Tokens Layer */
@layer tokens {
  :root {
    /* Colors */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-bg: #f9fafb;
    --color-surface: #ffffff;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;

    /* Typography */
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;

    /* Border Radius */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
  }
}

/* Base Layer */
@layer base {
  body {
    color: var(--color-text);
    background: var(--color-bg);
  }

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

/* Component Layer */
@layer components {
  /* Buttons - shared across views */
  .btn-primary {
    padding: var(--spacing-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-surface);
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 48px;
  }

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

  .btn-delete {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--color-danger);
    background: transparent;
    border: 1px solid var(--color-danger);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 36px;
  }

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

  .btn-edit {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 36px;
  }

  .btn-copy {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
  }

  .btn-delete-list {
    width: 100%;
    padding: var(--spacing-md);
    font-size: var(--font-size-base);
    color: var(--color-danger);
    background: transparent;
    border: 2px solid var(--color-danger);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 48px;
  }

  .btn-delete-list:hover {
    background: var(--color-danger);
    color: var(--color-surface);
  }

  /* Utilities */
  .hidden {
    display: none !important;
  }

  /* Flash Messages - Bubble Style */
  #flash-messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    pointer-events: none; /* Allow clicking through the container */
    max-width: 400px;
  }

  .flash {
    position: relative;
    margin-bottom: 10px;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius);
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
    cursor: pointer;
    pointer-events: auto; /* Allow clicking on individual messages */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: none;
    max-width: 100%;
    word-wrap: break-word;
  }

  .flash-fade-out {
    opacity: 0;
    transform: translateX(100%);
  }

  .flash-notice {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid #10b981;
  }

  .flash-alert {
    background: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
  }

  /* Stack messages from top down */
  .flash:nth-child(1) { transform: translateY(0); }
  .flash:nth-child(2) { transform: translateY(10px); }
  .flash:nth-child(3) { transform: translateY(20px); }

  /* Mobile responsiveness */
  @media (max-width: 640px) {
    #flash-messages {
      top: 10px;
      right: 10px;
      left: 10px;
      max-width: none;
    }

    .flash {
      font-size: 13px;
      padding: var(--spacing-xs) var(--spacing-sm);
    }
  }
}
