/* Palette from user screenshot: light gray, olive, sage, beige, warm brown */
:root {
  --bg: #cac6b2; /* #f4f3ef;          /* soft light gray/cream */
  --card: #ffffff;
  --text: #3a3428;        /* dark warm brown for contrast */
  --muted: #7a7166;
  --accent: #6a7340;      /* olive green */
  --accent-hover: #556033;
  --accent-soft: #e8eadf; /* light sage tint */
  --border: #e0d9cc;      /* warm beige border */
  --tag-bg: #e8e4d8;      /* beige */
  --tag-text: #5c5348;
  --shadow: 0 1px 3px rgba(58,52,40,.08), 0 1px 2px rgba(58,52,40,.05);
  --radius: 12px;
  --star: #b07d55;        /* warm brown */
  --star-empty: #c4b8a8;
  --featured: #8a6a4a;    /* deeper brown */
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 1.5rem;
  padding-top: .5rem;
}
.top-identity {
  position: absolute;
  top: 0;
  left: 0;
  font-size: .8rem;
  color: var(--muted);
  letter-spacing: .02em;
}
.header-inner {
  display: inline-flex;
  align-items: center;
  gap: .9rem;
  text-align: left;
}
.site-logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 10px;
}
.header-text h1 {
  margin: 0 0 .15rem;
  font-size: 2rem;
  font-weight: 700;
}
.header-text p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.search { flex: 1; min-width: 200px; }
.search input {
  width: 100%;
  padding: .65rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}
.search input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.view-switcher {
  display: flex;
  gap: .25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .2rem;
}
.view-switcher button {
  padding: .4rem .7rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  color: var(--muted);
}
.view-switcher button.active {
  background: var(--accent);
  color: white;
}

.sort-select {
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: .85rem;
  cursor: pointer;
}
.sort-select:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}
.fav-toggle.active {
  background: var(--star);
  color: white;
  border-color: var(--star);
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
.labels-toggle {
  padding: .3rem .7rem;
  border-radius: 999px;
  background: var(--featured);
  color: white;
  font-size: .8rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.labels-toggle:hover {
  filter: brightness(1.1);
}
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: 0;
}
body.labels-hidden #tag-filters {
  display: none;
}
body.labels-hidden .item .tags {
  display: none;
}
.tag {
  padding: .3rem .65rem;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: .8rem;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  transition: all .15s;
}
.tag:hover, .tag.active {
  background: var(--accent);
  color: white;
}
.tag.active { font-weight: 600; }

/* Base item */
.item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.item.featured { border-color: var(--featured); box-shadow: 0 0 0 1px var(--featured), var(--shadow); }
.item.favorited { box-shadow: 0 0 0 2px var(--star), var(--shadow); }

.icon-area {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar {
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--accent);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.star-btn, .share-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: .35rem .5rem;
  font-size: 1.25rem;
  color: var(--star-empty);
  line-height: 1;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.star-btn:hover, .share-btn:hover {
  background: var(--accent-soft);
}
.star-btn.active, .item.favorited .star-btn {
  color: var(--star);
}
.share-btn { 
  font-size: 1.15rem; 
  color: var(--muted); 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
}
.share-btn:hover { color: var(--accent); }

.type-badge {
  display: inline-block;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .15rem .4rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
}
.item h3 {
  margin: 0 0 .35rem;
  font-size: 1.05rem;
  line-height: 1.3;
}
.item h3 a {
  color: inherit;
  text-decoration: none;
}
.item h3 a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.avatar-link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.item .desc {
  margin: 0 0 .75rem;
  color: var(--muted);
  font-size: .9rem;
}
.item .tags { margin: 0 0 .75rem; }
.item .tag { font-size: .7rem; padding: .15rem .45rem; cursor: default; }

.actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-top: auto;
}
.btn {
  display: inline-block;
  padding: .5rem .9rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
  text-align: center;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn.danger { background: #dc2626; }
.btn.danger:hover { background: #b91c1c; }

/* Full view (default) */
#grid.view-full {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
#grid.view-full .item {
  display: flex;
  flex-direction: column;
  padding: 1.1rem;
  height: 100%;
}
#grid.view-full .icon-area {
  margin-bottom: .75rem;
  width: 100%;
}
#grid.view-full .avatar-link {
  display: block;
  width: 100%;
}
#grid.view-full .avatar {
  width: 100%;
  height: 140px;
  border-radius: 8px;
  font-size: 2.5rem;
  align-items: flex-start;
  justify-content: center;
}
#grid.view-full .star-btn {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: rgba(255,255,255,.92);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

