:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --line: #d8dee6;
  --primary: #151a20;
  --accent: #0f8f6f;
  --accent-soft: #dff5ef;
  --warn: #c92828;
  --protein: #e88a1a;
  --training: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.container {
  width: min(100%, 880px);
  margin: 0 auto;
  padding: 20px 14px 40px;
}

.app-header {
  margin: 6px 0 18px;
  text-align: center;
}

.user-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.user-bar form {
  margin: 0;
}

.nav-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(26px, 8vw, 40px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 24px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 6px;
  font-size: 17px;
}

.panel {
  margin-bottom: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(25, 34, 44, 0.06);
}

.message-panel h2 {
  font-size: clamp(24px, 7vw, 34px);
  line-height: 1.25;
}

.section-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.ok {
  color: var(--accent);
  font-weight: 700;
}

.ng {
  color: var(--warn);
  font-weight: 700;
}

.connection-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef1f5;
}

.dispense-panel {
  padding: 10px;
}

.dispense-button {
  width: 100%;
  min-height: 74px;
  background: var(--primary);
  color: #fff;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 800;
}

.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  padding: 11px 14px;
  font-weight: 700;
}

.secondary-button {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.ghost-button {
  background: #edf1f5;
  color: var(--text);
}

.compact-button {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
}

.danger-button {
  background: #f9e6e6;
  color: var(--warn);
}

.icon-button {
  width: 48px;
  background: #edf1f5;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.today-count {
  min-width: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.today-count span {
  display: block;
  font-size: 30px;
  font-weight: 800;
}

.today-count small {
  color: var(--muted);
  font-weight: 700;
}

.progress-track {
  height: 18px;
  margin: 8px 0 10px;
  overflow: hidden;
  background: #e8edf2;
  border-radius: 999px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #38b58f);
  transition: width 180ms ease;
}

.goal-text {
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 700;
}

.goal-text.achieved {
  color: var(--accent);
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.button-row {
  display: grid;
  gap: 10px;
}

.calendar-header {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
}

.calendar-header h2 {
  margin-bottom: 0;
  text-align: center;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.calendar-legend span,
.marks {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mark {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.mark.training {
  background: var(--training);
}

.mark.protein {
  background: var(--protein);
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.weekday-row {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.calendar-blank,
.calendar-day {
  min-height: 54px;
}

.calendar-day {
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 7px 3px;
  background: #f8fafc;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 800;
}

.calendar-day.today {
  border-color: var(--accent);
}

.calendar-day.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.selected-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.selected-summary span {
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.training-list {
  display: grid;
  gap: 10px;
}

.training-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.training-item p {
  margin-bottom: 0;
  color: var(--muted);
}

.training-memo {
  margin-top: 8px;
  white-space: pre-wrap;
}

.training-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-container {
  width: min(100%, 460px);
  min-height: 100vh;
  display: grid;
  align-items: center;
  margin: 0 auto;
  padding: 20px 14px;
}

.auth-panel h1 {
  text-align: left;
  font-size: 30px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.form-error {
  padding: 12px;
  background: #f9e6e6;
  border: 1px solid #f1c8c8;
  border-radius: 8px;
  color: var(--warn);
  font-weight: 700;
}

.form-success {
  padding: 12px;
  background: var(--accent-soft);
  border: 1px solid #b6e2d6;
  border-radius: 8px;
  color: var(--accent);
  font-weight: 700;
}

.flash-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.flash-list p {
  margin-bottom: 0;
}

.auth-link {
  margin: 16px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.auth-link a {
  color: var(--accent);
}

.token-panel {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
}

.token-panel h2 {
  margin-bottom: 6px;
}

.token-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

.device-item {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.device-item h2 {
  margin-bottom: 4px;
}

.device-code {
  margin-bottom: 12px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
}

.device-meta {
  display: grid;
  gap: 10px;
  margin: 0;
}

.device-meta div {
  display: grid;
  gap: 3px;
}

.device-meta dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.device-meta dd {
  margin: 0;
  font-weight: 700;
}

.device-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.device-actions form {
  margin: 0;
}

.device-actions button,
.device-actions a {
  width: 100%;
  min-width: 0;
  white-space: normal;
}

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

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

.share-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.share-item h2 {
  margin-bottom: 4px;
}

.share-item form,
.share-item button {
  width: 100%;
}

.command-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.command-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.command-title h2 {
  margin-bottom: 0;
}

.command-status.pending {
  color: #9a5b00;
  background: #fff2d9;
}

.command-status.processing {
  color: #1b4fb0;
  background: #e5efff;
}

.command-status.completed {
  color: var(--accent);
  background: var(--accent-soft);
}

.command-status.failed,
.command-status.cancelled {
  color: var(--warn);
  background: #f9e6e6;
}

@media (min-width: 680px) {
  .container {
    padding: 32px 20px 56px;
  }

  .panel {
    padding: 24px;
  }

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

  .full-width {
    grid-column: 1 / -1;
  }

  .button-row {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, auto);
    align-items: center;
  }

  .selected-summary {
    grid-template-columns: 1fr 1fr;
  }

  .training-item {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .device-item {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .device-actions {
    width: 240px;
  }

  .share-item {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .calendar-blank,
  .calendar-day {
    min-height: 68px;
  }
}
