/* ═══════════════════════════════════════════════════════════
   Webkatalog – Minimal Design
   Font: DM Sans (body) + DM Mono (accents)
   Dark mode default, light mode toggle
═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

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

/* ── Dark mode (default) ─────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #222636;
  --border:    #2e3245;
  --text:      #e8eaf0;
  --muted:     #6b7280;
  --accent:    #4f8ef7;
  --accent-bg: rgba(79,142,247,.12);
  --danger:    #f87171;
  --success:   #4ade80;
  --warn:      #fbbf24;
  --star:      #fbbf24;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-md: 0 2px 8px rgba(0,0,0,.5), 0 8px 24px rgba(0,0,0,.4);
  --font:      'DM Sans', system-ui, sans-serif;
  --mono:      'DM Mono', monospace;
  --sidebar-w: 240px;
  --header-h:  56px;
}

/* ── Light mode ──────────────────────────────────────────── */
html.light {
  --bg:        #f9f8f6;
  --surface:   #ffffff;
  --surface2:  #f3f2ef;
  --border:    #e8e4df;
  --text:      #1a1714;
  --muted:     #8a8078;
  --accent:    #2563eb;
  --accent-bg: #eff6ff;
  --danger:    #dc2626;
  --success:   #16a34a;
  --warn:      #d97706;
  --star:      #f59e0b;
  --shadow:    0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06);
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Theme toggle button ─────────────────────────────────── */
.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); background: var(--border); }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
html.light .theme-toggle .icon-sun  { display: block; }
html.light .theme-toggle .icon-moon { display: none; }

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background .2s, border-color .2s;
}

.app-logo {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}
.app-logo svg { color: var(--accent); }

.search-bar {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.search-bar input {
  width: 100%;
  padding: 7px 12px 7px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  transition: border .15s, box-shadow .15s, background .2s;
}
.search-bar input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.search-bar input::placeholder { color: var(--muted); }
.search-bar .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ── Sidebar ─────────────────────────────────────────────── */
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  transition: background .2s, border-color .2s;
}

.sidebar-section { padding: 0 12px; margin-bottom: 4px; }
.sidebar-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: .9rem;
  color: var(--text);
  text-decoration: none;
  transition: background .12s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--surface2); text-decoration: none; }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-item .badge {
  margin-left: auto;
  font-size: .7rem;
  font-family: var(--mono);
  color: var(--muted);
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 99px;
}

.nav-color-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 10px 12px; }

/* ── Main ────────────────────────────────────────────────── */
.app-main {
  padding: 24px;
  overflow-y: auto;
  max-width: 1200px;
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.page-title { font-size: 1.25rem; font-weight: 600; letter-spacing: -.02em; }
.page-header .actions { margin-left: auto; display: flex; gap: 8px; }

/* ── Stats row ───────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: background .2s, border-color .2s;
}
.stat-card .num { font-size: 1.6rem; font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.stat-card .lbl { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* ── Filters bar ─────────────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font: inherit;
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
}

/* ── Bookmark grid ───────────────────────────────────────── */
.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.bookmark-list { display: flex; flex-direction: column; gap: 8px; }

.bm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s, transform .12s, background .2s, border-color .2s;
  animation: cardIn .2s ease both;
}
.bm-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

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

.bm-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 2rem;
}
.bm-thumb img { width: 100%; height: 100%; object-fit: cover; }

.bm-body { padding: 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }

