/* =========================================
   LinkNest — Phase 1 UI Foundation
   Light theme default, dark via [data-theme="dark"]
   ========================================= */

:root {
  /* Color tokens — light */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-soft-2: #e0e7ff;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
  --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-width: 260px;
  --header-height: 64px;

  --transition-fast: 150ms ease;
  --transition-base: 220ms ease;
  --transition-slow: 320ms ease;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #17191f;
  --surface-2: #1f2229;
  --border: #2a2e36;
  --border-strong: #3a3f4a;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-subtle: #6b7280;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-soft: #1e2140;
  --accent-soft-2: #252a52;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-base), color var(--transition-base);
}

img, svg { display: block; max-width: 100%; }

button, input { font: inherit; color: inherit; }

button { cursor: pointer; border: none; background: none; }

a { color: inherit; text-decoration: none; }

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 12px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  z-index: 1000;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 12px; }

/* App shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 20px;
  overflow-y: auto;
  transition: transform var(--transition-base), background-color var(--transition-base), border-color var(--transition-base);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-icon { flex-shrink: 0; opacity: 0.9; }

.nav-section { display: flex; flex-direction: column; gap: 6px; }

.nav-section__title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin: 0 0 2px 10px;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.category-dot--dev { background: #6366f1; }
.category-dot--design { background: #ec4899; }
.category-dot--productivity { background: #10b981; }
.category-dot--learning { background: #f59e0b; }

.sidebar__footer {
  padding: 8px 10px 0;
  border-top: 1px solid var(--border);
}
.sidebar__hint {
  font-size: 11px;
  color: var(--text-subtle);
}

.sidebar-overlay {
  display: none;
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  transition: background-color var(--transition-base), border-color var(--transition-base);
}

.sidebar-toggle { display: grid; }

.header__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  white-space: nowrap;
}

.header__search {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin-left: 8px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}
.search-input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}
.search-input::placeholder { color: var(--text-subtle); }
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
  white-space: nowrap;
}
.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:active { transform: translateY(1px); }
.btn--primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.icon-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Theme toggle icon visibility */
.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Content */
.content {
  padding: 24px;
  flex: 1;
}

.cards-section { width: 100%; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Card */
.bookmark-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base), background-color var(--transition-base);
  position: relative;
}
.bookmark-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card__top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.card__favicon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
}
.card__favicon img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.card__meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card__name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__url {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn--ghost {
  width: 30px;
  height: 30px;
  background: transparent;
  border: none;
  color: var(--text-subtle);
}
.icon-btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.favorite-btn.is-favorite { color: #f59e0b; }
.favorite-btn.is-favorite svg { fill: #f59e0b; }

.card__desc {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}
.category-badge--dev { background: #eef2ff; color: #4f46e5; }
.category-badge--design { background: #fce7f3; color: #be185d; }
.category-badge--productivity { background: #ecfdf5; color: #047857; }
.category-badge--learning { background: #fffbeb; color: #b45309; }
[data-theme="dark"] .category-badge--dev { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .category-badge--design { background: #3b1d2e; color: #f472b6; }
[data-theme="dark"] .category-badge--productivity { background: #132a24; color: #34d399; }
[data-theme="dark"] .category-badge--learning { background: #2a2414; color: #fbbf24; }

.card__domain {
  font-size: 11.5px;
  color: var(--text-subtle);
}

/* Empty state */
.empty-state {
  max-width: 420px;
  margin: 60px auto 0;
  text-align: center;
  padding: 40px 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.empty-state__icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
}
.empty-state__title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.empty-state__text {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 20px;
  line-height: 1.6;
}

/* Responsive */
@media (max-width: 900px) {
  .header { padding: 0 16px; gap: 8px; }
  .header__search { max-width: 260px; }
  .header__title { font-size: 18px; }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(var(--sidebar-width), 85vw);
    z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    z-index: 40;
    border: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
  }
  .sidebar-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar-toggle { display: grid; }
  .header__search { max-width: none; flex: 1; }
  .content { padding: 16px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
}

@media (max-width: 480px) {
  .header { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 10px; }
  .header__title { order: 1; }
  .sidebar-toggle { order: 0; }
  .header__search { order: 3; width: 100%; max-width: none; margin-left: 0; }
  .btn--primary span { display: none; }
  .card-grid { grid-template-columns: 1fr; }
  .empty-state { margin-top: 32px; padding: 32px 20px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible global fallback */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* =========================================
   Phase 2 additions
   ========================================= */

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--surface); border-color: var(--border-strong); }

.icon-btn--sm { width: 28px; height: 28px; }

.lang-toggle {
  width: auto;
  min-width: 0;
  padding: 0 12px;
  white-space: nowrap;
  overflow: visible;
}

.nav-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 2px 10px;
}
.nav-section__header .nav-section__title { margin: 0; }

.category-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}
.category-row .nav-item { flex: 1; }
.category-actions {
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.category-row:hover .category-actions,
.category-row:focus-within .category-actions { opacity: 1; }
@media (max-width: 768px) { .category-actions { opacity: 1; } }

.header__count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
  z-index: 30;
  display: none;
}
.menu.is-open { display: block; }
.menu__item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu__item:hover { background: var(--surface-2); }
.menu__item--danger { color: var(--danger); }
.menu__item--danger:hover { background: #fef2f2; }
[data-theme="dark"] .menu__item--danger:hover { background: #2a1a1a; }

.card__menu { position: relative; }

.modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(480px, 92vw);
  max-height: 90vh;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
}
.modal::backdrop {
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(2px);
}
.modal--sm { width: min(400px, 92vw); }
.modal__form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal__title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 13px; font-weight: 600; color: var(--text); }
.req { color: var(--danger); }
.field__input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
  resize: vertical;
}
.field__textarea { height: auto; padding: 10px 12px; min-height: 72px; }
.field__input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field__input.is-invalid { border-color: var(--danger); }
.field__error {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
  min-height: 14px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: 90vw;
}
.toast.is-error { background: var(--danger); color: #fff; }

.card__name-link {
  color: inherit;
  text-decoration: none;
}
.card__name-link:hover { color: var(--accent); text-decoration: underline; }

@media (max-width: 768px) {
  .modal { width: 94vw; }
}
/* =========================================
   RTL support (Arabic)
   ========================================= */
[dir="rtl"] .sidebar {
  right: 0;
  left: auto;
  border-right: none;
  border-left: 1px solid var(--border);
}

[dir="rtl"] .search-icon {
  left: auto;
  right: 12px;
}
[dir="rtl"] .search-input {
  padding: 0 36px 0 12px;
}

[dir="rtl"] .menu {
  right: auto;
  left: 0;
}

[dir="rtl"] .sidebar-overlay {
  /* unchanged */
}

/* mobile drawer in RTL */
@media (max-width: 768px) {
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }
  [dir="rtl"] .sidebar.is-open {
    transform: translateX(0);
  }
}
/* =========================================
   Desktop sidebar collapse
   ========================================= */
@media (min-width: 769px) {
  .app.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  .app.sidebar-collapsed .sidebar {
    display: none;
  }
}
.field__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.btn--sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}
.field__status {
  font-size: 12px;
  color: var(--text-muted);
}
