/* ============================================
   My Brain — Dashboard Styles
   YouTube-inspired clean grid layout
   ============================================ */

/* --- CSS Variables (Light Mode) --- */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-hover: #fafafa;
  --text: #1d1d1f;
  --text-secondary: #606060;
  --text-tertiary: #aeaeb2;
  --border: #e5e5ea;
  --shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;

  /* Type accent colors */
  --color-link: #007aff;
  --color-video: #ff3b30;
  --color-idea: #ff9500;
  --color-note: #34c759;
  --color-image: #af52de;
  --color-file: #ff6723;

  /* Type accent backgrounds (soft) */
  --bg-link: #007aff12;
  --bg-video: #ff3b3012;
  --bg-idea: #ff950012;
  --bg-note: #34c75912;
  --bg-image: #af52de12;
  --bg-file: #ff672312;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #272727;
  --text: #f1f1f1;
  --text-secondary: #aaaaaa;
  --text-tertiary: #717171;
  --border: #303030;
  --shadow: none;
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.4);

  --bg-link: #007aff20;
  --bg-video: #ff3b3020;
  --bg-idea: #ff950020;
  --bg-note: #34c75920;
  --bg-image: #af52de20;
  --bg-file: #ff672320;
}

/* --- Login Screen --- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-icon {
  font-size: 64px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

#loginForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input:focus {
  border-color: var(--color-link);
  box-shadow: 0 0 0 3px var(--bg-link);
}

.login-input::placeholder {
  color: var(--text-tertiary);
}

.login-button {
  width: 100%;
  padding: 12px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-button:hover {
  opacity: 0.85;
}

.login-error {
  font-size: 14px;
  color: #ff3b30;
  min-height: 20px;
}

/* --- Logout Button --- */
.logout-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.logout-button:hover {
  background: var(--surface-hover);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.item-count {
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 12px;
}

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

/* --- Search --- */
.search-box {
  position: relative;
  width: 240px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--border);
  box-shadow: 0 0 0 2px var(--bg-link);
}

.search-box input::placeholder {
  color: var(--text-tertiary);
}

/* --- Theme Toggle --- */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.theme-toggle:hover {
  background: var(--surface-hover);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Show/hide sun/moon icons based on theme */
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
:root:not([data-theme="dark"]) .sun-icon,
body:not([data-theme="dark"]) .sun-icon { display: none; }
:root:not([data-theme="dark"]) .moon-icon,
body:not([data-theme="dark"]) .moon-icon { display: block; }

/* --- Filter Tabs (YouTube-style pills) --- */
.filters {
  display: flex;
  gap: 10px;
  padding: 12px 24px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.filter-tab:hover {
  background: var(--border);
}

.filter-tab.active {
  background: var(--text);
  color: var(--bg);
}

/* --- Card Grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding: 16px 24px 32px;
}

/* --- Card (YouTube-inspired) --- */
.card {
  background: transparent;
  border-radius: var(--radius);
  border: none;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease;
  animation: fadeIn 0.3s ease forwards;
  opacity: 0;
  position: relative;
}

.card:hover {
  transform: scale(1.02);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Stagger animation for cards */
.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.06s; }
.card:nth-child(4) { animation-delay: 0.08s; }
.card:nth-child(5) { animation-delay: 0.10s; }
.card:nth-child(6) { animation-delay: 0.12s; }
.card:nth-child(7) { animation-delay: 0.14s; }
.card:nth-child(8) { animation-delay: 0.16s; }
.card:nth-child(9) { animation-delay: 0.18s; }

/* Card thumbnail — big, YouTube-style 16:9ish */
.card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--surface);
  display: block;
  border-radius: var(--radius);
}

/* Placeholder for cards without thumbnails */
.card-icon-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  border-radius: var(--radius);
}

/* Type-specific placeholder colors */
.card-icon-placeholder.type-link { background: var(--bg-link); }
.card-icon-placeholder.type-video { background: var(--bg-video); }
.card-icon-placeholder.type-idea { background: var(--bg-idea); }
.card-icon-placeholder.type-note { background: var(--bg-note); }
.card-icon-placeholder.type-image { background: var(--bg-image); }
.card-icon-placeholder.type-file { background: var(--bg-file); }

/* Card body — tight, minimal like YouTube */
.card-body {
  padding: 10px 4px 4px;
}

