/* ==========================================================================
   CareMetrix — App shell: header, sidebar, content
   ========================================================================== */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app__body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* --------------------------------------------------------------- Header -- */

.topbar {
  height: 70px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo { height: 34px; width: auto; }

.header-toggle {
  border: none;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all .2s ease;
  color: var(--text);
}
.header-toggle:hover { background: var(--surface-3); color: var(--brand-purple); }
.hamburger-icon { width: 22px; height: 22px; fill: none; }

.topbar__center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 16px;
}

/* The wrapper is a plain flex box — the pill lives on the field itself. */
label:has(> input[type="search"]),
.search-field:has(> input[type="search"]),
.topbar-search {
  border: 0;
  background: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  gap: 0;
  height: auto;
  min-height: 0;
}

.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 240px;
  max-width: 520px;
  width: 100%;
  --form-search-radius: 999px;
}
.topbar-search > svg {
  position: absolute;
  left: 15px;
  width: 17px;
  height: 17px;
  fill: var(--text-3);
  pointer-events: none;
}
.topbar-search > input[type="search"] {
  width: 100%;
  height: 38px;
  padding: 0 16px 0 42px;
  font-size: 13.5px;
  color: var(--text);
  border: 1px solid #e1e4ef;
  border-radius: var(--form-search-radius);
  background: var(--surface-alt);
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.topbar-search > input[type="search"]::placeholder { color: var(--text-3); }
.topbar-search > input[type="search"]:focus {
  border-color: var(--form-focus);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--form-focus-ring);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all .2s ease;
}

/* gradient hairline border, painted as two stacked backgrounds */
.topbar__actions .icon-btn {
  border: 1.5px solid transparent;
  background: var(--surface);
  background-image: linear-gradient(var(--surface), var(--surface)), var(--brand-gradient);
  background-origin: border-box;
  background-clip: padding-box, border-box;
}
.topbar__actions .icon-btn:hover { box-shadow: var(--shadow-sm); }
.topbar__actions .icon-btn svg { width: 21px; height: 21px; }

.icon-btn--notify { position: relative; }
.notify-dot {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red-dot);
  border: 2px solid var(--surface);
}

/* ------------------------------------------------------- Profile menu -- */

.profile-menu { position: relative; }

.profile-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all .2s ease;
}
.profile-trigger:hover { background: var(--surface-3); }
.profile-trigger__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #F0E7FB;
}
.profile-trigger__meta { display: flex; flex-direction: column; align-items: flex-start; }
.profile-trigger__name { font-size: 14px; font-weight: 700; line-height: 1.25; }
.profile-trigger__role { font-size: 12px; color: var(--text-2); line-height: 1.25; }

.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 70;
  min-width: 244px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: none;
}
.profile-menu.is-open .profile-dropdown { display: block; }

.profile-dropdown__header {
  width: 100%;
  padding: 16px 14px;
  border-radius: var(--r-sm);
  text-align: center;
  cursor: pointer;
  transition: all .2s ease;
}
.profile-dropdown__header:hover { background: var(--surface-2); }
.profile-dropdown__avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 10px;
  border: 2px solid #F0E7FB;
}
.profile-dropdown__name { font-size: 14px; font-weight: 700; }
.profile-dropdown__role { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.profile-dropdown__item {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  text-align: left;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s ease;
}
.profile-dropdown__item:hover { background: var(--surface-3); color: var(--text); }
.profile-dropdown__item--danger { color: var(--red); }
.profile-dropdown__item--danger:hover { background: var(--red-bg); color: var(--red); }

/* -------------------------------------------------------------- Sidebar -- */

.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  width: var(--sidebar-w);
  flex: none;
  background: var(--sidebar-gradient);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
  transition: width var(--sidebar-duration) var(--sidebar-ease);
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-menu {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

/* ---- parent row ---- */

.sidebar-parent {
  width: 100%;
  min-height: 40px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--sidebar-icon);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  cursor: pointer;
  transition: width var(--sidebar-duration) var(--sidebar-ease),
              padding var(--sidebar-duration) var(--sidebar-ease),
              border-radius var(--sidebar-duration) var(--sidebar-ease),
              margin .2s ease, background .16s ease, color .16s ease;
}
.app[data-sidebar="expanded"] .sidebar-parent { padding: 8px 12px; }

.sidebar-parent:hover { background: rgba(var(--white-rgb), .10); }
.sidebar-parent.active { background: rgba(var(--white-rgb), .14); }
.sidebar-parent.is-open { background: rgba(var(--white-rgb), .12); margin-bottom: .5rem; }

.sidebar-parent__label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  justify-content: flex-start;
  transition: gap var(--sidebar-duration) var(--sidebar-ease);
}

