/* Home dashboard — palette from logo-ncdplussu.png */
:root {
  --color-navy: #0a3d6e;
  --color-navy-dark: #062a4d;
  --color-navy-deep: #041e36;
  --color-blue: #1a6eb5;
  --color-blue-mid: #2d8fd4;
  --color-cyan: #00b4e4;
  --color-cyan-light: #5ec8f2;
  --color-cyan-pale: #a8e4f7;

  --home-bg-gradient: linear-gradient(
    168deg,
    #0e5285 0%,
    var(--color-navy) 32%,
    #072f52 68%,
    var(--color-navy-deep) 100%
  );
  --home-card: rgba(255, 255, 255, 0.1);
  --home-card-hover: rgba(255, 255, 255, 0.15);
  --home-card-border: rgba(94, 200, 242, 0.14);
  --home-text: #ffffff;
  --home-muted: rgba(168, 228, 247, 0.88);
  --home-accent: var(--color-cyan);
  --home-accent-light: var(--color-cyan-light);
  --home-title-gradient: linear-gradient(
    90deg,
    var(--color-cyan-light) 0%,
    var(--color-cyan) 55%,
    var(--color-blue-mid) 100%
  );
}

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

body.home-page {
  margin: 0;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  font-family: 'Kanit', system-ui, sans-serif;
  font-size: 1rem;
  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);
  color: var(--home-text);
  -webkit-font-smoothing: antialiased;
}

.home-wrap {
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: clamp(0.5rem, 1.2dvh, 1.25rem) clamp(0.75rem, 2vw, 1.25rem);
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

.home-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(94, 200, 242, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(94, 200, 242, 0.04) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 80%);
  pointer-events: none;
}

.home-panel {
  position: relative;
  z-index: 1;
  width: min(1140px, 100%);
  max-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  flex: 0 1 auto;
}

/* ── Profile ── */
.home-topbar {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  background: rgba(10, 61, 110, 0.45);
  border: 1px solid rgba(94, 200, 242, 0.22);
  border-radius: 999px;
  padding: 0.55rem 0.65rem 0.55rem 0.55rem;
  backdrop-filter: blur(10px);
  max-width: min(100%, 720px);
  width: 100%;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.profile-meta {
  min-width: 0;
  flex: 1;
  padding: 0.1rem 0;
}

.profile-divider {
  width: 1px;
  height: 44px;
  flex-shrink: 0;
  background: rgba(94, 200, 242, 0.22);
}

.profile-logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
  margin-right: 0.15rem;
  padding: 0.5rem 0.85rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #fca5a5;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.profile-logout-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.profile-logout-btn:hover {
  background: rgba(248, 113, 113, 0.18);
  color: #fff;
}

.profile-logout-btn:focus-visible {
  outline: 2px solid #fca5a5;
  outline-offset: 2px;
}

.profile-avatar-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: rgba(0, 180, 228, 0.15);
  border: 2px solid rgba(94, 200, 242, 0.35);
  flex-shrink: 0;
}

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

.profile-avatar-fallback {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--home-accent-light);
}

.profile-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-email {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--home-muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-hospital {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: rgba(94, 200, 242, 0.95);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Header ── */
.home-header {
  text-align: center;
  margin-bottom: 0.65rem;
  flex-shrink: 0;
}

.home-header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.6dvh, 1.5rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--home-title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.home-welcome {
  margin: clamp(0.15rem, 0.5dvh, 0.35rem) 0 0;
  font-size: clamp(0.85rem, 1.8dvh, 1rem);
  font-weight: 400;
  color: var(--home-muted);
}

/* ── Menu grid (6 per row, incomplete row aligns left) ── */
.menu-grid {
  --menu-cols: 6;
  --menu-gap: clamp(0.4rem, 0.65dvh, 0.65rem);
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: flex-start;
  gap: var(--menu-gap);
}

.menu-card {
  flex: 0 0
    calc((100% - (var(--menu-cols) - 1) * var(--menu-gap)) / var(--menu-cols));
  max-width: calc((100% - (var(--menu-cols) - 1) * var(--menu-gap)) / var(--menu-cols));
  box-sizing: border-box;
  background: var(--home-card);
  border: 1px solid var(--home-card-border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--home-text);
  min-height: clamp(72px, 11dvh, 100px);
  padding: 0.75rem 0.45rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.menu-card:hover {
  transform: translateY(-2px);
  background: var(--home-card-hover);
  border-color: rgba(0, 180, 228, 0.45);
  box-shadow: 0 8px 22px rgba(0, 180, 228, 0.14), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.menu-card:focus-visible {
  outline: 2px solid var(--home-accent);
  outline-offset: 2px;
}

.menu-card-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid transparent;
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.menu-card:hover .menu-card-icon {
  transform: scale(1.05);
}

.menu-card-icon svg {
  width: 22px;
  height: 22px;
}

/* Icon colors by menu category */
.menu-card--profile .menu-card-icon {
  color: #5ec8f2;
  background: rgba(94, 200, 242, 0.16);
  border-color: rgba(94, 200, 242, 0.28);
}

.menu-card--rights .menu-card-icon {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.14);
  border-color: rgba(74, 222, 128, 0.28);
}

.menu-card--health .menu-card-icon {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.28);
}

.menu-card--pageview .menu-card-icon {
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.14);
  border-color: rgba(167, 139, 250, 0.28);
}

.menu-card--sugar .menu-card-icon {
  color: #f472b6;
  background: rgba(244, 114, 182, 0.14);
  border-color: rgba(244, 114, 182, 0.28);
}

.menu-card--bp .menu-card-icon {
  color: #fb7185;
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.28);
}

