:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px 110px;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }

a { color: var(--accent); }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.empty { color: var(--muted); text-align: center; margin-top: 60px; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.useremail {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.navlink { font-size: 0.9rem; text-decoration: none; }
.navlink:hover { text-decoration: underline; }

/* ------------------------------------------------------------- link groups */
.group { margin-bottom: 28px; }

.group h2 {
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.link-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.link-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.link-name { font-weight: 600; }
.link-meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.link-note { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }

.link-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.72rem;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 2px 8px;
}

/* -------------------------------------------------------------- toggle bar */
.toggle-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 18px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.seg {
  pointer-events: auto;
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.seg button {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
}

.seg button.active {
  background: var(--accent);
  color: #fff;
}

/* ------------------------------------------------------------------- forms */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
}

.panel h2 { margin-top: 0; }

input[type="text"], select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}

textarea { resize: vertical; margin-bottom: 10px; }

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; }

.link-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.link-form input[type="hidden"] { display: none; }

@media (min-width: 720px) {
  .link-form { grid-template-columns: 1.2fr 1fr 1.6fr 1.4fr auto auto; }
}

.btn {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 3px 10px; font-size: 0.8rem; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }

.plain-list { list-style: none; padding: 0; margin: 0; }

.plain-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.row-actions { display: flex; gap: 6px; }

.link-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.link-table th, .link-table td {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.url-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------- login */
.login-card {
  max-width: 420px;
  margin: 10vh auto 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
}

.login-card h1 { margin-top: 0; }
.login-card .g_id_signin { display: flex; justify-content: center; }