.sidebar-parent__icon {
  font-size: 22px;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  line-height: 1;
}

.sidebar-parent__text {
  font-size: 12.5px;
  font-weight: 600;
  flex: 1;
  white-space: normal;
  line-height: 1.3;
  max-width: 200px;
  overflow: hidden;
  text-align: left;
  transition: max-width var(--sidebar-duration) var(--sidebar-ease), opacity .14s ease;
}

.sidebar-parent__chevron {
  width: 16px;
  height: 16px;
  flex: none;
  margin-left: auto;
  opacity: .85;
  transition: transform .22s var(--sidebar-ease), opacity .14s ease;
}
.sidebar-parent.is-open .sidebar-parent__chevron { transform: rotate(180deg); }

/* ---- submenu ---- */

.sidebar-submenu {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--sidebar-duration) var(--sidebar-ease);
}
.sidebar-submenu.is-open { grid-template-rows: 1fr; }
.sidebar-submenu__inner {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  width: 100%;
  min-height: 36px;
  border: none;
  background: transparent;
  border-radius: 10px;
  color: rgba(var(--white-rgb), .82);
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}
.sidebar-subitem { padding: 7px 12px 7px 44px; }
.sidebar-item:hover { background: rgba(var(--white-rgb), .10); color: #fff; }
.sidebar-item.active {
  background: rgba(var(--white-rgb), .18);
  color: #fff;
}
.sidebar-item.active .sidebar-item__text { font-weight: 700; }

.sidebar-item__text {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
}

/* ---- collapsed rail ---- */

.app[data-sidebar="collapsed"] .sidebar { width: var(--sidebar-w-collapsed); padding: 18px 12px; }
.app[data-sidebar="collapsed"] .sidebar-parent { padding: 8px; justify-content: center; }
.app[data-sidebar="collapsed"] .sidebar-parent__label { gap: 0; }
.app[data-sidebar="collapsed"] .sidebar-parent__text { max-width: 0; opacity: 0; }
.app[data-sidebar="collapsed"] .sidebar-parent__chevron { display: none; }
.app[data-sidebar="collapsed"] .sidebar-submenu { display: none; }

/* -------------------------------------------------------------- Content -- */

.content {
  flex: 1;
  min-width: 0;
  padding: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.page-loader { display: grid; place-items: center; padding: 120px 0; }
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--brand-purple);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.content > .page { animation: fade-up .32s var(--ease) both; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.scrim {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(36, 28, 60, .45);
  z-index: 40;
}

/* ------------------------------------------------------------ Responsive -- */

@media (max-width: 1180px) {
  :root { --gutter: 20px; }
  .topbar-search { min-width: 0; }
}

@media (max-width: 900px) {
  .topbar { padding: 0 12px; }
  .profile-trigger__meta { display: none; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    z-index: 50;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    transition: transform .26s var(--ease);
  }
  .app.is-mobile-open .sidebar { transform: none; }
  .app.is-mobile-open .scrim { display: block; }
  /* the rail never applies on mobile — the sidebar is a full-width drawer */
  .app[data-sidebar="collapsed"] .sidebar { width: var(--sidebar-w); padding: 18px 14px; }
  .app[data-sidebar="collapsed"] .sidebar-parent { padding: 8px 12px; justify-content: flex-start; }
  .app[data-sidebar="collapsed"] .sidebar-parent__label { gap: 10px; }
  .app[data-sidebar="collapsed"] .sidebar-parent__text { max-width: 200px; opacity: 1; }
  .app[data-sidebar="collapsed"] .sidebar-parent__chevron { display: block; }
  .app[data-sidebar="collapsed"] .sidebar-submenu { display: grid; }
}

@media (max-width: 620px) {
  .topbar__center { display: none; }
}
