:root {
  --bg: #f5f6f8;
  --bg-alt: #eceef3;
  --fg: #1c1e21;
  --fg-muted: #656d7a;
  --card: #ffffff;
  --nav-bg: rgba(255, 255, 255, 0.75);
  --border: #e1e4e8;
  --accent: #4f6ef7;
  --accent-2: #8a5cf6;
  --accent-soft: #edf0ff;
  --danger: #e0554f;
  --danger-soft: rgba(224, 85, 79, 0.1);
  --success: #1f9d63;
  --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 20px rgba(16, 24, 40, 0.1), 0 2px 6px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --bg-alt: #171a20;
    --fg: #e6e8eb;
    --fg-muted: #9aa1ad;
    --card: #191c22;
    --nav-bg: rgba(16, 18, 22, 0.7);
    --border: #282c34;
    --accent: #7c98ff;
    --accent-2: #b09bfa;
    --accent-soft: rgba(124, 152, 255, 0.14);
    --danger: #f2726c;
    --danger-soft: rgba(242, 114, 108, 0.14);
    --success: #3ddc91;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.24);
    --shadow-lg: 0 10px 26px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(700px circle at 12% -10%, var(--accent-soft), transparent 55%),
    radial-gradient(600px circle at 100% 30%, var(--accent-soft), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='90' viewBox='0 0 260 90'%3E%3Cpath d='M0 45 H90 L104 15 L118 75 L132 30 L146 60 L160 45 H260' fill='none' stroke='%234f6ef7' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 260px 90px;
  pointer-events: none;
  z-index: 0;
}

@media (prefers-color-scheme: dark) {
  body::after { opacity: 0.07; }
}

nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 0.95rem 2rem;
  background: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

nav .brand { margin-right: 0.5rem; }

nav a {
  position: relative;
  color: var(--fg-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  padding: 0.3rem 0.05rem;
  transition: color 0.15s ease;
}

nav a:hover { color: var(--fg); }

nav a.active { color: var(--fg); font-weight: 600; }

nav a.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.95rem;
  height: 2px;
  border-radius: 2px;
  background: var(--gradient);
}

.nav-spacer { flex: 1; }

.nav-user { color: var(--fg-muted); font-size: 0.88rem; font-weight: 500; }

.nav-logout-form { display: inline; }

.nav-logout {
  background: transparent;
  color: var(--fg-muted);
  box-shadow: none;
  padding: 0.3rem 0.6rem;
  font-weight: 500;
  font-size: 0.85rem;
}
.nav-logout:hover { color: var(--danger); background: var(--danger-soft); transform: none; box-shadow: none; }

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  margin-left: 0.3rem;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: 2px;
}

.friend-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.friend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  box-shadow: var(--shadow);
}

.friend-row a { color: var(--fg); font-weight: 600; text-decoration: none; }
.friend-row a:hover { color: var(--accent); }

.friend-actions { display: flex; gap: 0.5rem; }
.friend-row form { display: inline; }
.friend-row button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

.row-actions { display: flex; gap: 0.5rem; }
.row-actions form { display: inline; }
.row-actions button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

main {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem;
}

.login-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.login-brand { font-size: 1.3rem; text-align: center; }

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form button { width: 100%; padding: 0.65rem; }

h1 { margin-top: 0; font-weight: 800; letter-spacing: -0.01em; }

h2 {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1.1rem;
  font-weight: 700;
}

h2::before {
  content: "";
  width: 4px;
  height: 1.05rem;
  border-radius: 2px;
  background: var(--gradient);
}

.stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.5rem 1rem 1.9rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--gradient);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-value { font-size: 1.85rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 0.85rem; color: var(--fg-muted); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-alt);
}

tr:last-child td { border-bottom: none; }
tbody tr, table tr:not(:first-child) { transition: background-color 0.12s ease; }
table tr:not(:first-child):hover td { background: var(--accent-soft); }

.entry-form {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-bottom: 2rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--fg-muted); }
.field-wide { flex: 1; min-width: 200px; }
.field-full { flex-basis: 100%; }

input, select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  padding: 0.55rem 1.15rem;
  border: none;
  border-radius: 8px;
  background: var(--gradient);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

button:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); filter: brightness(1.04); }
button:active { transform: translateY(0); }

button.danger {
  background: var(--danger);
  padding: 0.35rem 0.75rem;
  font-weight: 500;
  box-shadow: none;
}
button.danger:hover { filter: brightness(1.08); box-shadow: var(--shadow); }

.empty { color: var(--fg-muted); font-style: italic; }

.flashes {
  list-style: none;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.5rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.flashes li { display: flex; align-items: center; gap: 0.5rem; }
.flashes li::before {
  content: "✓";
  color: var(--accent);
  font-weight: 800;
}

section { margin-bottom: 2.5rem; }

.insights-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.insight {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.insight:hover { transform: translateX(3px); box-shadow: var(--shadow-lg); }

.insight-icon {
  flex-shrink: 0;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: white;
}

.insight-warn .insight-icon { background: var(--danger); }
.insight-good .insight-icon { background: var(--success); }
.insight-info .insight-icon { background: var(--gradient); }

#set-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.set-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  animation: set-row-in 0.18s ease;
}

@keyframes set-row-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.set-row .set-index {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--gradient);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.set-row input { width: 6rem; }

.set-row .remove-set {
  margin-left: auto;
  background: transparent;
  color: var(--danger);
  box-shadow: none;
  padding: 0.3rem 0.55rem;
  font-weight: 700;
}
.set-row .remove-set:hover { background: var(--danger-soft); transform: none; box-shadow: none; }

#add-set-btn {
  align-self: flex-start;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  box-shadow: none;
}
#add-set-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: none;
  box-shadow: none;
  filter: none;
}
