:root {
  --color-primary: #6c5ce7;
  --color-primary-hover: #5a4bd1;
  --color-success: #00b894;
  --color-error: #d63031;
  --color-bg: #f5f6fa;
  --color-surface: #ffffff;
  --color-border: #e1e4e8;
  --color-text: #2d3436;
  --color-text-secondary: #636e72;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.web-saved-banner {
  width: 100%;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  background: rgba(108, 92, 231, 0.08);
  border-bottom: 1px solid rgba(108, 92, 231, 0.2);
  text-align: center;
}

.web-saved-banner a {
  color: var(--color-primary);
  font-weight: 600;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 20px 32px;
}

.header {
  margin-bottom: 20px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-link {
  display: inline-block;
  line-height: 0;
}

.logo {
  height: 60px;
  width: auto;
  display: block;
}

.btn-icon-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.btn-icon-header:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.auth-bar {
  background: linear-gradient(135deg, #f8f7ff 0%, #f0eeff 100%);
  border: 1px solid #e8e5f0;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.auth-section.hidden {
  display: none !important;
}

#auth-logged-out {
  text-align: center;
}

#auth-logged-in {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.btn-signin {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--color-surface);
  border: 1px solid #dadce0;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: #3c4043;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.btn-signin:hover {
  background: #f7f8f8;
}

.auth-hint {
  color: var(--color-text-secondary);
  font-size: 12px;
  margin-top: 8px;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
}

.user-email {
  font-size: 13px;
  color: var(--color-text);
  font-weight: 500;
}

.btn-upgrade {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
  color: white !important;
  text-decoration: none !important;
  font-size: 12px;
  font-weight: 700;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
  transition: all 0.2s ease;
  white-space: nowrap;
  margin-left: 8px;
}

.btn-upgrade:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
  filter: brightness(1.1);
}

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

