.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(140deg, rgba(242, 248, 255, 0.82), rgba(255, 255, 255, 0.96)),
    #ffffff;
  box-shadow: var(--shadow);
}

.stat-card {
  position: relative;
  padding: 15px 15px 12px;
  overflow: hidden;
}

.stat-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 6px;
  content: "";
  background: linear-gradient(90deg, var(--accent), var(--summit));
}

.stat-card::after {
  position: absolute;
  right: -20px;
  bottom: -22px;
  width: 96px;
  height: 72px;
  content: "";
  opacity: 0.55;
  background: repeating-radial-gradient(ellipse at center, transparent 0 7px, currentColor 8px 9px, transparent 10px 15px);
}

.stat-card:nth-child(1) {
  color: var(--blue);
}

.stat-card:nth-child(2) {
  color: var(--green);
}

.stat-card:nth-child(3) {
  color: var(--trail);
}

.stat-card:nth-child(4) {
  color: var(--summit);
}

.stat-card span {
  display: block;
  margin-bottom: 6px;
  color: #9ab2d3;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-family: var(--display);
  font-size: clamp(2rem, 4vw, 3.25rem);
  letter-spacing: -0.045em;
  line-height: 0.95;
  font-weight: 800;
}

.stat-card small {
  color: #8ca4c5;
  font-size: 0.78rem;
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  position: relative;
  min-width: 0;
  padding: 16px;
  overflow: hidden;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.panel-header {
  border-bottom: 1px solid var(--line);
  margin: -2px 0 12px;
  padding-bottom: 8px;
}

.panel-header.split {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

canvas {
  filter: saturate(1.22) contrast(1.08);
}

.inline-form,
.chat-form {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

button[type="submit"],
.inline-form button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 14px;
  background: linear-gradient(180deg, #3190ea, #1d78cf);
  color: #ffffff;
  font-weight: 900;
}

.activity-list {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  background:
    linear-gradient(90deg, rgba(87, 180, 255, 0.16), transparent 36%),
    rgba(255, 255, 255, 0.95);
}

.activity-item:nth-child(even) {
  background:
    linear-gradient(90deg, rgba(123, 141, 255, 0.1), transparent 36%),
    rgba(245, 250, 255, 0.98);
}

.activity-item strong {
  display: block;
  margin-bottom: 3px;
  font-family: var(--display);
  font-weight: 700;
}

.activity-item span,
.activity-item small {
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 0.84rem;
}

th {
  background: linear-gradient(180deg, #e4f1ff, #d8eaff);
  color: #1a4b81;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

tbody tr:nth-child(even) {
  background: rgba(236, 245, 255, 0.7);
}

tbody tr:hover {
  background: rgba(87, 180, 255, 0.16);
}

.big-number {
  display: block;
  margin: 16px 0 10px;
  font-family: var(--display);
  font-size: 4.1rem;
  letter-spacing: -0.07em;
  font-weight: 800;
}

.plan-list {
  display: grid;
  gap: 12px;
}

.plan-milestones {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.milestone-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(233, 244, 255, 0.6), rgba(255, 255, 255, 0.95)),
    #ffffff;
  color: #2a6db1;
}

.milestone-card::after {
  position: absolute;
  right: 8px;
  bottom: 7px;
  width: 34px;
  height: 22px;
  content: "";
  opacity: 0.32;
  background: repeating-radial-gradient(ellipse at center, transparent 0 5px, currentColor 6px 7px, transparent 8px 13px);
}

.milestone-card span,
.milestone-card small {
  display: block;
  color: #6280a3;
}

.milestone-card span {
  margin-bottom: 6px;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.milestone-card strong {
  display: block;
  margin-bottom: 3px;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 800;
}

.milestone-card.type-race {
  border-color: var(--red);
  color: var(--red);
}

.milestone-card.type-milestone {
  border-color: var(--blue);
  color: var(--blue);
}

.milestone-card.type-travel {
  border-color: var(--summit);
  color: var(--summit);
}

.milestone-card.type-training {
  border-color: var(--green);
  color: var(--green);
}

.milestone-card.type-admin {
  border-color: var(--trail);
  color: var(--trail);
}

.plan-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.plan-legend span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(243, 248, 255, 0.9);
  color: #2c5b8d;
  font-size: 0.76rem;
  font-weight: 800;
}

.phase-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(87, 180, 255, 0.16), rgba(123, 141, 255, 0.08), transparent);
  margin: 14px 0 0;
  padding: 9px 2px 4px;
}

.phase-header h3 {
  margin: 0;
  color: var(--green);
  font-family: var(--display);
  font-weight: 800;
}

.phase-header span {
  color: var(--muted);
}

.week-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background:
    linear-gradient(90deg, rgba(87, 180, 255, 0.14), transparent 28%),
    rgba(255, 255, 255, 0.96);
}

.week-card.current {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent), 0 0 0 1px rgba(87, 180, 255, 0.25);
  background:
    linear-gradient(90deg, rgba(87, 180, 255, 0.2), rgba(255, 255, 255, 0.96) 30%),
    rgba(255, 255, 255, 0.96);
}

