:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e4e6eb;
  --text: #1c2129;
  --text-muted: #6b7280;
  --primary: #3861fb;
  --primary-hover: #2d4fd6;
  --danger: #d1435b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-hover: 0 8px 20px rgba(16, 24, 40, 0.10), 0 3px 6px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html { font-size: 17px; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(28, 33, 41, 0.055) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

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

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  margin: 0 auto;
  padding: 18px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  width: 22px;
  height: 22px;
  flex: none;
}
.brand-mark span {
  border-radius: 3px;
  background: var(--primary);
}
.brand-mark span:nth-child(2) { background: #6a8bff; }
.brand-mark span:nth-child(3) { background: #6a8bff; }
.brand-mark span:nth-child(4) { background: #b8c7ff; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}
.lang-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.lang-switch-active {
  font-weight: 700;
  color: var(--text);
}
.lang-switch-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}
.lang-switch-link:hover { color: var(--primary); }

/* Layout */
.page {
  margin: 0 auto;
  padding: 40px 48px 80px;
}
.page-with-sidebar {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 40px;
  align-items: start;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}
.search-form { display: flex; gap: 10px; }
.search-input {
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 260px;
  font-size: 0.95rem;
  background: var(--surface);
}
.search-input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.active-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.active-filter strong { color: var(--text); }
.clear-filter {
  color: var(--primary);
  font-weight: 600;
}
.clear-filter:hover { text-decoration: underline; }

/* Sidebar tag filter (Django-admin style) */
.sidebar {
  position: sticky;
  top: 96px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.sidebar-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 14px;
}
.tag-filter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tag-filter-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.92rem;
  color: var(--text);
}
.tag-filter-item:hover { background: var(--bg); }
.tag-filter-active { background: var(--primary); color: #fff; }
.tag-filter-active:hover { background: var(--primary); }
.tag-filter-active .tag-count { color: #fff; opacity: 0.85; }
.tag-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.tag-count {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Tag chips on cards */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-chip {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.tag-chip:hover { filter: brightness(0.92); }

/* Grid + cards */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.card { flex: 1 1 300px; max-width: 340px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.18s ease, transform 0.18s ease;
  display: flex;
  flex-direction: column;
}
.card:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); }

.card-thumb-link { display: block; }
.card-thumb {
  width: 100%;
  height: 190px;
  object-fit: cover;
  object-position: top;
  display: block;
  background: var(--bg);
}
.card-thumb-placeholder {
  height: 190px;
}

.card-icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}
.card-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 10px; }
.card-header { display: flex; align-items: center; gap: 10px; }
.card-title { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.card-title:hover { color: var(--primary); }

.card-desc { color: var(--text-muted); font-size: 0.92rem; margin: 0; }
.card-url {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.card-actions a { color: var(--text-muted); }
.card-actions a:hover { color: var(--primary); }
.inline-form { display: inline; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text-muted);
  cursor: pointer;
}
.link-btn:hover { color: var(--primary); }
.link-btn-danger:hover { color: var(--danger); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 100px 20px;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 20px; font-size: 1.1rem; }

/* Forms */
.form-page {
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow);
}
.form-page h1 { font-size: 1.4rem; margin: 0 0 26px; }
.bookmark-form { display: flex; flex-direction: column; gap: 20px; }
.bookmark-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}
.optional { font-weight: 400; }
.bookmark-form input,
.bookmark-form select {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}
.bookmark-form input:focus,
.bookmark-form select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; }

/* Flash messages */
.flash-stack { margin-bottom: 28px; display: flex; flex-direction: column; gap: 10px; }
.flash {
  padding: 13px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.flash-success { background: #e8f6ee; color: #1a7f4e; border-color: #bfe8d3; }
.flash-error { background: #fdecee; color: #b3273f; border-color: #f6c4cd; }

@media (max-width: 900px) {
  .page-with-sidebar { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 16px;
  }
  .sidebar-title { flex-basis: 100%; margin-bottom: 4px; }
  .tag-filter-list { flex-direction: row; flex-wrap: wrap; }
  .tag-filter-item { padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; }
}

@media (max-width: 600px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-input { flex: 1; min-width: 0; }
}
