/* Core components from design system v1. Class names match the design system page. */
@layer components {
  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
  }

  /* Buttons */
  .btn {
    border: 1px solid transparent;
    border-radius: var(--r-ctl);
    padding: 10px 18px;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: filter .15s, transform .1s, border-color .15s;

    &:active { transform: translateY(1px); }
    &[disabled] { opacity: .45; cursor: not-allowed; }
    & svg { width: 16px; height: 16px; }

    &.primary { background: var(--accent); color: var(--on-accent); }
    &.primary:hover { filter: brightness(1.06); }
    &.dark { background: var(--ink); color: var(--bg); }
    &.secondary { background: var(--panel); border-color: var(--line); color: var(--ink); }
    &.secondary:hover { border-color: var(--muted); }
    &.danger { background: var(--panel); border-color: var(--fatigue); color: var(--ink); }
    &.danger:hover { background: var(--fatigue); color: var(--bg); }
    &.ghost { background: transparent; color: var(--accent-text); padding-inline: 8px; }
    &.sm { padding: 6px 12px; font-size: 13.5px; }
    &.block { width: 100%; }
  }

  /* Form controls */
  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;

    & label { font-size: 13.5px; font-weight: 600; }
    & .hint { font-size: 12.5px; color: var(--muted); }
  }

  .inp {
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--r-ctl);
    background: var(--bg);
    padding: 0 12px;
    min-height: 42px;
    transition: border-color .15s;

    &:focus-within { border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-wash); }
    & input, & select {
      border: 0;
      background: transparent;
      color: var(--ink);
      flex: 1;
      min-width: 0;
      outline: 0;
      padding: 8px 0;
    }
    & .unit { font-family: var(--mono); font-size: 13px; color: var(--muted); }
    &.warn { border-color: var(--accent); }
  }

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

  .check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 14.5px;
    cursor: pointer;

    & input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
  }

  /* Pills */
  .pill {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;

    &.plan { background: var(--accent-wash); color: var(--accent-ink); }
    &.good { background: var(--good-wash); color: var(--good); }
    &.actual { border: 1px solid var(--line); color: var(--actual); }
    &.neutral { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
    &.solid { background: var(--ink); color: var(--bg); }
    & i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
  }

  /* Metric tiles */
  .metric {
    display: flex;
    flex-direction: column;
    gap: 4px;

    & .big {
      font-family: var(--display);
      font-weight: var(--d-weight);
      font-size: 48px;
      line-height: 1;
      letter-spacing: -.03em;
      font-variant-numeric: tabular-nums;
    }
    & small { font-size: 13.5px; color: var(--muted); }
  }

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

  .mt {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--r-inner);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
  }

  .verdict {
    font-family: var(--display);
    font-weight: 600;
    font-size: 22px;
    line-height: 1.2;
    letter-spacing: -.02em;
  }

  /* Alerts and flash messages */
  .alert {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px 14px;
    align-items: center;
    padding: 14px 16px;
    border-radius: var(--r-inner);
    background: var(--accent-wash);
    color: var(--accent-ink);

    &.good { background: var(--good-wash); color: var(--good); }
    & svg { width: 20px; height: 20px; }
    & p { color: var(--ink); font-size: 14.5px; }
    & p b { font-weight: 600; }
  }

  /* Week strip */
  .wk {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
  }

  .day {
    border: 1px solid var(--line);
    border-radius: var(--r-inner);
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    background: var(--bg);

    &.today { border-color: var(--ink); background: var(--panel); }
    & .d { display: flex; justify-content: space-between; font-size: 12px; font-family: var(--mono); color: var(--muted); }
    & .d b { color: var(--ink); font-weight: 500; }
    & .t { font-size: 12.5px; font-weight: 600; line-height: 1.25; min-height: 2.5em; }
    & .l { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: center; }
  }

  /* Progress bar: teal fill is what happened, a violet tick marks the plan */
  .prog {
    display: flex;
    flex-direction: column;
    gap: 6px;

    & .track { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; position: relative; }
    & .track span { position: absolute; inset: 0 auto 0 0; background: var(--actual); border-radius: 999px; transition: width .3s; }
    & .track em { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--accent); }
    & .lbl { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); gap: 8px; flex-wrap: wrap; }
  }

  /* Tables */
  .tblw {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-inner);

    & table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 460px; }
    & th, & td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
    & tr:last-child td { border-bottom: 0; }
    & th {
      font-family: var(--mono);
      font-weight: 500;
      font-size: 11px;
      letter-spacing: .06em;
      text-transform: uppercase;
      color: var(--muted);
      background: var(--bg);
    }
    & td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; }
  }

  /* Toast */
  .toast {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    background: var(--ink);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: var(--r-inner);
    font-size: 14.5px;
    box-shadow: 0 8px 24px rgb(0 0 0 / .18);
  }

  /* Empty state */
  .empty {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: clamp(24px, 5vw, 40px);

    & h2 { font-size: clamp(26px, 4vw, 34px); }
    & p { color: var(--muted); max-width: 36em; }
  }

  @media (max-width: 760px) {
    .metrics { grid-template-columns: 1fr; }
    .wk { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  }

  @media (max-width: 480px) {
    .fields { grid-template-columns: 1fr; }
    .wk { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
}
