// ==========================================================================
// Design tokens
// ==========================================================================
$color-bg:            #f7f8fa;
$color-card-bg:        #ffffff;
$color-border:         #e6e8ec;
$color-text:           #1f2430;
$color-text-muted:     #7a8194;
$color-text-faint:     #9aa1b0;

$color-primary:        #2f6fed;
$color-primary-hover:  #2a63d6;

$color-green-bg:       #e5f7ec;
$color-green-text:     #1e9e53;

$color-blue-bg:        #e8f0fe;
$color-blue-text:      #3467d6;

$color-red:            #e04b4b;

$color-navy-banner:    #0f2440;

$radius-sm:  6px;
$radius-md:  10px;
$radius-lg:  14px;

$shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
$shadow-modal: 0 20px 50px rgba(15, 23, 42, 0.25);

$font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

// ==========================================================================
// Page shell
// ==========================================================================
:host {
  display: block;
  font-family: $font-stack;
  color: $color-text;
}

.page {
  background: $color-bg;
  min-height: 100vh;
  padding: 28px 40px 60px;
  box-sizing: border-box;
}

// ==========================================================================
// Top bar / breadcrumb
// ==========================================================================
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.breadcrumb {
  font-size: 13px;
  color: $color-text-faint;

  &__item {
    &--current {
      color: $color-text-muted;
    }
  }

  &__sep {
    margin: 0 6px;
  }
}

// ==========================================================================
// Buttons
// ==========================================================================
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: $radius-md;
  padding: 9px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;

  &:active {
    transform: translateY(1px);
  }

  &--primary {
    background: $color-primary;
    color: #fff;

    &:hover {
      background: $color-primary-hover;
    }
  }

  &--ghost {
    background: #fff;
    color: $color-text-muted;
    border-color: $color-border;

    &:hover {
      background: #f2f3f5;
    }
  }

  &__icon {
    font-size: 15px;
    line-height: 1;
  }
}

// ==========================================================================
// Page header
// ==========================================================================
.page-header {
  margin-bottom: 20px;

  &__title {
    margin: 0 0 6px;
    font-size: 26px;
    font-weight: 700;
    color: $color-text;
  }

  &__subtitle {
    margin: 0;
    font-size: 14px;
    color: $color-text-muted;
  }
}

// ==========================================================================
// Cards
// ==========================================================================
.card {
  background: $color-card-bg;
  border: 1px solid $color-border;
  border-radius: $radius-lg;
  box-shadow: $shadow-card;

  & + & {
    margin-top: 20px;
  }
}

.card--select {
  padding: 18px 22px;
  margin-bottom: 20px;
}

.card--table {
  padding: 20px 22px 8px;
}

.select-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;

  &__label {
    color: $color-text-muted;
    font-weight: 600;
  }

  &__control {
    flex: 0 0 auto;
    min-width: 260px;
    padding: 8px 12px;
    border-radius: $radius-sm;
    border: 1px solid $color-border;
    background: #f4f5f7;
    font-size: 14px;
    color: $color-text;
    font-family: inherit;
  }
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
}

.card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: $color-text;
}

.card__count {
  font-size: 13px;
  color: $color-text-faint;
}

// ==========================================================================
// Table
// ==========================================================================
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;

  thead th {
    text-align: left;
    font-size: 11.5px;
    letter-spacing: 0.03em;
    text-transform: none;
    color: $color-text-faint;
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid $color-border;
    white-space: nowrap;
  }

  tbody td {
    padding: 14px;
    border-bottom: 1px solid $color-border;
    color: $color-text;
    white-space: nowrap;
  }

  tbody tr:last-child td {
    border-bottom: none;
  }
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;

  &--type {
    background: $color-green-bg;
    color: $color-green-text;
  }

  &--mode {
    background: $color-blue-bg;
    color: $color-blue-text;
  }
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: $color-border;

  &--active {
    background: #22c55e;
  }
}

.actions {
  display: flex;
  gap: 14px;
}

.link {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;

  &--edit {
    color: $color-primary;

    &:hover {
      text-decoration: underline;
    }
  }

  &--del {
    color: $color-red;

    &:hover {
      text-decoration: underline;
    }
  }
}

.empty-state {
  padding: 30px 4px;
  text-align: center;
  color: $color-text-muted;
  font-size: 14px;

  .link {
    margin-left: 6px;
  }
}

// ==========================================================================
// Modal
// ==========================================================================
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  box-sizing: border-box;
  animation: fadeIn 0.18s ease-out;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: #fff;
  border-radius: $radius-lg;
  box-shadow: $shadow-modal;
  animation: scaleIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 14px;
}

.modal__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: $color-text;
}

.modal__close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: $color-text-faint;
  cursor: pointer;
  padding: 4px;

  &:hover {
    color: $color-text;
  }
}

.modal__body {
  padding: 0 24px 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;

  label {
    font-size: 12.5px;
    font-weight: 600;
    color: $color-text-muted;
  }

  select,
  input,
  textarea {
    font-family: inherit;
    font-size: 14px;
    color: $color-text;
    border: 1px solid $color-border;
    border-radius: $radius-sm;
    padding: 9px 11px;
    background: #fff;
    width: 100%;
    box-sizing: border-box;

    &:focus {
      outline: none;
      border-color: $color-primary;
      box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
    }
  }

  textarea {
    resize: vertical;
    min-height: 64px;
  }

  &--full {
    margin-bottom: 14px;
  }

  &--toggle {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;

    label {
      font-size: 13px;
    }
  }
}

.req {
  color: $color-red;
}

.input-icon,
.time-field {
  position: relative;
  display: flex;
  gap: 8px;

  input {
    flex: 1;
  }
}

.time-field .meridiem {
  width: 76px;
  flex: 0 0 auto;
}

// Info banner (Standalone / Combined explanation)
.info-banner {
  background: $color-navy-banner;
  color: #dce6f7;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 16px;
  border-radius: $radius-sm;
  margin-bottom: 18px;

  strong {
    color: #fff;
  }
}

.section-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: $color-text-faint;
  text-transform: uppercase;
  padding-bottom: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid $color-border;
}

// Toggle switch
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  border: none;
  background: #d5d9e0;
  cursor: pointer;
  transition: background-color 0.15s ease;
  flex: 0 0 auto;

  &__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease;
  }

  &--on {
    background: #1e9e53;

    .toggle__thumb {
      transform: translateX(18px);
    }
  }
}

.modal--delete {
  max-width: 420px;
}

.modal__title--danger {
  color: $color-red;
}

.delete-text {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: $color-text;
}

.delete-chip {
  background: #fdeceb;
  border: 1px solid #f6c6c2;
  color: #c23b2f;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: $radius-sm;
  margin-bottom: 20px;
}

.btn--danger {
  background: $color-red;
  color: #fff;

  &:hover {
    background: #c23b2f;
  }
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
  padding-top: 4px;
}

// ==========================================================================
// Responsive
// ==========================================================================
@media (max-width: 640px) {
  .page {
    padding: 20px 16px 40px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    max-width: 100%;
  }
}