/* Components: buttons, forms, cards, badges, modals, lists, timeline, toast. */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  cursor: pointer;
  font-weight: 600;
  min-height: 2.5rem; /* touch target */
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--c-primary);
  color: #fff;
}

.btn--primary:not(:disabled):hover {
  background: var(--c-primary-hover);
}

.btn--ghost {
  background: transparent;
  border-color: var(--c-border);
}

.btn--ghost:hover {
  background: rgb(15 23 42 / 0.05);
}

.btn--danger {
  background: var(--c-danger);
  color: #fff;
}

.btn--danger-ghost {
  background: transparent;
  border-color: var(--c-danger);
  color: var(--c-danger);
}

.btn--danger-ghost:hover {
  background: var(--c-danger-bg);
}

.btn--sm {
  padding: 0.3rem 0.6rem;
  min-height: 2rem;
  font-size: 0.875rem;
}

.btn--block {
  width: 100%;
}

.btn--icon {
  padding: 0.25rem;
  width: 2.5rem;
  min-height: 2.5rem;
  font-size: 1.4rem;
  line-height: 1;
  background: transparent;
  border-color: var(--c-border);
}

/* ---- Forms ---- */
.field {
  margin-bottom: 0.9rem;
}

.field label,
.typegroup legend {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.label-hint {
  font-weight: 400;
  color: var(--c-muted);
}

.field input,
.field select,
.field textarea,
.cal-toolbar__picker select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
}

.field textarea {
  resize: vertical;
}

.form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.form-error {
  color: var(--c-danger);
  background: var(--c-danger-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
}

.help {
  color: var(--c-muted);
  font-size: 0.875rem;
}

.help--warn {
  color: var(--c-extra-text);
  background: var(--c-extra-bg);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
}

.empty {
  color: var(--c-muted);
  text-align: center;
  padding: 1rem 0;
}

/* ---- Cards ---- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem;
  max-width: 28rem;
}

/* ---- Type radio group ---- */
.typegroup {
  border: 0;
  padding: 0;
  margin: 0 0 0.9rem;
}

/* Two equal full-width segments — comfortable thumb targets on mobile. */
.typegroup__options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.35rem;
}

.typegroup .typechoice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.6rem 0.5rem;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

/* The colored segment itself signals the selection; the native radio dot
   only adds clutter. Kept in the DOM (visually hidden) for accessibility
   and keyboard navigation. */
.typegroup .typechoice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.typechoice--normal.typechoice--selected {
  border-color: var(--c-normal);
  background: var(--c-normal-bg);
  color: var(--c-normal-text);
}

.typechoice--extra.typechoice--selected {
  border-color: var(--c-extra);
  background: var(--c-extra-bg);
  color: var(--c-extra-text);
}

.typechoice:focus-within {
  outline: 3px solid var(--c-normal);
  outline-offset: 2px;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge--normal {
  background: var(--c-normal-bg);
  color: var(--c-normal-text);
}

.badge--extra {
  background: var(--c-extra-bg);
  color: var(--c-extra-text);
}

.badge--active {
  background: var(--c-success-bg);
  color: var(--c-success);
}

.badge--inactive {
  background: rgb(15 23 42 / 0.08);
  color: var(--c-muted);
}

.badge--admin {
  background: var(--c-normal-bg);
  color: var(--c-normal-text);
}

/* ---- Modals ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: end center;
  background: rgb(15 23 42 / 0.5);
  padding: 0;
}

.modal--above {
  z-index: 50;
}

.modal--top {
  z-index: 60;
  place-items: center;
  padding: 1rem;
}

.modal__panel {
  width: 100%;
  max-width: 30rem;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--c-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1rem;
  margin: 0;
}

.modal--top .modal__panel {
  border-radius: var(--radius);
}

.modal__panel--sm {
  max-width: 22rem;
}

@media (min-width: 640px) {
  .modal {
    place-items: center;
    padding: 1rem;
  }

  .modal__panel {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.modal__title {
  margin: 0;
  font-size: 1.15rem;
}

.modal__foot {
  margin-top: 1rem;
}

/* ---- Entry list (day detail) ---- */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.entry-card {
  border: 1px solid var(--c-border);
  border-left: 5px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}

.entry-card--normal {
  border-left-color: var(--c-normal);
}

.entry-card--extra {
  border-left-color: var(--c-extra);
}

.entry-card__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.entry-card__range {
  font-variant-numeric: tabular-nums;
}

.entry-card__duration {
  color: var(--c-muted);
  font-size: 0.875rem;
}

.entry-card__note {
  margin: 0.35rem 0 0;
  color: var(--c-muted);
  font-size: 0.9rem;
}

.entry-card__actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

/* ---- User list (admin) ---- */
.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.user-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.user-card__info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  min-width: 0;
}

.user-card__username {
  color: var(--c-muted);
  font-size: 0.9rem;
  word-break: break-all;
}

.user-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

/* ---- Audit timeline ---- */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.timeline__item {
  border-left: 3px solid var(--c-border);
  padding-left: 0.75rem;
}

.timeline__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.6rem;
}

.timeline__action {
  font-weight: 700;
}

.timeline__action--create {
  color: var(--c-success);
}

.timeline__action--update {
  color: var(--c-normal);
}

.timeline__action--delete {
  color: var(--c-danger);
}

.timeline__actor {
  font-weight: 600;
}

.timeline__when {
  color: var(--c-muted);
  font-size: 0.85rem;
}

.timeline__changes {
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

.timeline__change {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.15rem 0;
}

.timeline__field {
  font-weight: 600;
}

.timeline__field::after {
  content: ':';
}

.timeline__before {
  color: var(--c-muted);
  text-decoration: line-through;
}

.timeline__arrow {
  color: var(--c-muted);
}

/* Full-page variant used by the admin change-log screen: each item is a
   card of its own instead of a left-rail line inside a modal. */
.timeline--page {
  max-width: 46rem;
}

.timeline--page .timeline__item {
  border-left: 0;
  padding: 0.75rem 0.9rem;
}

.timeline__entity {
  font-weight: 700;
}

.timeline__actor {
  color: var(--c-muted);
}

.timeline--page .timeline__when {
  margin-left: auto;
}

.form__actions--center {
  justify-content: center;
  margin-top: 0.9rem;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(92vw, 26rem);
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #fff;
  font-weight: 600;
  text-align: center;
}

.toast--success {
  background: var(--c-success);
}

.toast--error {
  background: var(--c-danger);
}