/* List view */
#grid.view-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
#grid.view-list .item {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: .75rem 1rem;
  gap: .9rem;
  border: 1px solid var(--border);
}
#grid.view-list .item.featured {
  border-color: var(--featured);
}
#grid.view-list .icon-area { flex-shrink: 0; }
#grid.view-list .avatar {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  font-size: 1.2rem;
  border: 1px solid var(--border);
}
#grid.view-list .content { flex: 1; min-width: 0; }
#grid.view-list .desc {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#grid.view-list .tags, #grid.view-list .type-badge { display: none; }
#grid.view-list .actions { margin-top: 0; flex-shrink: 0; }
#grid.view-list .star-btn { margin-right: .25rem; }

/* Large icon view */
#grid.view-icons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
}
#grid.view-icons .item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.25rem .5rem .75rem;
  position: relative;
  border: 1px solid var(--border);
}
#grid.view-icons .item.featured {
  border-color: var(--featured);
}
#grid.view-icons .avatar-link {
  display: block;
}
#grid.view-icons .avatar {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  font-size: 1.8rem;
  margin-bottom: .5rem;
  border: 1px solid var(--border);
}
#grid.view-icons .desc, #grid.view-icons .tags, #grid.view-icons .actions, #grid.view-icons .type-badge { display: none; }
#grid.view-icons h3 { font-size: .85rem; margin: 0; }
#grid.view-icons .star-btn {
  position: absolute;
  top: .35rem;
  right: .35rem;
  font-size: 1.05rem;
  z-index: 2;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.site-footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  font-size: .85rem;
  color: var(--muted);
}
.site-footer a {
  color: var(--muted);
  text-decoration: none;
}
.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.footer-sep {
  margin: 0 .4rem;
  opacity: .6;
}
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  opacity: .35;
  font-size: .75rem;
  color: var(--muted);
  text-decoration: none;
}
.admin-link:hover { opacity: 1; }

/* Admin styles (kept) */
.admin-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  background: transparent;
}
.admin-table th, .admin-table td {
  padding: .6rem .75rem;
  text-align: left;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.admin-table th:first-child, .admin-table td:first-child {
  border-left: 1px solid var(--border);
  border-radius: 6px 0 0 6px;
}
.admin-table th:last-child, .admin-table td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
}
.admin-table tbody tr {
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
/* Sortable drag feedback */
.sortable-ghost {
  opacity: 0.35 !important;
  background: var(--accent-soft) !important;
}
.sortable-ghost td {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
}
.sortable-chosen td {
  background: #e8f5e9 !important;
}
.sortable-drag {
  opacity: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,.18) !important;
}
.feat-star {
  display: inline-flex;
  align-items: center;
  margin-left: .4rem;
  cursor: pointer;
  color: var(--star-empty);
  font-size: 1.1rem;
  user-select: none;
}
.feat-star input {
  display: none;
}
.feat-star input:checked + span {
  color: var(--star);
}
  cursor: grab;
  color: var(--muted);
  font-size: 1.1rem;
  user-select: none;
  text-align: center;
  width: 32px;
}
.drag-handle:active { cursor: grabbing; }
.admin-table .inline-edit {
  width: 100%;
  padding: .25rem .4rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: .9rem;
}
.admin-table .inline-edit:focus {
  border-color: var(--accent);
  background: var(--card);
  outline: none;
}
.admin-table input[type="date"].inline-edit {
  width: auto;
}
.save-row {
  background: var(--accent);
  color: white;
  font-size: .8rem;
  padding: .35rem .6rem;
}
.admin-table th { background: var(--tag-bg); font-weight: 600; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .35rem; font-weight: 500; }
.form-group input:not([type="checkbox"]),
.form-group textarea,
.form-group select {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: normal;
  cursor: pointer;
}
.form-group input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
.actions { display: flex; gap: .5rem; }
.login-box {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem;
  grid-column: 1 / -1;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: white;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 100;
}
.toast.show { opacity: 1; }
