$surface: #f7f9fc;
$surface-card: #ffffff;
$surface-accent: #eef2ff;
$border: #d7deea;
$primary: #1e4dd8;
$primary-strong: #1239a2;
$danger: #da1b4d;
$text: #0f172a;
$muted: #5c6474;
$success: #0f8b5f;

@mixin elevated-card {
  background: $surface-card;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow:
    0 20px 45px rgba(15, 23, 42, 0.08),
    0 2px 6px rgba(15, 23, 42, 0.04);
}

@mixin focus-ring {
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 77, 216, 0.25);
}

:host {
  display: block;
}

.appointments-section {
  margin: 1.5rem auto;
  max-width: 1400px;
  padding: 2.5rem;
  position: relative;
  background: linear-gradient(180deg, #fdfdff 0%, #f1f4fb 100%);
  border-radius: 32px;
  border: 1px solid rgba(15, 23, 42, 0.04);
  box-shadow:
    0 30px 80px rgba(15, 23, 42, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  overflow: hidden;

  &::after {
    content: '';
    position: absolute;
    inset: 1.5rem;
    border-radius: 26px;
    border: 1px solid rgba(30, 77, 216, 0.08);
    pointer-events: none;
  }

  @media (max-width: 768px) {
    padding: 1.75rem;
  }
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;

  h2,
  p {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  }

  h2 {
    margin: 0;
    font-size: 1.5rem;
    color: $text;
    letter-spacing: -0.01em;
  }

  .info-text {
    margin: 0.35rem 0 0;
    color: $muted;
  }

  @media (max-width: 640px) {
    flex-direction: column;
    align-items: flex-start;
  }
}

.request-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: none;
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  background: linear-gradient(120deg, $primary, $primary-strong);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  box-shadow: 0 18px 35px rgba(30, 77, 216, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;

  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 25px 45px rgba(18, 57, 162, 0.35);
  }

  &:focus-visible {
    @include focus-ring;
  }
}

.request-form-container {
  margin-bottom: 2rem;
}

.create-form-container {
  @include elevated-card;
  padding: 1.75rem;
  background: linear-gradient(160deg, rgba(30, 77, 216, 0.08), rgba(255, 255, 255, 0)) $surface-card;
  border: 1px solid rgba(30, 77, 216, 0.1);
}

.form-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;

  h3 {
    margin: 0;
    font-size: 1.25rem;
    color: $text;
  }

  p {
    margin: 0.25rem 0 0;
    color: $muted;
  }
}

.icon-btn {
  border: none;
  background: rgba(15, 23, 42, 0.07);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;

  &:hover {
    background: rgba(15, 23, 42, 0.12);
    transform: translateY(-1px);
  }

  &:focus-visible {
    @include focus-ring;
  }
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-label {
  font-weight: 600;
  color: $text;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.required-indicator {
  color: $danger;
}

.form-input,
.form-select {
  border: 1px solid $border;
  border-radius: 14px;
  padding: 0.85rem;
  font-size: 1rem;
  background: $surface-card;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;

  &:focus {
    border-color: $primary;
    @include focus-ring;
  }
}

.loading-slots,
.no-slots,
.selected-time-info {
  padding: 0.85rem;
  border-radius: 14px;
  background: rgba(30, 77, 216, 0.07);
  color: $text;
  border: 1px solid rgba(30, 77, 216, 0.1);
}

.time-slots-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.time-slot-btn {
  border: 1px solid $border;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  background: $surface-card;
  cursor: pointer;
  transition: all 0.2s ease;

  &.selected {
    border-color: $primary;
    background: linear-gradient(120deg, rgba(30, 77, 216, 0.12), rgba(255, 255, 255, 0));
    color: $primary;
    box-shadow: 0 10px 18px rgba(30, 77, 216, 0.15);
  }

  &:hover:not(.selected) {
    border-color: rgba(30, 77, 216, 0.4);
  }

  &:focus-visible {
    @include focus-ring;
  }
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.cancel-btn,
.submit-button {
  border-radius: 12px;
  padding: 0.75rem 1.5rem;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

.cancel-btn {
  background: rgba(15, 23, 42, 0.08);
  color: $text;
  border: 1px solid rgba(15, 23, 42, 0.08);

  &:hover {
    background: rgba(15, 23, 42, 0.12);
  }
}

.submit-button {
  background: linear-gradient(120deg, $primary, $primary-strong);
  color: #fff;
  box-shadow: 0 20px 30px rgba(30, 77, 216, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;

  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 25px 40px rgba(18, 57, 162, 0.35);
  }

  &:focus-visible {
    @include focus-ring;
  }
}

.appointment-group {
  margin-bottom: 2rem;
}

.group-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: $text;
}

.appointments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.appointment-card {
  @include elevated-card;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 1px solid transparent;
    background: linear-gradient(120deg, rgba(30, 77, 216, 0.15), rgba(255, 255, 255, 0)) border-box;
    -webkit-mask:
      linear-gradient(#fff 0 0) padding-box,
      linear-gradient(#fff 0 0);
    -webkit-mask-composite: destination-out;
    mask:
      linear-gradient(#fff 0 0) padding-box,
      linear-gradient(#fff 0 0);
    mask-composite: exclude;
    pointer-events: none;
  }
}

.appointment-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.doctor-name {
  margin: 0;
  font-size: 1.05rem;
  color: $text;
}

.appointment-date,
.appointment-duration {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.25rem 0;
  color: $muted;
  font-size: 0.9rem;
}

.status-badge {
  align-self: flex-start;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;

  &.status-completed {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.25);
    color: $success;
  }
  &.status-confirmed {
    background: rgba(37, 99, 235, 0.12);
    border-color: rgba(37, 99, 235, 0.25);
    color: #1d4ed8;
  }
  &.status-cancelled {
    background: rgba(234, 72, 72, 0.12);
    border-color: rgba(234, 72, 72, 0.25);
    color: #b91c1c;
  }
  &.status-scheduled {
    background: rgba(234, 179, 8, 0.14);
    border-color: rgba(234, 179, 8, 0.3);
    color: #92400e;
  }
}

.appointment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.action-btn {
  border: 1px solid $border;
  border-radius: 14px;
  padding: 0.6rem 1.1rem;
  background: $surface-card;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;

  &:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  }

  &:focus-visible {
    @include focus-ring;
  }

  &.action-btn-cancel {
    color: #b45309;
    border-color: rgba(234, 179, 8, 0.5);
  }

  &.action-btn-delete {
    color: $danger;
    border-color: rgba(218, 27, 77, 0.4);
  }
}

.appointment-warning {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.15);
  color: #92400e;
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.empty-state {
  text-align: center;
  padding: 2rem;
  border-radius: 16px;
  border: 2px dashed rgba(148, 163, 184, 0.5);
  color: $muted;
  background: $surface-accent;

  .empty-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem;
    color: rgba(148, 163, 184, 0.8);
  }
}

