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

/* ── Variables ── */
:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --card-bg: var(--surface); /* alias for legacy JS toast */
  --border: #e2e2de;
  --border-strong: #c4c4bf;
  --text: #1a1a18;
  --text-soft: #5c5c56;
  --text-muted: #9a9892;
  --accent: #2563eb;
  --btn-bg: #eeede9;
  --btn-border: #d8d8d4;
  --card-radius: 9px;
}

body.dark {
  --bg: #111110;
  --surface: #1c1c1a;
  --card-bg: var(--surface); /* alias for legacy JS toast */
  --border: #2a2a27;
  --border-strong: #3c3c38;
  --text: #e5e0d8;
  --text-soft: #8a8780;
  --text-muted: #5a5853;
  --accent: #4d8ef8;
  --btn-bg: #252523;
  --btn-border: #333330;
}

/* ── Base ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
  transition: background 0.25s, color 0.25s;
}

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
}

.title-wrap h1,
h1 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--text);
}

.info-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1px;
  padding: 5px 16px;
  border-bottom: 1px solid var(--border);
}

#datetime {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
  opacity: 1;
  margin: 0;
}

#weather {
  font-size: 10px;
  color: var(--text-muted);
  font-style: normal;
}

.auth-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 16px;
}

.auth-bar form {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.auth-bar input,
#authPanel input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  flex: 1 1 90px;
  min-width: 80px;
}

.auth-bar input:focus,
#authPanel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}

#authStatus {
  font-size: 12px;
  color: var(--text-muted);
}

a.header-link,
#profileLink {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  transition: color 0.15s;
}

a.header-link:hover,
#profileLink:hover {
  color: var(--text);
}

/* ── Buttons (global) ── */
button {
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.auth-bar button,
#authPanel button {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text-soft);
}

.auth-bar button:hover,
#authPanel button:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--border-strong);
}

#doLogin {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
}

#doLogin:hover {
  opacity: 0.88;
}

#toggleDark {
  padding: 5px 8px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1;
}

#toggleDark:hover {
  background: var(--border);
  color: var(--text);
}

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 4px;
  position: sticky;
  top: var(--header-height, 0);
  z-index: 10;
}

/* ── Hide empty linksList ul (JS renders into #links instead) ── */
#linksList {
  display: none;
}

#linkFilter {
  width: 180px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#linkFilter:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.1);
}

#linkFilter::placeholder {
  color: var(--text-muted);
}

/* ── Links list ── */
#linksList {
  list-style: none;
  padding: 8px 12px 12px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 4px;
  max-width: calc(3 * 340px + 60px);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-left-color: var(--accent);
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

body.dark .card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.card a {
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color 0.15s;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card a:hover {
  color: var(--accent);
}

.card img {
  border-radius: 3px;
  flex-shrink: 0;
}

.card.dragging {
  opacity: 0.4;
  border: 1.5px dashed var(--border-strong);
}

.card button {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 3px 7px;
  font-size: 11px;
  border-radius: 5px;
  cursor: pointer;
  margin-left: 2px;
  flex-shrink: 0;
}

.card button:hover {
  background: var(--btn-bg);
  border-color: var(--btn-border);
  color: var(--text);
}

/* ── Main (#links element) ── */
main {
  padding: 8px 12px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 4px;
  max-width: calc(3 * 340px + 60px);
  margin: 0 auto;
}

/* ── Footer ── */
.footer {
  display: flex;
  justify-content: flex-end;
  padding: 7px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: center;
  position: sticky;
  bottom: 0;
}

.footer > div {
  display: flex;
  align-items: center;
  gap: 2px;
}

.footer button {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: 5px;
}

.footer button:hover {
  background: var(--btn-bg);
  border-color: var(--btn-border);
  color: var(--text);
}

#version {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 10px;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

/* ── Auth panel ── */
#authPanel {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* ── Footer secondary ── */
footer:not(.footer) {
  margin-top: 16px;
  text-align: right;
  padding: 0 16px 16px;
}

footer:not(.footer) p {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Stats ── */
#linkStats { margin-top: 16px; }

#linkStatsList {
  list-style: none;
  padding: 0;
}

#linkStatsList li {
  font-size: 12px;
  color: var(--text-soft);
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

/* ── Misc links ── */
.footer-link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-link:hover {
  color: var(--text);
}

a.profile-link {
  text-decoration: none;
  color: var(--text-soft);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}

a.profile-link:hover {
  color: var(--text);
}
