/* ==========================================================================
   App shell: top bar, user menu, sidebar, page frames
   ========================================================================== */

.shell { display: flex; flex-direction: column; height: 100%; }
.app-body { display: flex; flex: 1; min-height: 0; }
.pages { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.page { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.page-scroll { flex: 1; overflow-y: auto; }


/* ---------- Top bar ---------- */

.topbar {
  display: flex; align-items: center; flex-shrink: 0;
  height: 47px; padding-left: 16px;
  background: var(--km-green); color: #fff; border-bottom: 3px solid var(--km-lime);
}

/* Brand block pushes area + user to the right edge */
.topbar-brand { display: flex; align-items: center; gap: 12px; margin-right: auto; padding-right: 20px; }
.topbar-brand .km { display: block; height: 20px; width: auto; }
.topbar-brand .logo { display: block; height: 28px; width: auto; }
.topbar-brand .divider { width: 1px; height: 22px; background: rgba(255, 255, 255, .3); }

/* Working area (hidden on narrow screens) */
.topbar-area { display: flex; align-items: center; gap: 8px; padding: 0 20px; border-left: 1px solid rgba(255, 255, 255, .18); }
.topbar-area svg { width: 18px; height: 18px; opacity: .7; }
.topbar-area .label { font-size: 9px; line-height: 1.2; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }
.topbar-area .name { font-size: 12px; font-weight: 600; line-height: 1.2; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-area > div { min-width: 0; }

/* Signed-in user + dropdown menu */
.topbar-user {
  position: relative; display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 18px;
  border-left: 1px solid rgba(255, 255, 255, .18); cursor: pointer;
}
.topbar-user:hover { background: rgba(255, 255, 255, .08); }
.topbar-user .avatar {
  display: flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  background: rgba(255, 255, 255, .2); border: 1.5px solid rgba(255, 255, 255, .35); border-radius: 50%;
  font-size: 11px; font-weight: 600; color: #fff;
}
.topbar-user .who { line-height: 1.2; }
.topbar-user .who-name { font-size: 12px; font-weight: 600; color: #fff; }
.topbar-user .who-role { font-size: 10px; color: rgba(255, 255, 255, .55); }
.topbar-user .caret { margin-left: 4px; opacity: .5; }

.user-menu {
  position: absolute; top: calc(100% + 6px); right: 8px; z-index: 300; width: 260px; padding: 6px 0;
  background: #fff; color: var(--text); border: 1px solid var(--border-s); border-radius: 10px; box-shadow: var(--shadow-m);
  cursor: default;
}
.user-menu .head { padding: 10px 14px 12px; border-bottom: 1px solid var(--border); }
.user-menu .head b { display: block; font-size: 13px; }
.user-menu .head span:not(.role-pill) { display: block; margin: 2px 0 6px; font-size: 11.5px; color: var(--text-2); }
.user-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px;
  background: none; border: 0; text-align: left; font-size: 12.5px; color: var(--text); cursor: pointer;
}
.user-menu button:hover { background: var(--bg-2); }
.user-menu .logout { margin-top: 4px; border-top: 1px solid var(--border); color: var(--err); }


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

.side {
  display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; width: 224px; padding: 14px 10px;
  background: #fff; border-right: 1px solid var(--border);
}
.side .grp { padding: 8px 10px 6px; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-4); }
.side button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  background: none; border: 0; border-radius: 8px; text-align: left;
  font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.side button svg { flex-shrink: 0; color: var(--text-3); }
.side button:hover { background: var(--bg-2); color: var(--text); }
.side button.on { background: var(--pink-l); color: var(--pink); font-weight: 600; }
.side button.on svg { color: var(--pink); }
.side .label { white-space: nowrap; }   /* menu names fit one line in both languages */
.side .label-s { display: none; }                                        /* short name, phones only */
.side .grp:not(:first-child) { margin-top: 12px; }
.side .grp-rule { height: 1px; margin: 12px 10px 8px; background: var(--border); }
.side .spacer { flex: 1; }


/* ---------- Page header + table panel (Users page) ---------- */

.pg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--border); }
.pg-head .grow { flex: 1; min-width: 200px; }
.pg-head h1 { font-size: 16px; font-weight: 700; }
.pg-head p { margin-top: 2px; font-size: 12px; color: var(--text-2); }

