:root {
  --teal-900: #134e4a;
  --teal-800: #115e59;
  --teal-700: #0f766e;
  --teal-600: #0d9488;
  --teal-100: #ccfbf1;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --red-100: #fee2e2;
  --red-700: #b91c1c;
  --green-100: #dcfce7;
  --green-700: #15803d;
  --amber-100: #fef3c7;
  --amber-800: #92400e;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
  --nav-height: 64px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-50);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

a {
  color: var(--teal-700);
  text-decoration: none;
}

a:hover {
  color: var(--teal-800);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--teal-700);
  color: #fff;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.user-badge {
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.page h1,
.hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  color: var(--teal-900);
}

.subtitle {
  color: var(--gray-500);
  margin: 0 0 1.5rem;
}

.hero {
  text-align: center;
  padding: 2rem 0 1rem;
}

.btn-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn-primary {
  background: var(--teal-700);
  color: #fff;
}

.btn-primary:hover {
  background: var(--teal-800);
  color: #fff;
}

.btn-secondary {
  background: #fff;
  color: var(--teal-700);
  border: 1px solid var(--teal-600);
}

.btn-secondary:hover {
  background: var(--teal-100);
}

.btn-block {
  width: 100%;
}

.btn-danger {
  background: var(--red-700);
  color: #fff;
}

.card-list {
  display: grid;
  gap: 0.75rem;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card-link {
  display: block;
  color: inherit;
}

.card-link:active {
  transform: scale(0.99);
}

.card-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.card-meta {
  font-size: 0.875rem;
  color: var(--gray-500);
}

.card-badge {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--teal-100);
  color: var(--teal-800);
  text-transform: uppercase;
}

.empty {
  color: var(--gray-500);
  text-align: center;
  padding: 2rem 1rem;
}

.form-page {
  max-width: 420px;
  margin: 0 auto;
}

.form {
  display: grid;
  gap: 1rem;
}

.form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-700);
}

.input,
select.input,
textarea.input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fff;
}

.input:focus {
  outline: 2px solid var(--teal-600);
  border-color: transparent;
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400 !important;
}

.form-footer {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.flash-list {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.flash-success,
.flash-info {
  background: var(--green-100);
  color: var(--green-700);
}

.flash-warning {
  background: var(--amber-100);
  color: var(--amber-800);
}

.flash-danger,
.flash-error {
  background: var(--red-100);
  color: var(--red-700);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--gray-200);
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.7rem;
  color: var(--gray-500);
  padding: 0.35rem 0.5rem;
  min-width: 56px;
}

.nav-item.active {
  color: var(--teal-700);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th,
td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

th {
  background: var(--gray-100);
  font-weight: 600;
}

.section {
  margin-bottom: 1.5rem;
}

.section h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
  color: var(--teal-800);
}

.role-grid {
  display: grid;
  gap: 0.5rem;
}

.role-chip {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--gray-100);
}

.role-P { background: #fef9c3; }
.role-D { background: #dbeafe; }
.role-C { background: #dcfce7; }
.role-A { background: #fee2e2; }

.lineup-field {
  display: grid;
  gap: 0.5rem;
  padding: 1rem;
  background: linear-gradient(180deg, #166534 0%, #15803d 100%);
  border-radius: var(--radius);
  color: #fff;
  min-height: 200px;
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 0.35rem;
}

.auction-current {
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--teal-100);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.auction-current .player-name {
  font-size: 1.25rem;
  font-weight: 700;
}

.bid-amount {
  font-size: 2rem;
  font-weight: 800;
  color: var(--teal-800);
}

.help-box {
  margin: 0 0 1.25rem;
  background: var(--teal-100);
  border: 1px solid #99f6e4;
  border-radius: var(--radius);
  overflow: hidden;
}

.help-box-summary {
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--teal-900);
  cursor: pointer;
  list-style: none;
}

.help-box-summary::-webkit-details-marker {
  display: none;
}

.help-box-summary::before {
  content: "❓ ";
}

.help-box[open] .help-box-summary::before {
  content: "💡 ";
}

.help-box-body {
  padding: 0 1rem 1rem;
  font-size: 0.875rem;
  color: var(--gray-700);
}

.help-box-body p {
  margin: 0 0 0.65rem;
}

.help-box-body p:last-child {
  margin-bottom: 0;
}

.help-box-body ol,
.help-box-body ul {
  margin: 0.35rem 0 0.65rem 1.1rem;
  padding: 0;
}

.help-box-body li {
  margin-bottom: 0.35rem;
}

.help-box-body strong {
  color: var(--teal-900);
}

.help-box-body code {
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.6);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.quick-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--teal-800);
}

.chip:hover {
  background: var(--teal-100);
}

.admin-actions {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.card.highlight {
  border: 2px solid var(--teal-600);
}

.standings-table .highlight {
  background: var(--teal-100);
  font-weight: 600;
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip.active {
  background: var(--teal-700);
  color: #fff;
  border-color: var(--teal-700);
}

.filter-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.inline-bid-form {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.inline-bid-form .input {
  width: 5rem;
  padding: 0.45rem 0.5rem;
}

.lot-grid .lot-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.role-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  margin-right: 0.25rem;
}

.auction-page .auction-summary {
  margin-bottom: 1rem;
}

.chat-fab {
  position: fixed;
  top: calc(var(--header-height) + 0.75rem);
  right: 0.75rem;
  z-index: 200;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: none;
  background: var(--teal-700);
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--red-700);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.chat-fab-badge.hidden {
  display: none;
}

.chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 250;
}

.chat-backdrop.open {
  display: block;
}

.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 92vw);
  height: 100dvh;
  background: #fff;
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 16px rgba(15, 23, 42, 0.12);
}

.chat-drawer.open {
  transform: translateX(0);
}

.chat-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid var(--gray-200);
  background: var(--teal-100);
}

.chat-league-select {
  margin-top: 0.35rem;
  font-size: 0.85rem;
}

.chat-league-name {
  font-size: 0.85rem;
  color: var(--gray-500);
}

.chat-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--gray-700);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chat-msg {
  background: var(--gray-100);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  max-width: 95%;
}

.chat-msg.mine {
  align-self: flex-end;
  background: var(--teal-100);
}

.chat-msg-meta {
  font-size: 0.72rem;
  color: var(--gray-500);
  margin-bottom: 0.2rem;
}

.chat-msg-body {
  font-size: 0.9rem;
  word-break: break-word;
}

.chat-compose {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--gray-200);
  padding-bottom: calc(0.75rem + var(--safe-bottom));
}

.chat-compose .input {
  flex: 1;
}

@media (min-width: 640px) {
  .app-main {
    padding: 1.5rem;
  }

  .hero h1,
  .page h1 {
    font-size: 1.75rem;
  }
}