.card-type {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.card-type.type-link { color: var(--color-link); background: var(--bg-link); }
.card-type.type-video { color: var(--color-video); background: var(--bg-video); }
.card-type.type-idea { color: var(--color-idea); background: var(--bg-idea); }
.card-type.type-note { color: var(--color-note); background: var(--bg-note); }
.card-type.type-image { color: var(--color-image); background: var(--bg-image); }
.card-type.type-file { color: var(--color-file); background: var(--bg-file); }

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card footer — category + date, like YouTube's channel + views */
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-tags {
  display: none;
}

.tag {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}

.card-date {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 80px 24px;
}

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

.empty-state h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* --- Loading --- */
.loading {
  text-align: center;
  padding: 80px 24px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--color-link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.loading p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.modal-close:hover {
  background: var(--border);
}

.modal-content {
  padding: 24px;
}

.modal-thumb {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.modal-type {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 6px;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
}

.modal-summary {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.modal-content-text {
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin-bottom: 16px;
}

.modal-content-text a {
  color: var(--color-link);
  text-decoration: none;
}

.modal-content-text a:hover {
  text-decoration: underline;
}

.modal-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.modal-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.modal-date {
  font-size: 13px;
  color: var(--text-tertiary);
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-delete {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #ff3b30;
  background: transparent;
  color: #ff3b30;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-delete:hover {
  background: #ff3b3015;
}

.btn-open {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-link);
  background: transparent;
  color: var(--color-link);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-open:hover {
  background: var(--bg-link);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 10px;
    padding: 10px 16px;
  }

  .header-left, .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .search-box {
    flex: 1;
    width: auto;
  }

  .filters {
    padding: 8px 16px;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 8px 12px 24px;
    gap: 12px;
  }

  .card-title {
    font-size: 13px;
  }

  .card-type {
    font-size: 10px;
  }

  .modal {
    width: 95%;
    max-height: 85vh;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1400px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- Upload Button --- */
.upload-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.upload-button:hover {
  background: var(--surface-hover);
}

.upload-button.uploading {
  opacity: 0.5;
  pointer-events: none;
}

/* --- Category Filters --- */
.category-filters {
  padding-top: 0;
  gap: 8px;
}

.category-filters .filter-tab {
  font-size: 13px;
  padding: 6px 14px;
}

/* --- Card Category Badge --- */
.card-category {
  display: inline-block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 6px;
}

/* --- Modal Badges Row --- */
.modal-badges {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}

/* --- Modal Category Badge --- */
.modal-category {
  display: inline-block;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 6px;
  font-weight: 500;
}

/* --- Modal Summary Box --- */
.modal-summary-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
  border-left: 3px solid var(--color-link);
}

.modal-summary-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.modal-summary-box .modal-summary {
  margin-bottom: 0;
  color: var(--text);
}

/* --- File Info in Modal --- */
.modal-file-info {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.file-size {
  color: var(--text-tertiary);
  font-size: 13px;
}

/* --- Quick Delete X Button on Cards --- */
.card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, background 0.15s;
  z-index: 2;
}

.card:hover .card-delete {
  opacity: 1;
}

.card-delete:hover {
  background: #ff3b30;
}

/* --- Drag & Drop Overlay --- */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 122, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.drop-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.drop-message {
  text-align: center;
  color: var(--color-link);
}

.drop-icon {
  width: 80px;
  height: 80px;
  border: 3px dashed var(--color-link);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 300;
  margin: 0 auto 12px;
}

.drop-message p {
  font-size: 18px;
  font-weight: 500;
}

/* --- Ideas / To-Do Panel --- */
.ideas-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-hover);
  z-index: 150;
  transition: background 0.2s, transform 0.2s;
}

.ideas-toggle:hover {
  background: var(--surface-hover);
  transform: scale(1.05);
}

.ideas-panel {
  position: fixed;
  top: 0;
  right: -360px;
  width: 340px;
  max-width: 90vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.ideas-panel.open {
  right: 0;
}

.ideas-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.ideas-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.ideas-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
}

.ideas-input-row input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.ideas-input-row input:focus {
  border-color: var(--color-link);
}

.ideas-input-row input::placeholder {
  color: var(--text-tertiary);
}

.ideas-input-row button {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-link);
  background: var(--color-link);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ideas-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px;
}

.ideas-empty {
  color: var(--text-tertiary);
  font-size: 14px;
  text-align: center;
  padding: 24px 0;
}

.idea-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.idea-text {
  font-size: 14px;
  line-height: 1.4;
  flex: 1;
}

.idea-delete {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.idea-delete:hover {
  color: #ff3b30;
  background: #ff3b3015;
}

/* --- Custom Delete Confirmation Modal --- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.confirm-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.confirm-modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  width: 90%;
  max-width: 340px;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.2s ease;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.confirm-overlay.active .confirm-modal {
  transform: scale(1);
}

.confirm-text {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 24px;
  color: var(--text);
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-cancel {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.confirm-cancel:hover {
  background: var(--surface-hover);
}

.confirm-delete {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: #ff3b30;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.confirm-delete:hover {
  opacity: 0.85;
}