.subtabs { display: flex; gap: 4px; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--border); }
.subtabs button {
  padding: 10px; background: none; border: 0; border-bottom: 2px solid transparent;
  font-size: 12.5px; font-weight: 600; color: var(--text-3); cursor: pointer;
}
.subtabs button.on { color: var(--pink); border-bottom-color: var(--pink); }

.pg-body { display: grid; gap: 20px; padding: 20px 24px 40px; }
.panel { overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 12px; }
.tbl-wrap { overflow-x: auto; }

/* Search field (repository bar, users header) */
.search-box {
  display: flex; align-items: center; gap: 7px; width: 290px; padding: 6px 10px;   /* fits the full search hint in ID and EN */
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--rad);
}
.search-box input { width: 100%; -webkit-appearance: none; appearance: none; background: none; border: none; outline: none; font: inherit; font-size: 12px; color: var(--text); }
.search-box input::placeholder { color: var(--text-4); }


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

@media (max-width: 1100px) {
  /* working area stays visible, as the Puskesmas name only */
  .topbar-area { min-width: 0; padding: 0 14px; }
  .topbar-area svg, .topbar-area .label { display: none; }
  .topbar-area .name { max-width: 240px; }
}
@media (max-width: 900px) {
  /* Sidebar collapses to icons */
  .side { width: 64px; padding: 12px 8px; }
  .side .grp, .side .label { display: none; }
  .side button { justify-content: center; padding: 10px; }
}
@media (max-width: 700px) {
  .topbar { height: 50px; padding-left: 12px; }
  .topbar-brand { padding-right: 10px; }
  .topbar-brand .km { height: 16px; }
  .topbar-brand .logo { height: 24px; }
  .topbar-user { height: 40px; padding: 0 12px; }
  .topbar-user .who { display: none; }
  .topbar-area { padding: 0 10px; border-left: 0; }
  .topbar-area .name { max-width: 150px; font-size: 11px; }

  /* Sidebar becomes a bottom navigation bar: every menu visible, in thumb reach */
  .app-body { flex-direction: column; }
  .pages { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; flex-direction: row; gap: 0; width: 100%;
    padding: 4px 4px env(safe-area-inset-bottom, 0px); border-right: 0; border-top: 1px solid var(--border-s);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, .05);
  }
  .side .spacer { display: none; }
  .side button {
    flex: 1 1 0; flex-direction: column; justify-content: center; gap: 3px; min-width: 0; min-height: 52px; padding: 6px 2px;
    border-radius: 0; text-align: center;
  }
  .side .label { display: block; font-size: 10.5px; line-height: 1.2; white-space: normal; text-align: center; }
  .side button:has(.label-s) .label { display: none; }
  .side .label-s { display: block; font-size: 10.5px; line-height: 1.2; text-align: center; }
  .side .grp-rule { display: none; }
  .side.many button[data-p="settings"] { display: none; }   /* still in the user menu (top right) */
  .side button.on { background: none; box-shadow: inset 0 3px 0 var(--pink); }

  .pg-head, .pg-body { padding-inline: 16px; }
  .subtabs { padding: 0 16px; }
  .search-box { order: 5; width: 100%; }
}


/* ---------- Back to top ---------- */

.to-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 45;
  display: grid; place-items: center; width: 44px; height: 44px;
  background: #fff; border: 1px solid var(--border-s); border-radius: 50%; box-shadow: var(--shadow-m);
  color: var(--text); cursor: pointer;
}
.to-top:hover { border-color: var(--text); }
@media (max-width: 700px) {
  .to-top { right: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}
