@import url('/css/complete-profile.css');

:root {
  --color-navy: #0a3d6e;
  --color-navy-deep: #041e36;
  --color-cyan: #00b4e4;
  --color-cyan-light: #5ec8f2;
  --home-bg-gradient: linear-gradient(
    168deg,
    #0e5285 0%,
    var(--color-navy) 32%,
    #072f52 68%,
    var(--color-navy-deep) 100%
  );
  --home-text: #ffffff;
  --home-muted: rgba(168, 228, 247, 0.88);
  --profile-content-max: 920px;
}

html {
  font-size: 12px;
  touch-action: manipulation;
}

body.menu-profile-page {
  margin: 0;
  min-height: 100dvh;
  font-family: 'Kanit', system-ui, sans-serif;
  font-size: 1rem;
  color: var(--home-text);
  background: radial-gradient(ellipse 75% 50% at 50% -5%, rgba(0, 180, 228, 0.28) 0%, transparent 55%),
    radial-gradient(circle at 90% 85%, rgba(45, 143, 212, 0.18) 0%, transparent 45%),
    var(--home-bg-gradient);
  -webkit-font-smoothing: antialiased;
}

.menu-profile-shell {
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(0.75rem, 2vw, 1.5rem);
  padding-bottom: calc(clamp(0.75rem, 2vw, 1.5rem) + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.menu-profile-wrap {
  width: 100%;
  max-width: var(--profile-content-max);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.menu-profile-header {
  flex-shrink: 0;
  margin-bottom: 1rem;
  padding: 0.25rem 0 0.5rem;
}

.menu-profile-header h1 {
  margin: 0.5rem 0 0;
  font-size: clamp(1.35rem, 2.5vw, 1.65rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, var(--color-cyan-light), var(--color-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.menu-profile-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--home-muted);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.25rem 0;
  transition: color 0.2s;
}

.menu-profile-back:hover {
  color: var(--home-text);
}

.menu-profile-body {
  flex: 1;
  width: 100%;
}

.menu-profile-panel {
  margin: 0;
}

.menu-profile-card {
  background: var(--color-surface, #fff);
  border-radius: 16px;
  padding: clamp(1.15rem, 2.5vw, 1.75rem);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: var(--color-text, #1a2b3c);
}

.menu-profile-card--edit {
  padding-bottom: clamp(1rem, 2vw, 1.5rem);
}

.menu-profile-card-title {
  margin: 0 0 1.25rem;
  font-size: clamp(1.05rem, 2vw, 1.2rem);
  font-weight: 600;
  color: var(--color-navy, #0a3d6e);
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--color-border, #c5dff0);
}

.menu-profile-loading {
  text-align: center;
  color: var(--home-muted);
  margin: 2rem 0;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.85rem;
  font-size: 0.95rem;
}

.alert-error {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid rgba(231, 76, 60, 0.4);
  color: #ffd4d0;
}

/* ── Toast alert (บันทึกสำเร็จ) ── */
.profile-alert {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: min(420px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  background: #fff;
  color: #0d5c36;
  border: 1px solid #6ee7a8;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.3s ease;
}

.profile-alert.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.profile-alert__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #d1fae5;
  color: #059669;
}

.profile-alert__message {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
}

.profile-alert__close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #5a6b7c;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.profile-alert__close:hover {
  background: #f0f4f8;
  color: #1a2b3c;
}

/* ── View mode ── */
.profile-view-layout {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.profile-summary {
  display: flex;
  gap: clamp(1rem, 2.5vw, 1.5rem);
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border, #c5dff0);
}

.profile-summary-avatar {
  width: clamp(80px, 12vw, 112px);
  height: clamp(80px, 12vw, 112px);
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-cyan-pale, #a8e4f7);
  border: 3px solid var(--color-cyan, #00b4e4);
  box-shadow: 0 4px 12px rgba(0, 180, 228, 0.25);
}

.profile-summary-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-summary-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  font-weight: 600;
  color: var(--color-cyan, #00b4e4);
}

.profile-summary-meta {
  flex: 1;
  min-width: 0;
}

.profile-summary-meta h2 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.1rem, 2.2vw, 1.35rem);
  font-weight: 600;
  color: var(--color-navy, #0a3d6e);
  line-height: 1.35;
}

.profile-summary-muted {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-muted, #5a7a94);
  word-break: break-word;
}

.profile-summary-hospital {
  margin: 0.45rem 0 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-blue, #1a6eb5);
}

.profile-summary-provider {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--color-muted, #5a7a94);
}

.profile-section-title {
  margin: 1.25rem 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-navy, #0a3d6e);
}

.profile-details {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.profile-details--health {
  margin-bottom: 0.25rem;
}

.profile-form-section-label {
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border, #c5dff0);
}

.profile-form-section-label span {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-navy, #0a3d6e);
}

.profile-details-row {
  display: grid;
  grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
  gap: 0.5rem 1.25rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--color-border, #c5dff0);
  align-items: center;
}

.profile-details-row:last-child {
  border-bottom: none;
}

.profile-details-row dt {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-muted, #5a7a94);
  font-weight: 400;
}

.profile-details-row dd {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 500;
  color: var(--color-text, #1a2b3c);
  text-align: left;
  word-break: break-word;
}

.profile-view-actions {
  margin-top: 1.25rem;
  padding-top: 0.25rem;
}

.profile-view-actions .btn {
  width: 100%;
}

/* ── Edit form ── */
.menu-profile-card .profile-form {
  margin-top: 0;
  gap: 0;
  display: flex;
  flex-direction: column;
}

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

.profile-form-aside .profile-avatar-section {
  border-bottom: none;
  padding-bottom: 0;
  align-items: center;
}

.profile-form-aside .profile-avatar-label {
  align-self: center;
}

.profile-form-main {
  min-width: 0;
}

.profile-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

.form-group--full {
  grid-column: 1 / -1;
}

.menu-profile-card .form-group--hospital {
  z-index: 30;
}

.menu-profile-card .form-group--hospital .searchable-select.is-open {
  z-index: 50;
}

.menu-profile-card .profile-avatar-status {
  color: var(--color-muted, #5a7a94);
}

.profile-form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border, #c5dff0);
}

.profile-form-actions .btn {
  flex: 1;
  min-height: 44px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.25rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.12s, box-shadow 0.2s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-cyan, #00b4e4), #1a8fc9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 180, 228, 0.35);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 18px rgba(0, 180, 228, 0.45);
}

.btn-secondary {
  background: #eef5fb;
  color: var(--color-navy, #0a3d6e);
  border: 1px solid var(--color-border, #c5dff0);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2eef8;
}

.btn-block {
  width: 100%;
}

.profile-form.is-loading {
  opacity: 0.65;
  pointer-events: none;
}

/* ── Tablet ── */
@media (min-width: 600px) {
  .menu-profile-shell {
    align-items: center;
    padding: 1.5rem 2rem;
  }

  .profile-details {
    grid-template-columns: 1fr 1fr;
    column-gap: 2rem;
  }

  .profile-details-row--full {
    grid-column: 1 / -1;
  }

  .profile-form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.25rem;
  }
}

/* ── Desktop ── */
@media (min-width: 768px) {
  html {
    font-size: 13px;
  }

  .profile-summary {
    align-items: flex-start;
  }

  .profile-form-layout {
    display: grid;
    grid-template-columns: minmax(160px, 200px) minmax(0, 1fr);
    gap: 1.75rem 2rem;
    align-items: start;
  }

  .profile-form-aside .profile-avatar-section {
    position: sticky;
    top: 0.5rem;
  }

  .profile-form-actions {
    justify-content: flex-end;
  }

  .profile-form-actions .btn {
    flex: 0 1 auto;
    min-width: 140px;
  }

  .profile-view-actions {
    display: flex;
    justify-content: flex-end;
  }

  .profile-view-actions .btn {
    width: auto;
    min-width: 200px;
  }
}

@media (min-width: 1024px) {
  .menu-profile-card {
    padding: 2rem 2.25rem;
  }

  .profile-details-row {
    grid-template-columns: minmax(0, 10rem) minmax(0, 1fr);
    padding: 0.8rem 0;
  }
}