.week-card h3 {
  margin: 0 0 5px;
  font-family: var(--display);
  font-weight: 800;
}

.week-card h3 span {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 600;
}

.week-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 6px;
}

.plan-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.plan-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plan-toolbar-edit[hidden] {
  display: none !important;
}

.plan-toolbar-edit:not([hidden]) {
  display: flex;
  gap: 8px;
}

.day-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.9);
  line-height: 1.32;
  display: grid;
  gap: 6px;
}

.day-card.plan-done {
  box-shadow: inset 0 0 0 2px rgba(32, 163, 91, 0.45);
}

.day-card.plan-skipped {
  opacity: 0.72;
  box-shadow: inset 0 0 0 2px rgba(180, 35, 24, 0.35);
}

.plan-list.plan-editing .day-card {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(87, 180, 255, 0.22);
}

.day-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.day-card-top strong {
  flex: 1;
  min-width: 0;
}

.plan-edit-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5faff;
  color: #1a4b81;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.plan-edit-btn:hover,
.plan-edit-btn:focus-visible {
  background: rgba(87, 180, 255, 0.22);
  border-color: var(--accent);
  outline: none;
}

.plan-day-view {
  display: grid;
  gap: 6px;
}

.plan-type-pill {
  display: inline-block;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(87, 180, 255, 0.18);
  color: #1a4b81;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.plan-planned-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.plan-day-edit[hidden] {
  display: none !important;
}

.plan-day-edit:not([hidden]) {
  display: grid;
  gap: 8px;
}

.plan-field-label {
  display: grid;
  gap: 4px;
}

.plan-field-label > span {
  color: #9ab2d3;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.plan-save-btn,
.plan-cancel-btn {
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}

.plan-save-btn {
  border: 0;
  background: linear-gradient(180deg, #57b4ff, #168aad);
  color: #fff;
}

.plan-save-btn:hover,
.plan-save-btn:focus-visible {
  filter: brightness(1.05);
  outline: none;
}

.plan-cancel-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.plan-cancel-btn:hover,
.plan-cancel-btn:focus-visible {
  background: rgba(236, 245, 255, 0.9);
  outline: none;
}

.plan-status-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5faff;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.plan-status-btn.status-done {
  background: rgba(32, 163, 91, 0.2);
  border-color: #20a35b;
  color: #157a42;
}

.plan-status-btn.status-skipped {
  background: rgba(180, 35, 24, 0.12);
  border-color: #c44;
  color: #9b2c2c;
}

.plan-type-input,
.plan-planned-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
}

.plan-type-input:disabled,
.plan-planned-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.plan-planned-input {
  resize: vertical;
  min-height: 2.6rem;
  color: var(--ink);
}

.day-card strong {
  color: var(--ink);
  font-size: 0.82rem;
}

.week-focus {
  border-left: 4px solid var(--accent);
  margin: 11px 0 0;
  padding: 10px 12px;
  background:
    linear-gradient(90deg, rgba(87, 180, 255, 0.2), transparent),
    rgba(236, 245, 255, 0.82);
  color: #5c7898;
  font-size: 0.88rem;
}

.type-run,
.type-race,
.type-milestone {
  border-color: #6ba8ea;
  background:
    linear-gradient(135deg, rgba(46, 196, 255, 0.22), rgba(255, 253, 247, 0.78));
}

.type-zwift,
.type-training {
  border-color: #74d9be;
  background:
    linear-gradient(135deg, rgba(32, 163, 91, 0.22), rgba(255, 253, 247, 0.78));
}

.type-lift {
  border-color: #86c8f7;
  background:
    linear-gradient(135deg, rgba(255, 140, 66, 0.24), rgba(255, 253, 247, 0.78));
}

.type-travel,
.type-cayman {
  border-color: #9ca8f8;
  background:
    linear-gradient(135deg, rgba(155, 93, 229, 0.22), rgba(255, 253, 247, 0.78));
}

.type-easy-rest,
.type-rest,
.type-recovery,
.type-active-rest,
.type-easy,
.type-easy-walk {
  border-color: #bdd7f2;
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.2), rgba(255, 253, 247, 0.78));
}

