/* CSS Reset and Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 8px;
  --radius-sm: 4px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--gray-50);
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-900);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
}

.login-screen.hidden {
  display: none;
}

.login-container {
  text-align: center;
  padding: 40px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 100%;
}

.login-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--gray-500);
  margin-bottom: 32px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--gray-700);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-google:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.login-error {
  margin-top: 16px;
  padding: 12px;
  background: #fef2f2;
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.login-error.hidden {
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  min-width: 44px;
}

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

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

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

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

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

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--gray-500);
}

.btn-icon:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* Inputs */
.input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input::placeholder {
  color: var(--gray-400);
}

.input-small {
  width: auto;
  flex: 1;
}

.textarea {
  resize: vertical;
  min-height: 60px;
}

/* Quick Add */
.quick-add {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}

.quick-add-actions {
  display: flex;
  gap: 8px;
}

/* Sync Status */
.sync-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: var(--gray-100);
  font-size: 0.875rem;
  color: var(--gray-600);
}

.sync-status.hidden {
  display: none;
}

.sync-status.error {
  background: #fef2f2;
  color: var(--danger);
}

.sync-status.success {
  background: #f0fdf4;
  color: #16a34a;
}

.sync-icon {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.sync-status.error .sync-icon,
.sync-status.success .sync-icon {
  animation: none;
  border: none;
}

.sync-status.error .sync-icon::before {
  content: '!';
  font-weight: bold;
}

.sync-status.success .sync-icon::before {
  content: '✓';
}

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

/* Items Container */
.items-container {
  padding: 16px 20px;
  padding-bottom: 100px;
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Item Card */
.item-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}

.item-card:hover {
  box-shadow: var(--shadow-md);
}

.item-card.unsynced {
  border-left: 3px solid var(--gray-400);
}

.item-content {
  padding: 16px;
}

.item-category {
  display: inline-block;
  padding: 2px 8px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: var(--gray-500);
  background: var(--gray-100);
  border-radius: var(--radius-sm);
}

.item-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.item-title a {
  color: inherit;
  text-decoration: none;
}

.item-title a:hover {
  color: var(--primary);
}

.item-url {
  font-size: 0.75rem;
  color: var(--gray-400);
  word-break: break-all;
  margin-bottom: 8px;
}

.item-notes {
  font-size: 0.875rem;
  color: var(--gray-600);
  white-space: pre-wrap;
}

.item-actions {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-100);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-500);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h2 {
  font-size: 1.25rem;
  color: var(--gray-700);
  margin-bottom: 8px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.modal-large {
  max-width: 640px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.5rem;
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

/* Newsletter Preview */
.newsletter-preview {
  padding: 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}

.generate-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.divider {
  margin: 20px 0;
  border: none;
  border-top: 1px solid var(--gray-200);
}

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

.archive-note {
  font-size: 0.875rem;
  color: var(--gray-600);
  margin-bottom: 12px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--gray-800);
  color: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  animation: toast-in 0.2s ease;
}

.toast.success {
  background: #16a34a;
}

.toast.error {
  background: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* Mobile Styles */
@media (max-width: 640px) {
  .header {
    padding: 12px 16px;
  }

  .header-title {
    font-size: 1.125rem;
  }

  .quick-add {
    padding: 12px 16px;
  }

  .items-container {
    padding: 12px 16px;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    max-height: 85vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .generate-actions {
    flex-direction: column;
  }

  .generate-actions .btn {
    width: 100%;
  }
}

/* Touch-friendly targets */
@media (pointer: coarse) {
  .btn {
    min-height: 48px;
  }

  .input {
    min-height: 48px;
  }
}

/* Dark mode support (optional, respects system preference) */
@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
    --white: #1f2937;
  }

  body {
    background: #0f172a;
  }

  .input {
    background: var(--gray-100);
    color: var(--gray-800);
  }

  .newsletter-preview {
    background: var(--gray-100);
  }
}
