:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e2ddd2;
  --accent: #b8863f;
  --accent-ink: #1c1c1c;
  --danger: #a3402f;
  --needs-context: #c98a1f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1f1e19;
    --text: #f2ede1;
    --muted: #a39c8a;
    --border: #3a362c;
    --accent: #e0b16a;
    --accent-ink: #14130f;
    --danger: #e08a72;
    --needs-context: #e0b16a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.wordmark { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px;
}

#login-form {
  max-width: 320px;
  margin: 60px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input, select, button {
  font-size: 1rem;
  font-family: inherit;
}

input, select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font-weight: 600;
}

button.secondary, #clear-search-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.save-form, .search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.save-form input, .search-form input { flex: 1; }

.status-msg { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#links-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.link-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}

.link-main { display: flex; gap: 10px; }
.link-icon { font-size: 1.3rem; }
.link-body { flex: 1; min-width: 0; }

.link-title {
  display: block;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-desc {
  margin: 4px 0;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.link-meta {
  display: flex;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.link-category { text-transform: capitalize; }

.link-context {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--needs-context) 15%, transparent);
}

.link-context p { margin: 0 0 8px; font-size: 0.85rem; }
.context-form { display: flex; gap: 6px; margin: 0; }
.context-form input { flex: 1; }

.link-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.link-actions button {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  padding: 6px 10px;
  font-weight: 500;
}

.empty-msg { color: var(--muted); text-align: center; margin-top: 40px; }

[hidden] { display: none !important; }