.coach-panel {
  max-width: 920px;
}

.chat-clear-btn {
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  background: #fff;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}

.chat-clear-btn:hover,
.chat-clear-btn:focus-visible {
  background: rgba(236, 245, 255, 0.9);
  outline: none;
}

.chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chat-preset-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(236, 245, 255, 0.9);
  color: #1a4b81;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chat-preset-btn:hover,
.chat-preset-btn:focus-visible {
  background: rgba(87, 180, 255, 0.22);
  border-color: var(--accent);
  outline: none;
}

.chat-log {
  display: grid;
  gap: 12px;
  min-height: 320px;
  max-height: 54vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.95);
}

.chat-message {
  max-width: 82%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  line-height: 1.48;
}

.panel:hover,
.stat-card:hover,
.week-card:hover,
.milestone-card:hover {
  transform: translateY(-2px);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.chat-message.user {
  justify-self: end;
  background: rgba(87, 180, 255, 0.18);
}

.chat-message.assistant,
.chat-message.system {
  justify-self: start;
  background: rgba(236, 245, 255, 0.9);
}

.chat-form {
  margin-top: 14px;
  margin-bottom: 0;
  align-items: flex-end;
}

.empty-state {
  color: var(--muted);
}

.period-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.period-toggle button {
  border: 0;
  background: rgba(236, 245, 255, 0.9);
  color: var(--muted);
  padding: 7px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.period-toggle button.active {
  background: linear-gradient(180deg, #57b4ff, #168aad);
  color: #fff;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  width: 100%;
  border: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.15s ease;
}

.activity-item:hover,
.activity-item:focus-visible {
  background: rgba(87, 180, 255, 0.22);
  outline: none;
}

.activity-row {
  cursor: pointer;
}

.activity-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.activity-modal {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
}

.activity-modal::backdrop {
  background: rgba(16, 32, 52, 0.55);
}

.activity-modal-card {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}

.activity-modal-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.activity-modal-header h2 {
  margin: 4px 0 2px;
  font-family: var(--display);
  font-size: 1.5rem;
}

.activity-modal-header p {
  margin: 0;
  color: var(--muted);
}

.modal-close {
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  background: #f5faff;
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.insight-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.insight-stat {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(236, 245, 255, 0.65);
}

.insight-stat span {
  display: block;
  margin-bottom: 2px;
  color: #9ab2d3;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.insight-stat strong {
  font-family: var(--display);
  font-size: 1.05rem;
}

.insight-plan-context {
  margin-top: 4px;
}

.insight-plan-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: rgba(236, 245, 255, 0.65);
}

.insight-plan-box h3 {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a4b81;
}

.insight-plan-box p {
  margin: 0 0 4px;
  font-size: 0.84rem;
  line-height: 1.4;
}

.insight-plan-meta {
  color: var(--muted);
  font-size: 0.76rem !important;
}

.insight-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.insight-generate-btn,
.insight-regenerate-btn {
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.insight-generate-btn {
  border: 0;
  background: linear-gradient(180deg, #57b4ff, #168aad);
  color: #fff;
}

.insight-generate-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.insight-regenerate-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.insight-idle,
.insight-loading,
.insight-error,
.insight-cache-note {
  color: var(--muted);
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.45;
}

.insight-cache-note {
  margin-top: 10px;
  font-size: 0.76rem;
  font-style: italic;
}

.insight-error {
  color: #b42318;
}

.insight-prose {
  display: grid;
  gap: 12px;
}

.insight-section h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a4b81;
}

.insight-section ul {
  margin: 0;
  padding-left: 18px;
}

.insight-section li,
.insight-section p {
  margin: 0 0 6px;
  color: var(--ink);
  line-height: 1.45;
}

@media (max-width: 920px) {
  .stats-grid,
  .dashboard-grid,
  .plan-milestones {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .inline-form,
  .chat-form,
  .panel-header.split,
  .phase-header {
    flex-direction: column;
  }

  .day-grid {
    grid-template-columns: 1fr;
  }

  .insight-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
