* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f4f5f7;
    color: #1a1a1a;
}

.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d7dae0;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: #444;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary { background: #007fff; color: #fff; }
.btn-primary:hover { background: #0066cc; }
.btn-secondary { background: #e9ecef; color: #333; }
.btn-secondary:hover { background: #dde1e6; }
.btn-small { padding: 6px 10px; font-size: 0.8rem; }
.btn-danger { background: #dc3545; color: #fff; }

/* ---- Auth ---- */

.auth-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-box {
    background: #fff;
    padding: 36px 32px;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 360px;
}

.auth-box h1 {
    text-align: center;
    font-size: 1.4rem;
    margin: 0 0 20px;
    color: #0056b3;
}

.auth-tabs {
    display: flex;
    margin-bottom: 20px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #d7dae0;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: #f4f5f7;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
}

.auth-tab.active { background: #007fff; color: #fff; }

.auth-error {
    color: #dc3545;
    font-size: 0.85rem;
    margin-bottom: 10px;
    min-height: 1em;
}

/* ---- App shell ---- */

.app-header {
    background: linear-gradient(135deg, #007fff 0%, #0056b3 100%);
    color: #fff;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 { margin: 0; font-size: 1.2rem; }

.app-header-right {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.9rem;
}

.tabs {
    display: flex;
    gap: 4px;
    background: #fff;
    padding: 0 24px;
    border-bottom: 1px solid #e2e4e8;
}

.tab-btn {
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    color: #666;
    border-bottom: 3px solid transparent;
}

.tab-btn.active { color: #007fff; border-bottom-color: #007fff; }

.main-content { padding: 24px; max-width: 1400px; margin: 0 auto; }

.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.card h2 { margin-top: 0; font-size: 1.05rem; }

.empty-state { color: #888; font-style: italic; padding: 12px 0; }

/* ---- Roster ---- */

.roster-list { display: flex; flex-direction: column; gap: 8px; }

.roster-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

/* ---- Plans list ---- */

.plans-list { display: flex; flex-direction: column; gap: 8px; }

.plan-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: #f8f9fa;
    border-radius: 6px;
    cursor: pointer;
}

.plan-row:hover { background: #eef2f7; }

/* ---- Plan builder grid ---- */

.plan-builder-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    align-items: center;
}

.plan-builder-toolbar input,
.plan-builder-toolbar button {
    flex-shrink: 0;
}

.macro-group {
    border: 1px solid #d7e3ff;
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
}

.macro-group-header {
    background: #eaf3ff;
    color: #0056b3;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Plain 1fr (no minmax floor) — columns always shrink to fit the container
   so the full week is visible with no horizontal scrolling, on coach and
   athlete views alike. */
.week-row {
    display: grid;
    grid-template-columns: 160px repeat(7, 1fr);
    border-top: 1px solid #eee;
}

.week-row:first-child { border-top: none; }

/* No fixed rows/resize — height is set explicitly by autoGrowTextarea()
   (app.js) to match content, same treatment as the day-cell textareas,
   so notes are always fully visible with no inner scrolling. */
.week-notes {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #e2e4e8;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.72rem;
    line-height: 1.1;
    font-family: inherit;
    resize: none;
    overflow: hidden;
}

.week-notes-readonly {
    font-size: 0.72rem;
    line-height: 1.1;
    white-space: pre-wrap;
    color: #444;
    width: 100%;
}

.week-label {
    padding: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #666;
    background: #fafbfc;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.day-cell {
    border-left: 1px solid #eee;
    padding: 8px;
    min-height: 70px;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* box-shadow (not background) so the selection highlight still shows on
   top of a day-cell's heat-map gradient, which is set as an inline style
   and would otherwise win over a background set here. */
.day-cell.selected { box-shadow: inset 0 0 0 2px #e0a800; background: #fff3cd; }

.day-color-swatches {
    display: flex;
    gap: 4px;
    margin-top: auto;
    padding-top: 6px;
}

.day-color-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}

.day-color-swatch.active {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px #333;
}

/* No flex:1 — a stretched textarea just scrolls its overflow internally.
   Height is set explicitly by autoGrowTextarea() (app.js) to match content,
   which grows the day-cell and, via CSS Grid's auto-sized rows, the whole
   week row — so notes are always fully visible with no inner scrolling. */
.day-cell textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 40px;
    border: none;
    background: transparent;
    font-size: 0.8rem;
    line-height: 1.3;
    resize: none;
    overflow: hidden;
    font-family: inherit;
}

.day-cell textarea:focus { outline: 1px solid #007fff; background: #fff; }

.day-cell-content {
    flex: 1;
    line-height: 1.1;
}

.microcycle-tag {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #a15c00;
    background: #fff3cd;
    padding: 1px 6px;
    border-radius: 10px;
    margin-bottom: 4px;
}

.day-cell-select {
    position: absolute;
    top: 4px;
    right: 4px;
}

.ungrouped-weeks-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 18px 0 6px;
}

/* ---- Messaging ---- */

.messages-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    height: 500px;
}

.thread-list {
    background: #fff;
    border-radius: 8px;
    overflow-y: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.thread-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
}

.thread-item.active { background: #eaf3ff; font-weight: 600; }

.thread-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
}

.message-bubble.mine {
    background: #007fff;
    color: #fff;
    align-self: flex-end;
}

.message-bubble.theirs {
    background: #f0f1f3;
    color: #1a1a1a;
    align-self: flex-start;
}

.thread-compose {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #eee;
}

.thread-compose input { flex: 1; }

/* ---- Performance logs ---- */

.log-table { width: 100%; border-collapse: collapse; }
.log-table th, .log-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    font-size: 0.88rem;
}
.log-table th { color: #888; font-size: 0.75rem; text-transform: uppercase; }

@media (max-width: 768px) {
    .messages-layout { grid-template-columns: 1fr; height: auto; }
    .thread-list { max-height: 160px; }
    .week-row { grid-template-columns: 60px repeat(7, 1fr); }
    .main-content { padding: 14px; }
}