.toolbar-wrap {
  margin-bottom: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar-btn,
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.toolbar-btn:hover,
.btn-sm:hover {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.toolbar-btn.btn-danger {
  color: var(--color-error);
  border-color: rgba(214, 48, 49, 0.22);
  background: rgba(214, 48, 49, 0.04);
}

.toolbar-btn.btn-danger:hover {
  background: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.btn-signout:hover {
  background: var(--color-error);
  border-color: var(--color-error);
}

.add-bookmark-form {
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-bookmark-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.optional {
  opacity: 0.8;
}

.add-bookmark-input,
.add-bookmark-textarea,
.create-collection input,
.search-bar input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.add-bookmark-textarea {
  resize: vertical;
  min-height: 84px;
}

.add-bookmark-input:focus,
.add-bookmark-textarea:focus,
.create-collection input:focus,
.search-bar input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

.add-bookmark-actions,
.create-collection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text-secondary);
}

.btn-secondary:hover {
  background: #f0f0f0;
  color: var(--color-text);
  border-color: var(--color-border);
}

.usage-bar,
.notification {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.4;
}

.usage-bar {
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.usage-bar.usage-warning {
  background: rgba(225, 112, 85, 0.08);
  border-color: rgba(225, 112, 85, 0.2);
  color: #e17055;
  font-weight: 600;
}

.notification.success {
  background: #e6fff9;
  color: var(--color-success);
  border: 1px solid #b8f0dd;
}

.notification.error {
  background: #ffeef0;
  color: var(--color-error);
  border: 1px solid #ffc9cc;
}

.saved-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.search-bar {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  pointer-events: none;
}

.search-bar input {
  padding: 12px 44px 12px 44px;
  font-size: 15px;
}

.btn-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
}

.btn-clear:hover {
  background: #f0f0f0;
}

.collections-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.collection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.collection-pill:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.collection-pill.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.collection-add {
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  justify-content: center;
}

.col-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.col-delete {
  margin-left: 4px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
  cursor: pointer;
}

.collection-pill:hover .col-delete {
  opacity: 0.7;
}

.create-collection {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.color-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.selected {
  border-color: var(--color-text);
  transform: scale(1.15);
}

.results-info {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 0 0 12px;
}

.items-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.card-site {
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(108, 92, 231, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-favicon {
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border-radius: 2px;
}

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

.card-title {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.card-note {
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-ai-insights {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(108, 92, 231, 0.22);
  background: rgba(108, 92, 231, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-ai-insights-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-primary);
}

.card-ai-insights-body {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--color-text);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.card-ai-insights-body.is-collapsed {
  max-height: calc(1.5em * 8);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 8;
  -webkit-box-orient: vertical;
}

.card-ai-insights-body.is-expanded {
  max-height: none;
  display: block;
}

.card-ai-toggle {
  align-self: flex-start;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.card-ai-toggle:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

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

.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(108, 92, 231, 0.08);
  border: 1px solid rgba(108, 92, 231, 0.18);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
}

.card-link:hover {
  color: var(--color-primary-hover);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-action:hover {
  background: rgba(108, 92, 231, 0.08);
  color: var(--color-primary);
  border-color: rgba(108, 92, 231, 0.15);
}

.btn-action.btn-copy:hover {
  color: var(--color-success);
  background: #e6fff9;
  border-color: #b8f0dd;
}

.btn-action.btn-delete:hover {
  color: var(--color-error);
  background: #ffeef0;
  border-color: #ffc9cc;
}


.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 70px 20px;
  text-align: center;
}

.empty-state p {
  margin-top: 12px;
  font-size: 16px;
  color: var(--color-text-secondary);
}

.empty-sub {
  font-size: 13px;
  margin-top: 4px;
  opacity: 0.7;
}

.popover {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 100;
  min-width: 150px;
  overflow: hidden;
}

.popover-option {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  font-family: inherit;
}

.popover-option:hover {
  background: rgba(108, 92, 231, 0.08);
}

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

.spin {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

[data-theme="dark"] {
  --color-bg: #1a1a2e;
  --color-surface: #25253e;
  --color-border: #3a3a5c;
  --color-text: #e0e0f0;
  --color-text-secondary: #a0a0c0;
  --color-primary: #a29bfe;
  --color-primary-hover: #6c5ce7;
}

[data-theme="dark"] .auth-bar {
  background: linear-gradient(135deg, #25253e 0%, #2a2a4a 100%);
  border-color: #3a3a5c;
}

[data-theme="dark"] .btn-signin,
[data-theme="dark"] .toolbar-btn,
[data-theme="dark"] .btn-sm,
[data-theme="dark"] .btn-icon-header,
[data-theme="dark"] .add-bookmark-input,
[data-theme="dark"] .add-bookmark-textarea,
[data-theme="dark"] .create-collection input,
[data-theme="dark"] .search-bar input,
[data-theme="dark"] .popover {
  background: var(--color-surface);
  color: var(--color-text);
}

[data-theme="dark"] .notification.success {
  background: #1a2d24;
  color: #55efc4;
  border-color: #2a5c3d;
}

[data-theme="dark"] .notification.error {
  background: #2d1a1a;
  color: #ff7675;
  border-color: #5c2a2a;
}

[data-theme="dark"] .usage-bar.usage-warning {
  background: rgba(225, 112, 85, 0.15);
  border-color: rgba(225, 112, 85, 0.35);
  color: #ffb4a2;
}

[data-theme="dark"] .link-badge.ok {
  background: #1a2d24;
}

[data-theme="dark"] .link-badge.broken {
  background: #2d1a1a;
}

[data-theme="dark"] .btn-action.btn-copy:hover {
  background: #1a3d24;
  border-color: #2a5c3d;
}

[data-theme="dark"] .btn-action.btn-delete:hover {
  background: #3d1a1a;
  border-color: #5c2a2a;
}

[data-theme="dark"] .toolbar-btn.btn-danger {
  background: rgba(214, 48, 49, 0.12);
  border-color: rgba(214, 48, 49, 0.34);
  color: #ff9d9d;
}

@media (max-width: 820px) {
  .app {
    padding: 20px 14px 28px;
  }

  #auth-logged-in,
  .card-header,
  .card-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-site {
    max-width: 100%;
  }

  .items-container {
    grid-template-columns: 1fr;
  }
}

/* ─── Premium UI Styles ─────────────────────────── */

@keyframes pro-shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

.pro-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 40%, #fd79a8 100%);
  background-size: 200% auto;
  animation: pro-shimmer 3s ease-in-out infinite;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4), 0 0 0 1px rgba(255,255,255,0.15) inset;
  vertical-align: middle;
  white-space: nowrap;
}

.pro-badge::before {
  content: "⚡";
  font-size: 11px;
}

.pro-badge.hidden {
  display: none !important;
}

/* Usage bar for Pro users */
.usage-bar.usage-pro {
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.08) 0%, rgba(162, 155, 254, 0.12) 100%);
  border: 1px solid rgba(108, 92, 231, 0.25);
  color: var(--color-primary);
  font-weight: 700;
  font-size: 13px;
}

[data-theme="dark"] .usage-bar.usage-pro {
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.15) 0%, rgba(162, 155, 254, 0.08) 100%);
  border-color: rgba(162, 155, 254, 0.3);
  color: #a29bfe;
}

/* Locked feature button overlay */
.locked-pro {
  opacity: 0.55 !important;
  cursor: not-allowed !important;
  position: relative !important;
  pointer-events: auto;
}

.locked-pro:hover {
  background: var(--color-surface) !important;
  color: var(--color-text-secondary) !important;
  border-color: var(--color-border) !important;
}

.locked-pro::after {
  content: "PRO";
  position: absolute;
  top: -7px;
  right: -7px;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 2px 5px;
  border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(108, 92, 231, 0.4);
  z-index: 5;
}