.bm-title-row { display: flex; gap: 8px; align-items: flex-start; }
.bm-title {
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.bm-title:hover { color: var(--accent); text-decoration: none; }

.bm-url {
  font-size: .78rem;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bm-desc {
  font-size: .83rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bm-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.tag-pill {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
  color: white;
  cursor: pointer;
  transition: opacity .12s;
  text-decoration: none;
}
.tag-pill:hover { opacity: .8; text-decoration: none; }

.bm-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  transition: background .2s, border-color .2s;
}

.star-row { display: flex; gap: 1px; }
.star { font-size: .85rem; color: var(--border); }
.star.on { color: var(--star); }

.bm-date { font-size: .72rem; color: var(--muted); margin-left: auto; font-family: var(--mono); }

.bm-actions { display: flex; gap: 4px; }
.bm-actions .icon-btn { opacity: 0; }
.bm-card:hover .bm-actions .icon-btn { opacity: 1; }

/* list mode card */
.bm-card.list-mode {
  flex-direction: row;
  align-items: center;
  padding: 12px 16px;
  gap: 14px;
}
.bm-card.list-mode .bm-thumb { width: 48px; height: 48px; border-radius: 8px; border: none; flex-shrink: 0; font-size: 1.2rem; }
.bm-card.list-mode .bm-body { padding: 0; gap: 3px; }
.bm-card.list-mode .bm-footer { display: none; }

.public-badge {
  font-size: .65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .04em;
  flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s, box-shadow .12s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface2); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn-sm { padding: 4px 10px; font-size: .8rem; border-radius: 6px; }

.icon-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background .12s, color .12s;
  text-decoration: none;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.icon-btn.danger:hover { background: rgba(248,113,113,.15); color: var(--danger); }

/* ── Forms ───────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 560px;
  box-shadow: var(--shadow);
  transition: background .2s, border-color .2s;
}

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .83rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text);
}
.form-label .req { color: var(--danger); margin-left: 2px; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface2);
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  transition: border .15s, box-shadow .15s, background .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
  background: var(--surface);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--muted); }
.form-textarea { resize: vertical; min-height: 90px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* star rating input */
.star-input { display: flex; gap: 3px; }
.star-input label { font-size: 1.4rem; color: var(--border); cursor: pointer; transition: color .1s; }
.star-input input[type=radio] { display: none; }
.star-input { flex-direction: row-reverse; }
.star-input label:hover,
.star-input label:hover ~ label { color: var(--star); }

/* tag input */
.tag-input-wrap { position: relative; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tag-chip-rm { cursor: pointer; font-size: .8rem; opacity: .7; }
.tag-chip-rm:hover { opacity: 1; }

.thumb-preview { width: 100%; height: 160px; border: 2px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .85rem; margin-top: 6px; overflow: hidden; cursor: pointer; position: relative; background: var(--surface2); transition: border-color .15s; }
.thumb-preview:hover { border-color: var(--accent); }
.thumb-preview img { width: 100%; height: 100%; object-fit: cover; }
.thumb-preview input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  animation: slideUp .2s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Auth pages ──────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
  transition: background .2s;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  transition: background .2s, border-color .2s;
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo svg { color: var(--accent); }
.auth-logo h1 { font-size: 1.25rem; font-weight: 600; margin-top: 8px; letter-spacing: -.02em; }
.auth-logo p { font-size: .83rem; color: var(--muted); margin-top: 2px; }

/* theme toggle on auth page */
.auth-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
}

/* ── Alerts ──────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 7px; font-size: .88rem; margin-bottom: 14px; display: flex; gap: 8px; align-items: flex-start; }
.alert-error   { background: rgba(248,113,113,.15); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }
.alert-success { background: rgba(74,222,128,.12); color: var(--success); border: 1px solid rgba(74,222,128,.25); }
.alert-info    { background: var(--accent-bg); color: var(--accent); border: 1px solid rgba(79,142,247,.3); }

/* ── Table (admin) ───────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 8px 12px; text-align: left; border-bottom: 2px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: background .2s, border-color .2s; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state svg { opacity: .3; margin-bottom: 14px; }
.empty-state h3 { font-size: 1rem; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: .88rem; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: .88rem;
  box-shadow: var(--shadow-md);
  animation: toastIn .25s ease;
  max-width: 300px;
}
.toast.success { background: rgba(74,222,128,.15); color: var(--success); border-color: rgba(74,222,128,.3); }
.toast.error   { background: rgba(248,113,113,.15); color: var(--danger); border-color: rgba(248,113,113,.3); }
@keyframes toastIn { from { opacity: 0; transform: translateX(10px); } }

/* ── View toggle ─────────────────────────────────────────── */
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.view-toggle button {
  border: none;
  background: transparent;
  padding: 5px 9px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: background .12s, color .12s;
}
.view-toggle button.active { background: var(--accent); color: #fff; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .app-sidebar { display: none; }
  .app-layout { grid-template-columns: 1fr; }
  .app-main { padding: 16px; }
  .bookmark-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Misc ────────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.text-sm    { font-size: .83rem; }
.mt-auto    { margin-top: auto; }
.flex       { display: flex; }
.items-center { align-items: center; }
.gap-2      { gap: 8px; }
.ml-auto    { margin-left: auto; }
.truncate   { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.category-icon { font-size: .9rem; }
