/* -----------------------------------------------------------------------------
   Base styles — deliberately simple. Mobile-first: it looks fine on a phone
   and scales up. We'll build this out as the app grows.
----------------------------------------------------------------------------- */

:root {
    --navy: #1f3a5f;
    --blue: #2e6ca4;
    --ink: #222;
    --muted: #6b7683;
    --line: #d8e0ea;
    --bg: #f5f8fb;
    --ok: #2f6b4f;
    --bad: #b3261e;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.55;
    -webkit-text-size-adjust: 100%; /* stop mobile browsers from auto-resizing text */
}

.wrap {
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header / footer */
.site-header {
    background: var(--navy);
    color: #fff;
}
.site-header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: .9rem;
    padding-bottom: .9rem;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.15rem; }
.site-header nav a { color: #cfe0f0; text-decoration: none; margin-left: 1rem; }
.site-header nav a:hover { color: #fff; }

.site-footer {
    margin-top: 3rem;
    padding: 1.5rem 0;
    color: var(--muted);
    border-top: 1px solid var(--line);
}

/* Cards */
.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1.75rem;
    margin-top: 1.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
h1 { color: var(--navy); margin-top: 0; }
.lead { font-size: 1.1rem; color: var(--muted); }

/* Buttons */
.btn {
    display: inline-block;
    background: var(--blue);
    color: #fff;
    text-decoration: none;
    padding: .6rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
}
.btn:hover { background: var(--navy); }

.btn-secondary {
    display: inline-block;
    color: var(--blue);
    text-decoration: none;
    padding: .6rem 1.1rem;
    border: 1px solid var(--blue);
    border-radius: 8px;
    font-weight: 600;
}
.btn-secondary:hover { background: var(--blue); color: #fff; }
.home-cta { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* Health table */
table.health { border-collapse: collapse; width: 100%; margin-top: 1rem; }
table.health th, table.health td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); }
table.health .ok { color: var(--ok); font-weight: 600; }
table.health .bad { color: var(--bad); font-weight: 600; }

/* ---- Forms ---------------------------------------------------------------- */
.auth-card { max-width: 520px; }

.form-group { margin-bottom: 1rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .95rem; }
label .muted { font-weight: 400; color: var(--muted); }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"] {
    width: 100%;
    padding: .6rem .7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
}
input:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }

.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.field-error { color: var(--bad); font-size: .85rem; margin: .3rem 0 0; }

.btn-block { display: block; width: 100%; text-align: center; border: 0; cursor: pointer; font-size: 1rem; }

.auth-alt { margin-top: 1.25rem; color: var(--muted); }

/* ---- Alerts -------------------------------------------------------------- */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1.25rem; }
.alert-success { background: #e6f4ec; color: var(--ok); border: 1px solid #bfe0cd; }
.alert-error { background: #fbe9e7; color: var(--bad); border: 1px solid #f2c4bf; }

/* ---- Logout button styled as a nav link --------------------------------- */
.nav-logout { display: inline; margin: 0 0 0 1rem; }
.nav-logout button {
    background: none; border: 0; color: #cfe0f0; cursor: pointer;
    font: inherit; padding: 0;
}
.nav-logout button:hover { color: #fff; text-decoration: underline; }

/* Small screens: stack the two-column name row. */
@media (max-width: 520px) {
    .form-row { flex-direction: column; gap: 0; }
}

/* Selects match text inputs */
select {
    width: 100%;
    padding: .55rem .6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
}
select:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }

/* ---- League bar (secondary nav) ----------------------------------------- */
.league-bar { background: #fff; border-bottom: 1px solid var(--line); }
.league-bar .wrap { display: flex; align-items: center; gap: 1.25rem; padding: .55rem 1rem; flex-wrap: wrap; }
.league-name { font-weight: 700; color: var(--navy); }
.league-nav a { color: var(--slate, #44546a); text-decoration: none; margin-right: 1rem; font-size: .95rem; }
.league-nav a:hover { color: var(--blue); }

/* ---- Card header row ----------------------------------------------------- */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.card-head h1 { margin: 0; }
.section-title { color: var(--navy); font-size: 1.15rem; margin: 1.75rem 0 .6rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* ---- Data tables --------------------------------------------------------- */
table.data { border-collapse: collapse; width: 100%; margin-top: .75rem; }
table.data th, table.data td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.data td.right, table.data th.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---- Badges -------------------------------------------------------------- */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--slate, #44546a); border: 1px solid var(--line); }
.badge.role-owner { background: #eaf1fb; color: var(--navy); border-color: #cfe0f0; }
.badge.role-admin { background: #eef6ff; color: var(--blue); border-color: #cfe0f0; }

/* ---- Stat tiles ---------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .8rem; margin: 1rem 0; }
.tile { display: flex; flex-direction: column; align-items: center; padding: 1.1rem .5rem; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; background: #fff; }
.tile:hover { border-color: var(--blue); }
.tile-num { font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.tile-label { color: var(--muted); font-size: .9rem; }

/* ---- Inline "link" buttons + row forms ---------------------------------- */
.link { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; font: inherit; text-decoration: none; margin-left: .75rem; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }
form.inline { display: inline; }
.row-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.row-form select, .row-form input { width: auto; flex: 1; min-width: 160px; }
.row-form .short { flex: 0 0 110px; min-width: 0; }
.row-form .btn { flex: 0 0 auto; }
.form-group.check label { font-weight: 400; }
.form-group.check input { width: auto; margin-right: .4rem; }

/* Password requirements list under the password field */
ul.req { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .85rem; }
ul.req li { margin: .1rem 0; }

/* -------------------------------------------------------------------------
   Mobile / small screens. Families will mostly use this on a phone, so the
   layout collapses to a single, comfortable column with big tap targets.
   ------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .wrap { padding: 0 .85rem; }
    .card { padding: 1.15rem; border-radius: 10px; margin-top: 1rem; }
    h1 { font-size: 1.5rem; }

    /* Card header (title + action button) stacks; button goes full width */
    .card-head { flex-direction: column; align-items: stretch; gap: .6rem; }
    .card-head .btn, .card-head .btn-secondary { width: 100%; text-align: center; }

    /* Top bar and league bar wrap instead of overflowing */
    .site-header .wrap { flex-wrap: wrap; gap: .4rem .75rem; }
    .league-bar .wrap { gap: .4rem .9rem; }
    .league-nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; width: 100%; }
    .league-nav a { margin-right: 0; }

    /* Wide tables scroll sideways rather than breaking the page */
    table.data { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Inline row-forms (invite, add player) stack to full-width controls */
    .row-form { flex-direction: column; align-items: stretch; }
    .row-form select,
    .row-form input,
    .row-form .btn,
    .row-form .short { width: 100%; flex: none; min-width: 0; }

    .tiles { grid-template-columns: repeat(2, 1fr); }

    .home-cta { flex-direction: column; align-items: stretch; }
    .home-cta .btn, .home-cta .btn-secondary { width: 100%; text-align: center; }
}

/* Comfortable tap targets on touch devices */
@media (pointer: coarse) {
    .btn, .btn-secondary, button, select, input[type="text"], input[type="email"],
    input[type="tel"], input[type="password"], input[type="date"] { min-height: 44px; }
    .link { display: inline-block; padding: .35rem 0; }
}