.menu-card--physical .menu-card-icon {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.14);
  border-color: rgba(96, 165, 250, 0.28);
}

.menu-card--body .menu-card-icon {
  color: #34d399;
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.28);
}

.menu-card--food .menu-card-icon {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.28);
}

.menu-card--watch .menu-card-icon {
  color: #22d3ee;
  background: rgba(34, 211, 238, 0.14);
  border-color: rgba(34, 211, 238, 0.28);
}

.menu-card--poc .menu-card-icon {
  color: #fb923c;
  background: rgba(251, 146, 60, 0.14);
  border-color: rgba(251, 146, 60, 0.28);
}

.menu-card--cgm .menu-card-icon {
  color: #c084fc;
  background: rgba(192, 132, 252, 0.14);
  border-color: rgba(192, 132, 252, 0.28);
}

.menu-card--ai .menu-card-icon {
  color: #818cf8;
  background: rgba(129, 140, 248, 0.14);
  border-color: rgba(129, 140, 248, 0.28);
}

.menu-card--lab .menu-card-icon {
  color: #2dd4bf;
  background: rgba(45, 212, 191, 0.14);
  border-color: rgba(45, 212, 191, 0.28);
}

.menu-card:hover .menu-card-icon {
  color: #fff;
}

.menu-card > span:last-child {
  font-size: 0.83rem;
  font-weight: 500;
  line-height: 1.25;
  text-wrap: balance;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .menu-grid {
    --menu-cols: 4;
  }
}

@media (max-height: 720px) {
  .home-header {
    margin-bottom: 0.45rem;
  }

  .home-topbar {
    margin-bottom: 0.5rem;
  }

  .menu-card {
    min-height: clamp(64px, 10dvh, 88px);
    padding: 0.6rem 0.4rem;
  }
}

/* หน้าจอเตี้ยมาก — เลื่อนได้ */
@media (max-height: 620px) {
  body.home-page {
    overflow-y: auto;
  }

  .home-wrap {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    justify-content: flex-start;
    padding-top: 0.75rem;
  }
}

@media (max-width: 768px) {
  .home-wrap {
    padding: clamp(0.5rem, 1dvh, 1rem);
  }

  .profile-chip {
    width: 100%;
    max-width: 100%;
    gap: 0.65rem;
    padding: 0.5rem 0.55rem 0.5rem 0.5rem;
  }

  .profile-avatar-wrap {
    width: 44px;
    height: 44px;
  }

  .profile-name {
    font-size: 1.05rem;
  }

  .profile-email {
    font-size: 0.85rem;
  }

  .profile-hospital {
    font-size: 0.8rem;
  }

  .profile-divider {
    height: 38px;
  }

  .profile-meta {
    flex: 1;
  }

  .profile-logout-btn span {
    display: none;
  }

  .profile-logout-btn {
    padding: 0.5rem;
    margin-right: 0;
  }

  .menu-grid {
    --menu-cols: 3;
    --menu-gap: 0.5rem;
  }

  .menu-card {
    min-height: 80px;
  }
}

@media (max-width: 520px) {
  .menu-grid {
    --menu-cols: 2;
  }

  .menu-card-icon {
    width: 34px;
    height: 34px;
  }

  .menu-card-icon svg {
    width: 20px;
    height: 20px;
  }

  .menu-card > span:last-child {
    font-size: 0.78rem;
  }
}
