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

@view-transition {
  navigation: auto;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.6;
  color: #1a1a1a;
  background: #f5f5f5;
  overflow-x: hidden;
}

body > nav {
  background: #1a1a1a;
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

body > nav .brand {
  font-weight: 700;
  font-size: 1.25rem;
}

body > nav .auth-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  min-width: 0;
}

body > nav .auth-links span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body > nav .auth-links a {
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}

nav .auth-links a:hover {
  text-decoration: underline;
}

main {
  max-width: 640px;
  margin: 3rem auto;
  padding: 0 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.flash-success {
  background: #d4edda;
  border: 1px solid #c3e6cb;
  color: #155724;
}

.flash-error {
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  color: #721c24;
}

h1 {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.75rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.form-row select {
  flex: 1;
}

form.form-inline {
  flex-direction: row;
}

form input[type="text"] {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
}

form input[type="text"]:focus {
  border-color: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.15);
}

form button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

form button:hover {
  background: #333;
}

.groups-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.groups-header h2 {
  margin: 0;
}

.btn-new {
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.btn-new:hover {
  background: #333;
}

.group-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.group-card {
  display: block;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  text-decoration: none;
  color: #1a1a1a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.group-card:hover {
  border-color: #1a1a1a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.group-card-name {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.group-card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: #777;
}

.empty-groups {
  text-align: center;
  padding: 3rem 1rem;
}

/* --- Tabs --- */

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #eee;
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #888;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: #1a1a1a;
}

.tab.active {
  color: #1a1a1a;
  border-bottom-color: #1a1a1a;
}

/* --- Hint text --- */

.hint {
  font-size: 0.875rem;
  color: #999;
  margin-top: 0.5rem;
}

.group-currency {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 2rem;
}

/* --- Recent activity feed --- */

.recent-feed {
  margin-top: 1.5rem;
}

.recent-feed h2 {
  margin-bottom: 0.75rem;
}

.recent-item {
  display: block;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eee;
  text-decoration: none;
  color: #1a1a1a;
  transition: background 0.1s;
}

.recent-item:first-child {
  border-top: 1px solid #eee;
}

.recent-item:hover {
  background: #f9f9f9;
}

.recent-item-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.recent-desc {
  font-weight: 500;
}

.recent-amount {
  font-weight: 600;
  white-space: nowrap;
  margin-left: 1rem;
}

.recent-item-meta {
  display: flex;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: #999;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
}

th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  border-bottom: 2px solid #ddd;
}

td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #eee;
  font-size: 0.95rem;
}

select {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  background: #fff;
}

select:focus {
  border-color: #1a1a1a;
  box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.15);
}

label {
  display: flex;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 500;
  color: #555;
  white-space: nowrap;
  gap: 0.5rem;
}

.breadcrumbs {
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  color: #999;
}

.breadcrumbs a {
  color: #666;
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: #1a1a1a;
}

.breadcrumbs .sep {
  margin: 0 0.4rem;
  color: #ccc;
}

.empty-state {
  margin: 2rem 0;
  color: #999;
  font-style: italic;
}

.sort-link {
  color: #1a1a1a;
  text-decoration: none;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sort-link:hover {
  text-decoration: underline;
}

.pagination {
  display: flex;
  justify-content: space-between;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

.pagination a {
  color: #1a1a1a;
  text-decoration: none;
  font-weight: 500;
}

.pagination a:hover {
  text-decoration: underline;
}

.pagination-disabled {
  color: #ccc;
}

.back-link {
  color: #666;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  color: #1a1a1a;
}

.no-groups-msg {
  margin-bottom: 1.5rem;
  color: #666;
}

.no-groups-msg a {
  color: #1a1a1a;
  font-weight: 600;
}

/* --- Members & invites --- */

.members-section {
  margin-bottom: 2rem;
}

.member-list {
  list-style: none;
  margin: 0 0 1rem 0;
}

.member-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #eee;
  font-size: 0.95rem;
}

.member-list li:last-child {
  border-bottom: none;
}

.member-email {
  flex: 1;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 10px;
}

.badge-admin {
  background: #1a1a1a;
  color: #fff;
}

.invite-actions {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.invite-actions form {
  margin: 0;
}

.btn-expire {
  background: transparent;
  color: #c44;
  border: 1px solid #ecc;
}

.btn-expire:hover {
  background: #fff5f5;
  border-color: #c44;
}

.invite-link {
  background: #f0f4ff;
  border: 1px solid #d0d8f0;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.invite-link p {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 0.5rem;
}

.invite-link code {
  flex: 1;
  font-size: 0.875rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  word-break: break-all;
  user-select: all;
}

.invite-link-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-copy {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-copy:hover {
  background: #333;
}

.expense-form {
  margin-bottom: 1.5rem;
}

/* --- Table scroll for mobile --- */

.table-scroll {
  overflow-x: auto;
  margin: 1.5rem 0;
}

.table-scroll table {
  margin: 0;
}

/* --- Touch targets (≥44px) --- */

form input[type="text"],
form button,
select {
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
}

.tab {
  min-height: 44px;
}

/* --- Mobile: ≤480px --- */

@media (max-width: 480px) {
  main {
    margin: 1.5rem auto;
    padding: 0 0.75rem;
  }

  h1 { font-size: 1.4rem; margin-bottom: 1rem; }
  h2 { font-size: 1rem; }

  body > nav {
    padding: 0.6rem 1rem;
  }

  body > nav .brand {
    font-size: 1.1rem;
  }

  form.form-inline {
    flex-wrap: wrap;
  }

  .invite-actions {
    flex-direction: column;
  }

  .invite-actions form button {
    width: 100%;
  }

  .group-card {
    padding: 0.75rem 1rem;
  }
}

/* --- Mobile: ≤360px --- */

@media (max-width: 360px) {
  body > nav {
    flex-direction: column;
    align-items: flex-start;
  }

  form.form-inline {
    flex-direction: column;
  }

  form.form-inline button {
    width: 100%;
  }

  .groups-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .groups-header .btn-new {
    width: 100%;
    text-align: center;
  }
}
